[cairo-commit] src/cairo-truetype-subset.c
Adrian Johnson
ajohnson at kemper.freedesktop.org
Sat Jul 9 09:12:39 UTC 2016
src/cairo-truetype-subset.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
New commits:
commit b73c082c7f412f53eb2e4b52689601128a5f06a0
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Sat Jul 9 18:19:16 2016 +0930
truetype: Don't write glyph if num_contours == 0
According to the Opentype spec, num_contours in a glyf table entry can
be > 0 (single glyph) or < 0 (composite glyph). num_contours == 0 is
undefined.
The embedded font in the test case for this bug contained a space
glyph with num_contours == 0. This was failing on some printers.
According to the spec, glyphs with no outlines such as space are
required to have a 0 size entry in the loca table.
https://bugs.freedesktop.org/show_bug.cgi?id=79897
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 3aa637d..f47b966 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -652,16 +652,34 @@ cairo_truetype_font_write_glyf_table (cairo_truetype_font_t *font,
if (unlikely (status))
goto FAIL;
- if (size != 0) {
- status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
+ if (size > 1) {
+ tt_glyph_data_t *glyph_data;
+ int num_contours;
+
+ status = font->backend->load_truetype_table (font->scaled_font_subset->scaled_font,
TT_TAG_glyf, begin, buffer, &size);
if (unlikely (status))
goto FAIL;
- status = cairo_truetype_font_remap_composite_glyph (font, buffer, size);
- if (unlikely (status))
- goto FAIL;
- }
+ glyph_data = (tt_glyph_data_t *) buffer;
+ num_contours = (int16_t)be16_to_cpu (glyph_data->num_contours);
+ if (num_contours < 0) {
+ status = cairo_truetype_font_remap_composite_glyph (font, buffer, size);
+ if (unlikely (status))
+ goto FAIL;
+ } else if (num_contours == 0) {
+ /* num_contours == 0 is undefined in the Opentype
+ * spec. There are some embedded fonts that have a
+ * space glyph with num_contours = 0 that fails on
+ * some printers. The spec requires glyphs without
+ * contours to have a 0 size glyph entry in the loca
+ * table.
+ *
+ * If num_contours == 0, truncate the glyph to 0 size.
+ */
+ _cairo_array_truncate (&font->output, _cairo_array_num_elements (&font->output) - size);
+ }
+ }
}
status = cairo_truetype_font_align_output (font, &next);
More information about the cairo-commit
mailing list