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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var superscriptTag = new TextTag("SuperScript"); | |
//make the font smaller | |
superscriptTag.SizePoints = (baseFontSize/2); | |
//turn on the Rise settings | |
superscriptTag.RiseSet = true; | |
//move up | |
superscriptTag.Rise = (baseFontSize * 3 / 4) * 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var subscriptTag = new TextTag("SuperScript"); | |
//make the font smaller | |
subscriptTag.SizePoints = (baseFontSize/2); | |
//turn on the Rise settings | |
subscriptTag.RiseSet = true; | |
//move down | |
subscriptTag.Rise = -(baseFontSize / 4) * 1024; |
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:
Post a Comment