[cairo-commit] 2 commits - src/cairo-pdf-surface.c src/cairo-truetype-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Feb 4 00:38:16 PST 2007


 src/cairo-pdf-surface.c     |   21 +++++++++++++++++++--
 src/cairo-truetype-subset.c |   23 ++++++++++++++++-------
 2 files changed, 35 insertions(+), 9 deletions(-)

New commits:
diff-tree 05ff2c77da86c7be95924f9af4d3ad944afbbf66 (from 3f8d5f505af4d7569ce38452f1be5d40bf6a00b4)
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Feb 4 19:00:16 2007 +1030

    PDF: Add Encoding dictionary to TrueType fonts
    
    This is a fix for the bugs reported here
    
      http://lists.freedesktop.org/archives/cairo/2006-December/008984.html
    
      http://lists.freedesktop.org/archives/cairo/2007-January/009387.html
    
    Cairo PDFs will not print correctly from Adobe Reader. The symptoms are
    that all the glyphs on the page are replaced with the same glyph.
    
    According to the PDF Reference an Encoding dictionary is not required
    for the symbolic fonts used by cairo. However including the Encoding
    dictionary fixes the printing problem.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index bdfef00..17c4108 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1876,7 +1876,7 @@ static cairo_status_t
 _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 					      cairo_scaled_font_subset_t	*font_subset)
 {
-    cairo_pdf_resource_t stream, descriptor, subset_resource;
+    cairo_pdf_resource_t stream, descriptor, encoding, subset_resource;
     cairo_status_t status;
     cairo_pdf_font_t font;
     cairo_truetype_subset_t subset;
@@ -1939,6 +1939,21 @@ _cairo_pdf_surface_emit_truetype_font_su
 				 subset.descent,
 				 stream.id);
 
+    encoding = _cairo_pdf_surface_new_object (surface);
+    _cairo_output_stream_printf (surface->output,
+				 "%d 0 obj\r\n"
+				 "<< /Type /Encoding\r\n"
+				 "   /Differences [ ",
+                                 encoding.id);
+
+    for (i = 0; i < font_subset->num_glyphs; i++)
+            _cairo_output_stream_printf (surface->output, "/g%d ", i);
+
+    _cairo_output_stream_printf (surface->output,
+                                 " ]\r\n"
+				 ">>\r\n"
+				 "endobj\r\n");
+
     subset_resource = _cairo_pdf_surface_new_object (surface);
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\r\n"
@@ -1948,11 +1963,13 @@ _cairo_pdf_surface_emit_truetype_font_su
 				 "   /FirstChar 0\r\n"
 				 "   /LastChar %d\r\n"
 				 "   /FontDescriptor %d 0 R\r\n"
+				 "   /Encoding %d 0 R\r\n"
 				 "   /Widths [",
 				 subset_resource.id,
 				 subset.base_font,
 				 font_subset->num_glyphs - 1,
-				 descriptor.id);
+				 descriptor.id,
+                                 encoding.id);
 
     for (i = 0; i < font_subset->num_glyphs; i++)
 	_cairo_output_stream_printf (surface->output,
diff-tree 3f8d5f505af4d7569ce38452f1be5d40bf6a00b4 (from d22ba141e6c78bf1fc3dfc02c9aaf6d725233444)
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Feb 4 18:21:50 2007 +1030

    TrueType: Include notdef glyph in the subset
    
    Required by the TrueType specification.

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 1df7f18..de878e8 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -383,10 +383,10 @@ cairo_truetype_font_write_cmap_table (ca
     cairo_truetype_font_write_be16 (font, 6);
     cairo_truetype_font_write_be16 (font, 10 + 2 * (font->base.num_glyphs - 1));
     cairo_truetype_font_write_be16 (font, 0);
-    cairo_truetype_font_write_be16 (font, 1); /* First glyph */
-    cairo_truetype_font_write_be16 (font, font->base.num_glyphs - 1);
-    for (i = 1; i < font->base.num_glyphs; i++)
-	cairo_truetype_font_write_be16 (font, i);
+    cairo_truetype_font_write_be16 (font, 0); /* First character */
+    cairo_truetype_font_write_be16 (font, font->base.num_glyphs);
+    for (i = 0; i < font->base.num_glyphs; i++)
+	cairo_truetype_font_write_be16 (font, i + 1);
 
     return font->status;
 }
@@ -821,6 +821,10 @@ _cairo_truetype_subset_init (cairo_truet
     if (status)
 	return status;
 
+    /* Add the notdef glyph. This is required at glyph index 0
+     * in the subsetted font. */
+    cairo_truetype_font_use_glyph (font, 0);
+
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++) {
 	parent_glyph = font->scaled_font_subset->glyphs[i];
 	cairo_truetype_font_use_glyph (font, parent_glyph);
@@ -835,11 +839,16 @@ _cairo_truetype_subset_init (cairo_truet
     if (truetype_subset->base_font == NULL)
 	goto fail1;
 
-    truetype_subset->widths = calloc (sizeof (int), font->base.num_glyphs);
+    /* The widths array returned must contain only widths for
+     * the glyphs in font_subset. The notdef glyph at index 0
+     * and any subglyphs appended after font_subset->num_glyphs
+     * are omitted. */
+    truetype_subset->widths = calloc (sizeof (int),
+                                      font->scaled_font_subset->num_glyphs);
     if (truetype_subset->widths == NULL)
 	goto fail2;
-    for (i = 0; i < font->base.num_glyphs; i++)
-	truetype_subset->widths[i] = font->base.widths[i];
+    for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
+	truetype_subset->widths[i] = font->base.widths[i + 1];
 
     truetype_subset->x_min = font->base.x_min;
     truetype_subset->y_min = font->base.y_min;


More information about the cairo-commit mailing list