[cairo] Re: Drawing text with Windows bitmap fonts

Owen Taylor otaylor at redhat.com
Tue Jan 23 11:38:33 PST 2007

On Tue, 2007-01-23 at 02:56 +0100, Jan Slupski wrote:
> Hi all,
> I would like to refresh a topic from a year ago:
> Stuart Parmenter wrote:
>  > Has anyone gotten win32 bitmap fonts to render using cairo?  I'm using
>  > cairo_show_glyphs() with glyph indexes I've gotten from Uniscribe.
>  > Things fall apart in _cairo_win32_scaled_font_init_glyph_metrics in
>  > cairo-win32-font.c when it tries to do GetGlyphOutlineW().  According
>  > to the MSDN docs, using GGO_GLYPH_INDEX means that it is a true type
>  > index, which I'm not sure if bitmap fonts really respect.
>  > GetGlyphOutlineW ends up failing...  I could be going down the wrong
>  > path here.. was wondering if anyone else had done more digging or had
>  > any suggestions.
> Indeed, it seems that support for bitmap fonts is somewhat broken.
> I am trying to open Windows font called "Small Fonts" (smalle.fon).
> As stated above, cairo is using _scaled_* functions to operate

I'm not really sure what you mean by this. A "scaled" font in cairo
terms doesn't mean a scalable font like a TrueType font. It just means
a font for which we've selected a size and a matrix, so we know the
size at which we want to draw with it.

> on that font that seems to be wrong by definition.
> This ends up on querying the font with GetGlyphOutlineW that
> by MSDN definition "The GetGlyphOutline function retrieves the outline 
> or bitmap for a character in the *TrueType* font".
> I think cairo should either properly support windows bitmap fonts 
> (ignoring font size & rotation?)

Hmm, so:

 - Make bitmap fonts scale in a special way ... they always draw at
   the same size.

 - Make using bitmap fonts with general transforms have undefined

Might be useful.

> or fail in more meaningful way. It  could be either return of an error by 
> cairo's API call, or fallback to a default font in the same way as when 
> unknown font name is passed.

I don't think you want to return a cairo API error ... cairo error codes
generally are used for

 - Unrecoverable errors
 - Errors in using the API

They aren't convenient for dealing with bad user input. Treating them
like an unknown font name would be more useful, though that's a little
hard, since that fallback is happening inside windows; the cairo code
does no interpretation of font names, it just passes them straight to
CreateFontIndirect(). But you could probably examine the created font,
see if it's a bitmap font, then retry with a different name if

I'd be interested in what people who have real use cases for windows
fonts would prefer:

  - Pretend that the font didn't exist, so that the web page, or
    whatever, draws with a font that will actually size and scale

  - Use the font, but have rendering fall apart if you try to rotate
    or scale.

I suspect that for web browser use, the first is better ... if some page
specifies "MS Sans Serif" as the preferred font, the user is going to
be happier if they don't get it. But maybe there are situations where
the second is needed ... like a custom font with custom non-letter
glyphs in place of letters.

(Since font selection is a higher level function and not part of cairo,
it could be argued that if such a font even gets to cairo, the higher
level wanted exactly what it specified.)
						- Owen

More information about the cairo mailing list