texlive[49467] Build/source/texk/dvipdfm-x: Add a new special

commits+kakuto at tug.org commits+kakuto at tug.org
Fri Dec 21 04:39:51 CET 2018


Revision: 49467
          http://tug.org/svn/texlive?view=revision&revision=49467
Author:   kakuto
Date:     2018-12-21 04:39:51 +0100 (Fri, 21 Dec 2018)
Log Message:
-----------
Add a new special pdf:trailerid (S. Hirata)

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/pdfdoc.c
    trunk/Build/source/texk/dvipdfm-x/pdfdoc.h
    trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c
    trunk/Build/source/texk/dvipdfm-x/pdfencrypt.h
    trunk/Build/source/texk/dvipdfm-x/spc_pdfm.c
    trunk/Build/source/texk/dvipdfm-x/spc_tpic.c
    trunk/Build/source/texk/dvipdfm-x/tfm.c
    trunk/Build/source/texk/dvipdfm-x/tt_gsub.c

Modified: trunk/Build/source/texk/dvipdfm-x/ChangeLog
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/ChangeLog	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/ChangeLog	2018-12-21 03:39:51 UTC (rev 49467)
@@ -1,3 +1,10 @@
+2018-12-21  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
+
+	* dvi.[ch], dvipdfmx.c, pdfdoc.[ch], pdfencrypt.[ch],
+	spc_pdfm.c: Add a new special pdf:trailerid for directly
+	specifying trailer ID.
+	* spc_tpic.c, tfm.c, tt_gsub.c: Avoid compiler warning.
+
 2018-10-12  Shunsaku Hirata  <shunsaku.hirata74 at gmail.com>
 
 	* dvipdfmx.c: Fix a bug that landscape option is not handled

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -2310,10 +2310,46 @@
 }
 
 static int
+scan_special_trailerid (unsigned char *id1, unsigned char *id2,
+                        const char **curptr, const char *endptr)
+{
+  int         error = 0;
+  pdf_obj    *id_array;
+  const char *p = *curptr;
+
+  skip_white(&p, endptr);
+  id_array = parse_pdf_array(&p, endptr, NULL);
+  if (id_array) {
+    if (pdf_array_length(id_array) == 2) {
+      pdf_obj *tmp1, *tmp2;
+      tmp1 = pdf_get_array(id_array, 0);
+      tmp2 = pdf_get_array(id_array, 1);
+      if (PDF_OBJ_STRINGTYPE(tmp1) && pdf_string_length(tmp1) == 16 &&
+          PDF_OBJ_STRINGTYPE(tmp2) && pdf_string_length(tmp2) == 16) {
+        memcpy(id1, pdf_string_value(tmp1), 16);
+        memcpy(id2, pdf_string_value(tmp2), 16);
+      } else {
+        error = -1;
+      }
+    } else {
+      error = -1;
+    }
+    pdf_release_obj(id_array);
+  } else {
+    error = -1;
+  }
+  skip_white(&p, endptr);
+  *curptr = p;
+
+  return error;
+}
+
+static int
 scan_special (double *wd, double *ht, double *xo, double *yo, int *lm,
               int *majorversion, int *minorversion,
               int *enable_encryption, int *key_bits, int32_t *permission,
               char *opassword, char *upassword,
+              int *has_id, unsigned char *id1, unsigned char *id2,
               const char *buf, uint32_t size)
 {
   char  *q;
@@ -2320,7 +2356,6 @@
   const char *p = buf, *endptr;
   int    ns_pdf = 0, ns_dvipdfmx = 0, error = 0;
   double tmp;
-  double width = *wd, height = *ht; /* backup */
 
   endptr = p + size;
 
@@ -2441,11 +2476,19 @@
         *majorversion = (int)strtol(kv, NULL, 10);
         RELEASE(kv);
       }
-    } else if (ns_pdf && !strcmp(q, "encrypt")) {
+    } else if (enable_encryption && ns_pdf && !strcmp(q, "encrypt")) {
       *enable_encryption = 1;
       error = scan_special_encrypt(key_bits, permission, opassword, upassword, &p, endptr);
     } else if (ns_dvipdfmx && !strcmp(q, "config")) {
       read_config_special(&p, endptr);
+    } else if (has_id && id1 && id2 && ns_pdf && !strcmp(q, "trailerid")) {
+      error = scan_special_trailerid(id1, id2, &p, endptr);
+      if (error) {
+        WARN("Invalid argument for pdf:trailerid special.");
+        *has_id = 0;
+      } else {
+        *has_id = 1;
+      } 
     }
     RELEASE(q);
   }
@@ -2460,7 +2503,8 @@
                    double *x_offset, double *y_offset, int *landscape,
                    int *majorversion, int *minorversion,
                    int *do_enc, int *key_bits, int32_t *permission,
-                   char *owner_pw, char *user_pw)
+                   char *owner_pw, char *user_pw,
+                   int *has_id, unsigned char *id1, unsigned char *id2)
 {
   FILE          *fp = dvi_file;
   int32_t        offset;
@@ -2507,6 +2551,7 @@
       if (scan_special(page_width, page_height, x_offset, y_offset, landscape,
                        majorversion, minorversion,
                        do_enc, key_bits, permission, owner_pw, user_pw,
+                       has_id, id1, id2,
                        buf, size))
         WARN("Reading special command failed: \"%.*s\"", size, buf);
 #undef buf

Modified: trunk/Build/source/texk/dvipdfm-x/dvi.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvi.h	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/dvi.h	2018-12-21 03:39:51 UTC (rev 49467)
@@ -73,7 +73,7 @@
                                 double *x_offset, double *y_offset, int *landscape,
                                 int *majorversion, int *minorversion,
                                 int *do_enc, int *keybits, int32_t *perm,
-                                char *opasswd, char *upasswd);
+                                char *opasswd, char *upasswd, int *has_id, unsigned char *id1, unsigned char *id2);
 extern int   dvi_locate_font   (const char *name, spt_t ptsize);
 
 /* link or nolink:

Modified: trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/dvipdfmx.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -39,6 +39,7 @@
 #include "dpxconf.h"
 #include "dpxfile.h"
 #include "dpxutil.h"
+#include "dpxcrypt.h"
 
 #include "dvi.h"
 
@@ -452,6 +453,26 @@
   return 0;
 }
 
+static void
+compute_id_string (unsigned char *id, const char *producer,
+                   const char *dviname, const char *pdfname)
+{
+  char        datestr[32];
+  MD5_CONTEXT md5;
+
+  MD5_init(&md5);
+  /* Don't use timezone for compatibility */
+  dpx_util_format_asn_date(datestr, 0);
+  MD5_write(&md5, (const unsigned char *)datestr, strlen(datestr));
+  if (producer)
+    MD5_write(&md5, (const unsigned char *)producer, strlen(producer));
+  if (dviname)
+    MD5_write(&md5, (const unsigned char *)dviname, strlen(dviname));
+  if (pdfname)
+    MD5_write(&md5, (const unsigned char *)pdfname, strlen(pdfname));
+  MD5_final(id, &md5);
+}
+
 static const char *optstrig = ":hD:r:m:g:x:y:o:s:p:clf:i:qtvV:z:d:I:K:P:O:MSC:Ee";
 
 static struct option long_options[] = {
@@ -892,7 +913,8 @@
         w = page_width; h = page_height; lm = landscape_mode;
         xo = x_offset; yo = y_offset;
         dvi_scan_specials(page_no,
-                          &w, &h, &xo, &yo, &lm, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+                          &w, &h, &xo, &yo, &lm,
+                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         if (lm != landscape_mode) { /* already swapped for the first page */
           SWAP(w, h);
           landscape_mode = lm;
@@ -1015,7 +1037,9 @@
   char              *base;
   struct pdf_setting settings;
   char               uplain[MAX_PWD_LEN+1], oplain[MAX_PWD_LEN+1]; /* encryption password */
-  const char        *ids[4] = {NULL, NULL, NULL, NULL};
+  const char        *creator = NULL;
+  unsigned char      id1[16], id2[16];
+  int                has_id = 0;
 
 #ifdef WIN32
   int ac;
@@ -1112,12 +1136,13 @@
     dvi2pts = dvi_init(dvi_filename, mag);
     if (dvi2pts == 0.0)
       ERROR("dvi_init() failed!");
-    ids[3] = dvi_comment(); /* Set PDF Creator entry */
+    creator = dvi_comment(); /* Set PDF Creator entry */
     dvi_scan_specials(0,
                       &paper_width, &paper_height,
                       &x_offset, &y_offset, &landscape_mode,
                       &pdf_version_major, &pdf_version_minor,
-                      &do_encryption, &key_bits, &permission, oplain, uplain);
+                      &do_encryption, &key_bits, &permission, oplain, uplain,
+                      &has_id, id1, id2);
   }
 
   /* Command-line options take precedence */
@@ -1132,13 +1157,8 @@
 
   /* Encryption and Other Settings */
   {
-#define PRODUCER \
-"%s-%s, Copyright 2002-2015 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata"
-    char producer[256];
-
     memset(&settings.encrypt, 0, sizeof(struct pdf_enc_setting));
     settings.enable_encrypt = do_encryption;
-    sprintf(producer, PRODUCER, my_name, VERSION);
     settings.encrypt.use_aes          = 1;
     settings.encrypt.encrypt_metadata = 1;
     settings.encrypt.key_size   = key_bits;
@@ -1145,9 +1165,6 @@
     settings.encrypt.permission = permission;
     settings.encrypt.uplain     = uplain;
     settings.encrypt.oplain     = oplain;
-    ids[0] = producer;
-    ids[1] = dvi_filename;
-    ids[2] = pdf_filename;
   }
 
   if (opt_flags & OPT_PDFOBJ_NO_OBJSTM) {
@@ -1189,8 +1206,18 @@
   if (enable_thumbnail)
     pdf_doc_enable_manual_thumbnails();
 
+  if (!has_id) {
+#define PRODUCER \
+"%s-%s, Copyright 2002-2015 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata"
+    char producer[256];
+    
+    sprintf(producer, PRODUCER, my_name, VERSION);
+    compute_id_string(id1, producer, dvi_filename, pdf_filename);
+    memcpy(id2, id1, 16);
+  }
+
   /* Initialize PDF document creation routine. */
-  pdf_open_document(pdf_filename, ids, settings);
+  pdf_open_document(pdf_filename, creator, id1, id2, settings);
 
   if (opt_flags & OPT_CIDFONT_FIXEDPITCH)
     CIDFont_set_flags(CIDFONT_FORCE_FIXEDPITCH);

Modified: trunk/Build/source/texk/dvipdfm-x/pdfdoc.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfdoc.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/pdfdoc.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -2491,13 +2491,14 @@
 }
 
 void
-pdf_open_document (const char *filename, const char **ids, struct pdf_setting settings)
+pdf_open_document (const char *filename,
+                   const char *creator, const unsigned char *id1, const unsigned char *id2,
+                   struct pdf_setting settings)
 {
   pdf_doc *p = &pdoc;
 
-  pdf_enc_compute_id_string(ids[0], ids[1], ids[2]);
   if (settings.enable_encrypt)
-    pdf_init_encryption(settings.encrypt);
+    pdf_init_encryption(settings.encrypt, id1);
 
   pdf_out_init(filename, settings.enable_encrypt,
                settings.object.enable_objstm, settings.object.enable_predictor);
@@ -2515,10 +2516,10 @@
   pdf_init_images();
 
   pdf_doc_init_docinfo(p);
-  if (ids[3]) {
+  if (creator) {
     pdf_add_dict(p->info,
                  pdf_new_name("Creator"),
-                 pdf_new_string(ids[3], strlen(ids[3])));
+                 pdf_new_string(creator, strlen(creator)));
   }
 
   pdf_doc_init_bookmarks(p, settings.outline_open_depth);
@@ -2533,8 +2534,14 @@
     pdf_set_encrypt(encrypt);
     pdf_release_obj(encrypt);
   }
-  pdf_set_id(pdf_enc_id_array());
+  if (id1 && id2) {
+    pdf_obj *id_obj = pdf_new_array();
 
+    pdf_add_array(id_obj, pdf_new_string(id1, 16));
+    pdf_add_array(id_obj, pdf_new_string(id2, 16));
+    pdf_set_id(id_obj);
+  }
+
   /* Create a default name for thumbnail image files */
   if (manual_thumb_enabled) {
     if (strlen(filename) > 4 &&

Modified: trunk/Build/source/texk/dvipdfm-x/pdfdoc.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfdoc.h	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/pdfdoc.h	2018-12-21 03:39:51 UTC (rev 49467)
@@ -69,7 +69,9 @@
     struct pdf_obj_setting object;
 };
 
-extern void pdf_open_document (const char *filename, const char **ids,
+extern void pdf_open_document (const char *filename,
+                               const char *creator,
+                               const unsigned char *id1, const unsigned char *id2,
                                struct pdf_setting settings);
 extern void pdf_close_document(void);
 

Modified: trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/pdfencrypt.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -87,33 +87,17 @@
   0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a
 };
 
-void
-pdf_enc_compute_id_string (const char *producer,
-                           const char *dviname, const char *pdfname)
-{
-  struct pdf_sec *p = &sec_data;
-  char            datestr[32];
-  MD5_CONTEXT     md5;
-
-  MD5_init(&md5);
-  /* Don't use timezone for compatibility */
-  dpx_util_format_asn_date(datestr, 0);
-  MD5_write(&md5, (const unsigned char *)datestr, strlen(datestr));
-  if (producer)
-    MD5_write(&md5, (const unsigned char *)producer, strlen(producer));
-  if (dviname)
-    MD5_write(&md5, (const unsigned char *)dviname, strlen(dviname));
-  if (pdfname)
-    MD5_write(&md5, (const unsigned char *)pdfname, strlen(pdfname));
-  MD5_final(p->ID, &md5);
-}
-
 int
-pdf_init_encryption (struct pdf_enc_setting settings)
+pdf_init_encryption (struct pdf_enc_setting settings, const unsigned char *trailer_id)
 {
   time_t          current_time;
   struct pdf_sec *p = &sec_data;
 
+  if (trailer_id) {
+    memcpy(p->ID, trailer_id, 16);
+  } else {
+    memset(p->ID, 0, 16);
+  }
   current_time = dpx_util_get_unique_time_if_given();
   if (current_time == INVALID_EPOCH_VALUE)
     current_time = time(NULL);
@@ -748,17 +732,6 @@
   return doc_encrypt;
 }
 
-pdf_obj *pdf_enc_id_array (void)
-{
-  struct pdf_sec *p = &sec_data;
-  pdf_obj *id = pdf_new_array();
-
-  pdf_add_array(id, pdf_new_string(p->ID, 16));
-  pdf_add_array(id, pdf_new_string(p->ID, 16));
-
-  return id;
-}
-
 void pdf_enc_set_label (unsigned label)
 {
   struct pdf_sec *p = &sec_data;

Modified: trunk/Build/source/texk/dvipdfm-x/pdfencrypt.h
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/pdfencrypt.h	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/pdfencrypt.h	2018-12-21 03:39:51 UTC (rev 49467)
@@ -28,10 +28,7 @@
 
 #define MAX_PWD_LEN 127
 
-extern void pdf_enc_compute_id_string (const char *producer,
-                                       const char *dviname, const char *pdfname);
-extern pdf_obj *pdf_enc_id_array (void);
-extern int  pdf_init_encryption  (struct pdf_enc_setting);
+extern int  pdf_init_encryption  (struct pdf_enc_setting, const unsigned char *trailer_id);
 extern void pdf_enc_set_label      (unsigned label);
 extern void pdf_enc_set_generation (unsigned generation);
 extern void pdf_encrypt_data (const unsigned char *plain, size_t plain_len,

Modified: trunk/Build/source/texk/dvipdfm-x/spc_pdfm.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/spc_pdfm.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/spc_pdfm.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -2061,6 +2061,7 @@
   {"encrypt",      spc_handler_pdfm_do_nothing},
 
   {"pageresources", spc_handler_pdfm_pageresources},
+  {"trailerid", spc_handler_pdfm_do_nothing},
 };
 
 int

Modified: trunk/Build/source/texk/dvipdfm-x/spc_tpic.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/spc_tpic.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/spc_tpic.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -177,7 +177,7 @@
 {
   pdf_obj *dict;
   char     resname[32];
-  char     buf[32];
+  char     buf[256];
   int      alp, len = 0;
 
   if (a > 0.0) {

Modified: trunk/Build/source/texk/dvipdfm-x/tfm.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/tfm.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/tfm.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -446,7 +446,8 @@
 }
 
 #ifndef WITHOUT_ASCII_PTEX
-unsigned int get_unsigned_triple_kanji(FILE *file)
+static unsigned int
+get_unsigned_triple_kanji(FILE *file)
 {
   unsigned int triple = get_unsigned_byte(file);
   triple = (triple << 8) | get_unsigned_byte(file);

Modified: trunk/Build/source/texk/dvipdfm-x/tt_gsub.c
===================================================================
--- trunk/Build/source/texk/dvipdfm-x/tt_gsub.c	2018-12-21 01:23:59 UTC (rev 49466)
+++ trunk/Build/source/texk/dvipdfm-x/tt_gsub.c	2018-12-21 03:39:51 UTC (rev 49467)
@@ -1553,7 +1553,7 @@
   return retval;
 }
 
-int
+static int
 gsub_find (otl_gsub *gsub_list,
                  const char *script,
                  const char *language,



More information about the tex-live-commits mailing list