summaryrefslogtreecommitdiff
path: root/Build/source/texk
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-07-21 05:10:23 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2015-07-21 05:10:23 +0000
commit0b17c5165b50b8184cb459e11ed9298819cb42e0 (patch)
tree11c794e44bf0b63c1339c73eb1cb492cb5d3b9fe /Build/source/texk
parentfb8abbdf8dd3ace56dd0c0d49b8c7cc09cfe27c5 (diff)
dvipdfm-x: Support pagebox=artbox etc. in PDF inclusion. It works with a new dvipdfmx.def.
git-svn-id: svn://tug.org/texlive/trunk@37918 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk')
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog5
-rw-r--r--Build/source/texk/dvipdfm-x/pdfdoc.c223
-rw-r--r--Build/source/texk/dvipdfm-x/pdfobj.h29
-rw-r--r--Build/source/texk/dvipdfm-x/pdfximage.c51
-rw-r--r--Build/source/texk/dvipdfm-x/spc_util.c40
-rw-r--r--Build/source/texk/dvipdfm-x/xbb.c56
6 files changed, 261 insertions, 143 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index ce432aec0cc..3d87b6a8869 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,8 @@
+2015-07-21 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
+
+ * pdfdoc.c, pdfobj.h, pdfximage.c, spc_util.c, xbb.c: Support
+ pagebox=artbox etc. in PDF inclusion. It works with a new dvipdfmx.def.
+
2015-07-18 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* epdf.c, pdfobj.c: Try to embed a PDF image, even if the PDF version
diff --git a/Build/source/texk/dvipdfm-x/pdfdoc.c b/Build/source/texk/dvipdfm-x/pdfdoc.c
index 8e81fb2cd14..262ce8a82ff 100644
--- a/Build/source/texk/dvipdfm-x/pdfdoc.c
+++ b/Build/source/texk/dvipdfm-x/pdfdoc.c
@@ -473,9 +473,9 @@ asn_date (char *date_string)
#endif /* HAVE_TM_GMTOFF */
sprintf(date_string, "D:%04d%02d%02d%02d%02d%02d%c%02ld'%02ld'",
- 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) ? '+' : '-', labs(tz_offset) / 3600,
+ 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) ? '+' : '-', labs(tz_offset) / 3600,
(labs(tz_offset) / 60) % 60);
return strlen(date_string);
@@ -934,7 +934,7 @@ pdf_doc_close_page_tree (pdf_doc *p)
pdf_obj *
pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
- pdf_rect *bbox, pdf_obj **resources_p) {
+ pdf_rect *bbox, pdf_obj **resources_p) {
pdf_obj *page_tree = NULL;
pdf_obj *resources = NULL, *box = NULL, *rotate = NULL;
pdf_obj *catalog;
@@ -951,7 +951,7 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
pdf_obj *tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Count"));
if (!PDF_OBJ_NUMBERTYPE(tmp)) {
if (tmp)
- pdf_release_obj(tmp);
+ pdf_release_obj(tmp);
goto error;
}
count = pdf_number_value(tmp);
@@ -959,9 +959,9 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
if (count_p)
*count_p = count;
if (page_no <= 0 || page_no > count) {
- WARN("Page %ld does not exist.", page_no);
- goto error_silent;
- }
+ WARN("Page %ld does not exist.", page_no);
+ goto error_silent;
+ }
}
/*
@@ -969,69 +969,88 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
* (Note that these entries can be inherited.)
*/
{
+ pdf_obj *art_box = NULL, *trim_box = NULL, *bleed_box = NULL;
pdf_obj *media_box = NULL, *crop_box = NULL, *kids, *tmp;
int depth = PDF_OBJ_MAX_DEPTH;
long page_idx = page_no-1, kids_length = 1, i = 0;
while (--depth && i != kids_length) {
if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "MediaBox")))) {
- if (media_box)
- pdf_release_obj(media_box);
- media_box = tmp;
+ if (media_box)
+ pdf_release_obj(media_box);
+ media_box = tmp;
}
if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "CropBox")))) {
- if (crop_box)
- pdf_release_obj(crop_box);
- crop_box = tmp;
+ if (crop_box)
+ pdf_release_obj(crop_box);
+ crop_box = tmp;
+ }
+
+ if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "ArtBox")))) {
+ if (art_box)
+ pdf_release_obj(art_box);
+ art_box = tmp;
+ }
+
+ if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "TrimBox")))) {
+ if (trim_box)
+ pdf_release_obj(trim_box);
+ trim_box = tmp;
+ }
+
+ if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "BleedBox")))) {
+ if (bleed_box)
+ pdf_release_obj(bleed_box);
+ bleed_box = tmp;
}
if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Rotate")))) {
- if (rotate)
- pdf_release_obj(rotate);
- rotate = tmp;
+ if (rotate)
+ pdf_release_obj(rotate);
+ rotate = tmp;
}
if ((tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Resources")))) {
- if (resources)
- pdf_release_obj(resources);
- resources = tmp;
+ if (resources)
+ pdf_release_obj(resources);
+ resources = tmp;
}
kids = pdf_deref_obj(pdf_lookup_dict(page_tree, "Kids"));
if (!kids)
- break;
+ break;
else if (!PDF_OBJ_ARRAYTYPE(kids)) {
- pdf_release_obj(kids);
- goto error;
+ pdf_release_obj(kids);
+ goto error;
}
kids_length = pdf_array_length(kids);
for (i = 0; i < kids_length; i++) {
- long count;
-
- pdf_release_obj(page_tree);
- page_tree = pdf_deref_obj(pdf_get_array(kids, i));
- if (!PDF_OBJ_DICTTYPE(page_tree))
- goto error;
-
- tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Count"));
- if (PDF_OBJ_NUMBERTYPE(tmp)) {
- /* Pages object */
- count = pdf_number_value(tmp);
- pdf_release_obj(tmp);
- } else if (!tmp)
- /* Page object */
- count = 1;
- else {
- pdf_release_obj(tmp);
- goto error;
- }
-
- if (page_idx < count)
- break;
-
- page_idx -= count;
+ long count;
+
+ pdf_release_obj(page_tree);
+ page_tree = pdf_deref_obj(pdf_get_array(kids, i));
+ if (!PDF_OBJ_DICTTYPE(page_tree))
+ goto error;
+
+ tmp = pdf_deref_obj(pdf_lookup_dict(page_tree, "Count"));
+ if (PDF_OBJ_NUMBERTYPE(tmp)) {
+ /* Pages object */
+ count = pdf_number_value(tmp);
+ pdf_release_obj(tmp);
+ } else if (!tmp)
+ /* Page object */
+ count = 1;
+ else {
+ pdf_release_obj(tmp);
+ goto error;
+ }
+
+ if (page_idx < count)
+ break;
+
+ page_idx -= count;
}
pdf_release_obj(kids);
@@ -1039,24 +1058,74 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
if (!depth || kids_length == i) {
if (media_box)
- pdf_release_obj(media_box);
+ pdf_release_obj(media_box);
if (crop_box)
- pdf_release_obj(crop_box);
+ pdf_release_obj(crop_box);
goto error;
}
-
- if (crop_box)
- box = crop_box;
- else
- if (!(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "ArtBox"))) &&
- !(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "TrimBox"))) &&
- !(box = pdf_deref_obj(pdf_lookup_dict(page_tree, "BleedBox"))) &&
- media_box) {
- box = media_box;
- media_box = NULL;
- }
- if (media_box)
- pdf_release_obj(media_box);
+ if (PageBox == 1) {
+ if (crop_box)
+ box = crop_box;
+ else
+ if (!(box = art_box) &&
+ !(box = trim_box) &&
+ !(box = bleed_box) &&
+ media_box) {
+ box = media_box;
+ media_box = NULL;
+ }
+ if (media_box)
+ pdf_release_obj(media_box);
+ } else if (PageBox == 2) {
+ if (media_box)
+ box = media_box;
+ else
+ if (!(box = art_box) &&
+ !(box = trim_box) &&
+ !(box = bleed_box) &&
+ crop_box) {
+ box = crop_box;
+ }
+ } else if (PageBox == 3) {
+ if (art_box)
+ box = art_box;
+ else
+ if (!(box = crop_box) &&
+ !(box = trim_box) &&
+ !(box = bleed_box) &&
+ media_box) {
+ box = media_box;
+ media_box = NULL;
+ }
+ if (media_box)
+ pdf_release_obj(media_box);
+ } else if (PageBox == 4) {
+ if (trim_box)
+ box = trim_box;
+ else
+ if (!(box = art_box) &&
+ !(box = crop_box) &&
+ !(box = bleed_box) &&
+ media_box) {
+ box = media_box;
+ media_box = NULL;
+ }
+ if (media_box)
+ pdf_release_obj(media_box);
+ } else if (PageBox == 5) {
+ if (bleed_box)
+ box = bleed_box;
+ else
+ if (!(box = art_box) &&
+ !(box = trim_box) &&
+ !(box = crop_box) &&
+ media_box) {
+ box = media_box;
+ media_box = NULL;
+ }
+ if (media_box)
+ pdf_release_obj(media_box);
+ }
}
if (!PDF_OBJ_ARRAYTYPE(box) || pdf_array_length(box) != 4 ||
@@ -1066,7 +1135,7 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
if (PDF_OBJ_NUMBERTYPE(rotate)) {
if (pdf_number_value(rotate))
WARN("<< /Rotate %d >> found. (Not supported yet)",
- (int) pdf_number_value(rotate));
+ (int) pdf_number_value(rotate));
pdf_release_obj(rotate);
rotate = NULL;
} else if (rotate)
@@ -1079,8 +1148,8 @@ pdf_doc_get_page (pdf_file *pf, long page_no, long *count_p,
double x;
pdf_obj *tmp = pdf_deref_obj(pdf_get_array(box, i));
if (!PDF_OBJ_NUMBERTYPE(tmp)) {
- pdf_release_obj(tmp);
- goto error;
+ pdf_release_obj(tmp);
+ goto error;
}
x = pdf_number_value(tmp);
switch (i) {
@@ -1494,11 +1563,11 @@ pdf_doc_add_goto (pdf_obj *annot_dict)
else {
S = pdf_deref_obj(pdf_lookup_dict(A, "S"));
if (PDF_OBJ_UNDEFINED(S))
- goto undefined;
+ goto undefined;
else if (!PDF_OBJ_NAMETYPE(S))
- goto error;
+ goto error;
else if (strcmp(pdf_name_value(S), "GoTo"))
- goto cleanup;
+ goto cleanup;
dict = A;
key = "D";
@@ -1596,15 +1665,15 @@ pdf_doc_close_names (pdf_doc *p)
long count;
if (!pdoc.check_gotos || strcmp(p->names[i].category, "Dests"))
- name_tree = pdf_names_create_tree(data, &count, NULL);
+ name_tree = pdf_names_create_tree(data, &count, NULL);
else {
- name_tree = pdf_names_create_tree(data, &count, &pdoc.gotos);
+ name_tree = pdf_names_create_tree(data, &count, &pdoc.gotos);
- if (verbose && count < data->count)
- MESG("\nRemoved %ld unused PDF destinations\n", data->count-count);
+ if (verbose && count < data->count)
+ MESG("\nRemoved %ld unused PDF destinations\n", data->count-count);
- if (count < pdoc.gotos.count)
- warn_undef_dests(data, &pdoc.gotos);
+ if (count < pdoc.gotos.count)
+ warn_undef_dests(data, &pdoc.gotos);
}
if (name_tree) {
@@ -1649,7 +1718,7 @@ pdf_doc_close_names (pdf_doc *p)
void
pdf_doc_add_annot (unsigned page_no, const pdf_rect *rect,
- pdf_obj *annot_dict, int new_annot)
+ pdf_obj *annot_dict, int new_annot)
{
pdf_doc *p = &pdoc;
pdf_page *page;
@@ -2376,7 +2445,7 @@ static char *doccreator = NULL; /* Ugh */
void
pdf_open_document (const char *filename,
- int do_encryption,
+ int do_encryption,
double media_width, double media_height,
double annot_grow_amount, int bookmark_open_depth,
int check_gotos)
@@ -2691,7 +2760,7 @@ pdf_doc_break_annot (void)
annot_dict = pdf_new_dict();
pdf_merge_dict(annot_dict, breaking_state.annot_dict);
pdf_doc_add_annot(pdf_doc_current_page_number(), &(breaking_state.rect),
- annot_dict, !breaking_state.broken);
+ annot_dict, !breaking_state.broken);
pdf_release_obj(annot_dict);
breaking_state.broken = 1;
diff --git a/Build/source/texk/dvipdfm-x/pdfobj.h b/Build/source/texk/dvipdfm-x/pdfobj.h
index 41f5df3fa10..20b7e83db00 100644
--- a/Build/source/texk/dvipdfm-x/pdfobj.h
+++ b/Build/source/texk/dvipdfm-x/pdfobj.h
@@ -27,15 +27,15 @@
/* Here is the complete list of PDF object types */
-#define PDF_BOOLEAN 1
-#define PDF_NUMBER 2
-#define PDF_STRING 3
-#define PDF_NAME 4
-#define PDF_ARRAY 5
-#define PDF_DICT 6
-#define PDF_STREAM 7
+#define PDF_BOOLEAN 1
+#define PDF_NUMBER 2
+#define PDF_STRING 3
+#define PDF_NAME 4
+#define PDF_ARRAY 5
+#define PDF_DICT 6
+#define PDF_STREAM 7
#define PDF_NULL 8
-#define PDF_INDIRECT 9
+#define PDF_INDIRECT 9
#define PDF_UNDEFINED 10
#define PDF_OBJ_INVALID 0
@@ -140,17 +140,17 @@ extern void pdf_put_dict (pdf_obj *dict, const char *key, pdf_obj *value
* key to allow modification (fix) of key.
*/
extern int pdf_foreach_dict (pdf_obj *dict,
- int (*proc) (pdf_obj *, pdf_obj *, void *),
- void *pdata);
+ int (*proc) (pdf_obj *, pdf_obj *, void *),
+ void *pdata);
extern pdf_obj *pdf_new_stream (int flags);
extern void pdf_add_stream (pdf_obj *stream,
- const void *stream_data_ptr,
- long stream_data_len);
+ const void *stream_data_ptr,
+ long stream_data_len);
#if HAVE_ZLIB
extern int pdf_add_stream_flate (pdf_obj *stream,
- const void *stream_data_ptr,
- long stream_data_len);
+ const void *stream_data_ptr,
+ long stream_data_len);
#endif
extern int pdf_concat_stream (pdf_obj *dst, pdf_obj *src);
extern pdf_obj *pdf_stream_dict (pdf_obj *stream);
@@ -195,4 +195,5 @@ extern int pdfobj_escape_str (char *buffer, int size, const unsigned char *
extern pdf_obj *pdf_new_indirect (pdf_file *pf, unsigned long label, unsigned short generation);
+extern int PageBox;
#endif /* _PDFOBJ_H_ */
diff --git a/Build/source/texk/dvipdfm-x/pdfximage.c b/Build/source/texk/dvipdfm-x/pdfximage.c
index 53c1ddcab8c..7f91ac942fd 100644
--- a/Build/source/texk/dvipdfm-x/pdfximage.c
+++ b/Build/source/texk/dvipdfm-x/pdfximage.c
@@ -112,8 +112,8 @@ static struct ic_ _ic = {
static void
pdf_init_ximage_struct (pdf_ximage *I,
- const char *ident, const char *filename,
- long page_no, pdf_obj *dict)
+ const char *ident, const char *filename,
+ long page_no, pdf_obj *dict)
{
if (ident) {
I->ident = NEW(strlen(ident)+1, char);
@@ -186,18 +186,18 @@ pdf_close_images (void)
for (i = 0; i < ic->count; i++) {
pdf_ximage *I = ic->ximages+i;
if (I->tempfile) {
- /*
- * It is important to remove temporary files at the end because
- * we cache file names. Since we use mkstemp to create them, we
- * might get the same file name again if we delete the first file.
- * (This happens on NetBSD, reported by Jukka Salmi.)
- * We also use this to convert a PS file only once if multiple
- * pages are imported from that file.
- */
- if (_opts.verbose > 1 && keep_cache != 1)
- MESG("pdf_image>> deleting temporary file \"%s\"\n", I->filename);
- dpx_delete_temp_file(I->filename, false); /* temporary filename freed here */
- I->filename = NULL;
+ /*
+ * It is important to remove temporary files at the end because
+ * we cache file names. Since we use mkstemp to create them, we
+ * might get the same file name again if we delete the first file.
+ * (This happens on NetBSD, reported by Jukka Salmi.)
+ * We also use this to convert a PS file only once if multiple
+ * pages are imported from that file.
+ */
+ if (_opts.verbose > 1 && keep_cache != 1)
+ MESG("pdf_image>> deleting temporary file \"%s\"\n", I->filename);
+ dpx_delete_temp_file(I->filename, false); /* temporary filename freed here */
+ I->filename = NULL;
}
pdf_clean_ximage_struct(I);
}
@@ -306,16 +306,18 @@ load_image (const char *ident, const char *fullname, int format, FILE *fp,
{
int result = pdf_include_page(I, fp, fullname);
if (result > 0)
- /* PDF version too recent */
- result = ps_include_page(I, fullname);
+ /* PDF version too recent */
+ result = ps_include_page(I, fullname);
if (result < 0)
- goto error;
+ goto error;
}
if (_opts.verbose)
MESG(",Page:%ld", I->page_no);
I->subtype = PDF_XOBJECT_TYPE_FORM;
break;
- // case IMAGE_TYPE_EPS:
+/*
+ case IMAGE_TYPE_EPS:
+*/
default:
if (_opts.verbose)
MESG(format == IMAGE_TYPE_EPS ? "[PS]" : "[UNKNOWN]");
@@ -366,10 +368,15 @@ pdf_ximage_findresource (const char *ident, long page_no, pdf_obj *dict)
I = &ic->ximages[id];
if (I->ident && !strcmp(ident, I->ident)) {
f = I->filename;
+/*
+ PageBox can be differrent. So we retry.
+*/
+#if 0
if (I->page_no == page_no + (page_no < 0 ? I->page_count+1 : 0) &&
I->attr_dict == dict) {
- return id;
+ return id;
}
+#endif
}
}
@@ -523,8 +530,8 @@ pdf_ximage_set_image (pdf_ximage *I, void *image_info, pdf_obj *resource)
pdf_add_dict(dict, pdf_new_name("Width"), pdf_new_number(info->width));
pdf_add_dict(dict, pdf_new_name("Height"), pdf_new_number(info->height));
if (info->bits_per_component > 0) /* Ignored for JPXDecode filter. FIXME */
- pdf_add_dict(dict, pdf_new_name("BitsPerComponent"),
- pdf_new_number(info->bits_per_component));
+ pdf_add_dict(dict, pdf_new_name("BitsPerComponent"),
+ pdf_new_number(info->bits_per_component));
if (I->attr_dict)
pdf_merge_dict(dict, I->attr_dict);
@@ -581,7 +588,7 @@ pdf_ximage_get_reference (int id)
/* called from pdfdoc.c only for late binding */
int
pdf_ximage_defineresource (const char *ident,
- int subtype, void *info, pdf_obj *resource)
+ int subtype, void *info, pdf_obj *resource)
{
struct ic_ *ic = &_ic;
int id;
diff --git a/Build/source/texk/dvipdfm-x/spc_util.c b/Build/source/texk/dvipdfm-x/spc_util.c
index 869c9486358..56325e17cc9 100644
--- a/Build/source/texk/dvipdfm-x/spc_util.c
+++ b/Build/source/texk/dvipdfm-x/spc_util.c
@@ -533,6 +533,8 @@ spc_read_dimtrns_pdfm (struct spc_env *spe, transform_info *p, struct spc_arg *a
"page",
#define K__HIDE 11
"hide",
+#define K__PAGEBOX 12
+ "pagebox",
NULL
};
double xscale, yscale, rotate;
@@ -638,25 +640,40 @@ spc_read_dimtrns_pdfm (struct spc_env *spe, transform_info *p, struct spc_arg *a
if (!vp)
error = -1;
else {
- if (atof(vp))
- p->flags |= INFO_DO_CLIP;
- else
- p->flags &= ~INFO_DO_CLIP;
- RELEASE(vp);
+ if (atof(vp))
+ p->flags |= INFO_DO_CLIP;
+ else
+ p->flags &= ~INFO_DO_CLIP;
+ RELEASE(vp);
}
break;
case K__PAGE:
{
- double page;
- if (page_no && spc_util_read_numbers(&page, 1, ap) == 1)
- *page_no = (long) page;
- else
- error = -1;
+ double page;
+ if (page_no && spc_util_read_numbers(&page, 1, ap) == 1)
+ *page_no = (long) page;
+ else
+ error = -1;
}
break;
case K__HIDE:
p->flags |= INFO_DO_HIDE;
break;
+ case K__PAGEBOX:
+ {
+ char *q;
+ q = parse_c_ident (&ap->curptr, ap->endptr);
+ if (q) {
+ if (strcasecmp(q, "cropbox") == 0) PageBox = 1;
+ else if (strcasecmp(q, "mediabox") == 0) PageBox = 2;
+ else if (strcasecmp(q, "artbox") == 0) PageBox = 3;
+ else if (strcasecmp(q, "trimbox") == 0) PageBox = 4;
+ else if (strcasecmp(q, "bleedbox") == 0) PageBox = 5;
+ } else {
+ PageBox = 1;
+ }
+ }
+ break;
default:
error = -1;
break;
@@ -682,7 +699,7 @@ spc_read_dimtrns_pdfm (struct spc_env *spe, transform_info *p, struct spc_arg *a
spc_warn(spe, "Can't supply overall scale along with axis scales.");
error = -1;
} else if (has_matrix &&
- (has_scale || has_xscale || has_yscale || has_rotate)) {
+ (has_scale || has_xscale || has_yscale || has_rotate)) {
spc_warn(spe, "Can't supply transform matrix along with scales or rotate. Ignore scales and rotate.");
}
}
@@ -816,4 +833,3 @@ pdf_color_namedcolor (pdf_color *color, const char *name)
}
return -1;
}
-
diff --git a/Build/source/texk/dvipdfm-x/xbb.c b/Build/source/texk/dvipdfm-x/xbb.c
index e802f444f7d..1e9ed1c663a 100644
--- a/Build/source/texk/dvipdfm-x/xbb.c
+++ b/Build/source/texk/dvipdfm-x/xbb.c
@@ -43,6 +43,15 @@
#define XBB_PROGRAM "extractbb"
+int PageBox = 1;
+/*
+ PageBox=1 :cropbox
+ PageBox=2 :mediabox
+ PageBox=3 :artbox
+ PageBox=4 :trimbox
+ PageBox=5 :bleedbox
+*/
+
static long Include_Page = 1;
static void show_version(void)
@@ -57,18 +66,20 @@ static void show_version(void)
static void show_usage(void)
{
- fprintf (stdout, "\nUsage: " XBB_PROGRAM " [-p page] [-q|-v] [-O] [-m|-x] FILE...\n");
- fprintf (stdout, " " XBB_PROGRAM " --help|--version\n");
- fprintf (stdout, "Extract bounding box from PDF, PNG, or JPEG file; default output below.\n");
- fprintf (stdout, "\nOptions:\n");
- fprintf (stdout, " -h | --help\tShow this help message and exit\n");
- fprintf (stdout, " --version\tOutput version information and exit\n");
- fprintf (stdout, " -p page\tSpecify a PDF page to extract bounding box\n");
- fprintf (stdout, " -q\t\tBe quiet\n");
- fprintf (stdout, " -v\t\tBe verbose\n");
- fprintf (stdout, " -O\t\tWrite output to stdout\n");
- fprintf (stdout, " -m\t\tOutput .bb file used in DVIPDFM%s\n", compat_mode ? " (default)" : "");
- fprintf (stdout, " -x\t\tOutput .xbb file used in DVIPDFMx%s\n", compat_mode ? "" : " (default)");
+ printf ("\nUsage: " XBB_PROGRAM " [-B pagebox] [-p page] [-q|-v] [-O] [-m|-x] FILE...\n");
+ printf (" " XBB_PROGRAM " --help|--version\n");
+ printf ("Extract bounding box from PDF, PNG, or JPEG file; default output below.\n");
+ printf ("\nOptions:\n");
+ printf (" -B pagebox\tSpecify a PDF pagebox for bounding box\n");
+ printf (" \tpagebox=cropbox, mediabox, artbox, trimbox, bleedbox\n");
+ printf (" -h | --help\tShow this help message and exit\n");
+ printf (" --version\tOutput version information and exit\n");
+ printf (" -p page\tSpecify a PDF page to extract bounding box\n");
+ printf (" -q\t\tBe quiet\n");
+ printf (" -v\t\tBe verbose\n");
+ printf (" -O\t\tWrite output to stdout\n");
+ printf (" -m\t\tOutput .bb file used in DVIPDFM%s\n", compat_mode ? " (default)" : "");
+ printf (" -x\t\tOutput .xbb file used in DVIPDFMx%s\n", compat_mode ? "" : " (default)");
}
static void usage(void)
@@ -103,7 +114,7 @@ static char *make_xbb_filename(const char *name)
for (i = 0; i < sizeof(extensions) / sizeof(extensions[0]); i++) {
if (strlen(extensions[i]) < strlen(name) &&
- strncmp(name+strlen(name)-strlen(extensions[i]), extensions[i], strlen(extensions[i])) == 0)
+ strncmp(name+strlen(name)-strlen(extensions[i]), extensions[i], strlen(extensions[i])) == 0)
break;
}
if (i == sizeof(extensions) / sizeof(extensions[0])) {
@@ -120,9 +131,9 @@ static char *make_xbb_filename(const char *name)
}
static void write_xbb(char *fname,
- double bbllx_f, double bblly_f,
- double bburx_f, double bbury_f,
- int pdf_version, long pagecount)
+ double bbllx_f, double bblly_f,
+ double bburx_f, double bbury_f,
+ int pdf_version, long pagecount)
{
char *outname = NULL;
FILE *fp = NULL;
@@ -160,7 +171,7 @@ static void write_xbb(char *fname,
* it seems illegal to replace "0.0" by "0".
*/
fprintf(fp, "%%%%HiResBoundingBox: %f %f %f %f\n",
- bbllx_f, bblly_f, bburx_f, bbury_f);
+ bbllx_f, bblly_f, bburx_f, bbury_f);
if (pdf_version >= 0) {
fprintf(fp, "%%%%PDFVersion: 1.%d\n", pdf_version);
fprintf(fp, "%%%%Pages: %ld\n", pagecount);
@@ -256,7 +267,7 @@ static void do_pdf (FILE *fp, char *filename)
pdf_release_obj(page);
write_xbb(filename, bbox.llx, bbox.lly, bbox.urx, bbox.ury,
- pdf_file_get_version(pf), count);
+ pdf_file_get_version(pf), count);
}
int extractbb (int argc, char *argv[])
@@ -285,6 +296,15 @@ int extractbb (int argc, char *argv[])
}
fprintf(stderr, "Unknown option \"%s\"", argv[0]);
usage();
+ case 'B':
+ argc--;
+ argv++;
+ if (strcasecmp (argv[0], "cropbox") == 0) PageBox = 1;
+ else if (strcasecmp (argv[0], "mediabox") == 0) PageBox = 2;
+ else if (strcasecmp (argv[0], "artbox") == 0) PageBox = 3;
+ else if (strcasecmp (argv[0], "trimbox") == 0) PageBox = 4;
+ else if (strcasecmp (argv[0], "bleedbox") == 0) PageBox = 5;
+ break;
case 'O':
xbb_to_file = 0;
break;