From 0866741b109fde4a874b71685f92220fad324270 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Sun, 6 Aug 2017 07:02:46 +0000 Subject: dvipdfm-x: Support /Rotate page attribute in PDF inclusion (by S. Hirata). git-svn-id: svn://tug.org/texlive/trunk@44963 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/ChangeLog | 6 ++++ Build/source/texk/dvipdfm-x/configure | 22 ++++++------- Build/source/texk/dvipdfm-x/configure.ac | 2 +- Build/source/texk/dvipdfm-x/dpxutil.c | 22 ++++++++++++- Build/source/texk/dvipdfm-x/dpxutil.h | 5 ++- Build/source/texk/dvipdfm-x/epdf.c | 27 +++++---------- Build/source/texk/dvipdfm-x/pdfdoc.c | 56 +++++++++++++++++++++++++------- Build/source/texk/dvipdfm-x/pdfdoc.h | 4 +-- Build/source/texk/dvipdfm-x/pdfximage.c | 24 +++++++++++--- Build/source/texk/dvipdfm-x/xbb.c | 25 +++++++++++++- 10 files changed, 142 insertions(+), 51 deletions(-) (limited to 'Build/source/texk') diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog index 010dfbba3ee..412232ffb93 100644 --- a/Build/source/texk/dvipdfm-x/ChangeLog +++ b/Build/source/texk/dvipdfm-x/ChangeLog @@ -1,3 +1,9 @@ +2017-08-06 Shunsaku Hirata + + * dpxutil.[ch], epdf.c, pdfdoc.[ch], pdfximage.c, xbb.c: + Support for /Rotate page attribute in PDF inclusion. + configure.ac: Version 20170806. + 2017-06-27 Akira Kakuto * pdfdoc.c: Simplify the change in pdf_doc_get_page(). diff --git a/Build/source/texk/dvipdfm-x/configure b/Build/source/texk/dvipdfm-x/configure index a9688343232..939162f2b06 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) 20170627. +# Generated by GNU Autoconf 2.69 for dvipdfm-x (TeX Live) 20170806. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='dvipdfm-x (TeX Live)' PACKAGE_TARNAME='dvipdfm-x--tex-live-' -PACKAGE_VERSION='20170627' -PACKAGE_STRING='dvipdfm-x (TeX Live) 20170627' +PACKAGE_VERSION='20170806' +PACKAGE_STRING='dvipdfm-x (TeX Live) 20170806' 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) 20170627 to adapt to many kinds of systems. +\`configure' configures dvipdfm-x (TeX Live) 20170806 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) 20170627:";; + short | recursive ) echo "Configuration of dvipdfm-x (TeX Live) 20170806:";; 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 20170627 +dvipdfm-x (TeX Live) configure 20170806 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 20170627, which was +It was created by dvipdfm-x (TeX Live) $as_me 20170806, 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='20170627' + VERSION='20170806' cat >>confdefs.h <<_ACEOF @@ -14744,7 +14744,7 @@ Usage: $0 [OPTIONS] Report bugs to ." lt_cl_version="\ -dvipdfm-x (TeX Live) config.lt 20170627 +dvipdfm-x (TeX Live) config.lt 20170806 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 20170627, which was +This file was extended by dvipdfm-x (TeX Live) $as_me 20170806, 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 20170627 +dvipdfm-x (TeX Live) config.status 20170806 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 ed083e9d6b2..1cf05b723bc 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)], [20170627], [tex-k@tug.org]) +AC_INIT([dvipdfm-x (TeX Live)], [20170806], [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 af4008c93e9..e16ab74e563 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-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -49,6 +49,26 @@ xtoi (char c) return -1; } +double +min4 (double x1, double x2, double x3, double x4) +{ + double v = x1; + if (x2 < v) v = x2; + if (x3 < v) v = x3; + if (x4 < v) v = x4; + return v; +} + +double +max4 (double x1, double x2, double x3, double x4) +{ + double v = x1; + if (x2 > v) v = x2; + if (x3 > v) v = x3; + if (x4 > v) v = x4; + return v; +} + 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 e99920eb44f..79fae682f84 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-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -30,6 +30,9 @@ #undef ABS #define ABS(a) (((a) < 0) ? -(a) : (a)) +extern double min4(double v1, double v2, double v3, double v4); +extern double max4(double v1, double v2, double v3, double v4); + #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/epdf.c b/Build/source/texk/dvipdfm-x/epdf.c index 533c1e0cdec..3f7258abdfb 100644 --- a/Build/source/texk/dvipdfm-x/epdf.c +++ b/Build/source/texk/dvipdfm-x/epdf.c @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2007-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2007-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -51,13 +51,7 @@ #include "epdf.h" static int rect_equal (pdf_obj *rect1, pdf_obj *rect2); -#if 0 -#if HAVE_ZLIB -#include -static int add_stream_flate (pdf_obj *dst, const void *data, int len); -#endif -static int concat_stream (pdf_obj *dst, pdf_obj *src); -#endif + /* * From PDFReference15_v6.pdf (p.119 and p.834) * @@ -314,9 +308,6 @@ pdf_get_page_obj (pdf_file *pf, int page_no, } if (rotate) { - if (pdf_number_value(rotate) != 0.0) - WARN("<< /Rotate %d >> found. (Not supported yet)", - (int)pdf_number_value(rotate)); pdf_release_obj(rotate); rotate = NULL; } @@ -422,7 +413,7 @@ pdf_include_page (pdf_ximage *ximage, options.page_no = 1; page = pdf_doc_get_page(pf, options.page_no, options.bbox_type, - &info.bbox, &resources); + &info.bbox, &info.matrix, &resources); if(!page) goto error_silent; @@ -512,12 +503,12 @@ pdf_include_page (pdf_ximage *ximage, pdf_add_dict(contents_dict, pdf_new_name("BBox"), bbox); matrix = pdf_new_array(); - pdf_add_array(matrix, pdf_new_number(1.0)); - pdf_add_array(matrix, pdf_new_number(0.0)); - pdf_add_array(matrix, pdf_new_number(0.0)); - pdf_add_array(matrix, pdf_new_number(1.0)); - pdf_add_array(matrix, pdf_new_number(0.0)); - pdf_add_array(matrix, pdf_new_number(0.0)); + pdf_add_array(matrix, pdf_new_number(info.matrix.a)); + pdf_add_array(matrix, pdf_new_number(info.matrix.b)); + pdf_add_array(matrix, pdf_new_number(info.matrix.c)); + pdf_add_array(matrix, pdf_new_number(info.matrix.d)); + pdf_add_array(matrix, pdf_new_number(info.matrix.e)); + pdf_add_array(matrix, pdf_new_number(info.matrix.f)); pdf_add_dict(contents_dict, pdf_new_name("Matrix"), matrix); diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.c b/Build/source/texk/dvipdfm-x/pdfdoc.c index 0921924d0bf..cc5e3800499 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.c +++ b/Build/source/texk/dvipdfm-x/pdfdoc.c @@ -979,7 +979,8 @@ pdf_doc_get_page_count (pdf_file *pf) pdf_obj * pdf_doc_get_page (pdf_file *pf, int page_no, int options, /* load options */ - pdf_rect *bbox, pdf_obj **resources_p /* returned values */ + pdf_rect *bbox, pdf_tmatrix *matrix, /* returned value */ + pdf_obj **resources_p /* returned values */ ) { pdf_obj *page_tree = NULL; pdf_obj *resources = NULL, *box = NULL, *rotate = NULL, *medbox = NULL; @@ -1167,15 +1168,6 @@ pdf_doc_get_page (pdf_file *pf, !PDF_OBJ_DICTTYPE(resources)) goto error; - if (PDF_OBJ_NUMBERTYPE(rotate)) { - if (pdf_number_value(rotate)) - WARN("<< /Rotate %d >> found. (Not supported yet)", - (int) pdf_number_value(rotate)); - pdf_release_obj(rotate); - rotate = NULL; - } else if (rotate) - goto error; - { int i; @@ -1216,9 +1208,51 @@ pdf_doc_get_page (pdf_file *pf, } } } - pdf_release_obj(box); + matrix->a = matrix->d = 1.0; + matrix->b = matrix->c = 0.0; + matrix->e = matrix->f = 0.0; + if (PDF_OBJ_NUMBERTYPE(rotate)) { + double deg = pdf_number_value(rotate); + if (deg - (int)deg != 0.0) + WARN("Invalid value specified for /Rotate: %f", deg); + else if (deg != 0.0) { + int rot = (int) deg; + if (rot % 90 != 0.0) { + WARN("Invalid value specified for /Rotate: %f", deg); + } else { + rot = rot % 360; + if (rot < 0) rot += 360; + switch (rot) { + case 90: + matrix->a = matrix->d = 0; + matrix->b = -1; + matrix->c = 1; + matrix->e = bbox->llx - bbox->lly; + matrix->f = bbox->lly + bbox->urx; + break; + case 180: + matrix->a = matrix->d = -1; + matrix->b = matrix->c = 0; + matrix->e = bbox->llx + bbox->urx; + matrix->f = bbox->lly + bbox->ury; + break; + case 270: + matrix->a = matrix->d = 0; + matrix->b = 1; + matrix->c = -1; + matrix->e = bbox->llx + bbox->ury; + matrix->f = bbox->lly - bbox->llx; + break; + } + } + } + pdf_release_obj(rotate); + rotate = NULL; + } else if (rotate) + goto error; + if (resources_p) *resources_p = resources; else if (resources) diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.h b/Build/source/texk/dvipdfm-x/pdfdoc.h index 7eddecb653b..2d5923eedf2 100644 --- a/Build/source/texk/dvipdfm-x/pdfdoc.h +++ b/Build/source/texk/dvipdfm-x/pdfdoc.h @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2007-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2007-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -58,7 +58,7 @@ extern pdf_obj *pdf_doc_get_reference (const char *category); extern int pdf_doc_get_page_count (pdf_file *pf); extern pdf_obj *pdf_doc_get_page (pdf_file *pf, int page_no, int options, - pdf_rect *bbox, pdf_obj **resources_p); + 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); diff --git a/Build/source/texk/dvipdfm-x/pdfximage.c b/Build/source/texk/dvipdfm-x/pdfximage.c index 10be8f34709..1da7f86abd6 100644 --- a/Build/source/texk/dvipdfm-x/pdfximage.c +++ b/Build/source/texk/dvipdfm-x/pdfximage.c @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2007-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2007-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -29,6 +29,7 @@ #include "mem.h" #include "dpxfile.h" +#include "dpxutil.h" #include "pdfobj.h" @@ -552,13 +553,26 @@ void pdf_ximage_set_form (pdf_ximage *I, void *form_info, pdf_obj *resource) { xform_info *info = form_info; + pdf_coord p1, p2, p3, p4; I->subtype = PDF_XOBJECT_TYPE_FORM; - I->attr.bbox.llx = info->bbox.llx; - I->attr.bbox.lly = info->bbox.lly; - I->attr.bbox.urx = info->bbox.urx; - I->attr.bbox.ury = info->bbox.ury; + /* Image's attribute "bbox" here is affected by /Rotate entry of included + * PDF page. + */ + p1.x = info->bbox.llx; p1.y = info->bbox.lly; + pdf_dev_transform(&p1, &info->matrix); + p2.x = info->bbox.urx; p1.y = info->bbox.lly; + pdf_dev_transform(&p2, &info->matrix); + p3.x = info->bbox.urx; p3.y = info->bbox.ury; + pdf_dev_transform(&p3, &info->matrix); + p4.x = info->bbox.llx; p4.y = info->bbox.ury; + pdf_dev_transform(&p4, &info->matrix); + + I->attr.bbox.llx = min4(p1.x, p2.x, p3.x, p4.x); + I->attr.bbox.lly = min4(p1.y, p2.y, p3.y, p4.y); + I->attr.bbox.urx = max4(p1.x, p2.x, p3.x, p4.x); + I->attr.bbox.ury = max4(p1.y, p2.y, p3.y, p4.y); I->reference = pdf_ref_obj(resource); diff --git a/Build/source/texk/dvipdfm-x/xbb.c b/Build/source/texk/dvipdfm-x/xbb.c index ea453b16109..63d1fcffae4 100644 --- a/Build/source/texk/dvipdfm-x/xbb.c +++ b/Build/source/texk/dvipdfm-x/xbb.c @@ -24,6 +24,8 @@ #include #include +#include "dpxutil.h" + #include "numbers.h" #include "system.h" #include "mem.h" @@ -32,6 +34,7 @@ #include "pdfobj.h" #include "pdfdoc.h" #include "pdfparse.h" +#include "pdfdraw.h" #include "bmpimage.h" #include "jpegimage.h" @@ -255,6 +258,8 @@ static void do_pdf (FILE *fp, char *filename) int page_no = Include_Page; int count; pdf_rect bbox; + pdf_tmatrix matrix; + pdf_coord p1, p2, p3, p4; pf = pdf_open(filename, fp); if (!pf) { @@ -262,7 +267,7 @@ static void do_pdf (FILE *fp, char *filename) return; } count = pdf_doc_get_page_count(pf); - page = pdf_doc_get_page(pf, page_no, PageBox, &bbox, NULL); + page = pdf_doc_get_page(pf, page_no, PageBox, &bbox, &matrix, NULL); pdf_close(pf); @@ -270,6 +275,24 @@ static void do_pdf (FILE *fp, char *filename) return; pdf_release_obj(page); + + /* Image's attribute "bbox" here is affected by /Rotate entry of included + * PDF page. + */ + p1.x = bbox.llx; p1.y = bbox.lly; + pdf_dev_transform(&p1, &matrix); + p2.x = bbox.urx; p2.y = bbox.lly; + pdf_dev_transform(&p2, &matrix); + p3.x = bbox.urx; p3.y = bbox.ury; + pdf_dev_transform(&p3, &matrix); + p4.x = bbox.llx; p4.y = bbox.ury; + pdf_dev_transform(&p4, &matrix); + + bbox.llx = min4(p1.x, p2.x, p3.x, p4.x); + bbox.lly = min4(p1.y, p2.y, p3.y, p4.y); + bbox.urx = max4(p1.x, p2.x, p3.x, p4.x); + bbox.ury = max4(p1.y, p2.y, p3.y, p4.y); + write_xbb(filename, bbox.llx, bbox.lly, bbox.urx, bbox.ury, pdf_file_get_version(pf), count); } -- cgit v1.2.3