summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2016-07-09 18:19:16 +0930
committerAdrian Johnson <ajohnson@redneon.com>2016-07-09 18:31:55 +0930
commitb73c082c7f412f53eb2e4b52689601128a5f06a0 (patch)
tree7ee42b1a6481fc26c93e8b630270bc9a9df79d48
parent38fdcc30a3fe64800a732affaa211ac38eb8dfad (diff)
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
-rw-r--r--src/cairo-truetype-subset.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 3aa637d6f..f47b966a5 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);