[cairo] Cairo, pango and Win32.. incorrect font rendering
pcjc2 at cam.ac.uk
Mon Jan 18 12:28:21 PST 2010
On Mon, 2010-01-18 at 14:29 -0500, Behdad Esfahbod wrote:
> On 01/18/2010 08:02 AM, Peter Clifton wrote:
> > (gschem.exe:3036): Pango-WARNING **: couldn't load font "Arial 10 400000", falli
> > ng back to "Sans 400000", expect ugly output.
> What's with the 400,000pt size?!
Indeed - I've no idea..
I'm "probably doing something wrong"(TM), which happens to work with on
Linux (and some Windows boxes).
Lets say our user specifies a font-size of 10 in their schematic. There
is a small conversion factor (1.3) between our legacy internal units,
and "points", so we end up wanting a 13 point font. This is what I ask
for in the font description.
The question is.. what "13pt" ends up as when we request to draw it onto
the cairo surface?
In our function on line 153: setup_pango_return_metrics()
I set the scale factor between cairo units and pango units:
174 pango_cairo_context_set_resolution (context, 1000. * scale_factor);
Our internal coordinates are 1000ths of an inch, and the scale_factor is
a conversion factor between that and screen pixels (which is the units
we have our cairo context set to).
Summarising that again, since it just confused me:
cairo is getting units in screen pixels
1000 * scale_factor is 1000 gEDA units (1000ths of an inch), multiplied
by a (geda_units -> screen pixels) scale-factor which varies with zoom.
This gives the number of screen pixels (cairo units) for one inch
We then request the font size with:
175 font_size_pt = o_text_get_font_size_in_points(w_current->toplevel,
177 font_string = g_strdup_printf ("%s %f\n", FONT_NAME, font_size_pt);
178 desc = pango_font_description_from_string (font_string);
179 g_free (font_string);
So I'm asking Pango for a font size in points, passing as a floating
point representation of a string. (I don't want to artificially
introduce rounding errors in our legacy -> points conversion).
For the sake of pixel alignment of other objects, it is convenient that
we keep our cairo coordinates as integers.
Is the pango_cairo_context_set_resolution affecting the choice of fonts
being offered by the system?
I still can't figure out why this odd behaviour (which similar might
also have been noted on MacOS X) isn't manifesting for me under Wine, my
XP box, nor anyone's Linux installs.
It is certainly mis-behaving on at least two people's machines - and I
know at least one of those is also XP.
More information about the cairo