[cairo] font lifetime

Alexander Larsson alexl at redhat.com
Thu Jan 27 00:17:29 PST 2005


On Wed, 2005-01-26 at 10:44 -0500, Owen Taylor wrote:
> On Wed, 2005-01-26 at 16:17 +0100, Alexander Larsson wrote:
> > 
> > Its a bit sucky to use actually. You can create a cairo_font_t using it,
> > and then set it using cairo_set_font(). However, any time you change any
> > state in the cairo_t "_cairo_gstate_unset_font (gstate)" will be called,
> > and the next time you render text cairo_gstate_ensure_font() will try
> > create a new font using _cairo_font_create() instead of your own font.
> 
> The expectation with the new API is that you'll set a font just before
> using it.... we could remove the unsetting, but then you get silent
> metric screwiness rather than the wrong font. What sort of gstate
> changes are you making that are unsetting the font? It should just
> be transform and target surface that unset the font.

Given the way xpdf works internally this is not a real problem for me.
xpdf tracks all state changes and knows when it has to update the font.

However, it does seem to make using the cairo-ft.h interface a lot
harder to use in general.

> > Also, I'm not sure things are actually working right for me with several
> > sizes of a font. On the xpdf side i have an object that basically refers
> > to an scaled font, which owns the FT_Face. When i set the cairo font i
> > create a new cairo_font from this face, which in turn creates an
> > unscaled cairo font. When i do this twice for different sizes, won't i
> > get two cairo_unscaled_font_t referencing the same FT_Face? Won't this
> > break, since the unscaled font sets the size of the FT_Face?
> 
> Yes, you can't share the same FT_Face between multiple fonts created
> with cairo_ft_font_create_for_ft_face() since Cairo will be unaware
> of the sharing.

Thats pretty bad. Having to open multiple FT_Face just to show something
in different sizes.

> > What you really want is a way to create a cairo_unscaled_font_t from the
> > face, and then scaled versions from that. I think.
> 
> That's certainly possible, all the bits are there internally, they'd
> just have to be exported.
> 
> There's a bit of a problem in that there isn't necessarily and
> "unscaled font" for every backend. The Win32 font backend, for example,
> probably won't have one. So, you can't have
> 
>  cairo_font_create_for_unscaled_font()
>  cairo_font_get_unscaled_font()
> 
> Just:
> 
>  cairo_ft_font_create_for_unscaled_font()
>  cairo_ft_font_get_unscaled_font()

That sounds good enough for me. In fact, given an API like this cairo
could even generate a new custon FT_Face cairo_font_t in
_cairo_gstate_ensure_font().

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl at redhat.com    alla at lysator.liu.se 
He's an old-fashioned guerilla dwarf trapped in a world he never made. She's a 
man-hating psychic queen of the dead with the soul of a mighty warrior. They 
fight crime! 




More information about the cairo mailing list