texlive[41537] Build/source/texk/dvipdfm-x: dvipdfm-x: (From S.

commits+kakuto at tug.org commits+kakuto at tug.org
Sat Jun 25 16:08:05 CEST 2016


Revision: 41537
          http://tug.org/svn/texlive?view=revision&revision=41537
Author:   kakuto
Date:     2016-06-25 16:08:05 +0200 (Sat, 25 Jun 2016)
Log Message:
-----------
dvipdfm-x: (From S. Hirata) Modify to make PDF/A generation a bit easier.

Modified Paths:
--------------
    trunk/Build/source/texk/dvipdfm-x/ChangeLog
    trunk/Build/source/texk/dvipdfm-x/cidtype2.c
    trunk/Build/source/texk/dvipdfm-x/pdfobj.c
    trunk/Build/source/texk/dvipdfm-x/type1.c
    trunk/Build/source/texk/dvipdfm-x/type1c.c

Modified: trunk/Build/source/texk/dvipdfm-x/ChangeLog
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/ChangeLog	2016-06-25 06:05:34 UTC (rev 41536)
+++ trunk/Build/source/texk/dvipdfm-x/ChangeLog	2016-06-25 14:08:05 UTC (rev 41537)
@@ -1,3 +1,10 @@
+2016-06-25  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
+
+	Modify to make PDF/A generation a bit easier.
+	* pdfobj.c: Do not compress XMP Metadata.
+	* cidtype2.c, type1.c, type1c.c: Always write CIDSet for CIDType2 and
+	CharSet for Type1 font. Check consistency of glyph width.
+
 2016-06-19  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
 
 	* dvipdfmx.c: Disable overriding "D" option setting from

Modified: trunk/Build/source/texk/dvipdfm-x/cidtype2.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/cidtype2.c	2016-06-25 06:05:34 UTC (rev 41536)
+++ trunk/Build/source/texk/dvipdfm-x/cidtype2.c	2016-06-25 14:08:05 UTC (rev 41537)
@@ -915,8 +915,15 @@
 
   /*
    * CIDToGIDMap
+   * Adobe's PDF Reference had been describing it as "optional" and
+   * default value as "Identity". However, ISO 32000-1 requires it
+   * for Type 2 CIDFonts with embedded font programs.
    */
-  if (cidtogidmap) {
+  if (!cidtogidmap) {
+    pdf_add_dict(font->fontdict,
+                 pdf_new_name("CIDToGIDMap"),
+                 pdf_new_name("Identity"));
+  } else {
     pdf_obj *c2gmstream;
 
     c2gmstream = pdf_new_stream(STREAM_COMPRESS);

Modified: trunk/Build/source/texk/dvipdfm-x/pdfobj.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfobj.c	2016-06-25 06:05:34 UTC (rev 41536)
+++ trunk/Build/source/texk/dvipdfm-x/pdfobj.c	2016-06-25 14:08:05 UTC (rev 41537)
@@ -1937,10 +1937,14 @@
   memcpy(filtered, stream->stream, stream->stream_length);
   filtered_length = stream->stream_length;
 
-#if 0
-  if (stream->stream_length < 10)
-    stream->_flags &= ^STREAM_COMPRESS;
-#endif
+  /* PDF/A requires Metadata to be not filtered. */
+  {
+    pdf_obj *type;
+    type = pdf_lookup_dict(stream->dict, "Type");
+    if (type && !strcmp("Metadata", pdf_name_value(type))) {
+      stream->_flags &= ~STREAM_COMPRESS;
+    }
+  }
 
 #ifdef HAVE_ZLIB
   /* Apply compression filter if requested */

Modified: trunk/Build/source/texk/dvipdfm-x/type1.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/type1.c	2016-06-25 06:05:34 UTC (rev 41536)
+++ trunk/Build/source/texk/dvipdfm-x/type1.c	2016-06-25 14:08:05 UTC (rev 41537)
@@ -324,6 +324,10 @@
       pdf_release_obj(tmp_array);
       return;
     }
+    /* PLEASE FIX THIS
+     * It's wrong to use TFM width here... We should warn if TFM width
+     * and actual glyph width are different.
+     */
     tfm_id = tfm_open(pdf_font_get_mapname(font), 0);
     for (code = firstchar; code <= lastchar; code++) {
       if (usedchars[code]) {
@@ -330,8 +334,18 @@
         double width;
         if (tfm_id < 0) /* tfm is not found */
           width = scaling * widths[cff_glyph_lookup(cffont, enc_vec[code])];
-        else
+        else {
+          double diff;
           width = 1000. * tfm_get_width(tfm_id, code);
+          diff  = width -
+                    scaling * widths[cff_glyph_lookup(cffont, enc_vec[code])];
+          if (fabs(diff) > 1.) {
+            WARN("Glyph width mismatch for TFM and font (%s)",
+                 pdf_font_get_mapname(font));
+            WARN("TFM: %g vs. Type1 font: %g",
+                 width, widths[cff_glyph_lookup(cffont, enc_vec[code])]);
+            }
+        }
         pdf_add_array(tmp_array,
                       pdf_new_number(ROUND(width, 0.1)));
       } else {
@@ -356,7 +370,7 @@
 
 
 static int
-write_fontfile (pdf_font *font, cff_font *cffont)
+write_fontfile (pdf_font *font, cff_font *cffont, pdf_obj *pdfcharset)
 {
   pdf_obj   *descriptor;
   pdf_obj   *fontfile, *stream_dict;
@@ -467,7 +481,10 @@
                pdf_new_name("Subtype"),   pdf_new_name("Type1C"));
   pdf_add_stream (fontfile, (void *) stream_data_ptr,  offset);
   pdf_release_obj(fontfile);
-
+  pdf_add_dict(descriptor,
+               pdf_new_name("CharSet"),
+               pdf_new_string(pdf_stream_dataptr(pdfcharset),
+                              pdf_stream_length(pdfcharset)));
   RELEASE(stream_data_ptr);
 
   return offset;
@@ -478,6 +495,7 @@
 pdf_font_load_type1 (pdf_font *font)
 {
   pdf_obj      *fontdict;
+  pdf_obj      *pdfcharset; /* Actually string object */
   int           encoding_id;
   char         *usedchars, *ident;
   char         *fontname, *uniqueTag;
@@ -580,6 +598,7 @@
   /* Create CFF encoding, charset, sort glyphs */
 #define MAX_GLYPHS 1024
   GIDMap = NEW(MAX_GLYPHS, card16);
+  pdfcharset = pdf_new_stream(0);
   {
     int     prev, duplicate;
     int     gid;
@@ -652,7 +671,11 @@
         if (verbose > 2) {
           MESG("/%s", glyph);
         }
-
+        /* CharSet is actually string object. */
+        {
+          pdf_add_stream(pdfcharset, "/", 1);
+          pdf_add_stream(pdfcharset, glyph, strlen(glyph));
+        }
       }
     }
     if (cffont->encoding->num_supps > 0) {
@@ -776,10 +799,12 @@
 
   add_metrics(font, cffont, enc_vec, widths, num_glyphs);
 
-  offset = write_fontfile(font, cffont);
+  offset = write_fontfile(font, cffont, pdfcharset);
   if (verbose > 1)
     MESG("[%u glyphs][%ld bytes]", num_glyphs, offset);
 
+  pdf_release_obj(pdfcharset);
+
   cff_close(cffont);
 
   /* Cleanup */

Modified: trunk/Build/source/texk/dvipdfm-x/type1c.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/type1c.c	2016-06-25 06:05:34 UTC (rev 41536)
+++ trunk/Build/source/texk/dvipdfm-x/type1c.c	2016-06-25 14:08:05 UTC (rev 41537)
@@ -201,10 +201,18 @@
         double width;
         if (tfm_id < 0) /* tfm is not found */
           width = scaling * widths[code];
-        else
+        else {
+          double diff;
           width = 1000. * tfm_get_width(tfm_id, code);
+          diff  = width - scaling * widths[code];
+          if (fabs(diff) > 1.) {
+            WARN("Glyph width mismatch for TFM and font (%s)",
+                 pdf_font_get_mapname(font));
+            WARN("TFM: %g vs. CFF font: %g", width, widths[code]);
+            }
 	pdf_add_array(tmp_array,
 		      pdf_new_number(ROUND(width, 0.1)));
+        }
       } else {
 	pdf_add_array(tmp_array, pdf_new_number(0.0));
       }
@@ -229,6 +237,7 @@
 pdf_font_load_type1c (pdf_font *font)
 {
   pdf_obj      *fontdict, *descriptor;
+  pdf_obj      *pdfcharset; /* Actually string object */
   char         *usedchars;
   char         *fontname, *uniqueTag, *ident, *fullname;
   FILE         *fp = NULL;
@@ -449,6 +458,7 @@
    * Subset font
    */
   num_glyphs = 1;
+  pdfcharset = pdf_new_stream(0);
   for (code = 0; code < 256; code++) {
     card16 gid, j;
     s_SID  sid_orig, sid;
@@ -498,6 +508,9 @@
       usedchars[code] = 0; /* Set unused for writing correct encoding */
       continue;
     }
+    pdf_add_stream(pdfcharset, "/", 1);
+    pdf_add_stream(pdfcharset, enc_vec[code], strlen(enc_vec[code]));
+
     if (verbose > 2) {
       MESG("/%s", enc_vec[code]);
     }
@@ -717,10 +730,13 @@
   }
 
   /*
-   * CharSet might be recommended for subsetted font, but it is meaningful
-   * only for Type 1 font...
+   * CharSet
    */
-
+  pdf_add_dict(descriptor,
+               pdf_new_name("CharSet"),
+               pdf_new_string(pdf_stream_dataptr(pdfcharset),
+                              pdf_stream_length(pdfcharset)));
+  pdf_release_obj(pdfcharset);
   /*
    * Write PDF FontFile data.
    */



More information about the tex-live-commits mailing list