diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-09-15 21:18:43 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-09-15 21:18:43 +0000 |
commit | b48ee037bd610ca845b3d7e070fb73284083423f (patch) | |
tree | 2cb5bf32fa459b3f3bde84aca83ab45eb4c7a661 | |
parent | 1256fc8fd7b2e80c314e3a36c41012b70abf92f5 (diff) |
Cleanup. Remove duplicated code. Reorganize initialization process (S. Hirata).
git-svn-id: svn://tug.org/texlive/trunk@48671 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Build/source/texk/dvipdfm-x/ChangeLog | 7 | ||||
-rwxr-xr-x | Build/source/texk/dvipdfm-x/configure | 22 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/configure.ac | 2 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dpxutil.c | 110 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dpxutil.h | 8 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvi.c | 123 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvi.h | 3 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvipdfmx.c | 247 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfdoc.c | 121 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfdoc.h | 132 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfencrypt.c | 80 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfencrypt.h | 9 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.c | 38 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdffont.h | 2 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfobj.c | 10 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/pdfobj.h | 7 | ||||
-rw-r--r-- | Build/source/texk/dvipdfm-x/xbb.c | 2 |
17 files changed, 468 insertions, 455 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index 509eec7ab2f..b2cd7940c9d 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,10 @@ +2018-09-16 Shunsaku Hirata <shunsaku.hirata74@gmail.com> + + * dpxutil.[ch], dvi.[ch], dvipdfmx.c, pdfdoc.[ch], pdfencrypt.[ch], + pdffont.[ch], xbb.c: Remove duplicated code. Reorganize + initialization process. Use struct for passing options. + * configure.ac: Version 20180916. + 2018-09-14 Shunsaku Hirata <shunsaku.hirata74@gmail.com> * agl.[ch], bmpimage.c, cid.[ch], cidtype0.[ch], cidtype2.[ch], diff --git a/Build/source/texk/dvipdfm-x/configure b/Build/source/texk/dvipdfm-x/configure index 22a7aaab08a..cbf175976ff 100755 --- a/Build/source/texk/dvipdfm-x/configure +++ b/Build/source/texk/dvipdfm-x/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for dvipdfm-x (TeX Live) 20180914. +# Generated by GNU Autoconf 2.69 for dvipdfm-x (TeX Live) 20180916. # # Report bugs to <tex-k@tug.org>. # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='dvipdfm-x (TeX Live)' PACKAGE_TARNAME='dvipdfm-x--tex-live-' -PACKAGE_VERSION='20180914' -PACKAGE_STRING='dvipdfm-x (TeX Live) 20180914' +PACKAGE_VERSION='20180916' +PACKAGE_STRING='dvipdfm-x (TeX Live) 20180916' PACKAGE_BUGREPORT='tex-k@tug.org' PACKAGE_URL='' @@ -1350,7 +1350,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures dvipdfm-x (TeX Live) 20180914 to adapt to many kinds of systems. +\`configure' configures dvipdfm-x (TeX Live) 20180916 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1421,7 +1421,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20180914:";; + short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20180916:";; esac cat <<\_ACEOF @@ -1551,7 +1551,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -dvipdfm-x (TeX Live) configure 20180914 +dvipdfm-x (TeX Live) configure 20180916 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2390,7 +2390,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by dvipdfm-x (TeX Live) $as_me 20180914, which was +It was created by dvipdfm-x (TeX Live) $as_me 20180916, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -8075,7 +8075,7 @@ fi # Define the identity of the package. PACKAGE='dvipdfm-x--tex-live-' - VERSION='20180914' + VERSION='20180916' cat >>confdefs.h <<_ACEOF @@ -14744,7 +14744,7 @@ Usage: $0 [OPTIONS] Report bugs to <bug-libtool@gnu.org>." lt_cl_version="\ -dvipdfm-x (TeX Live) config.lt 20180914 +dvipdfm-x (TeX Live) config.lt 20180916 configured by $0, generated by GNU Autoconf 2.69. Copyright (C) 2011 Free Software Foundation, Inc. @@ -16624,7 +16624,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by dvipdfm-x (TeX Live) $as_me 20180914, which was +This file was extended by dvipdfm-x (TeX Live) $as_me 20180916, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -16694,7 +16694,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -dvipdfm-x (TeX Live) config.status 20180914 +dvipdfm-x (TeX Live) config.status 20180916 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/Build/source/texk/dvipdfm-x/configure.ac b/Build/source/texk/dvipdfm-x/configure.ac index 5ed24c5fb07..f0a3b7eb09e 100644 --- a/Build/source/texk/dvipdfm-x/configure.ac +++ b/Build/source/texk/dvipdfm-x/configure.ac @@ -7,7 +7,7 @@ dnl This file is free software; the copyright holder dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl -AC_INIT([dvipdfm-x (TeX Live)], [20180914], [tex-k@tug.org]) +AC_INIT([dvipdfm-x (TeX Live)], [20180916], [tex-k@tug.org]) AC_PREREQ([2.65]) AC_CONFIG_SRCDIR([agl.c]) AC_CONFIG_AUX_DIR([../../build-aux]) diff --git a/Build/source/texk/dvipdfm-x/dpxutil.c b/Build/source/texk/dvipdfm-x/dpxutil.c index e16ab74e563..8f884b98219 100644 --- a/Build/source/texk/dvipdfm-x/dpxutil.c +++ b/Build/source/texk/dvipdfm-x/dpxutil.c @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2002-2018 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> @@ -69,6 +69,114 @@ max4 (double x1, double x2, double x3, double x4) return v; } + +#if defined(_MSC_VER) +#define strtoll _strtoi64 +#endif + +/* If an environment variable SOURCE_DATE_EPOCH is correctly defined like + * SOURCE_DATE_EPOCH=1456304492, then returns this value, to be used as the + * 'current time', otherwise returns INVALID_EPOCH_VALUE (= (time_t)-1). + * In the case of Microsoft Visual Studio 2010, the value should be less + * than 32535291600. + */ + +time_t +dpx_util_get_unique_time_if_given(void) +{ + const char *source_date_epoch; + int64_t epoch; + char *endptr; + time_t ret = INVALID_EPOCH_VALUE; + + source_date_epoch = getenv("SOURCE_DATE_EPOCH"); + if (source_date_epoch) { + errno = 0; + epoch = strtoll(source_date_epoch, &endptr, 10); + if (!(epoch < 0 || *endptr != '\0' || errno != 0)) { + ret = (time_t) epoch; +#if defined(_MSC_VER) + if (ret > 32535291599ULL) + ret = 32535291599ULL; +#endif + } + } + return ret; +} + + +#ifndef HAVE_TM_GMTOFF +#ifndef HAVE_TIMEZONE + +/* auxiliary function to compute timezone offset on + systems that do not support the tm_gmtoff in struct tm, + or have a timezone variable. Such as i386-solaris. */ + +static int32_t +compute_timezone_offset() +{ + time_t now; + struct tm tm; + struct tm local; + time_t gmtoff; + + now = get_unique_time_if_given(); + if (now == INVALID_EPOCH_VALUE) { + now = time(NULL); + localtime_r(&now, &local); + gmtime_r(&now, &tm); + return (mktime(&local) - mktime(&tm)); + } else { + return(0); + } +} + +#endif /* HAVE_TIMEZONE */ +#endif /* HAVE_TM_GMTOFF */ + +/* + * Docinfo + */ +int +dpx_util_format_asn_date (char *date_string, int need_timezone) +{ + int32_t tz_offset; + time_t current_time; + struct tm *bd_time; + + current_time = dpx_util_get_unique_time_if_given(); + if (current_time == INVALID_EPOCH_VALUE) { + time(¤t_time); + bd_time = localtime(¤t_time); + +#ifdef HAVE_TM_GMTOFF + tz_offset = bd_time->tm_gmtoff; +#else +# ifdef HAVE_TIMEZONE + tz_offset = -timezone; +# else + tz_offset = compute_timezone_offset(); +# endif /* HAVE_TIMEZONE */ +#endif /* HAVE_TM_GMTOFF */ + } else { + bd_time = gmtime(¤t_time); + tz_offset = 0; + } + if (need_timezone) { + sprintf(date_string, "D:%04d%02d%02d%02d%02d%02d%c%02d'%02d'", + bd_time->tm_year + 1900, bd_time->tm_mon + 1, bd_time->tm_mday, + bd_time->tm_hour, bd_time->tm_min, bd_time->tm_sec, + (tz_offset > 0) ? '+' : '-', abs(tz_offset) / 3600, + (abs(tz_offset) / 60) % 60); + } else { + sprintf(date_string, "D:%04d%02d%02d%02d%02d%02d", + bd_time->tm_year + 1900, bd_time->tm_mon + 1, bd_time->tm_mday, + bd_time->tm_hour, bd_time->tm_min, bd_time->tm_sec); + } + + return strlen(date_string); +} + void skip_white_spaces (unsigned char **s, unsigned char *endptr) { diff --git a/Build/source/texk/dvipdfm-x/dpxutil.h b/Build/source/texk/dvipdfm-x/dpxutil.h index 79fae682f84..8268659917f 100644 --- a/Build/source/texk/dvipdfm-x/dpxutil.h +++ b/Build/source/texk/dvipdfm-x/dpxutil.h @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2002-2018 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> @@ -23,6 +23,8 @@ #ifndef _DPXUTIL_H_ #define _DPXUTIL_H_ +#include <time.h> + #undef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #undef MAX @@ -33,6 +35,10 @@ extern double min4(double v1, double v2, double v3, double v4); extern double max4(double v1, double v2, double v3, double v4); +#define INVALID_EPOCH_VALUE ((time_t)-1) +extern time_t dpx_util_get_unique_time_if_given (void); +extern int dpx_util_format_asn_date (char *date_string, int need_timezone); + #ifndef is_space #define is_space(c) ((c) == ' ' || (c) == '\t' || (c) == '\f' || \ (c) == '\r' || (c) == '\n' || (c) == '\0') diff --git a/Build/source/texk/dvipdfm-x/dvi.c b/Build/source/texk/dvipdfm-x/dvi.c index 25ba3ffd397..10c9ccd890f 100644 --- a/Build/source/texk/dvipdfm-x/dvi.c +++ b/Build/source/texk/dvipdfm-x/dvi.c @@ -42,11 +42,11 @@ #include "mfileio.h" #include "numbers.h" #include "dpxconf.h" +#include "dpxutil.h" #include "pdfdev.h" #include "pdfdoc.h" #include "pdfparse.h" -#include "pdfencrypt.h" #include "pdfresource.h" #include "pdfdraw.h" @@ -2252,18 +2252,76 @@ read_length (double *vp, double mag, const char **pp, const char *endptr) return error; } +static int +scan_special_encrypt (int *key_bits, int32_t *permission, char *opassword, char *upassword, + const char **curptr, const char *endptr) +{ + int error = 0; + const char *p = *curptr; + + skip_white(&p, endptr); + + opassword[0] = '\0'; + upassword[0] = '\0'; + while (!error && p < endptr) { + char *kp = parse_c_ident(&p, endptr); + if (!kp) + break; + else { + pdf_obj *obj; + skip_white(&p, endptr); + if (!strcmp(kp, "ownerpw")) { + if ((obj = parse_pdf_string(&p, endptr))) { + if (pdf_string_value(obj)) + strncpy(opassword, pdf_string_value(obj), sizeof(opassword)-1); + pdf_release_obj(obj); + } else + error = -1; + } else if (!strcmp(kp, "userpw")) { + if ((obj = parse_pdf_string(&p, endptr))) { + if (pdf_string_value(obj)) + strncpy(upassword, pdf_string_value(obj), sizeof(upassword)-1); + pdf_release_obj(obj); + } else + error = -1; + } else if (!strcmp(kp, "length")) { + if ((obj = parse_pdf_number(&p, endptr)) && PDF_OBJ_NUMBERTYPE(obj)) { + *key_bits = (unsigned) pdf_number_value(obj); + } else + error = -1; + if (obj) + pdf_release_obj(obj); + } else if (!strcmp(kp, "perm")) { + if ((obj = parse_pdf_number(&p, endptr)) && PDF_OBJ_NUMBERTYPE(obj)) { + *permission = (unsigned) pdf_number_value(obj); + } else + error = -1; + if (obj) + pdf_release_obj(obj); + } else + error = -1; + RELEASE(kp); + } + skip_white(&p, endptr); + } + *curptr = p; + + return error; +} static int -scan_special (double *wd, double *ht, double *xo, double *yo, int *lm, +scan_special (int has_paper_option, int has_encrypt_option, + double *wd, double *ht, double *xo, double *yo, int *lm, int *majorversion, int *minorversion, - int *do_enc, int *key_bits, int32_t *permission, - char *owner_pw, char *user_pw, + int *enable_encryption, int *key_bits, int32_t *permission, + char *opassword, char *upassword, 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; @@ -2384,49 +2442,10 @@ 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") && do_enc) { - *do_enc = 1; - *owner_pw = *user_pw = 0; - while (!error && p < endptr) { - char *kp = parse_c_ident(&p, endptr); - if (!kp) - break; - else { - pdf_obj *obj; - skip_white(&p, endptr); - if (!strcmp(kp, "ownerpw")) { - if ((obj = parse_pdf_string(&p, endptr))) { - if (pdf_string_value(obj)) - strncpy(owner_pw, pdf_string_value(obj), MAX_PWD_LEN); - pdf_release_obj(obj); - } else - error = -1; - } else if (!strcmp(kp, "userpw")) { - if ((obj = parse_pdf_string(&p, endptr))) { - if (pdf_string_value(obj)) - strncpy(user_pw, pdf_string_value(obj), MAX_PWD_LEN); - pdf_release_obj(obj); - } else - error = -1; - } else if (!strcmp(kp, "length")) { - if ((obj = parse_pdf_number(&p, endptr)) && PDF_OBJ_NUMBERTYPE(obj)) { - *key_bits = (unsigned) pdf_number_value(obj); - } else - error = -1; - if (obj) - pdf_release_obj(obj); - } else if (!strcmp(kp, "perm")) { - if ((obj = parse_pdf_number(&p, endptr)) && PDF_OBJ_NUMBERTYPE(obj)) { - *permission = (unsigned) pdf_number_value(obj); - } else - error = -1; - if (obj) - pdf_release_obj(obj); - } else - error = -1; - RELEASE(kp); - } - skip_white(&p, endptr); + } else if (ns_pdf && !strcmp(q, "encrypt")) { + if (!has_encrypt_option) { + *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); @@ -2434,12 +2453,19 @@ scan_special (double *wd, double *ht, double *xo, double *yo, int *lm, RELEASE(q); } + /* Recover papersizes specified via command line option */ + if (has_paper_option) { + *wd = width; + *ht = height; + } + return error; } void dvi_scan_specials (int page_no, + int has_paper_option, int has_encrypt_option, double *page_width, double *page_height, double *x_offset, double *y_offset, int *landscape, int *majorversion, int *minorversion, @@ -2488,7 +2514,8 @@ dvi_scan_specials (int page_no, #define buf ((char*)(dvi_page_buffer + dvi_page_buf_index)) if (fread(buf, sizeof(char), size, fp) != size) ERROR("Reading DVI file failed!"); - if (scan_special(page_width, page_height, x_offset, y_offset, landscape, + if (scan_special(has_paper_option, has_encrypt_option, + page_width, page_height, x_offset, y_offset, landscape, majorversion, minorversion, do_enc, key_bits, permission, owner_pw, user_pw, buf, size)) diff --git a/Build/source/texk/dvipdfm-x/dvi.h b/Build/source/texk/dvipdfm-x/dvi.h index efcaf69292e..f1f4930d8c5 100644 --- a/Build/source/texk/dvipdfm-x/dvi.h +++ b/Build/source/texk/dvipdfm-x/dvi.h @@ -69,7 +69,8 @@ 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, - double *width, double *height, + int has_paper_option, int has_encrypt_option, + double *width, double *height, double *x_offset, double *y_offset, int *landscape, int *majorversion, int *minorversion, int *do_enc, int *keybits, int32_t *perm, diff --git a/Build/source/texk/dvipdfm-x/dvipdfmx.c b/Build/source/texk/dvipdfm-x/dvipdfmx.c index 5600d138b42..d58bbac6b0b 100644 --- a/Build/source/texk/dvipdfm-x/dvipdfmx.c +++ b/Build/source/texk/dvipdfm-x/dvipdfmx.c @@ -69,10 +69,9 @@ const char *my_name = "ApTeX"; const char *my_name; #endif /* LIBDPX */ -static int verbose = 0; - -static int opt_flags = 0; +static int verbose = 0; +static int opt_flags = 0; #define OPT_TPIC_TRANSPARENT_FILL (1 << 1) #define OPT_CIDFONT_FIXEDPITCH (1 << 2) #define OPT_FONTMAP_FIRST_MATCH (1 << 3) @@ -80,40 +79,47 @@ static int opt_flags = 0; #define OPT_PDFOBJ_NO_PREDICTOR (1 << 5) #define OPT_PDFOBJ_NO_OBJSTM (1 << 6) -static char ignore_colors = 0; -static double annot_grow = 0.0; -static int bookmark_open = 0; -static double mag = 1.0; -static int font_dpi = 600; -static int really_quiet = 0; +static int pdf_version_major = 1; +static int pdf_version_minor = 5; +static int compression_level = 9; + +static char ignore_colors = 0; +static double annot_grow = 0.0; +static int bookmark_open = 0; +static double mag = 1.0; +static int font_dpi = 600; +static int enable_thumbnail = 0; +static int really_quiet = 0; /* * Precision is essentially limited to 0.01pt. * See, dev_set_string() in pdfdev.c. */ -static int pdfdecimaldigits = 3; +static int pdfdecimaldigits = 3; /* Image cache life in hours */ /* 0 means erase all old images and leave new images */ /* -1 means erase all old images and also erase new images */ /* -2 means ignore image cache (default) */ -static int image_cache_life = -2; +static int image_cache_life = -2; +/* Image format conversion filter template */ +static char *filter_template = NULL; /* Encryption */ static int do_encryption = 0; static int key_bits = 40; static int32_t permission = 0x003C; -/* Object stream */ -static int enable_objstm = 1; - /* Page device */ double paper_width = 595.0; double paper_height = 842.0; static double x_offset = 72.0; static double y_offset = 72.0; int landscape_mode = 0; -static int psize_optionp = 0; -static char *psize_optarg = NULL; + + +/* Command line option takes precedence */ +static int has_paper_option = 0; +static int has_encrypt_option = 0; int always_embed = 0; /* always embed fonts, regardless of licensing flags */ @@ -406,7 +412,7 @@ select_pages (const char *pagespec) static char * getpass (const char *prompt) { - static char pwd_buf[128]; + static char pwd_buf[MAX_PWD_LEN]; size_t i; fputs(prompt, stderr); @@ -427,22 +433,22 @@ getpass (const char *prompt) #endif /* WIN32 */ static int -get_enc_password (char *uplain, char *oplain) +get_enc_password (char *oplain, char *uplain) { char *retry_passwd; while (1) { - strncpy(uplain, getpass("Owner password: "), MAX_PWD_LEN); + strncpy(oplain, getpass("Owner password: "), MAX_PWD_LEN); retry_passwd = getpass("Re-enter owner password: "); - if (!strncmp(uplain, retry_passwd, MAX_PWD_LEN)) + if (!strncmp(oplain, retry_passwd, MAX_PWD_LEN)) break; fputs("Password is not identical.\nTry again.\n", stderr); fflush(stderr); } while (1) { - strncpy(oplain, getpass("User password: "), MAX_PWD_LEN); + strncpy(uplain, getpass("User password: "), MAX_PWD_LEN); retry_passwd = getpass("Re-enter user password: "); - if (!strncmp(oplain, retry_passwd, MAX_PWD_LEN)) + if (!strncmp(uplain, retry_passwd, MAX_PWD_LEN)) break; fputs("Password is not identical.\nTry again.\n", stderr); fflush(stderr); @@ -523,13 +529,6 @@ do_args (int argc, char *argv[], const char *source, int unsafe) const char *nnextptr; optind = 1; - /* clear psize_optionp and psize_optarg here, since do_args() - is called several times */ - psize_optionp = 0; - if (psize_optarg) - RELEASE(psize_optarg); - psize_optarg = NULL; - while ((c = getopt_long(argc, argv, optstrig, long_options, NULL)) != -1) { switch(c) { case 'h': case 130: case 131: case 1000: case 'q': case 'v': /* already done */ @@ -547,7 +546,10 @@ do_args (int argc, char *argv[], const char *source, int unsafe) if (unsafe) { WARN("Ignoring \"D\" option for dvipdfmx:config special. (unsafe)"); } else { - set_distiller_template(optarg); + if (filter_template) + RELEASE(filter_template); + filter_template = NEW(strlen(optarg)+1, char); + strcpy(filter_template, optarg); } break; @@ -586,19 +588,12 @@ do_args (int argc, char *argv[], const char *source, int unsafe) break; case 't': - pdf_doc_enable_manual_thumbnails(); + enable_thumbnail = 1; break; case 'p': select_paper(optarg); - /* save data for later use in order to overwrite papersize and - pagesize specials */ - psize_optionp = 1; - /* there may be multiple -p options */ - if (psize_optarg) - RELEASE(psize_optarg); - psize_optarg = NEW(strlen(optarg) + 1, char); - strcpy(psize_optarg, optarg); + has_paper_option = 1; break; case 'c': @@ -626,34 +621,19 @@ do_args (int argc, char *argv[], const char *source, int unsafe) case 'V': { - int version, ver_major, ver_minor; - if (strchr(optarg, '.')) { /* new format X.X */ double tmp = atof(optarg); - ver_major = (int) tmp; - ver_minor = (int) (10 * (tmp - ver_major) + 0.5); + pdf_version_major = (int) tmp; + pdf_version_minor = (int) (10 * (tmp - pdf_version_major) + 0.5); } else { - ver_major = 1; - ver_minor = atoi(optarg); + pdf_version_major = 1; + pdf_version_minor = atoi(optarg); } - version = ver_major * 10 + ver_minor; - if (version < PDF_VERSION_MIN) { - WARN("PDF version %d.%d not supported. Using PDF %d.%d instead.", - ver_major, ver_minor, PDF_VERSION_MIN/10, PDF_VERSION_MIN%10); - ver_minor = PDF_VERSION_MIN; - version = ver_major * 10 + ver_minor; - } else if (version > PDF_VERSION_MAX) { - WARN("PDF version %d.%d not supported. Using PDF %d.%d instead.", - ver_major, ver_minor, PDF_VERSION_MAX/10, PDF_VERSION_MAX%10); - ver_minor = PDF_VERSION_MAX; - version = ver_major * 10 + ver_minor; - } - pdf_set_version(version); break; } case 'z': - pdf_set_compression(atoi(optarg)); + compression_level = atoi(optarg); break; case 'd': @@ -666,6 +646,7 @@ do_args (int argc, char *argv[], const char *source, int unsafe) case 'S': do_encryption = 1; + has_encrypt_option = 1; break; case 'K': @@ -819,10 +800,10 @@ read_config_special (const char **start, const char *end) if (*start < end) { argc += 1; if (**start == '"') { - argv[2] = parse_c_string (start, end); + argv[2] = parse_c_string (start, end); } else - argv[2] = parse_ident (start, end); + argv[2] = parse_ident (start, end); } } do_args (argc, argv, argv0, 1); /* Set to unsafe */ @@ -909,7 +890,8 @@ do_dvi_pages (void) page_width = paper_width; page_height = paper_height; 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); + dvi_scan_specials(page_no, has_paper_option, has_encrypt_option, + &w, &h, &xo, &yo, &lm, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (lm != landscape_mode) { SWAP(w, h); landscape_mode = lm; @@ -1028,8 +1010,12 @@ main (int argc, char *argv[]) #endif /* LIBDPX */ #endif { - double dvi2pts; - char *base; + double dvi2pts; + char *base; + struct pdf_setting settings; + char uplain[MAX_PWD_LEN], oplain[MAX_PWD_LEN]; /* encryption password */ + const char *ids[4] = {NULL, NULL, NULL, NULL}; + #ifdef WIN32 int ac; char **av, *enc; @@ -1116,118 +1102,105 @@ main (int argc, char *argv[]) MESG("%s -> %s\n", dvi_filename ? dvi_filename : "stdin", pdf_filename ? pdf_filename : "stdout"); - pdf_enc_compute_id_string(dvi_filename, pdf_filename); - if (do_encryption) { - char uplain[MAX_PWD_LEN], oplain[MAX_PWD_LEN]; - if (key_bits > 40 && pdf_check_version(1, 4) < 0) - ERROR("Chosen key length requires at least PDF 1.4. " - "Use \"-V 4\" to change."); - get_enc_password(uplain, oplain); - pdf_enc_set_passwd(key_bits, permission, uplain, oplain); - } - if (dpx_conf.compat_mode == dpx_mode_mpost_mode) { x_offset = 0.0; y_offset = 0.0; dvi2pts = 0.01; /* dvi2pts controls accuracy. */ } else { - int version, ver_major = 1, ver_minor = 0; - char owner_pw[MAX_PWD_LEN], user_pw[MAX_PWD_LEN]; /* Dependency between DVI and PDF side is rather complicated... */ dvi2pts = dvi_init(dvi_filename, mag); if (dvi2pts == 0.0) ERROR("dvi_init() failed!"); - pdf_doc_set_creator(dvi_comment()); + ids[3] = dvi_comment(); /* Set PDF Creator entry */ if (do_encryption) { - /* command line takes precedence */ - dvi_scan_specials(0, - &paper_width, &paper_height, - &x_offset, &y_offset, &landscape_mode, - &ver_major, &ver_minor, - NULL, NULL, NULL, NULL, NULL); - /* FIXME: pdf_set_version() should come before ecrcyption setting. - * It's too late to set here... - */ - version = ver_major * 10 + ver_minor; - if (version >= PDF_VERSION_MIN && version <= PDF_VERSION_MAX) { - pdf_set_version(version); - } - } else { - dvi_scan_specials(0, - &paper_width, &paper_height, - &x_offset, &y_offset, &landscape_mode, - &ver_major, &ver_minor, - &do_encryption, &key_bits, &permission, owner_pw, user_pw); - version = ver_major * 10 + ver_minor; - if (version >= PDF_VERSION_MIN && version <= PDF_VERSION_MAX) { - pdf_set_version(version); - } - if (do_encryption) { - if (!(key_bits >= 40 && key_bits <= 128 && (key_bits % 8 == 0)) && - key_bits != 256) - ERROR("Invalid encryption key length specified: %u", key_bits); - else if (key_bits > 40 && pdf_check_version(1, 4) < 0) - ERROR("Chosen key length requires at least PDF 1.4. " \ - "Use \"-V 4\" to change."); - do_encryption = 1; - pdf_enc_set_passwd(key_bits, permission, owner_pw, user_pw); - } - } - /* overwrite previous papersize by that given in -p option */ - if (psize_optionp) { - select_paper(psize_optarg); - RELEASE(psize_optarg); - psize_optarg = NULL; - psize_optionp = 0; + get_enc_password(oplain, uplain); } + dvi_scan_specials(0, has_paper_option, has_encrypt_option, + &paper_width, &paper_height, + &x_offset, &y_offset, &landscape_mode, + &pdf_version_major, &pdf_version_minor, + &do_encryption, &key_bits, &permission, oplain, uplain); + if (landscape_mode) { SWAP(paper_width, paper_height); } } - pdf_files_init(); - - if (opt_flags & OPT_PDFOBJ_NO_OBJSTM) - enable_objstm = 0; + /* 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) { + settings.object.enable_objstm = 0; + } else { + settings.object.enable_objstm = 1; + } + if (opt_flags & OPT_PDFOBJ_NO_PREDICTOR) { + settings.object.enable_predictor = 0; + } else { + settings.object.enable_predictor = 1; + } /* Set default paper size here so that all page's can inherite it. * annot_grow: Margin of annotation. * bookmark_open: Miximal depth of open bookmarks. */ - pdf_open_document(pdf_filename, do_encryption, enable_objstm, - paper_width, paper_height, annot_grow, bookmark_open, - !(opt_flags & OPT_PDFDOC_NO_DEST_REMOVE)); - - /* Ignore_colors placed here since - * they are considered as device's capacity. + settings.media_width = paper_width; + settings.media_height = paper_height; + settings.annot_grow_amount = annot_grow; + settings.outline_open_depth = bookmark_open; + settings.check_gotos = !(opt_flags & OPT_PDFDOC_NO_DEST_REMOVE); + + settings.device.dvi2pts = dvi2pts; + settings.device.precision = pdfdecimaldigits; + settings.device.ignore_colors = ignore_colors; + + set_distiller_template(filter_template); + /* This must come before pdf_open_document where initialization + * of pdf_enc takes place. */ - pdf_init_device(dvi2pts, pdfdecimaldigits, ignore_colors); + { + int version = pdf_version_major * 10 + pdf_version_minor; + pdf_set_version(version); + } + pdf_set_compression(compression_level); + if (enable_thumbnail) + pdf_doc_enable_manual_thumbnails(); + + /* Initialize PDF document creation routine. */ + pdf_open_document(pdf_filename, ids, settings); if (opt_flags & OPT_CIDFONT_FIXEDPITCH) CIDFont_set_flags(CIDFONT_FORCE_FIXEDPITCH); - /* Please move this to spc_init_specials(). */ if (opt_flags & OPT_TPIC_TRANSPARENT_FILL) tpic_set_fill_mode(1); if (translate_origin) mps_set_translate_origin(1); - if (opt_flags & OPT_PDFOBJ_NO_PREDICTOR) - pdf_set_use_predictor(0); /* No prediction */ - if (dpx_conf.compat_mode == dpx_mode_mpost_mode) { do_mps_pages(); } else { do_dvi_pages(); } - pdf_files_close(); - - /* Order of close... */ - pdf_close_device (); - /* pdf_close_document flushes XObject (image) and other resources. */ pdf_close_document(); pdf_close_fontmaps(); /* pdf_font may depend on fontmap. */ diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.c b/Build/source/texk/dvipdfm-x/pdfdoc.c index 5826a006ee7..eca1fad797d 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.c +++ b/Build/source/texk/dvipdfm-x/pdfdoc.c @@ -29,8 +29,6 @@ #include <config.h> #endif -#include <time.h> - #include "system.h" #include "mem.h" #include "error.h" @@ -418,72 +416,6 @@ pdf_doc_set_eop_content (const char *content, unsigned length) return; } -#ifndef HAVE_TM_GMTOFF -#ifndef HAVE_TIMEZONE - -/* auxiliary function to compute timezone offset on - systems that do not support the tm_gmtoff in struct tm, - or have a timezone variable. Such as i386-solaris. */ - -static int32_t -compute_timezone_offset() -{ - time_t now; - struct tm tm; - struct tm local; - time_t gmtoff; - - now = get_unique_time_if_given(); - if (now == INVALID_EPOCH_VALUE) { - now = time(NULL); - localtime_r(&now, &local); - gmtime_r(&now, &tm); - return (mktime(&local) - mktime(&tm)); - } else { - return(0); - } -} - -#endif /* HAVE_TIMEZONE */ -#endif /* HAVE_TM_GMTOFF */ - -/* - * Docinfo - */ -static int -asn_date (char *date_string) -{ - int32_t tz_offset; - time_t current_time; - struct tm *bd_time; - - current_time = get_unique_time_if_given(); - if (current_time == INVALID_EPOCH_VALUE) { - time(¤t_time); - bd_time = localtime(¤t_time); - -#ifdef HAVE_TM_GMTOFF - tz_offset = bd_time->tm_gmtoff; -#else -# ifdef HAVE_TIMEZONE - tz_offset = -timezone; -# else - tz_offset = compute_timezone_offset(); -# endif /* HAVE_TIMEZONE */ -#endif /* HAVE_TM_GMTOFF */ - } else { - bd_time = gmtime(¤t_time); - tz_offset = 0; - } - sprintf(date_string, "D:%04d%02d%02d%02d%02d%02d%c%02d'%02d'", - bd_time->tm_year + 1900, bd_time->tm_mon + 1, bd_time->tm_mday, - bd_time->tm_hour, bd_time->tm_min, bd_time->tm_sec, - (tz_offset > 0) ? '+' : '-', abs(tz_offset) / 3600, - (abs(tz_offset) / 60) % 60); - - return strlen(date_string); -} - static void pdf_doc_init_docinfo (pdf_doc *p) { @@ -547,7 +479,7 @@ pdf_doc_close_docinfo (pdf_doc *p) if (!pdf_lookup_dict(docinfo, "CreationDate")) { char now[32]; - asn_date(now); + dpx_util_format_asn_date(now, 1); pdf_add_dict(docinfo, pdf_new_name ("CreationDate"), pdf_new_string(now, strlen(now))); @@ -2558,23 +2490,23 @@ pdf_doc_add_page_content (const char *buffer, unsigned length) return; } -static char *doccreator = NULL; /* Ugh */ - void -pdf_open_document (const char *filename, - int enable_encrypt, int enable_objstm, - double media_width, double media_height, - double annot_grow_amount, int bookmark_open_depth, - int check_gotos) +pdf_open_document (const char *filename, const char **ids, struct pdf_setting settings) { pdf_doc *p = &pdoc; - pdf_out_init(filename, enable_encrypt, enable_objstm); + pdf_enc_compute_id_string(ids[0], ids[1], ids[2]); + if (settings.enable_encrypt) + pdf_init_encryption(settings.encrypt); + + pdf_out_init(filename, settings.enable_encrypt, + settings.object.enable_objstm, settings.object.enable_predictor); + pdf_files_init(); pdf_doc_init_catalog(p); - p->opt.annot_grow = annot_grow_amount; - p->opt.outline_open_depth = bookmark_open_depth; + p->opt.annot_grow = settings.annot_grow_amount; + p->opt.outline_open_depth = settings.outline_open_depth; pdf_init_resources(); pdf_init_colors(); @@ -2583,21 +2515,20 @@ pdf_open_document (const char *filename, pdf_init_images(); pdf_doc_init_docinfo(p); - if (doccreator) { + if (ids[3]) { pdf_add_dict(p->info, pdf_new_name("Creator"), - pdf_new_string(doccreator, strlen(doccreator))); - RELEASE(doccreator); doccreator = NULL; + pdf_new_string(ids[3], strlen(ids[3]))); } - pdf_doc_init_bookmarks(p, bookmark_open_depth); + pdf_doc_init_bookmarks(p, settings.outline_open_depth); pdf_doc_init_articles (p); - pdf_doc_init_names (p, check_gotos); - pdf_doc_init_page_tree(p, media_width, media_height); + pdf_doc_init_names (p, settings.check_gotos); + pdf_doc_init_page_tree(p, settings.media_width, settings.media_height); pdf_doc_set_bgcolor(NULL); - if (enable_encrypt) { + if (settings.enable_encrypt) { pdf_obj *encrypt = pdf_encrypt_obj(); pdf_set_encrypt(encrypt); pdf_release_obj(encrypt); @@ -2618,27 +2549,20 @@ pdf_open_document (const char *filename, } p->pending_forms = NULL; - - return; -} -void -pdf_doc_set_creator (const char *creator) -{ - if (!creator || - creator[0] == '\0') - return; + pdf_init_device(settings.device.dvi2pts, settings.device.precision, + settings.device.ignore_colors); - doccreator = NEW(strlen(creator)+1, char); - strcpy(doccreator, creator); /* Ugh */ + return; } - void pdf_close_document (void) { pdf_doc *p = &pdoc; + pdf_close_device(); + /* * Following things were kept around so user can add dictionary items. */ @@ -2656,6 +2580,7 @@ pdf_close_document (void) pdf_close_resources(); /* Should be at last. */ + pdf_files_close(); pdf_out_flush(); if (thumb_basename) diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.h b/Build/source/texk/dvipdfm-x/pdfdoc.h index e3d81f46db4..6612fb46480 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.h +++ b/Build/source/texk/dvipdfm-x/pdfdoc.h @@ -26,7 +26,8 @@ #include "pdfobj.h" #include "pdfdev.h" -enum pdf_page_boundary { +enum pdf_page_boundary +{ pdf_page_boundary__auto = 0, pdf_page_boundary_mediabox, pdf_page_boundary_cropbox, @@ -37,40 +38,61 @@ enum pdf_page_boundary { #define PDF_DOC_GRABBING_NEST_MAX 4 -extern void pdf_open_document (const char *filename, - int enable_encrypt, - int enable_objstm, - double media_width, double media_height, - double annot_grow_amount, - int bookmark_open_depth, - int check_gotos); -extern void pdf_close_document (void); +struct pdf_dev_setting { + double dvi2pts; /* conversion unit */ + int precision; /* number of decimal digits kept */ + int ignore_colors; /* 1 for black or white */ +}; +struct pdf_enc_setting { + int key_size; + uint32_t permission; + const char *uplain, *oplain; /* password */ + int use_aes; + int encrypt_metadata; +}; -/* PDF document metadata */ -extern void pdf_doc_set_creator (const char *creator); +struct pdf_obj_setting { + int enable_objstm; + int enable_predictor; +}; +struct pdf_setting +{ + double media_width, media_height; + double annot_grow_amount; + int outline_open_depth; + int check_gotos; + int enable_encrypt; + struct pdf_enc_setting encrypt; + struct pdf_dev_setting device; + struct pdf_obj_setting object; +}; + +extern void pdf_open_document (const char *filename, const char **ids, + struct pdf_setting settings); +extern void pdf_close_document(void); /* They just return PDF dictionary object. * Callers are completely responsible for doing right thing... */ -extern pdf_obj *pdf_doc_get_dictionary (const char *category); -extern pdf_obj *pdf_doc_get_reference (const char *category); +extern pdf_obj *pdf_doc_get_dictionary(const char *category); +extern pdf_obj *pdf_doc_get_reference(const char *category); #define pdf_doc_page_tree() pdf_doc_get_dictionary("Pages") -#define pdf_doc_catalog() pdf_doc_get_dictionary("Catalog") -#define pdf_doc_docinfo() pdf_doc_get_dictionary("Info") -#define pdf_doc_names() pdf_doc_get_dictionary("Names") +#define pdf_doc_catalog() pdf_doc_get_dictionary("Catalog") +#define pdf_doc_docinfo() pdf_doc_get_dictionary("Info") +#define pdf_doc_names() pdf_doc_get_dictionary("Names") #define pdf_doc_this_page() pdf_doc_get_dictionary("@THISPAGE") -extern int pdf_doc_get_page_count (pdf_file *pf); -extern pdf_obj *pdf_doc_get_page (pdf_file *pf, int page_no, enum pdf_page_boundary opt_bbox, - pdf_rect *bbox, pdf_tmatrix *matrix, pdf_obj **resources_p); +extern int pdf_doc_get_page_count(pdf_file *pf); +extern pdf_obj *pdf_doc_get_page(pdf_file *pf, int page_no, enum pdf_page_boundary opt_bbox, + pdf_rect *bbox, pdf_tmatrix *matrix, pdf_obj **resources_p); -extern int pdf_doc_current_page_number (void); -extern pdf_obj *pdf_doc_current_page_resources (void); +extern int pdf_doc_current_page_number(void); +extern pdf_obj *pdf_doc_current_page_resources(void); -extern pdf_obj *pdf_doc_ref_page (unsigned page_no); +extern pdf_obj *pdf_doc_ref_page(unsigned page_no); #define pdf_doc_this_page_ref() pdf_doc_get_reference("@THISPAGE") #define pdf_doc_next_page_ref() pdf_doc_get_reference("@NEXTPAGE") #define pdf_doc_prev_page_ref() pdf_doc_get_reference("@PREVPAGE") @@ -78,57 +100,55 @@ extern pdf_obj *pdf_doc_ref_page (unsigned page_no); /* Not really managing tree... * There should be something for number tree. */ -extern int pdf_doc_add_names (const char *category, - const void *key, int keylen, pdf_obj *value); +extern int pdf_doc_add_names(const char *category, + const void *key, int keylen, pdf_obj *value); -extern void pdf_doc_set_bop_content (const char *str, unsigned length); -extern void pdf_doc_set_eop_content (const char *str, unsigned length); +extern void pdf_doc_set_bop_content(const char *str, unsigned length); +extern void pdf_doc_set_eop_content(const char *str, unsigned length); /* Page */ -extern void pdf_doc_begin_page (double scale, double x_origin, double y_origin); -extern void pdf_doc_end_page (void); +extern void pdf_doc_begin_page(double scale, double x_origin, double y_origin); +extern void pdf_doc_end_page(void); -extern void pdf_doc_set_mediabox (unsigned page_no, const pdf_rect *mediabox); +extern void pdf_doc_set_mediabox(unsigned page_no, const pdf_rect *mediabox); -extern void pdf_doc_add_page_content (const char *buffer, unsigned length); -extern void pdf_doc_add_page_resource (const char *category, - const char *resource_name, pdf_obj *resources); +extern void pdf_doc_add_page_content(const char *buffer, unsigned length); +extern void pdf_doc_add_page_resource(const char *category, + const char *resource_name, pdf_obj *resources); /* Article thread */ -extern void pdf_doc_begin_article (const char *article_id, pdf_obj *info); -extern void pdf_doc_add_bead (const char *article_id, - const char *bead_id, - int page_no, const pdf_rect *rect); +extern void pdf_doc_begin_article(const char *article_id, pdf_obj *info); +extern void pdf_doc_add_bead(const char *article_id, + const char *bead_id, + int page_no, const pdf_rect *rect); /* Bookmarks */ -extern int pdf_doc_bookmarks_up (void); -extern int pdf_doc_bookmarks_down (void); -extern void pdf_doc_bookmarks_add (pdf_obj *dict, int is_open); -extern int pdf_doc_bookmarks_depth (void); - +extern int pdf_doc_bookmarks_up(void); +extern int pdf_doc_bookmarks_down(void); +extern void pdf_doc_bookmarks_add(pdf_obj *dict, int is_open); +extern int pdf_doc_bookmarks_depth(void); /* Returns xobj_id of started xform. */ -extern int pdf_doc_begin_grabbing (const char *ident, - double ref_x, double ref_y, - const pdf_rect *cropbox); -extern void pdf_doc_end_grabbing (pdf_obj *attrib); - +extern int pdf_doc_begin_grabbing(const char *ident, + double ref_x, double ref_y, + const pdf_rect *cropbox); +extern void pdf_doc_end_grabbing(pdf_obj *attrib); /* Annotation */ -extern void pdf_doc_add_annot (unsigned page_no, - const pdf_rect *rect, - pdf_obj *annot_dict, - int new_annot); +extern void pdf_doc_add_annot(unsigned page_no, + const pdf_rect *rect, + pdf_obj *annot_dict, + int new_annot); /* Annotation with auto- clip and line (or page) break */ -extern void pdf_doc_begin_annot (pdf_obj *dict); -extern void pdf_doc_end_annot (void); +extern void pdf_doc_begin_annot(pdf_obj *dict); +extern void pdf_doc_end_annot(void); -extern void pdf_doc_break_annot (void); -extern void pdf_doc_expand_box (const pdf_rect *rect); +extern void pdf_doc_break_annot(void); +extern void pdf_doc_expand_box(const pdf_rect *rect); /* Manual thumbnail */ -extern void pdf_doc_enable_manual_thumbnails (void); +extern void pdf_doc_enable_manual_thumbnails(void); #if 0 /* PageLabels - */ @@ -140,6 +160,6 @@ extern void pdf_doc_set_pagelabel (int page_start, /* Similar to bop_content */ #include "pdfcolor.h" -extern void pdf_doc_set_bgcolor (const pdf_color *color); +extern void pdf_doc_set_bgcolor(const pdf_color *color); #endif /* _PDFDOC_H_ */ diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.c b/Build/source/texk/dvipdfm-x/pdfencrypt.c index 23f4ea5c94b..f34e41c0fc8 100644 --- a/Build/source/texk/dvipdfm-x/pdfencrypt.c +++ b/Build/source/texk/dvipdfm-x/pdfencrypt.c @@ -32,6 +32,8 @@ #include "numbers.h" #include "error.h" #include "dpxconf.h" +#include "dpxutil.h" + #include "pdfobj.h" #include "unicode.h" #include "dpxcrypt.h" @@ -43,6 +45,9 @@ * TODO: Convert password to PDFDocEncoding. SASLPrep stringpref for AESV3. */ +static void pdf_enc_set_passwd (unsigned int bits, unsigned int perm, + const char *oplain, const char *uplain); + /* PDF-2.0 is not published yet. */ #define USE_ADOBE_EXTENSION 1 @@ -82,57 +87,20 @@ static const unsigned char padding_bytes[32] = { 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a }; -static void -pdf_enc_init (int use_aes, int encrypt_metadata) -{ - time_t current_time; - struct pdf_sec *p = &sec_data; - - current_time = get_unique_time_if_given(); - if (current_time == INVALID_EPOCH_VALUE) - current_time = time(NULL); - srand(current_time); /* For AES IV */ - p->setting.use_aes = use_aes; - p->setting.encrypt_metadata = encrypt_metadata; - p->setting.need_adobe_extension = 0; -} - -#define PRODUCER \ -"%s-%s, Copyright 2002-2015 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata" - void -pdf_enc_compute_id_string (char *dviname, char *pdfname) +pdf_enc_compute_id_string (const char *producer, + const char *dviname, const char *pdfname) { struct pdf_sec *p = &sec_data; - char *date_string, *producer; - time_t current_time; - struct tm *bd_time; + char datestr[32]; MD5_CONTEXT md5; - /* FIXME: This should be placed in main() or somewhere. */ - pdf_enc_init(1, 1); - MD5_init(&md5); - - date_string = NEW(15, char); - current_time = get_unique_time_if_given(); - if (current_time == INVALID_EPOCH_VALUE) { - time(¤t_time); - bd_time = localtime(¤t_time); - } else { - bd_time = gmtime(¤t_time); - } - sprintf(date_string, "%04d%02d%02d%02d%02d%02d", - bd_time->tm_year + 1900, bd_time->tm_mon + 1, bd_time->tm_mday, - bd_time->tm_hour, bd_time->tm_min, bd_time->tm_sec); - MD5_write(&md5, (unsigned char *)date_string, strlen(date_string)); - RELEASE(date_string); - - producer = NEW(strlen(PRODUCER)+strlen(my_name)+strlen(VERSION), char); - sprintf(producer, PRODUCER, my_name, VERSION); - MD5_write(&md5, (unsigned char *)producer, strlen(producer)); - RELEASE(producer); - + /* Don't use timezone for compatibility */ + dpx_util_format_asn_date(datestr, 0); + MD5_write(&md5, (unsigned char *)datestr, strlen(datestr)); + if (producer) + MD5_write(&md5, (unsigned char *)producer, strlen(producer)); if (dviname) MD5_write(&md5, (unsigned char *)dviname, strlen(dviname)); if (pdfname) @@ -140,6 +108,26 @@ pdf_enc_compute_id_string (char *dviname, char *pdfname) MD5_final(p->ID, &md5); } +int +pdf_init_encryption (struct pdf_enc_setting settings) +{ + time_t current_time; + struct pdf_sec *p = &sec_data; + + current_time = dpx_util_get_unique_time_if_given(); + if (current_time == INVALID_EPOCH_VALUE) + current_time = time(NULL); + srand(current_time); /* For AES IV */ + p->setting.use_aes = settings.use_aes; + p->setting.encrypt_metadata = settings.encrypt_metadata; + p->setting.need_adobe_extension = 0; + + pdf_enc_set_passwd(settings.key_size, settings.permission, + settings.oplain, settings.uplain); + + return 0; +} + static void passwd_padding (const char *src, unsigned char *dst) { @@ -517,7 +505,7 @@ preproc_password (const char *passwd, char *outbuf, int V) return error; } -void +static void pdf_enc_set_passwd (unsigned int bits, unsigned int perm, const char *oplain, const char *uplain) { diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.h b/Build/source/texk/dvipdfm-x/pdfencrypt.h index 22f548279f1..cc2e0bf9c00 100644 --- a/Build/source/texk/dvipdfm-x/pdfencrypt.h +++ b/Build/source/texk/dvipdfm-x/pdfencrypt.h @@ -24,15 +24,16 @@ #define _PDFENCRYPT_H_ #include "pdfobj.h" +#include "pdfdoc.h" #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 void pdf_enc_compute_id_string (char *dviname, char *pdfname); -extern void pdf_enc_set_label (unsigned label); +extern int pdf_init_encryption (struct pdf_enc_setting); +extern void pdf_enc_set_label (unsigned label); extern void pdf_enc_set_generation (unsigned generation); -extern void pdf_enc_set_passwd (unsigned int size, unsigned int perm, - const char *owner, const char *user); extern void pdf_encrypt_data (const unsigned char *plain, size_t plain_len, unsigned char **cipher, size_t *cipher_len); extern pdf_obj *pdf_encrypt_obj (void); diff --git a/Build/source/texk/dvipdfm-x/pdffont.c b/Build/source/texk/dvipdfm-x/pdffont.c index e50503e94ec..d957977e05c 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.c +++ b/Build/source/texk/dvipdfm-x/pdffont.c @@ -25,7 +25,6 @@ #endif #include <string.h> -#include <time.h> #include "system.h" #include "error.h" @@ -62,41 +61,6 @@ pdf_font_set_dpi (int font_dpi) PKFont_set_dpi(font_dpi); } - -#if defined(_MSC_VER) -#define strtoll _strtoi64 -#endif - -/* If an environment variable SOURCE_DATE_EPOCH is correctly defined like - * SOURCE_DATE_EPOCH=1456304492, then returns this value, to be used as the - * 'current time', otherwise returns INVALID_EPOCH_VALUE (= (time_t)-1). - * In the case of Microsoft Visual Studio 2010, the value should be less - * than 32535291600. - */ - -time_t -get_unique_time_if_given(void) -{ - const char *source_date_epoch; - int64_t epoch; - char *endptr; - time_t ret = INVALID_EPOCH_VALUE; - - source_date_epoch = getenv("SOURCE_DATE_EPOCH"); - if (source_date_epoch) { - errno = 0; - epoch = strtoll(source_date_epoch, &endptr, 10); - if (!(epoch < 0 || *endptr != '\0' || errno != 0)) { - ret = (time_t) epoch; -#if defined(_MSC_VER) - if (ret > 32535291599ULL) - ret = 32535291599ULL; -#endif - } - } - return ret; -} - void pdf_font_make_uniqueTag (char *tag) { @@ -106,7 +70,7 @@ pdf_font_make_uniqueTag (char *tag) if (first) { time_t current_time; - current_time = get_unique_time_if_given(); + current_time = dpx_util_get_unique_time_if_given(); if (current_time == INVALID_EPOCH_VALUE) current_time = time(NULL); srand(current_time); diff --git a/Build/source/texk/dvipdfm-x/pdffont.h b/Build/source/texk/dvipdfm-x/pdffont.h index 0efcce44de5..de6b9cf2b3e 100644 --- a/Build/source/texk/dvipdfm-x/pdffont.h +++ b/Build/source/texk/dvipdfm-x/pdffont.h @@ -55,7 +55,7 @@ extern void pdf_close_fonts (void); * various optical sizes supported in the future. */ extern int pdf_font_findresource (const char *font_name, - double font_scale, fontmap_rec *mrec); + double font_scale, fontmap_rec *mrec); extern int pdf_get_font_subtype (int font_id); extern pdf_obj *pdf_get_font_reference (int font_id); diff --git a/Build/source/texk/dvipdfm-x/pdfobj.c b/Build/source/texk/dvipdfm-x/pdfobj.c index 54a6337848e..f5868f7d69d 100644 --- a/Build/source/texk/dvipdfm-x/pdfobj.c +++ b/Build/source/texk/dvipdfm-x/pdfobj.c @@ -280,12 +280,6 @@ pdf_get_output_file (void) return pdf_output_file; } -void -pdf_set_use_predictor (int bval) -{ - compression_use_predictor = bval ? 1 : 0; -} - static int pdf_version = PDF_VERSION_DEFAULT; void @@ -341,7 +335,8 @@ add_xref_entry (unsigned label, unsigned char type, unsigned int field2, unsigne #define BINARY_MARKER "%\344\360\355\370\n" void -pdf_out_init (const char *filename, int do_encryption, int enable_objstm) +pdf_out_init (const char *filename, + int do_encryption, int enable_objstm, int enable_predictor) { char v; @@ -394,6 +389,7 @@ pdf_out_init (const char *filename, int do_encryption, int enable_objstm) enc_mode = 0; doc_enc_mode = do_encryption; + compression_use_predictor = enable_predictor; } static void diff --git a/Build/source/texk/dvipdfm-x/pdfobj.h b/Build/source/texk/dvipdfm-x/pdfobj.h index b8aea029fc6..a5474a4ba90 100644 --- a/Build/source/texk/dvipdfm-x/pdfobj.h +++ b/Build/source/texk/dvipdfm-x/pdfobj.h @@ -56,7 +56,8 @@ extern void pdf_error_cleanup (void); extern FILE *pdf_get_output_file (void); extern void pdf_out_init (const char *filename, - int enable_encrypt, int enable_objstm); + int enable_encrypt, int enable_objstm, + int enable_predictor); extern void pdf_out_flush (void); extern void pdf_set_version (int version); extern int pdf_get_version (void); @@ -176,7 +177,6 @@ extern int pdf_compare_reference (pdf_obj *ref1, pdf_obj *ref2); */ extern void pdf_set_compression (int level); -extern void pdf_set_use_predictor (int bval); extern void pdf_set_info (pdf_obj *obj); extern void pdf_set_root (pdf_obj *obj); @@ -199,9 +199,6 @@ extern int pdfobj_escape_str (char *buffer, int size, const unsigned char * extern pdf_obj *pdf_new_indirect (pdf_file *pf, unsigned label, unsigned short generation); -extern time_t get_unique_time_if_given(void); -#define INVALID_EPOCH_VALUE ((time_t)-1) - extern int pdf_check_version (int major, int minor); #endif /* _PDFOBJ_H_ */ diff --git a/Build/source/texk/dvipdfm-x/xbb.c b/Build/source/texk/dvipdfm-x/xbb.c index 04a0ed3dc9c..b887d544688 100644 --- a/Build/source/texk/dvipdfm-x/xbb.c +++ b/Build/source/texk/dvipdfm-x/xbb.c @@ -88,7 +88,7 @@ static void do_time(FILE *file) time_t current_time; struct tm *bd_time; - current_time = get_unique_time_if_given(); + current_time = dpx_util_get_unique_time_if_given(); if (current_time == INVALID_EPOCH_VALUE) { time(¤t_time); bd_time = localtime(¤t_time); |