[cairo] Font size issue when using pango + cairo

Behdad Esfahbod behdad at behdad.org
Tue Jan 6 17:10:00 PST 2009


Emmanuel Pacaud wrote:
> Hi,
> 
> Le lundi 05 janvier 2009 à 17:02 -0500, Behdad Esfahbod a écrit :
>>> 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.
> 
> I don't really want to inheritate the font options, since I'd like to
> obtain a layout that doesn't depend on the target, which can be either
> an image or a vector surface.

You really should inherit the font options from the display if you are going
to show it there, or it will look ugly and out of place.  For vector surfaces,
sure, you can create a new surface.

behdad


>> 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".
> 
> That's the solution. I'm pretty sure I've already tried to use
> pango_cairo_context_set_resolution before, but without success. Now, it
> works.
> 
> Thanks a lot.
> 
> 	Emmanuel.
> 


More information about the cairo mailing list