[cairo-commit] src/cairo-truetype-subset.c src/cairo-truetype-subset-private.h

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Feb 15 14:09:25 PST 2007


 src/cairo-truetype-subset-private.h |    1 
 src/cairo-truetype-subset.c         |   67 ++++++++++++++++++++++++++++++++----
 2 files changed, 62 insertions(+), 6 deletions(-)

New commits:
diff-tree 16e20568a502b86d96c3087515e663bb7996f167 (from 2715f2098127d04d2f9e304580a26cd0842c0e64)
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Feb 16 08:38:26 2007 +1030

    TrueType: Add post table and 3,0 cmap encoding
    
    Commit 05ff2c77da86c7be95924f9af4d3ad944afbbf66 contained
    a fix for the acroread printing problem. However this
    patch caused a problem for the Mac Preview PDF viewer.
    
      http://lists.freedesktop.org/archives/cairo/2007-February/009615.html
    
    This patch fixes the Mac Preview problem. The patch
    
    - Adds a platform 3, encoding 0 cmap table
    - Adds a post table that maps the glyph names in the
      PDF truetype font dictionary (/g0 /g1 /g2 ...)
      to glyph indices in the font.

diff --git a/src/cairo-truetype-subset-private.h b/src/cairo-truetype-subset-private.h
index 80baa28..25c798d 100644
--- a/src/cairo-truetype-subset-private.h
+++ b/src/cairo-truetype-subset-private.h
@@ -62,6 +62,7 @@
 #define TT_TAG_loca   MAKE_TT_TAG('l','o','c','a')
 #define TT_TAG_maxp   MAKE_TT_TAG('m','a','x','p')
 #define TT_TAG_name   MAKE_TT_TAG('n','a','m','e')
+#define TT_TAG_post   MAKE_TT_TAG('p','o','s','t')
 #define TT_TAG_prep   MAKE_TT_TAG('p','r','e','p')
 
 /* All tt_* structs are big-endian */
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 46e26be..1143dba 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -377,12 +377,35 @@ cairo_truetype_font_write_cmap_table (ca
 {
     unsigned int i;
 
-    cairo_truetype_font_write_be16 (font, 0);
-    cairo_truetype_font_write_be16 (font, 1);
+    cairo_truetype_font_write_be16 (font, 0);  /* Table version */
+    cairo_truetype_font_write_be16 (font, 2);  /* Num tables */
 
-    cairo_truetype_font_write_be16 (font, 1);
-    cairo_truetype_font_write_be16 (font, 0);
-    cairo_truetype_font_write_be32 (font, 12);
+    cairo_truetype_font_write_be16 (font, 3);  /* Platform */
+    cairo_truetype_font_write_be16 (font, 0);  /* Encoding */
+    cairo_truetype_font_write_be32 (font, 20); /* Offset to start of table */
+
+    cairo_truetype_font_write_be16 (font, 1);  /* Platform */
+    cairo_truetype_font_write_be16 (font, 0);  /* Encoding */
+    cairo_truetype_font_write_be32 (font, 52); /* Offset to start of table */
+
+    /* Output a format 4 encoding table. */
+
+    cairo_truetype_font_write_be16 (font, 4);  /* Format */
+    cairo_truetype_font_write_be16 (font, 32); /* Length */
+    cairo_truetype_font_write_be16 (font, 0);  /* Version */
+    cairo_truetype_font_write_be16 (font, 4);  /* 2*segcount */
+    cairo_truetype_font_write_be16 (font, 4);  /* searchrange */
+    cairo_truetype_font_write_be16 (font, 1);  /* entry selector */
+    cairo_truetype_font_write_be16 (font, 0);  /* rangeshift */
+    cairo_truetype_font_write_be16 (font, 0xf000 + font->base.num_glyphs - 2); /* end count[0] */
+    cairo_truetype_font_write_be16 (font, 0xffff);  /* end count[1] */
+    cairo_truetype_font_write_be16 (font, 0);       /* reserved */
+    cairo_truetype_font_write_be16 (font, 0xf000);  /* startCode[0] */
+    cairo_truetype_font_write_be16 (font, 0xffff);  /* startCode[1] */
+    cairo_truetype_font_write_be16 (font, 0x1001);  /* delta[0] */
+    cairo_truetype_font_write_be16 (font, 1);       /* delta[1] */
+    cairo_truetype_font_write_be16 (font, 0);       /* rangeOffset[0] */
+    cairo_truetype_font_write_be16 (font, 0);       /* rangeOffset[1] */
 
     /* Output a format 6 encoding table. */
 
@@ -649,6 +672,37 @@ cairo_truetype_font_write_maxp_table (ca
     return font->status;
 }
 
+static int
+cairo_truetype_font_write_post_table (cairo_truetype_font_t *font,
+				      unsigned long          tag)
+{
+    char buf[10];
+    int n;
+    unsigned i;
+
+    cairo_truetype_font_write_be32 (font, 0x00020000);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be16 (font, 0);
+    cairo_truetype_font_write_be16 (font, 1);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be32 (font, 0);
+    cairo_truetype_font_write_be16 (font, font->base.num_glyphs);
+    cairo_truetype_font_write_be16 (font, 0);
+    for (i = 1; i < font->base.num_glyphs; i++)
+        cairo_truetype_font_write_be16 (font, i + 257);
+
+    for (i = 1; i < font->base.num_glyphs; i++) {
+        n = snprintf(buf + 1, 10, "g%d", i - 1);
+        buf[0] = n;
+        cairo_truetype_font_write (font, buf, n + 1);
+    }
+
+    return font->status;
+}
+
 typedef struct table table_t;
 struct table {
     unsigned long tag;
@@ -675,7 +729,8 @@ static const table_t truetype_tables[] =
     { TT_TAG_loca, cairo_truetype_font_write_loca_table,     7 },
     { TT_TAG_maxp, cairo_truetype_font_write_maxp_table,     8 },
     { TT_TAG_name, cairo_truetype_font_write_generic_table,  9 },
-    { TT_TAG_prep, cairo_truetype_font_write_generic_table, 10 },
+    { TT_TAG_post, cairo_truetype_font_write_post_table,    10 },
+    { TT_TAG_prep, cairo_truetype_font_write_generic_table, 11 },
 };
 
 static cairo_status_t


More information about the cairo-commit mailing list