diff options
Diffstat (limited to 'Build/source/texk/dvipdfm-x/dvipdfmx.c')
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvipdfmx.c | 247 |
1 files changed, 110 insertions, 137 deletions
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. */ |