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 /Build/source/texk/dvipdfm-x/dvi.c | |
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
Diffstat (limited to 'Build/source/texk/dvipdfm-x/dvi.c')
-rw-r--r-- | Build/source/texk/dvipdfm-x/dvi.c | 123 |
1 files changed, 75 insertions, 48 deletions
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)) |