texlive[42741] Build/source/texk/dvipdfm-x: dvipdfm-x: Merge libdpx

commits+kakuto at tug.org commits+kakuto at tug.org
Sun Dec 18 10:59:25 CET 2016


Revision: 42741
          http://tug.org/svn/texlive?view=revision&revision=42741
Author:   kakuto
Date:     2016-12-18 10:59:24 +0100 (Sun, 18 Dec 2016)
Log Message:
-----------
dvipdfm-x: Merge libdpx by Clerk Ma at https://github.com/clerkma/ptex-ng

Modified Paths:
--------------
    trunk/Build/source/texk/dvipdfm-x/ChangeLog
    trunk/Build/source/texk/dvipdfm-x/dvi.c
    trunk/Build/source/texk/dvipdfm-x/dvi.h
    trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c
    trunk/Build/source/texk/dvipdfm-x/mpost.c
    trunk/Build/source/texk/dvipdfm-x/pdfencoding.c
    trunk/Build/source/texk/dvipdfm-x/pdfobj.c
    trunk/Build/source/texk/dvipdfm-x/pdfparse.c
    trunk/Build/source/texk/dvipdfm-x/pdfparse.h
    trunk/Build/source/texk/dvipdfm-x/tt_cmap.c
    trunk/Build/source/texk/dvipdfm-x/type0.c
    trunk/Build/source/texk/dvipdfm-x/type1.c
    trunk/Build/source/texk/dvipdfm-x/vf.c
    trunk/Build/source/texk/dvipdfm-x/xbb.c

Modified: trunk/Build/source/texk/dvipdfm-x/ChangeLog
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/ChangeLog	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/ChangeLog	2016-12-18 09:59:24 UTC (rev 42741)
@@ -1,3 +1,9 @@
+2016-12-18  Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
+
+	* dvi.c, dvi.h, dvipdfmx.c, mpost.c, pdfencoding.c, pdfobj.c,
+	pdfparse.c, pdfparse.h, tt_cmap.c, type0.c, type1.c, vf.c, xbb.c:
+	Merge libdpx by Clerk Ma at https://github.com/clerkma/ptex-ng.
+
 2016-10-30  Akira Kakuto  <kakuto at fuk.kindai.ac.jp>
 
 	* pdffont.c, pdfobj.h: Use (time_t)-1 for INVALID_EPOCH_VALUE.

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -942,7 +942,11 @@
   return  cur_id;
 }
 
+#if defined(LIBDPX)
+int
+#else
 static int
+#endif /* LIBDPX */
 dvi_locate_native_font (const char *filename, uint32_t index,
                         spt_t ptsize, int layout_dir, int extend, int slant, int embolden)
 {
@@ -1302,10 +1306,10 @@
 }
 
 void
-dvi_dir (unsigned char dir)
+dvi_dirchg (unsigned char dir)
 {
   if (verbose)
-    fprintf(stderr, "  > dvi_dir %d\n", dir);
+    fprintf(stderr, "  > dvi_dirchg %d\n", dir);
   dvi_state.d = dir;
   pdf_dev_set_dirmode(dvi_state.d); /* 0: horizontal, 1,3: vertical */
 }
@@ -2528,3 +2532,6 @@
 
   return;
 }
+#if defined(LIBDPX)
+#include "dvi_ng.c"
+#endif /* LIBDPX */

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.h	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.h	2016-12-18 09:59:24 UTC (rev 42741)
@@ -67,7 +67,7 @@
 extern void dvi_y0    (void);
 extern void dvi_z     (int32_t ch);
 extern void dvi_z0    (void);
-extern void dvi_dir   (unsigned char dir);
+extern void dvi_dirchg(unsigned char dir);
 
 extern void  dvi_do_page  (double paper_height, double x_offset, double y_offset);
 extern void  dvi_scan_specials (int page_no,

Modified: trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -66,7 +66,11 @@
 int is_xdv = 0;
 int translate_origin = 0;
 
+#if defined(LIBDPX)
+const char *my_name = "ApTeX";
+#else
 const char *my_name;
+#endif /* LIBDPX */
 
 int compat_mode = 0;     /* 0 = dvipdfmx, 1 = dvipdfm */
 
@@ -916,6 +920,7 @@
   }
 }
 
+#if !defined(LIBDPX)
 /* Support to make DLL in W32TeX */
 #define DLLPROC dlldvipdfmxmain
 
@@ -924,6 +929,7 @@
 #else
 #undef DLLPROC
 #endif
+#endif /* !LIBDPX */
 
 #if defined(MIKTEX)
 #  define main Main
@@ -933,7 +939,11 @@
 #if defined(DLLPROC)
 DLLPROC (int argc, char *argv[])
 #else
+#if defined(LIBDPX)
+dvipdfmx_main (int argc, char *argv[])
+#else
 main (int argc, char *argv[])
+#endif /* LIBDPX */
 #endif
 {
   double dvi2pts;

Modified: trunk/Build/source/texk/dvipdfm-x/mpost.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/mpost.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/mpost.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -263,7 +263,7 @@
         return 0;
       }
     }
-    skip_line (pp, endptr);
+    pdfparse_skip_line (pp, endptr);
     while (*pp < endptr && isspace((unsigned char)**pp))
       (*pp)++;
   }
@@ -285,13 +285,13 @@
       break;
     if (!strncmp(*start, "%%EndProlog", 11)) {
       found_prolog = 1;
-      skip_line(start, end);
+      pdfparse_skip_line(start, end);
       break;
     } else if (!strncmp(*start, "%%Page:", 7)) {
-      skip_line(start, end);
+      pdfparse_skip_line(start, end);
       break;
     }
-    skip_line(start, end);
+    pdfparse_skip_line(start, end);
   }
   if (!found_prolog) {
     *start = save;

Modified: trunk/Build/source/texk/dvipdfm-x/pdfencoding.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfencoding.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/pdfencoding.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -318,7 +318,7 @@
    * Skip comment lines.
    */
   while (p < endptr && p[0] == '%') {
-    skip_line (&p, endptr);
+    pdfparse_skip_line (&p, endptr);
     skip_white(&p, endptr);
   }
   if (p[0] == '/')

Modified: trunk/Build/source/texk/dvipdfm-x/pdfobj.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfobj.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/pdfobj.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -455,6 +455,14 @@
   pdf_release_obj(xref_stream);
 }
 
+#if defined(LIBDPX)
+long
+pdf_output_stats (void)
+{
+  return pdf_output_file_position;
+}
+#endif /* LIBDPX */
+
 void
 pdf_out_flush (void)
 {
@@ -496,7 +504,9 @@
     pdf_out(pdf_output_file, format_buffer, length);
     pdf_out(pdf_output_file, "%%EOF\n", 6);
 
+#if !defined(LIBDPX)
     MESG("\n");
+#endif /* !LIBDPX */
     if (verbose) {
       if (compression_level > 0) {
 	MESG("Compression saved %ld bytes%s\n", compression_saved,
@@ -503,7 +513,9 @@
 	     pdf_version < 5 ? ". Try \"-V 5\" for better compression" : "");
       }
     }
+#if !defined(LIBDPX)
     MESG("%ld bytes written", pdf_output_file_position);
+#endif /* !LIBDPX */
 
     MFCLOSE(pdf_output_file);
   }

Modified: trunk/Build/source/texk/dvipdfm-x/pdfparse.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfparse.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/pdfparse.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -95,7 +95,7 @@
  } while (0)
 
 void
-skip_line (const char **start, const char *end)
+pdfparse_skip_line (const char **start, const char *end)
 {
   while (*start < end && **start != '\n' && **start != '\r')
     (*start)++;
@@ -121,7 +121,7 @@
    */
   while (*start < end && (is_space(**start) || **start == '%')) {
     if (**start == '%')
-      skip_line(start, end);
+      pdfparse_skip_line(start, end);
     else
       (*start)++;
   }

Modified: trunk/Build/source/texk/dvipdfm-x/pdfparse.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfparse.h	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/pdfparse.h	2016-12-18 09:59:24 UTC (rev 42741)
@@ -29,7 +29,7 @@
 /* Please remove this */
 extern void dump (const char *start, const char *end);
 
-extern void skip_line  (const char **start, const char *end);
+extern void pdfparse_skip_line (const char **start, const char *end);
 extern void skip_white (const char **start, const char *end);
 
 extern char *parse_number   (const char **start, const char *end);

Modified: trunk/Build/source/texk/dvipdfm-x/tt_cmap.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/tt_cmap.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/tt_cmap.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -902,10 +902,12 @@
         }
 #undef MAX_UNICODES
         if (unicode_count == -1) {
-          if (name)
-            MESG("No Unicode mapping available: GID=%u, name=%s\n", gid, name);
-          else
-            MESG("No Unicode mapping available: GID=%u\n", gid);
+          if(verbose > VERBOSE_LEVEL_MIN) {
+            if (name)
+              MESG("No Unicode mapping available: GID=%u, name=%s\n", gid, name);
+            else
+              MESG("No Unicode mapping available: GID=%u\n", gid);
+          }
         } else {
           /* the Unicode characters go into wbuf[2] and following, in UTF16BE */
           /* we rely on WBUF_SIZE being more than adequate for MAX_UNICODES  */
@@ -1267,7 +1269,7 @@
       break;
     }
   }
-  if (cmap_obj == NULL)
+  if (cmap_obj == NULL && verbose > VERBOSE_LEVEL_MIN)
     WARN("Unable to read OpenType/TrueType Unicode cmap table.");
   tt_cmap_release(ttcmap);
   CMap_set_silent(0);
@@ -1871,7 +1873,11 @@
     ttcmap = tt_cmap_read(sfont, 3, 1); /* Microsoft UCS2 */
     if (!ttcmap) {
       ttcmap = tt_cmap_read(sfont, 0, 3); /* Unicode 2.0 or later */
+#if defined(LIBDPX)
+      if (!ttcmap && verbose > VERBOSE_LEVEL_MIN) {
+#else
       if (!ttcmap) {
+#endif /* LIBDPX */
         ERROR("Unable to read OpenType/TrueType Unicode cmap table.");
       }
     }

Modified: trunk/Build/source/texk/dvipdfm-x/type0.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/type0.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/type0.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -254,7 +254,8 @@
     pdf_add_dict(font->fontdict,
                  pdf_new_name("ToUnicode"), tounicode);
   } else {
-    WARN("Failed to load ToUnicode CMap for font \"%s\"", fontname);
+    if (__verbose)
+      WARN("Failed to load ToUnicode CMap for font \"%s\"", fontname);
   }
 
   return;

Modified: trunk/Build/source/texk/dvipdfm-x/type1.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/type1.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/type1.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -324,10 +324,6 @@
       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]) {
@@ -334,18 +330,8 @@
         double width;
         if (tfm_id < 0) /* tfm is not found */
           width = scaling * widths[cff_glyph_lookup(cffont, enc_vec[code])];
-        else {
-          double diff;
+        else
           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 {
@@ -370,7 +356,7 @@
 
 
 static int
-write_fontfile (pdf_font *font, cff_font *cffont, pdf_obj *pdfcharset)
+write_fontfile (pdf_font *font, cff_font *cffont)
 {
   pdf_obj   *descriptor;
   pdf_obj   *fontfile, *stream_dict;
@@ -481,10 +467,7 @@
                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;
@@ -495,7 +478,6 @@
 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;
@@ -598,7 +580,6 @@
   /* 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;
@@ -671,11 +652,7 @@
         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) {
@@ -799,12 +776,10 @@
 
   add_metrics(font, cffont, enc_vec, widths, num_glyphs);
 
-  offset = write_fontfile(font, cffont, pdfcharset);
+  offset = write_fontfile(font, cffont);
   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/vf.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/vf.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/vf.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -504,7 +504,7 @@
 	  }
 	  break;
 	case PTEXDIR:
-	  dvi_dir (unsigned_byte (&start, end));
+	  dvi_dirchg (unsigned_byte (&start, end));
 	  break;
 	default:
 	  if (opcode <= SET_CHAR_127) {
@@ -557,3 +557,6 @@
     RELEASE (vf_fonts);
   return;
 }
+#if defined(LIBDPX)
+#include "vf_ng.c"
+#endif /* LIBDPX */

Modified: trunk/Build/source/texk/dvipdfm-x/xbb.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/xbb.c	2016-12-18 01:05:39 UTC (rev 42740)
+++ trunk/Build/source/texk/dvipdfm-x/xbb.c	2016-12-18 09:59:24 UTC (rev 42741)
@@ -398,3 +398,179 @@
 
   return 0;
 }
+
+#if defined(LIBDPX)
+static void do_aptex_bmp (FILE *fp, char *filename, pdf_rect * box)
+{
+  int    width, height;
+  double xdensity, ydensity;
+
+  if (bmp_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+    WARN("%s does not look like a BMP file...\n", filename);
+    return;
+  }
+
+  box->llx = 0.0;
+  box->lly = 0.0;
+  box->urx = xdensity*width;
+  box->ury = ydensity*height;
+  return;
+}
+
+static void do_aptex_jpeg (FILE *fp, char *filename, pdf_rect * box)
+{
+  int    width, height;
+  double xdensity, ydensity;
+
+  if (jpeg_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+    WARN("%s does not look like a JPEG file...\n", filename);
+    return;
+  }
+
+  box->llx = 0.0;
+  box->lly = 0.0;
+  box->urx = xdensity*width;
+  box->ury = ydensity*height;
+  return;
+}
+
+static void do_aptex_jp2 (FILE *fp, char *filename, pdf_rect * box)
+{
+  int    width, height;
+  double xdensity, ydensity;
+
+  if (jp2_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+    WARN("%s does not look like a JP2/JPX file...\n", filename);
+    return;
+  }
+
+  box->llx = 0.0;
+  box->lly = 0.0;
+  box->urx = xdensity*width;
+  box->ury = ydensity*height;
+  return;
+}
+
+#ifdef HAVE_LIBPNG
+static void do_aptex_png (FILE *fp, char *filename, pdf_rect * box)
+{
+  uint32_t width, height;
+  double xdensity, ydensity;
+
+  if (png_get_bbox(fp, &width, &height, &xdensity, &ydensity) < 0) {
+    WARN("%s does not look like a PNG file...\n", filename);
+    return;
+  }
+
+  box->llx = 0.0;
+  box->lly = 0.0;
+  box->urx = xdensity*width;
+  box->ury = ydensity*height;
+  return;
+}
+#endif /* HAVE_LIBPNG */
+
+static void do_aptex_pdf (FILE *fp, char *filename, pdf_rect * box)
+{
+  pdf_obj *page;
+  pdf_file *pf;
+  int page_no = Include_Page;
+  int count;
+  pdf_rect bbox;
+
+  pf = pdf_open(filename, fp);
+  if (!pf) {
+    WARN("%s does not look like a PDF file...\n", filename);
+    return;
+  }
+  count = pdf_doc_get_page_count(pf);
+  page  = pdf_doc_get_page(pf, page_no, PageBox, &bbox, NULL);
+
+  pdf_close(pf);
+
+  if (!page)
+    return;
+
+  pdf_release_obj(page);
+
+  box->llx = bbox.llx;
+  box->lly = bbox.lly;
+  box->urx = bbox.urx;
+  box->ury = bbox.ury;
+}
+
+void aptex_extractbb (char * pict, uint32_t page, uint32_t rect, pdf_rect * bbox)
+{
+  FILE *infile = NULL;
+  char *kpse_file_name = NULL;
+  int    pictwd, pictht;
+  double xdensity, ydensity;
+
+  if (page == 0)
+    Include_Page = 1;
+  else
+    Include_Page = page;
+
+  PageBox = rect;
+
+  if (kpse_in_name_ok(pict))
+  {
+    infile = MFOPEN(pict, FOPEN_RBIN_MODE);
+    if (infile)
+    {
+      kpse_file_name = xstrdup(pict);
+    }
+    else
+    {
+      kpse_file_name = kpse_find_pict(pict);
+      if (kpse_file_name && kpse_in_name_ok(kpse_file_name))
+        infile = MFOPEN(kpse_file_name, FOPEN_RBIN_MODE);
+    }
+  }
+  if (infile == NULL)
+  {
+    WARN("Can't find file (%s), or it is forbidden to read ...skipping\n", pict);
+    goto cont;
+  }
+  if (check_for_bmp(infile))
+  {
+    do_aptex_bmp(infile, kpse_file_name, bbox);
+    goto cont;
+  }
+  if (check_for_jpeg(infile))
+  {
+    do_aptex_jpeg(infile, kpse_file_name, bbox);
+    goto cont;
+  }
+  if (check_for_jp2(infile))
+  {
+    do_aptex_jp2(infile, kpse_file_name, bbox);
+    goto cont;
+  }
+  if (check_for_pdf(infile))
+  {
+    pdf_files_init();
+    pdf_set_version(PDF_VERSION_MAX);
+    do_aptex_pdf(infile, kpse_file_name, bbox);
+    pdf_files_close();
+    goto cont;
+  }
+#ifdef HAVE_LIBPNG
+  if (check_for_png(infile))
+  {
+    do_aptex_png(infile, kpse_file_name, bbox);
+    goto cont;
+  }
+#endif /* HAVE_LIBPNG */
+  WARN("Can't handle file type for file named %s\n", pict);
+  bbox->llx = 0.0;
+  bbox->lly = 0.0;
+  bbox->urx = 0.0;
+  bbox->ury = 0.0;
+cont:
+  if (kpse_file_name)
+    RELEASE(kpse_file_name);
+  if (infile)
+    MFCLOSE(infile);
+}
+#endif /* LIBDPX */



More information about the tex-live-commits mailing list