[cairo] Re: Drawing text with Windows bitmap fonts

Stuart Parmenter stuartp at gmail.com
Tue Jan 23 10:16:00 PST 2007

We always create the font with size * WIN32_FONT_LOGICAL_SCALE...

    if (scaled_font->preserve_axes) {
        scaled_font->logical_size = WIN32_FONT_LOGICAL_SCALE *
                                    _cairo_lround (scaled_font->y_scale);
    if (!scaled_font->preserve_axes) {
        scaled_font->logical_size = _cairo_lround (WIN32_FONT_LOGICAL_SCALE *

which means that:
        logfont.lfHeight = -scaled_font->logical_size;
        scaled_font->scaled_hfont = CreateFontIndirectW (&logfont);

so for a 10px font we'll create a 320px bitmap font and then we
SetWorldTransform it back down when we draw it.  This just doesn't
work.  Most bitmap fonts aren't going to have 320px versions.

This is how it has always worked... if this isn't how you intended it
to work you might want to take a look at it.  fwiw, rotated and scaled
text works fine with this set to 1.


On 1/23/07, Owen Taylor <otaylor at redhat.com> wrote:
> On Tue, 2007-01-23 at 00:22 -0800, Stuart Parmenter wrote:
> > So the main problem with bitmap fonts in cairo is
> > WIN32_FONT_LOGICAL_SCALE (in cairo-win32-private.h) being 32.  This
> > will break all bitmap fonts since we'll always ask for much larger
> > fonts than you really want.
> I'm actually surprised by this ... remember, we aren't asking for
> a larger font size to appear on the screen, we are still asking for
> a 10px font or whatever ... all that the logical scale does is change
> the coordinate space that we use with our DC.
> If we actually asked for a larger pixel size from Windows, then all
> our metrics would be wrong for scalable fonts, since windows would
> hint to the wrong pixel size.
> Saying that bitmap fonts don't work with a LOGICAL_SCALE of other
> than 1, is really saying that they don't work if you call
> SetWorldTransform(), which I find a little hard to believe.
> >   In Mozilla we change this to 1 without
> > any real problems.  You may want to give this a shot.  We can probably
> > just remove all the logical scale code but we avoid going through the
> > cairo-win32-font code mostly so I'm not sure if it breaks paths we
> > don't hit.
> >
> > Try changing it to 1 and see if it works for you!
> An interesting experiment, but, not I think, the right long-term
> fix. Changing LOGICAL_SCALE to 1, is going to cause considerable
> inaccuracy in positioning of rotated and otherwise transformed text.
> If LOGICAL_SCALE is actually a problem, then instead of never using
> it, you'd only want to skip it when:
>  - scaled_font->preserve_axes  (The transform is a 90 degree
>    rotation or flip)
>  - options->hint_metrics
> are true (well, options->hint_metrics isn't actually paid attention
> to by the windows backend right now... not that it is hard to
> implement.)
>                                         - Owen

More information about the cairo mailing list