[cairo] Font size issue when using pango + cairo

Behdad Esfahbod behdad at behdad.org
Mon Jan 5 14:02:48 PST 2009


James Cloos wrote:
>>>>>> "Emmanuel" == Emmanuel Pacaud <emmanuel.pacaud at lapp.in2p3.fr> writes:
> 
> Emmanuel> I should have said "almost the same" (in the goffice case, the
> Emmanuel> scale_x value is used for both the x and y scales). The
> Emmanuel> difference is too small to explain the font size issue.
> 
> The nasty side effect of reading mail just after waking up.... ;-/
> 
> A closer look shows that the glyphs rendered by gnumeric have a 9-pixel
> cap height/digit height, are LCD optimized and look to have been pixel-
> fit by glyf instructions.  The axis labels, OTOH, have a digit height of
> 10 pixels and look to have been rendered w/o any hinting or pixel fitting
> --certainly w/o use of instructions.  The large 10 under the chart has a
> pixel height of 13 or 14 and was also rendered w/o instructions and,
> again, probably w/o any hinting or pixel fitting.

Yeah, I'm guessing that Emmanuel is drawing the graph to an image surface and
then copying to the X drawable?  You should instead create a surface using
cairo_surface_create_similar(), such that font options are propagated
correctly.  That should fix the hinting issue.

As for the size, I'm not sure what you're doing.  A 10 font size in pango is
10 points, and the dpi will come in when converting that to pixels.  The
default 96dpi means a 96/72=1.33 scale factor, which explains the difference
between 10px and 13px fonts.  You can either set dpi on the pango context
(pango_cairo_context_set_resolution), or use absolute font sizes, either using
pango_font_description_set_absolute_size, or the string syntax "10px" instead
of "10".

behdad


> The small difference in the matrices could make for a 1 pixel height
> difference.  The lack of instruction could also make for a 1 pixel height
> difference.  (Look at the font with ft2demo's ftdiff(1) and magnification
> to see whether it makes a difference at that pixel size.)
> 
> Also, your terminal app looks to be using DejaVu Sans Mono w/
> instructions but is not using LCD optimization.  And the LCD filtering is
> different; gnumeric looks to be using the legacy filter whereas the wm
> looks to be using the instructions and LCD optimization but either w/o
> any lcd filter or with freetype's filter.
> 
> Given the hinting and filtering differences, you may also have a dpi
> difference.  You may have dpi set in gnome's settings but not in xft's.
> And the charting app may be ignoring either or both of those.
> 
> -JimC


More information about the cairo mailing list