Changes

Jump to navigation Jump to search
Line 48: Line 48:  
* In general, font sizes should never be specified. Use the default Sugar font (e.g. which is what you get if you create a gtk.Label), as this is what the user has chosen as their preferred font size.
 
* In general, font sizes should never be specified. Use the default Sugar font (e.g. which is what you get if you create a gtk.Label), as this is what the user has chosen as their preferred font size.
 
** also use variations using pango markup e.g. <nowiki><big> <small> <b></nowiki>
 
** also use variations using pango markup e.g. <nowiki><big> <small> <b></nowiki>
** FIXME: document how the point sizes of<nowiki> <big> and <small></nowiki> can be read by an activity (I think it's just based on scale factor 1.2) and maybe propose helper functions to make these values dead-easy to retrieve.
+
** If the user cannot or does not want to use pango markup in a particular scenario, Sugar could provide a helper function to scale the font size from the default for a given widget (see suggested code below)
 
* There may be exceptional cases where applications want to scale a font to fit nicely in a given space. In this situation, they should use the standard Pango rendering pipelines to render text offscreen (using a sensible seed size value), measure the resultant pixel size, and then retry the rendering based on a new font size if the result was too big or too small.
 
* There may be exceptional cases where applications want to scale a font to fit nicely in a given space. In this situation, they should use the standard Pango rendering pipelines to render text offscreen (using a sensible seed size value), measure the resultant pixel size, and then retry the rendering based on a new font size if the result was too big or too small.
 
** The Memorize activity is one example of this - it dynamically chooses a font size which causes the text to fit nicely within the tiles of the game.
 
** The Memorize activity is one example of this - it dynamically chooses a font size which causes the text to fit nicely within the tiles of the game.
Line 56: Line 56:     
Not (unnecessarily) messing with font sizes will just become another step in "effective Sugarization" of an activity.
 
Not (unnecessarily) messing with font sizes will just become another step in "effective Sugarization" of an activity.
 +
 +
Here is sample code for scaling fonts as described above:
 +
def scale_font(widget, scale_steps):
 +
    if scale_steps == 0:
 +
        return
 +
    font = widget.get_pango_context().get_font_description()
 +
    font.set_size(int(font.get_size() * pango.SCALE_LARGE * scale_steps))
 +
    widget.modify_font(font)
 +
 +
The above function will work for any GtkWidget, allowing the font to be scaled. A scape_steps value of 0 will cause no scaling, -1 is equivalent to <nowiki><small>,  2 is equivalent to <big><big> or <span font_size="x-large">, </nowiki> etc. It works based on the fact that pango.SCALE_LARGE is the scaling factor for a single step up, which has value 1.2 as used in all pango font scaling (and the CSS world).
    
=== Additional fonts ===
 
=== Additional fonts ===
105

edits

Navigation menu