[cairo] Possible API change to handle invalid glyph indexes

Baz brian.ewins at gmail.com
Mon Jan 15 09:43:25 PST 2007


(Opening up https://bugs.freedesktop.org/show_bug.cgi?id=9530 for
wider discussion)

Here's the problem:

/* glyph id outside range 0x0 - 0xfffe */
cairo_glyph_t glyph = { -1L, 0, 0 };
cairo_show_glyphs(cr, &glyph, 1);

This use of an out-of-range glyph index causes the ATSUI font backend
to return CAIRO_INT_STATUS_UNSUPPORTED and the FT font backend to
return CAIRO_STATUS_NO_MEMORY, neither of which are desirable - we're
not out of memory and the functions being called are supported, just
failing.

Behdad suggested this solution, which requires changes of return type
from 'void' to 'cairo_status_t' in various bits of the public API:
>So, all we need to do is to check what the returned error is, and act
appropriately.
>
>We need to decide what we're gonna do though.  I suggest:
>
 > - If the glyph id is nonexistent, the backend should report
>CAIRO_STATUS_INVALID_INDEX.
>
>  - Scaled font layer acts if nonexistent glyphs had extents 0,0,0,0.  We also
>change cairo_show_glyphs, cairo_glyph_extents, and
>cairo_scaled_font_glyph_extents to return cairo_status_t, and return
>INVALID_INDEX if at least one glyph id was such.  However, that error can be
>ignored.
>
>  - Possibly do similar for cairo_show_text, cairo_text_extents, and
>cairo_scaled_font_text_extents too: they return something other than SUCCESS if
>there was at least one char that didn't map to any glyphs.

Comments? For myself, this looks at odds with the use of
cairo_status_t elsewhere in the API (always for errors, not
warnings?), and IIRC this will bust assertions on cairo_status
becoming SUCCESS when it was previously non-zero. I also don't think
the toy api calls (cairo_show_text, cairo_text_extents,
cairo_text_path) need changed at all since the user can't supply an
invalid glyph id this way.

- Brian


More information about the cairo mailing list