[cairo] Error handling in cairo_type1_font_subset_get_glyph_names_and_widths
Peter Weilbacher
mozilla at weilbacher.org
Wed Oct 29 17:11:43 PDT 2008
I was investigating (full, mostly irrelevant details at
https://bugzilla.mozilla.org/show_bug.cgi?id=446290) why I saw
problems creating a PDF when I noticed an error message
could not load glyph 499
from cairo.
It turns out that the font used is broken (or FreeType is broken
that it cannot load glyph 499 from it), but I wonder if the
error handling in cairo_type1_font_subset_get_glyph_names_and_widths()
makes sense.[1][2] To me (someone without any PS knowledge) it seems
that this function gets data for many glyphs; at least in my case
most of them won't be used. So my workaround is to only access the
glyph width for success and otherwise set width=0 and just continue.
Patch appended below.
Not sure how wrong this is but at least the PDF created with this
workaround seems to be OK while the original one was so garbled
that all viewers had trouble displaying it...
So, I guess I'm asking what the best way would be to make cairo
more robust against slightly broken fonts for this case.
1: It's probably not optimal for a library to print errors to
stdout, but in this case I am happy about that because it made
it easier for me to locate the problem. :-)
2: Returning CAIRO_STATUS_NO_MEMORY is probably also not optimal
for an FT_Load_Glyph() failure, the error I get is really
"opcode syntax error"...
Cheers,
Peter.
diff --git a/gfx/cairo/cairo/src/cairo-type1-subset.c b/gfx/cairo/cairo/src/cairo-type1-subset.c
--- a/gfx/cairo/cairo/src/cairo-type1-subset.c
+++ b/gfx/cairo/cairo/src/cairo-type1-subset.c
@@ -566,10 +566,10 @@
FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM);
if (error != 0) {
printf ("could not load glyph %d\n", i);
- return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+ font->glyphs[i].width = 0;
+ } else {
+ font->glyphs[i].width = font->face->glyph->metrics.horiAdvance;
}
-
- font->glyphs[i].width = font->face->glyph->metrics.horiAdvance;
error = FT_Get_Glyph_Name(font->face, i, buffer, sizeof buffer);
if (error != 0) {
More information about the cairo
mailing list