From 2daa55943e8c636fa3e239259539126821009288 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Fri, 21 Dec 2018 03:39:51 +0000 Subject: Add a new special pdf:trailerid (S. Hirata) git-svn-id: svn://tug.org/texlive/trunk@49467 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/ChangeLog | 7 +++++ Build/source/texk/dvipdfm-x/dvi.c | 51 ++++++++++++++++++++++++++++-- Build/source/texk/dvipdfm-x/dvi.h | 2 +- Build/source/texk/dvipdfm-x/dvipdfmx.c | 53 ++++++++++++++++++++++++-------- Build/source/texk/dvipdfm-x/pdfdoc.c | 19 ++++++++---- Build/source/texk/dvipdfm-x/pdfdoc.h | 4 ++- Build/source/texk/dvipdfm-x/pdfencrypt.c | 39 ++++------------------- Build/source/texk/dvipdfm-x/pdfencrypt.h | 5 +-- Build/source/texk/dvipdfm-x/spc_pdfm.c | 1 + Build/source/texk/dvipdfm-x/spc_tpic.c | 2 +- Build/source/texk/dvipdfm-x/tfm.c | 3 +- Build/source/texk/dvipdfm-x/tt_gsub.c | 2 +- 12 files changed, 124 insertions(+), 64 deletions(-) (limited to 'Build/source') diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index 7844f324a42..66891b5842e 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,10 @@ +2018-12-21 Shunsaku Hirata + + * 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 * dvipdfmx.c: Fix a bug that landscape option is not handled diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c index b9648cf12cf..fb2ce8b351a 100644 --- a/Build/source/texk/dvipdfm-x/dvi.c +++ b/Build/source/texk/dvipdfm-x/dvi.c @@ -2309,18 +2309,53 @@ scan_special_encrypt (int *key_bits, int32_t *permission, char *opassword, char return error; } +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; 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 @@ scan_special (double *wd, double *ht, double *xo, double *yo, int *lm, *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 @@ dvi_scan_specials (int page_no, 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 @@ dvi_scan_specials (int page_no, 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 diff --git a/Build/source/texk/dvipdfm-x/dvi.h b/Build/source/texk/dvipdfm-x/dvi.h index 380f464e5ea..720db74b841 100644 --- a/Build/source/texk/dvipdfm-x/dvi.h +++ b/Build/source/texk/dvipdfm-x/dvi.h @@ -73,7 +73,7 @@ extern void dvi_scan_specials (int page_no, 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: diff --git a/Build/source/texk/dvipdfm-x/dvipdfmx.c b/Build/source/texk/dvipdfm-x/dvipdfmx.c index 6efb3c4a5d1..a804d84c508 100644 --- a/Build/source/texk/dvipdfm-x/dvipdfmx.c +++ b/Build/source/texk/dvipdfm-x/dvipdfmx.c @@ -39,6 +39,7 @@ #include "dpxconf.h" #include "dpxfile.h" #include "dpxutil.h" +#include "dpxcrypt.h" #include "dvi.h" @@ -452,6 +453,26 @@ get_enc_password (char *oplain, char *uplain) 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 @@ do_dvi_pages (void) 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 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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,22 +1157,14 @@ main (int argc, char *argv[]) /* 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; 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 @@ main (int argc, char *argv[]) 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); diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.c b/Build/source/texk/dvipdfm-x/pdfdoc.c index eca1fad797d..b03a62711b7 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.c +++ b/Build/source/texk/dvipdfm-x/pdfdoc.c @@ -2491,13 +2491,14 @@ pdf_doc_add_page_content (const char *buffer, unsigned length) } 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_open_document (const char *filename, const char **ids, struct pdf_setting se 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,7 +2534,13 @@ pdf_open_document (const char *filename, const char **ids, struct pdf_setting se 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) { diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.h b/Build/source/texk/dvipdfm-x/pdfdoc.h index 6612fb46480..0e6f287db42 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.h +++ b/Build/source/texk/dvipdfm-x/pdfdoc.h @@ -69,7 +69,9 @@ struct pdf_setting 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); diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.c b/Build/source/texk/dvipdfm-x/pdfencrypt.c index 229d7d554ac..a1c02561da4 100644 --- a/Build/source/texk/dvipdfm-x/pdfencrypt.c +++ b/Build/source/texk/dvipdfm-x/pdfencrypt.c @@ -87,33 +87,17 @@ static const unsigned char padding_bytes[32] = { 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 @@ pdf_encrypt_obj (void) 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; diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.h b/Build/source/texk/dvipdfm-x/pdfencrypt.h index cc2e0bf9c00..98e4b48e31b 100644 --- a/Build/source/texk/dvipdfm-x/pdfencrypt.h +++ b/Build/source/texk/dvipdfm-x/pdfencrypt.h @@ -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, diff --git a/Build/source/texk/dvipdfm-x/spc_pdfm.c b/Build/source/texk/dvipdfm-x/spc_pdfm.c index ead09a03bf5..4708e2fc674 100644 --- a/Build/source/texk/dvipdfm-x/spc_pdfm.c +++ b/Build/source/texk/dvipdfm-x/spc_pdfm.c @@ -2061,6 +2061,7 @@ static struct spc_handler pdfm_handlers[] = { {"encrypt", spc_handler_pdfm_do_nothing}, {"pageresources", spc_handler_pdfm_pageresources}, + {"trailerid", spc_handler_pdfm_do_nothing}, }; int diff --git a/Build/source/texk/dvipdfm-x/spc_tpic.c b/Build/source/texk/dvipdfm-x/spc_tpic.c index f4c9c99c752..854f589302e 100644 --- a/Build/source/texk/dvipdfm-x/spc_tpic.c +++ b/Build/source/texk/dvipdfm-x/spc_tpic.c @@ -177,7 +177,7 @@ set_fillstyle (double g, double a, int f_ais) { pdf_obj *dict; char resname[32]; - char buf[32]; + char buf[256]; int alp, len = 0; if (a > 0.0) { diff --git a/Build/source/texk/dvipdfm-x/tfm.c b/Build/source/texk/dvipdfm-x/tfm.c index 5336e8d59e5..cf432501bb7 100644 --- a/Build/source/texk/dvipdfm-x/tfm.c +++ b/Build/source/texk/dvipdfm-x/tfm.c @@ -446,7 +446,8 @@ tfm_get_sizes (FILE *tfm_file, off_t tfm_file_size, struct tfm_font *tfm) } #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); diff --git a/Build/source/texk/dvipdfm-x/tt_gsub.c b/Build/source/texk/dvipdfm-x/tt_gsub.c index 25a7b89a5bc..0ae31330749 100644 --- a/Build/source/texk/dvipdfm-x/tt_gsub.c +++ b/Build/source/texk/dvipdfm-x/tt_gsub.c @@ -1553,7 +1553,7 @@ otl_gsub_apply_lig (otl_gsub *gsub_list, return retval; } -int +static int gsub_find (otl_gsub *gsub_list, const char *script, const char *language, -- cgit v1.2.3