[cairo] User font take 2

Kristian Høgsberg krh at bitplanet.net
Mon May 8 09:34:03 PDT 2006


On 5/5/06, Keith Packard <keithp at keithp.com> wrote:
> On Fri, 2006-05-05 at 15:54 -0400, Kristian Høgsberg wrote:
>
> > There is; I really don't see how that would work.  Could you give a
> > more detailed description of the API you propose and how it avoids
> > making every text drawing part of an application worry about the glyph
> > cache contents before calling invoking a text function?
>
> Just
>
> create_user_font
> add_glyph
>
> cworth suggested that we'd have a 'glyph surface' onto which the glyphs
> themselves would be painted:
>
> cr = cairo_create (get_glyph_surface (glyph))
> draw...

So thinking about this, yeah, this might just work.  I was working
with different assumptions, though; that the API should support on
demand loading of glyphs (to support fonts with a large number of
glyphs) and that we would want to do hinting.  However, none of the
custom document fonts (ps and pdf type3 font, svg fonts) that would
use this feature support hinting and it's probably a safe assumption
that none of these font formats will be used for big fonts.  In the
event that we need to support a new full featured font format, that's
better done as a full cairo font backend or in freetype anyway.

So, to flesh out the API a bit more, here's what I think would work (I
haven't implemented this yet, just looking for comments):

    cairo_font_face_t *
    cairo_create_user_font_face(cairo_matrix_t *glyph_to_user);

Creates a user font face with no glyphs using the given matrix for
glyph to font design space (where the em-square is 1pt by 1pt, as
described in the cairo_set_font_matrix() documentation) conversion.

    cairo_t *
    cairo_user_font_face_add_glyph(cairo_font_face_t    *font_face,
                                   cairo_content_t       content,
                                   cairo_text_extents_t *metrics,
                                   int                   ucs4,
                                   int                   index);

Add a glyph to the specified user font face with the specified content
type (allows for ARGB glyphs) with the given metrics (in glyph space)
at the given glyph index (need to be able to specify this, since, e.g.
poppler uses cairo_show_glyhps() and expect certain glyphs to have
certain indices), with the specified unicode code point (optional, for
users of the cairo text functions).  The application then render the
glyph into the given cairo_t and then destroys the context.  The
coordinate space for the returned cairo_t is glyph space.  Internally
cairo stores the glyph as a meta surface and uses this surface to
render bitmaps for the glyph cache or in turn to output ps or pdf
type3 glyph or svg font glyphs.

The glyph space conversion isn't strictly necessary, we could just
require that users specify metrics and define the glyph in the font
design space, but it's a nice convenience.  Also, this ignores the
fact that we have no way to replay a meta surface under a
transformation, which will be necessary for rendering glyph cache
bitmaps at different sizes.

cheers,
Kristian


More information about the cairo mailing list