<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Edd Dumbill's Weblog: 'gnome' articles</title>
  <link href="http://times.usefulinc.com/taggnomeatom" rel="self"/>
  <link href="http://times.usefulinc.com/taggnome" rel="alternate"/>
  <id>http://times.usefulinc.com/</id>
  <updated>2006-01-31T20:23:24Z</updated>
  <author>
    <name>Edd Dumbill</name>
    <email>edd-web@usefulinc.com</email>
  </author>
  <entry>
    <title>GObject subclassing in Ruby</title>
    <link href="http://times.usefulinc.com/2006/01/31-subclass" rel="alternate"/>
    <id>http://times.usefulinc.com/public/read/840</id>
    <updated>2006-01-31T20:23:24Z</updated>
    <published>2006-01-31T20:05:57Z</published>
    <summary>An update to yesterday's Ruby GNOME adventures.</summary>
    <category term="ruby"/>
    <category term="gnome"/>
    <category term="mono"/>
    <content type="html">
 &lt;p&gt;Thanks to everybody who wrote in with suggestions following on from my initial &lt;a href="http://times.usefulinc.com/2006/01/30-ruby-gnome"&gt;Ruby GNOME investigations&lt;/a&gt; yesterday.&lt;/p&gt; &lt;p&gt;After talking at cross purposes for some time in a bug report with a Ruby GNOME developer, I was pointed to a good example of how to do what I wanted: subclassing a GObject in Ruby.&lt;/p&gt; &lt;p&gt;This is something that the Mono Gtk# bindings do so well, I'd forgotten the required mechanics. Here's a simple subclass of button. I've highlighted the required magic in bold.&lt;br /&gt; &lt;/p&gt; &lt;pre&gt;class MyButton &amp;lt; Gtk::Button&lt;br /&gt;   attr_accessor :hitcount&lt;br /&gt; &lt;strong&gt;  # tell the GLib object system this is a new type&lt;br /&gt;   type_register&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt;   def initialize(text)&lt;br /&gt;     super(&amp;quot;label&amp;quot; =&amp;gt; text)&lt;br /&gt;     self.hitcount = 0&lt;br /&gt;   end&lt;br /&gt; &lt;br /&gt; &lt;strong&gt;  # rather than overriding 'clicked', we must&lt;br /&gt;   # override the signal_do_clicked method&lt;br /&gt;   def signal_do_clicked(*args)&lt;br /&gt; &lt;/strong&gt;    self.hitcount+=1&lt;br /&gt;     super&lt;br /&gt;   end&lt;br /&gt; end&lt;/pre&gt; &lt;p&gt;The &lt;em&gt;type_register&lt;/em&gt; call registers the new class with the GLib type system (something the Mono bindings do for you automatically).&amp;nbsp; The second key was knowing the name of the default signal handler, which turns out to be of the form &lt;em&gt;signal_do_signalname&lt;/em&gt;.&lt;/p&gt; &lt;p&gt;So, to follow up yesterday, I hadn't found a bug, merely a gap in the documentation. Thanks to  					Masao Mutoh for taking the time to answer my questions.&lt;/p&gt; &lt;p&gt;For comparison, here's the same implementation in Gtk#. There are pros and cons of both languages. Ruby's succinct &lt;em&gt;attr_accessor&lt;/em&gt; is balanced by the neat GObject-aware subclassing and the constructor inheritance of C#.&lt;br /&gt; &lt;/p&gt;  &lt;pre&gt;class MyButton : Button {&lt;br /&gt;        private int hitcount;&lt;br /&gt;&lt;br /&gt;        public MyButton (string text) : base (text)&lt;br /&gt;        {&lt;br /&gt;                hitcount = 0;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void OnClicked ()&lt;br /&gt;        {&lt;br /&gt;                hitcount++;&lt;br /&gt;                base.OnClicked ();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public int HitCount {&lt;br /&gt;                get&lt;br /&gt;                {&lt;br /&gt;                        return hitcount;&lt;br /&gt;                }&lt;br /&gt;                set&lt;br /&gt;                {&lt;br /&gt;                        hitcount = value;&lt;br /&gt;                }&lt;br /&gt;        }&lt;br /&gt;} &lt;/pre&gt; &lt;p&gt;&lt;a href="http://times.usefulinc.com/2006/01/31-subclass#disqus_thread"&gt;Join the conversation about this post&lt;/a&gt;&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Beginnings with Ruby GNOME</title>
    <link href="http://times.usefulinc.com/2006/01/30-ruby-gnome" rel="alternate"/>
    <id>http://times.usefulinc.com/public/read/839</id>
    <updated>2006-01-31T02:37:24Z</updated>
    <published>2006-01-30T23:56:00Z</published>
    <summary>My first experiments with writing small GNOME applications in Ruby.</summary>
    <category term="ruby"/>
    <category term="gnome"/>
    <content type="html">
  &lt;p&gt;A while back I started porting the GTK &lt;a href="http://examples.oreilly.com/monoadn/"&gt;examples&lt;/a&gt; from &lt;a href="http://www.oreilly.com/catalog/monoadn/"&gt;Mono: A Developer's Notebook&lt;/a&gt; to IronPython and Boo, the r&lt;a href="http://svn.usefulinc.com/svn/repos/trunk/ironpython/monodn/"&gt;esults of which are available in my Subversion repository&lt;/a&gt;.&lt;/p&gt;   &lt;p&gt;Although I've not finished that task yet, I thought I'd investigate the state of the &lt;a href="http://ruby-gnome2.sourceforge.jp/"&gt;Ruby GNOME bindings&lt;/a&gt; by porting those same examples. They have the advantage of increasing gently in complexity.&lt;/p&gt;   &lt;p&gt;Before I go on, you can find the work in progress posted in the &lt;a href="http://svn.usefulinc.com/svn/repos/trunk/ruby-gnome/monodn/"&gt;ruby-gnome/monodn branch of my Subversion repository&lt;/a&gt;.&lt;/p&gt;   &lt;p&gt;Now for a few observations. At the basic level, Ruby GNOME has a lot in common with all the other GNOME bindings out there. One distinguishing feature however is signal handlers, which take a Ruby closure as an argument. Look at this handler for closing the window, for example:&lt;/p&gt;   &lt;pre&gt;w = Gtk::Window.new(&amp;quot;My Window&amp;quot;)&lt;br /&gt;w.signal_connect(&amp;quot;delete_event&amp;quot;) { Gtk.main_quit } &lt;/pre&gt;  &lt;p&gt;This is fine for simple handlers. Developers wanting to reuse handlers might wish to specify a method here to use. The best way of doing this I've found is:&lt;/p&gt;   &lt;pre&gt;def my_handler(but)&lt;br /&gt;  &amp;nbsp;&amp;nbsp; ...&lt;br /&gt;end&lt;br /&gt; &lt;br /&gt;button.signal_connect(&amp;quot;changed&amp;quot;, &amp;amp;method(:my_handler))&lt;/pre&gt;  &lt;p&gt;This involves a little bit more magic, as you can see.&lt;/p&gt;   &lt;p&gt;I've also run into an unexpected barrier with subclassing and the class default signal handler. The subclassing example from the Mono Notebook shows an example of overriding the &lt;em&gt;clicked&lt;/em&gt; method of a &lt;em&gt;Button.&lt;/em&gt; In C# this looks like this:&lt;/p&gt;   &lt;pre&gt;class MyButton : Button {&lt;br /&gt; ...&lt;br /&gt; protected override void OnClicked ()&lt;br /&gt; {&lt;br /&gt;  &amp;nbsp; hitcount++;&lt;br /&gt;  &amp;nbsp; base.OnClicked ();&lt;br /&gt; }&lt;/pre&gt; &lt;p&gt;In Ruby I would write this:&lt;/p&gt;  &lt;pre&gt;class MyButton &amp;lt; Gtk::Button&lt;br /&gt; ...&lt;br /&gt; def clicked&lt;br /&gt; &amp;nbsp; self.hitcount += 1&lt;br /&gt; &amp;nbsp; super&lt;br /&gt; end&lt;/pre&gt; &lt;p&gt;However, when you click the button it's clear the overridden method isn't being called. I've &lt;a href="http://sourceforge.net/tracker/index.php?func=detail&amp;amp;aid=1419230&amp;amp;group_id=53614&amp;amp;atid=470969"&gt;filed a bug&lt;/a&gt; with what I think is the underlying problem. In this instance, I worked round it by adding a signal handler in the constructor:&lt;/p&gt; &lt;pre&gt;self.signal_connect(&amp;quot;clicked&amp;quot;) { |b| b.hitcount += 1 }&lt;/pre&gt;&lt;p&gt;At the moment it feels like I'm writing rather C-like Ruby, rather than it being idiomatic. But then again, I am porting examples from C# in as literal manner as possible, in order to facilitate comparison.&lt;br /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://times.usefulinc.com/2006/01/30-ruby-gnome#disqus_thread"&gt;Join the conversation about this post&lt;/a&gt;&lt;/p&gt;    </content>
  </entry>
  <entry>
    <title>Linux fonts: still wanting</title>
    <link href="http://times.usefulinc.com/2006/01/16-fonts" rel="alternate"/>
    <id>http://times.usefulinc.com/public/read/829</id>
    <updated>2006-01-22T16:02:26Z</updated>
    <published>2006-01-16T09:15:51Z</published>
    <summary>Recent work cross-checking how this site looks on various platforms leads to unhappy conclusions about how fonts are handled on Linux.</summary>
    <category term="linux"/>
    <category term="typography"/>
    <category term="gnome"/>
    <content type="html">
  &lt;p&gt;Fonts on Linux have had a chequered history. Mostly, &lt;a href="http://jeremy.zawodny.com/blog/archives/000773.html" title="A rant from Jeremy Zawodny about how difficult it is to get fonts looking right on Linux"&gt;they've been bad&lt;/a&gt;. Once, there was an excuse for this: GNOME and KDE were unable to render anti-aliased text, and there was a paucity of decent free TrueType fonts. Now, with Xft, Freetype and &lt;a href="http://www.bitstream.com/font_rendering/products/dev_fonts/vera.html" title="The Bitstream Vera family"&gt;Bitstream Vera fonts&lt;/a&gt; things are different.&lt;/p&gt;   &lt;p&gt;Unfortunately, it's hard to find Linux distributions that have gone the extra mile to make the fonts look good by default. Let's take a brief look through default fonts in various operating systems.&lt;/p&gt;   &lt;p&gt;&lt;img width="252" height="220" src="http://times.usefulinc.com/asset/name/12/tiger.png" alt="OS X Tiger default fonts" title="OS X Tiger default fonts" /&gt;&lt;/p&gt;   &lt;p&gt;Mac OS X offers a great default, which looks good on all modern machines. No user configuration required.&lt;/p&gt;   &lt;p&gt;&lt;img width="252" height="220" src="http://times.usefulinc.com/asset/name/10/windows-noct.png" alt="Windows default fonts" title="Windows default fonts" /&gt;&lt;/p&gt;   &lt;p&gt;Windows default is blocky, as there's no anti-aliasing to speak of, but the hinting on the fonts is excellent and they're crisp. If you dig a bit and find the crazily hidden Display properties - Appearance - Effects dialog, you can turn on ClearType.&lt;/p&gt;   &lt;p&gt;&lt;img width="252" height="220" src="http://times.usefulinc.com/asset/name/11/windows-ct.png" alt="Windows ClearType fonts" title="Windows ClearType fonts" /&gt;&amp;nbsp;&lt;/p&gt;   &lt;p&gt;Windows ClearType offers a pleasing level of font smoothing. Now, let's look at the GNOME default, taken from a screenshot on the GNOME 2.12 start page.&lt;/p&gt;   &lt;p&gt;&lt;img width="252" height="220" title="GNOME default fonts" alt="GNOME default fonts" src="http://times.usefulinc.com/asset/name/8/gnome-default.png" /&gt;&lt;/p&gt;   &lt;p&gt;This is pretty much how default GNOME looks on any machine. In particular, it's the default look you get when you install Ubuntu. This corresponds to a setting of full hinting in the font preferences, with the font Bitstream Vera Sans. The quality of the type, however, is poor.&amp;nbsp; It has a spidery and ungainly quality to it.&lt;br /&gt;  &lt;/p&gt;   &lt;p&gt;In and of itself, Vera is not an ugly font. There's some combination of the font's hinting and the Freetype hinting engine that conspires to make things ugly. On my desktop I've tried to work around this by altering the font settings somewhat.&lt;/p&gt;   &lt;p&gt;&lt;img width="252" height="220" title="GNOME: Edd's fonts" alt="GNOME: Edd's fonts" src="http://times.usefulinc.com/asset/name/9/gnome-edd.png" /&gt;&lt;/p&gt;   &lt;p&gt;The effect isn't perfect, but a lot better to look at. The font is Bitstream Vera Sans as before. To get this, I had to switch off any hinting then slowly play with the DPI setting until I get letterforms that rendered neatly.&lt;/p&gt;   &lt;p&gt;Alas, this brings problems of its own. For a start, not all popular GNOME applications respect this setting. Firefox often gets its own idea about such matters as screen DPI, and OpenOffice.org2 completely ignores my hinting preferences and gives me nasty looking menu bars. Murray Cumming's recent &lt;a href="http://www.murrayc.com/blog/permalink/2005/12/06/gnome-for-bad-eyesight/"&gt;GNOME for bad eyesight&lt;/a&gt; blog post also gets into many of these issues.&lt;/p&gt;   &lt;p&gt;For most users without time or inclination to hunt this down the choice is either to live with the ugliness, or opt for an operating system that gets it right.&lt;/p&gt; &lt;p&gt;(Lest I seem churlish here, I should celebrate the amazing work done with internationalization on the Linux desktop, which continues to bring computing access to many in the world for whom choice is a luxury.)&amp;nbsp;&lt;/p&gt;   &lt;p&gt;There is one Linux distribution that makes a reasonable job of good-looking fonts. The Fedora Core 4 distribution ships with a different default font and out of the box settings giving reasonably attractive letterforms. Courtesy of OSDIR, here are &lt;a href="http://shots.osdir.com/slideshows/slideshow.php?release=363&amp;amp;slide=1&amp;amp;title=fedora+core+4+gnome+screenshots"&gt;GNOME&lt;/a&gt; and &lt;a href="http://shots.osdir.com/slideshows/slideshow.php?release=362&amp;amp;slide=1&amp;amp;title=fedora+core+4+kde+screenshots"&gt;KDE&lt;/a&gt; screenshots. However, I'm pretty sure it doesn't solve the rest of the font integration issues.&lt;br /&gt;  &lt;/p&gt;   &lt;p&gt;I'm no typography expert, but I find that good-looking fonts enable me to work more effectively. And on the advocacy side, I want my Linux desktop to look as good or better than the OS X and Windows alternatives.&lt;/p&gt;   &lt;p&gt;Lots of great effort was made getting us to the point of anti-aliased rendering and the licensing of the Bitstream Vera Fonts. Having got this far, it seems a shame not to hunt down the remaining irritations in font handling.&lt;/p&gt; &lt;p&gt;Further reading:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://www.freetype.org/patents.html"&gt;Freetype &amp;amp; Patents&lt;/a&gt;, goes some way to explain the variable state of font hinting on Linux.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://times.usefulinc.com/2006/01/16-fonts#disqus_thread"&gt;Join the conversation about this post&lt;/a&gt;&lt;/p&gt;    </content>
  </entry>
</feed>
