Saturday, March 16, 2013

Subscript and Superscript in GTK#

In Wide Margin I had a need to use superscript for verse numbers. This is quite common in printed bibles because it reduces the impact of the verse number on the readability of the text. In Wide Margin I use a Gtk TextView to display my text, formatting in a Gtk TextView is achieved using TextTags which specify formatting for a range in the text.

A TextTag does not have a property for subscript or superscript rather it has a property call Rise. Setting this to a positive value moves the text up and setting it to negative moves the text below the line.

In GTK3 the value of Rise is in pixels, in GTK2 the value of Rise is in Pango Units, There are 1024 pango units in a Pixel. This confused me for quite a while because I was reading the GTK3 docs and assuming a unit of Pixels, but I was using GTK2. I was trying to Rise my text by 5 units which in GTK2 is smaller then what can be rendered.

 Setting Rise will move the character up or down but will leave the size unaffected. To get superscript or subscript you will also need to reduce the font size.

Superscript (GTK2) Subscript (GTK2)
The exact amount you want to move change the size and move the the text up or down will depend on how you want it to look. So have a play until you get it right.

No comments: