diff options
Diffstat (limited to 'source/tools/pdfinfo.c')
-rw-r--r-- | source/tools/pdfinfo.c | 501 |
1 files changed, 250 insertions, 251 deletions
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c index ff05012f..41989982 100644 --- a/source/tools/pdfinfo.c +++ b/source/tools/pdfinfo.c @@ -87,62 +87,62 @@ typedef struct globals_s int psobjs; } globals; -static void closexref(globals *glo) +static void closexref(fz_context *ctx, globals *glo) { int i; if (glo->doc) { - pdf_close_document(glo->doc); + pdf_close_document(ctx, glo->doc); glo->doc = NULL; } if (glo->dim) { for (i = 0; i < glo->dims; i++) - fz_free(glo->ctx, glo->dim[i].u.dim.bbox); - fz_free(glo->ctx, glo->dim); + fz_free(ctx, glo->dim[i].u.dim.bbox); + fz_free(ctx, glo->dim); glo->dim = NULL; glo->dims = 0; } if (glo->font) { - fz_free(glo->ctx, glo->font); + fz_free(ctx, glo->font); glo->font = NULL; glo->fonts = 0; } if (glo->image) { - fz_free(glo->ctx, glo->image); + fz_free(ctx, glo->image); glo->image = NULL; glo->images = 0; } if (glo->shading) { - fz_free(glo->ctx, glo->shading); + fz_free(ctx, glo->shading); glo->shading = NULL; glo->shadings = 0; } if (glo->pattern) { - fz_free(glo->ctx, glo->pattern); + fz_free(ctx, glo->pattern); glo->pattern = NULL; glo->patterns = 0; } if (glo->form) { - fz_free(glo->ctx, glo->form); + fz_free(ctx, glo->form); glo->form = NULL; glo->forms = 0; } if (glo->psobj) { - fz_free(glo->ctx, glo->psobj); + fz_free(ctx, glo->psobj); glo->psobj = NULL; glo->psobjs = 0; } @@ -164,48 +164,48 @@ infousage(void) } static void -showglobalinfo(globals *glo) +showglobalinfo(fz_context *ctx, globals *glo) { pdf_obj *obj; fz_output *out = glo->out; pdf_document *doc = glo->doc; - fz_printf(out, "\nPDF-%d.%d\n", doc->version / 10, doc->version % 10); + fz_printf(ctx, out, "\nPDF-%d.%d\n", doc->version / 10, doc->version % 10); - obj = pdf_dict_gets(pdf_trailer(doc), "Info"); + obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Info"); if (obj) { - fz_printf(out, "Info object (%d %d R):\n", pdf_to_num(obj), pdf_to_gen(obj)); - pdf_output_obj(out, pdf_resolve_indirect(obj), 1); + fz_printf(ctx, out, "Info object (%d %d R):\n", pdf_to_num(ctx, obj), pdf_to_gen(ctx, obj)); + pdf_output_obj(ctx, out, pdf_resolve_indirect(ctx, obj), 1); } - obj = pdf_dict_gets(pdf_trailer(doc), "Encrypt"); + obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Encrypt"); if (obj) { - fz_printf(out, "\nEncryption object (%d %d R):\n", pdf_to_num(obj), pdf_to_gen(obj)); - pdf_output_obj(out, pdf_resolve_indirect(obj), 1); + fz_printf(ctx, out, "\nEncryption object (%d %d R):\n", pdf_to_num(ctx, obj), pdf_to_gen(ctx, obj)); + pdf_output_obj(ctx, out, pdf_resolve_indirect(ctx, obj), 1); } - fz_printf(out, "\nPages: %d\n\n", glo->pagecount); + fz_printf(ctx, out, "\nPages: %d\n\n", glo->pagecount); } static void -gatherdimensions(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj) +gatherdimensions(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj) { fz_rect bbox; pdf_obj *obj; int j; - obj = pdf_dict_gets(pageobj, "MediaBox"); - if (!pdf_is_array(obj)) + obj = pdf_dict_gets(ctx, pageobj, "MediaBox"); + if (!pdf_is_array(ctx, obj)) return; - pdf_to_rect(glo->ctx, obj, &bbox); + pdf_to_rect(ctx, obj, &bbox); - obj = pdf_dict_gets(pageobj, "UserUnit"); - if (pdf_is_real(obj)) + obj = pdf_dict_gets(ctx, pageobj, "UserUnit"); + if (pdf_is_real(ctx, obj)) { - float unit = pdf_to_real(obj); + float unit = pdf_to_real(ctx, obj); bbox.x0 *= unit; bbox.y0 *= unit; bbox.x1 *= unit; @@ -219,24 +219,24 @@ gatherdimensions(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj) if (j < glo->dims) return; - glo->dim = fz_resize_array(glo->ctx, glo->dim, glo->dims+1, sizeof(struct info)); + glo->dim = fz_resize_array(ctx, glo->dim, glo->dims+1, sizeof(struct info)); glo->dims++; glo->dim[glo->dims - 1].page = page; glo->dim[glo->dims - 1].pageref = pageref; glo->dim[glo->dims - 1].pageobj = pageobj; - glo->dim[glo->dims - 1].u.dim.bbox = fz_malloc(glo->ctx, sizeof(fz_rect)); + glo->dim[glo->dims - 1].u.dim.bbox = fz_malloc(ctx, sizeof(fz_rect)); memcpy(glo->dim[glo->dims - 1].u.dim.bbox, &bbox, sizeof (fz_rect)); return; } static void -gatherfonts(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gatherfonts(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *fontdict = NULL; @@ -245,26 +245,26 @@ gatherfonts(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj pdf_obj *name = NULL; int k; - fontdict = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(fontdict)) + fontdict = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, fontdict)) { - fz_warn(glo->ctx, "not a font dict (%d %d R)", pdf_to_num(fontdict), pdf_to_gen(fontdict)); + fz_warn(ctx, "not a font dict (%d %d R)", pdf_to_num(ctx, fontdict), pdf_to_gen(ctx, fontdict)); continue; } - subtype = pdf_dict_gets(fontdict, "Subtype"); - basefont = pdf_dict_gets(fontdict, "BaseFont"); - if (!basefont || pdf_is_null(basefont)) - name = pdf_dict_gets(fontdict, "Name"); + subtype = pdf_dict_gets(ctx, fontdict, "Subtype"); + basefont = pdf_dict_gets(ctx, fontdict, "BaseFont"); + if (!basefont || pdf_is_null(ctx, basefont)) + name = pdf_dict_gets(ctx, fontdict, "Name"); for (k = 0; k < glo->fonts; k++) - if (!pdf_objcmp(glo->font[k].u.font.obj, fontdict)) + if (!pdf_objcmp(ctx, glo->font[k].u.font.obj, fontdict)) break; if (k < glo->fonts) continue; - glo->font = fz_resize_array(glo->ctx, glo->font, glo->fonts+1, sizeof(struct info)); + glo->font = fz_resize_array(ctx, glo->font, glo->fonts+1, sizeof(struct info)); glo->fonts++; glo->font[glo->fonts - 1].page = page; @@ -277,11 +277,11 @@ gatherfonts(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj } static void -gatherimages(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gatherimages(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *imagedict; @@ -294,46 +294,46 @@ gatherimages(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj pdf_obj *altcs; int k; - imagedict = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(imagedict)) + imagedict = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, imagedict)) { - fz_warn(glo->ctx, "not an image dict (%d %d R)", pdf_to_num(imagedict), pdf_to_gen(imagedict)); + fz_warn(ctx, "not an image dict (%d %d R)", pdf_to_num(ctx, imagedict), pdf_to_gen(ctx, imagedict)); continue; } - type = pdf_dict_gets(imagedict, "Subtype"); - if (strcmp(pdf_to_name(type), "Image")) + type = pdf_dict_gets(ctx, imagedict, "Subtype"); + if (strcmp(pdf_to_name(ctx, type), "Image")) continue; - filter = pdf_dict_gets(imagedict, "Filter"); + filter = pdf_dict_gets(ctx, imagedict, "Filter"); altcs = NULL; - cs = pdf_dict_gets(imagedict, "ColorSpace"); - if (pdf_is_array(cs)) + cs = pdf_dict_gets(ctx, imagedict, "ColorSpace"); + if (pdf_is_array(ctx, cs)) { pdf_obj *cses = cs; - cs = pdf_array_get(cses, 0); - if (pdf_is_name(cs) && (!strcmp(pdf_to_name(cs), "DeviceN") || !strcmp(pdf_to_name(cs), "Separation"))) + cs = pdf_array_get(ctx, cses, 0); + if (pdf_is_name(ctx, cs) && (!strcmp(pdf_to_name(ctx, cs), "DeviceN") || !strcmp(pdf_to_name(ctx, cs), "Separation"))) { - altcs = pdf_array_get(cses, 2); - if (pdf_is_array(altcs)) - altcs = pdf_array_get(altcs, 0); + altcs = pdf_array_get(ctx, cses, 2); + if (pdf_is_array(ctx, altcs)) + altcs = pdf_array_get(ctx, altcs, 0); } } - width = pdf_dict_gets(imagedict, "Width"); - height = pdf_dict_gets(imagedict, "Height"); - bpc = pdf_dict_gets(imagedict, "BitsPerComponent"); + width = pdf_dict_gets(ctx, imagedict, "Width"); + height = pdf_dict_gets(ctx, imagedict, "Height"); + bpc = pdf_dict_gets(ctx, imagedict, "BitsPerComponent"); for (k = 0; k < glo->images; k++) - if (!pdf_objcmp(glo->image[k].u.image.obj, imagedict)) + if (!pdf_objcmp(ctx, glo->image[k].u.image.obj, imagedict)) break; if (k < glo->images) continue; - glo->image = fz_resize_array(glo->ctx, glo->image, glo->images+1, sizeof(struct info)); + glo->image = fz_resize_array(ctx, glo->image, glo->images+1, sizeof(struct info)); glo->images++; glo->image[glo->images - 1].page = page; @@ -350,11 +350,11 @@ gatherimages(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj } static void -gatherforms(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gatherforms(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *xobjdict; @@ -365,33 +365,33 @@ gatherforms(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj pdf_obj *reference; int k; - xobjdict = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(xobjdict)) + xobjdict = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, xobjdict)) { - fz_warn(glo->ctx, "not a xobject dict (%d %d R)", pdf_to_num(xobjdict), pdf_to_gen(xobjdict)); + fz_warn(ctx, "not a xobject dict (%d %d R)", pdf_to_num(ctx, xobjdict), pdf_to_gen(ctx, xobjdict)); continue; } - type = pdf_dict_gets(xobjdict, "Subtype"); - if (strcmp(pdf_to_name(type), "Form")) + type = pdf_dict_gets(ctx, xobjdict, "Subtype"); + if (strcmp(pdf_to_name(ctx, type), "Form")) continue; - subtype = pdf_dict_gets(xobjdict, "Subtype2"); - if (!strcmp(pdf_to_name(subtype), "PS")) + subtype = pdf_dict_gets(ctx, xobjdict, "Subtype2"); + if (!strcmp(pdf_to_name(ctx, subtype), "PS")) continue; - group = pdf_dict_gets(xobjdict, "Group"); - groupsubtype = pdf_dict_gets(group, "S"); - reference = pdf_dict_gets(xobjdict, "Ref"); + group = pdf_dict_gets(ctx, xobjdict, "Group"); + groupsubtype = pdf_dict_gets(ctx, group, "S"); + reference = pdf_dict_gets(ctx, xobjdict, "Ref"); for (k = 0; k < glo->forms; k++) - if (!pdf_objcmp(glo->form[k].u.form.obj, xobjdict)) + if (!pdf_objcmp(ctx, glo->form[k].u.form.obj, xobjdict)) break; if (k < glo->forms) continue; - glo->form = fz_resize_array(glo->ctx, glo->form, glo->forms+1, sizeof(struct info)); + glo->form = fz_resize_array(ctx, glo->form, glo->forms+1, sizeof(struct info)); glo->forms++; glo->form[glo->forms - 1].page = page; @@ -404,11 +404,11 @@ gatherforms(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj } static void -gatherpsobjs(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gatherpsobjs(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *xobjdict; @@ -416,27 +416,27 @@ gatherpsobjs(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj pdf_obj *subtype; int k; - xobjdict = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(xobjdict)) + xobjdict = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, xobjdict)) { - fz_warn(glo->ctx, "not a xobject dict (%d %d R)", pdf_to_num(xobjdict), pdf_to_gen(xobjdict)); + fz_warn(ctx, "not a xobject dict (%d %d R)", pdf_to_num(ctx, xobjdict), pdf_to_gen(ctx, xobjdict)); continue; } - type = pdf_dict_gets(xobjdict, "Subtype"); - subtype = pdf_dict_gets(xobjdict, "Subtype2"); - if (strcmp(pdf_to_name(type), "PS") && - (strcmp(pdf_to_name(type), "Form") || strcmp(pdf_to_name(subtype), "PS"))) + type = pdf_dict_gets(ctx, xobjdict, "Subtype"); + subtype = pdf_dict_gets(ctx, xobjdict, "Subtype2"); + if (strcmp(pdf_to_name(ctx, type), "PS") && + (strcmp(pdf_to_name(ctx, type), "Form") || strcmp(pdf_to_name(ctx, subtype), "PS"))) continue; for (k = 0; k < glo->psobjs; k++) - if (!pdf_objcmp(glo->psobj[k].u.form.obj, xobjdict)) + if (!pdf_objcmp(ctx, glo->psobj[k].u.form.obj, xobjdict)) break; if (k < glo->psobjs) continue; - glo->psobj = fz_resize_array(glo->ctx, glo->psobj, glo->psobjs+1, sizeof(struct info)); + glo->psobj = fz_resize_array(ctx, glo->psobj, glo->psobjs+1, sizeof(struct info)); glo->psobjs++; glo->psobj[glo->psobjs - 1].page = page; @@ -447,39 +447,39 @@ gatherpsobjs(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj } static void -gathershadings(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gathershadings(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *shade; pdf_obj *type; int k; - shade = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(shade)) + shade = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, shade)) { - fz_warn(glo->ctx, "not a shading dict (%d %d R)", pdf_to_num(shade), pdf_to_gen(shade)); + fz_warn(ctx, "not a shading dict (%d %d R)", pdf_to_num(ctx, shade), pdf_to_gen(ctx, shade)); continue; } - type = pdf_dict_gets(shade, "ShadingType"); - if (!pdf_is_int(type) || pdf_to_int(type) < 1 || pdf_to_int(type) > 7) + type = pdf_dict_gets(ctx, shade, "ShadingType"); + if (!pdf_is_int(ctx, type) || pdf_to_int(ctx, type) < 1 || pdf_to_int(ctx, type) > 7) { - fz_warn(glo->ctx, "not a shading type (%d %d R)", pdf_to_num(shade), pdf_to_gen(shade)); + fz_warn(ctx, "not a shading type (%d %d R)", pdf_to_num(ctx, shade), pdf_to_gen(ctx, shade)); type = NULL; } for (k = 0; k < glo->shadings; k++) - if (!pdf_objcmp(glo->shading[k].u.shading.obj, shade)) + if (!pdf_objcmp(ctx, glo->shading[k].u.shading.obj, shade)) break; if (k < glo->shadings) continue; - glo->shading = fz_resize_array(glo->ctx, glo->shading, glo->shadings+1, sizeof(struct info)); + glo->shading = fz_resize_array(ctx, glo->shading, glo->shadings+1, sizeof(struct info)); glo->shadings++; glo->shading[glo->shadings - 1].page = page; @@ -491,11 +491,11 @@ gathershadings(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_o } static void -gatherpatterns(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) +gatherpatterns(fz_context *ctx, globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_obj *dict) { int i, n; - n = pdf_dict_len(dict); + n = pdf_dict_len(ctx, dict); for (i = 0; i < n; i++) { pdf_obj *patterndict; @@ -505,49 +505,49 @@ gatherpatterns(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_o pdf_obj *shading = NULL; int k; - patterndict = pdf_dict_get_val(dict, i); - if (!pdf_is_dict(patterndict)) + patterndict = pdf_dict_get_val(ctx, dict, i); + if (!pdf_is_dict(ctx, patterndict)) { - fz_warn(glo->ctx, "not a pattern dict (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); + fz_warn(ctx, "not a pattern dict (%d %d R)", pdf_to_num(ctx, patterndict), pdf_to_gen(ctx, patterndict)); continue; } - type = pdf_dict_gets(patterndict, "PatternType"); - if (!pdf_is_int(type) || pdf_to_int(type) < 1 || pdf_to_int(type) > 2) + type = pdf_dict_gets(ctx, patterndict, "PatternType"); + if (!pdf_is_int(ctx, type) || pdf_to_int(ctx, type) < 1 || pdf_to_int(ctx, type) > 2) { - fz_warn(glo->ctx, "not a pattern type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); + fz_warn(ctx, "not a pattern type (%d %d R)", pdf_to_num(ctx, patterndict), pdf_to_gen(ctx, patterndict)); type = NULL; } - if (pdf_to_int(type) == 1) + if (pdf_to_int(ctx, type) == 1) { - paint = pdf_dict_gets(patterndict, "PaintType"); - if (!pdf_is_int(paint) || pdf_to_int(paint) < 1 || pdf_to_int(paint) > 2) + paint = pdf_dict_gets(ctx, patterndict, "PaintType"); + if (!pdf_is_int(ctx, paint) || pdf_to_int(ctx, paint) < 1 || pdf_to_int(ctx, paint) > 2) { - fz_warn(glo->ctx, "not a pattern paint type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); + fz_warn(ctx, "not a pattern paint type (%d %d R)", pdf_to_num(ctx, patterndict), pdf_to_gen(ctx, patterndict)); paint = NULL; } - tiling = pdf_dict_gets(patterndict, "TilingType"); - if (!pdf_is_int(tiling) || pdf_to_int(tiling) < 1 || pdf_to_int(tiling) > 3) + tiling = pdf_dict_gets(ctx, patterndict, "TilingType"); + if (!pdf_is_int(ctx, tiling) || pdf_to_int(ctx, tiling) < 1 || pdf_to_int(ctx, tiling) > 3) { - fz_warn(glo->ctx, "not a pattern tiling type (%d %d R)", pdf_to_num(patterndict), pdf_to_gen(patterndict)); + fz_warn(ctx, "not a pattern tiling type (%d %d R)", pdf_to_num(ctx, patterndict), pdf_to_gen(ctx, patterndict)); tiling = NULL; } } else { - shading = pdf_dict_gets(patterndict, "Shading"); + shading = pdf_dict_gets(ctx, patterndict, "Shading"); } for (k = 0; k < glo->patterns; k++) - if (!pdf_objcmp(glo->pattern[k].u.pattern.obj, patterndict)) + if (!pdf_objcmp(ctx, glo->pattern[k].u.pattern.obj, patterndict)) break; if (k < glo->patterns) continue; - glo->pattern = fz_resize_array(glo->ctx, glo->pattern, glo->patterns+1, sizeof(struct info)); + glo->pattern = fz_resize_array(ctx, glo->pattern, glo->patterns+1, sizeof(struct info)); glo->patterns++; glo->pattern[glo->patterns - 1].page = page; @@ -562,7 +562,7 @@ gatherpatterns(globals *glo, int page, pdf_obj *pageref, pdf_obj *pageobj, pdf_o } static void -gatherresourceinfo(globals *glo, int page, pdf_obj *rsrc, int show) +gatherresourceinfo(fz_context *ctx, globals *glo, int page, pdf_obj *rsrc, int show) { pdf_obj *pageobj; pdf_obj *pageref; @@ -573,88 +573,88 @@ gatherresourceinfo(globals *glo, int page, pdf_obj *rsrc, int show) pdf_obj *subrsrc; int i; - pageref = pdf_lookup_page_obj(glo->doc, page-1); - pageobj = pdf_resolve_indirect(pageref); + pageref = pdf_lookup_page_obj(ctx, glo->doc, page-1); + pageobj = pdf_resolve_indirect(ctx, pageref); if (!pageobj) - fz_throw(glo->ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); - font = pdf_dict_gets(rsrc, "Font"); + font = pdf_dict_gets(ctx, rsrc, "Font"); if (show & FONTS && font) { int n; - gatherfonts(glo, page, pageref, pageobj, font); - n = pdf_dict_len(font); + gatherfonts(ctx, glo, page, pageref, pageobj, font); + n = pdf_dict_len(ctx, font); for (i = 0; i < n; i++) { - pdf_obj *obj = pdf_dict_get_val(font, i); + pdf_obj *obj = pdf_dict_get_val(ctx, font, i); - subrsrc = pdf_dict_gets(obj, "Resources"); - if (subrsrc && pdf_objcmp(rsrc, subrsrc)) - gatherresourceinfo(glo, page, subrsrc, show); + subrsrc = pdf_dict_gets(ctx, obj, "Resources"); + if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc)) + gatherresourceinfo(ctx, glo, page, subrsrc, show); } } - xobj = pdf_dict_gets(rsrc, "XObject"); + xobj = pdf_dict_gets(ctx, rsrc, "XObject"); if (show & XOBJS && xobj) { int n; - gatherimages(glo, page, pageref, pageobj, xobj); - gatherforms(glo, page, pageref, pageobj, xobj); - gatherpsobjs(glo, page, pageref, pageobj, xobj); - n = pdf_dict_len(xobj); + gatherimages(ctx, glo, page, pageref, pageobj, xobj); + gatherforms(ctx, glo, page, pageref, pageobj, xobj); + gatherpsobjs(ctx, glo, page, pageref, pageobj, xobj); + n = pdf_dict_len(ctx, xobj); for (i = 0; i < n; i++) { - pdf_obj *obj = pdf_dict_get_val(xobj, i); - subrsrc = pdf_dict_gets(obj, "Resources"); - if (subrsrc && pdf_objcmp(rsrc, subrsrc)) - gatherresourceinfo(glo, page, subrsrc, show); + pdf_obj *obj = pdf_dict_get_val(ctx, xobj, i); + subrsrc = pdf_dict_gets(ctx, obj, "Resources"); + if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc)) + gatherresourceinfo(ctx, glo, page, subrsrc, show); } } - shade = pdf_dict_gets(rsrc, "Shading"); + shade = pdf_dict_gets(ctx, rsrc, "Shading"); if (show & SHADINGS && shade) - gathershadings(glo, page, pageref, pageobj, shade); + gathershadings(ctx, glo, page, pageref, pageobj, shade); - pattern = pdf_dict_gets(rsrc, "Pattern"); + pattern = pdf_dict_gets(ctx, rsrc, "Pattern"); if (show & PATTERNS && pattern) { int n; - gatherpatterns(glo, page, pageref, pageobj, pattern); - n = pdf_dict_len(pattern); + gatherpatterns(ctx, glo, page, pageref, pageobj, pattern); + n = pdf_dict_len(ctx, pattern); for (i = 0; i < n; i++) { - pdf_obj *obj = pdf_dict_get_val(pattern, i); - subrsrc = pdf_dict_gets(obj, "Resources"); - if (subrsrc && pdf_objcmp(rsrc, subrsrc)) - gatherresourceinfo(glo, page, subrsrc, show); + pdf_obj *obj = pdf_dict_get_val(ctx, pattern, i); + subrsrc = pdf_dict_gets(ctx, obj, "Resources"); + if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc)) + gatherresourceinfo(ctx, glo, page, subrsrc, show); } } } static void -gatherpageinfo(globals *glo, int page, int show) +gatherpageinfo(fz_context *ctx, globals *glo, int page, int show) { pdf_obj *pageobj; pdf_obj *pageref; pdf_obj *rsrc; - pageref = pdf_lookup_page_obj(glo->doc, page-1); - pageobj = pdf_resolve_indirect(pageref); + pageref = pdf_lookup_page_obj(ctx, glo->doc, page-1); + pageobj = pdf_resolve_indirect(ctx, pageref); if (!pageobj) - fz_throw(glo->ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); + fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page); - gatherdimensions(glo, page, pageref, pageobj); + gatherdimensions(ctx, glo, page, pageref, pageobj); - rsrc = pdf_dict_gets(pageobj, "Resources"); - gatherresourceinfo(glo, page, rsrc, show); + rsrc = pdf_dict_gets(ctx, pageobj, "Resources"); + gatherresourceinfo(ctx, glo, page, rsrc, show); } static void -printinfo(globals *glo, char *filename, int show, int page) +printinfo(fz_context *ctx, globals *glo, char *filename, int show, int page) { int i; int j; @@ -664,85 +664,85 @@ printinfo(globals *glo, char *filename, int show, int page) if (show & DIMENSIONS && glo->dims > 0) { - fz_printf(out, "Mediaboxes (%d):\n", glo->dims); + fz_printf(ctx, out, "Mediaboxes (%d):\n", glo->dims); for (i = 0; i < glo->dims; i++) { - fz_printf(out, PAGE_FMT "[ %g %g %g %g ]\n", + fz_printf(ctx, out, PAGE_FMT "[ %g %g %g %g ]\n", glo->dim[i].page, - pdf_to_num(glo->dim[i].pageref), - pdf_to_gen(glo->dim[i].pageref), + pdf_to_num(ctx, glo->dim[i].pageref), + pdf_to_gen(ctx, glo->dim[i].pageref), glo->dim[i].u.dim.bbox->x0, glo->dim[i].u.dim.bbox->y0, glo->dim[i].u.dim.bbox->x1, glo->dim[i].u.dim.bbox->y1); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & FONTS && glo->fonts > 0) { - fz_printf(out, "Fonts (%d):\n", glo->fonts); + fz_printf(ctx, out, "Fonts (%d):\n", glo->fonts); for (i = 0; i < glo->fonts; i++) { - fz_printf(out, PAGE_FMT "%s '%s' (%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "%s '%s' (%d %d R)\n", glo->font[i].page, - pdf_to_num(glo->font[i].pageref), - pdf_to_gen(glo->font[i].pageref), - pdf_to_name(glo->font[i].u.font.subtype), - pdf_to_name(glo->font[i].u.font.name), - pdf_to_num(glo->font[i].u.font.obj), - pdf_to_gen(glo->font[i].u.font.obj)); + pdf_to_num(ctx, glo->font[i].pageref), + pdf_to_gen(ctx, glo->font[i].pageref), + pdf_to_name(ctx, glo->font[i].u.font.subtype), + pdf_to_name(ctx, glo->font[i].u.font.name), + pdf_to_num(ctx, glo->font[i].u.font.obj), + pdf_to_gen(ctx, glo->font[i].u.font.obj)); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & IMAGES && glo->images > 0) { - fz_printf(out, "Images (%d):\n", glo->images); + fz_printf(ctx, out, "Images (%d):\n", glo->images); for (i = 0; i < glo->images; i++) { char *cs = NULL; char *altcs = NULL; - fz_printf(out, PAGE_FMT "[ ", + fz_printf(ctx, out, PAGE_FMT "[ ", glo->image[i].page, - pdf_to_num(glo->image[i].pageref), - pdf_to_gen(glo->image[i].pageref)); + pdf_to_num(ctx, glo->image[i].pageref), + pdf_to_gen(ctx, glo->image[i].pageref)); - if (pdf_is_array(glo->image[i].u.image.filter)) + if (pdf_is_array(ctx, glo->image[i].u.image.filter)) { - int n = pdf_array_len(glo->image[i].u.image.filter); + int n = pdf_array_len(ctx, glo->image[i].u.image.filter); for (j = 0; j < n; j++) { - pdf_obj *obj = pdf_array_get(glo->image[i].u.image.filter, j); - char *filter = fz_strdup(glo->ctx, pdf_to_name(obj)); + pdf_obj *obj = pdf_array_get(ctx, glo->image[i].u.image.filter, j); + char *filter = fz_strdup(ctx, pdf_to_name(ctx, obj)); if (strstr(filter, "Decode")) *(strstr(filter, "Decode")) = '\0'; - fz_printf(out, "%s%s", + fz_printf(ctx, out, "%s%s", filter, - j == pdf_array_len(glo->image[i].u.image.filter) - 1 ? "" : " "); - fz_free(glo->ctx, filter); + j == pdf_array_len(ctx, glo->image[i].u.image.filter) - 1 ? "" : " "); + fz_free(ctx, filter); } } else if (glo->image[i].u.image.filter) { pdf_obj *obj = glo->image[i].u.image.filter; - char *filter = fz_strdup(glo->ctx, pdf_to_name(obj)); + char *filter = fz_strdup(ctx, pdf_to_name(ctx, obj)); if (strstr(filter, "Decode")) *(strstr(filter, "Decode")) = '\0'; - fz_printf(out, "%s", filter); - fz_free(glo->ctx, filter); + fz_printf(ctx, out, "%s", filter); + fz_free(ctx, filter); } else - fz_printf(out, "Raw"); + fz_printf(ctx, out, "Raw"); if (glo->image[i].u.image.cs) { - cs = fz_strdup(glo->ctx, pdf_to_name(glo->image[i].u.image.cs)); + cs = fz_strdup(ctx, pdf_to_name(ctx, glo->image[i].u.image.cs)); if (!strncmp(cs, "Device", 6)) { @@ -761,7 +761,7 @@ printinfo(globals *glo, char *filename, int show, int page) } if (glo->image[i].u.image.altcs) { - altcs = fz_strdup(glo->ctx, pdf_to_name(glo->image[i].u.image.altcs)); + altcs = fz_strdup(ctx, pdf_to_name(ctx, glo->image[i].u.image.altcs)); if (!strncmp(altcs, "Device", 6)) { @@ -779,25 +779,25 @@ printinfo(globals *glo, char *filename, int show, int page) fz_strlcpy(altcs, "Sep", 4); } - fz_printf(out, " ] %dx%d %dbpc %s%s%s (%d %d R)\n", - pdf_to_int(glo->image[i].u.image.width), - pdf_to_int(glo->image[i].u.image.height), - glo->image[i].u.image.bpc ? pdf_to_int(glo->image[i].u.image.bpc) : 1, + fz_printf(ctx, out, " ] %dx%d %dbpc %s%s%s (%d %d R)\n", + pdf_to_int(ctx, glo->image[i].u.image.width), + pdf_to_int(ctx, glo->image[i].u.image.height), + glo->image[i].u.image.bpc ? pdf_to_int(ctx, glo->image[i].u.image.bpc) : 1, glo->image[i].u.image.cs ? cs : "ImageMask", glo->image[i].u.image.altcs ? " " : "", glo->image[i].u.image.altcs ? altcs : "", - pdf_to_num(glo->image[i].u.image.obj), - pdf_to_gen(glo->image[i].u.image.obj)); + pdf_to_num(ctx, glo->image[i].u.image.obj), + pdf_to_gen(ctx, glo->image[i].u.image.obj)); - fz_free(glo->ctx, cs); - fz_free(glo->ctx, altcs); + fz_free(ctx, cs); + fz_free(ctx, altcs); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & SHADINGS && glo->shadings > 0) { - fz_printf(out, "Shading patterns (%d):\n", glo->shadings); + fz_printf(ctx, out, "Shading patterns (%d):\n", glo->shadings); for (i = 0; i < glo->shadings; i++) { char *shadingtype[] = @@ -812,23 +812,23 @@ printinfo(globals *glo, char *filename, int show, int page) "Tensor patch", }; - fz_printf(out, PAGE_FMT "%s (%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "%s (%d %d R)\n", glo->shading[i].page, - pdf_to_num(glo->shading[i].pageref), - pdf_to_gen(glo->shading[i].pageref), - shadingtype[pdf_to_int(glo->shading[i].u.shading.type)], - pdf_to_num(glo->shading[i].u.shading.obj), - pdf_to_gen(glo->shading[i].u.shading.obj)); + pdf_to_num(ctx, glo->shading[i].pageref), + pdf_to_gen(ctx, glo->shading[i].pageref), + shadingtype[pdf_to_int(ctx, glo->shading[i].u.shading.type)], + pdf_to_num(ctx, glo->shading[i].u.shading.obj), + pdf_to_gen(ctx, glo->shading[i].u.shading.obj)); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & PATTERNS && glo->patterns > 0) { - fz_printf(out, "Patterns (%d):\n", glo->patterns); + fz_printf(ctx, out, "Patterns (%d):\n", glo->patterns); for (i = 0; i < glo->patterns; i++) { - if (pdf_to_int(glo->pattern[i].u.pattern.type) == 1) + if (pdf_to_int(ctx, glo->pattern[i].u.pattern.type) == 1) { char *painttype[] = { @@ -844,67 +844,67 @@ printinfo(globals *glo, char *filename, int show, int page) "Constant/fast tiling", }; - fz_printf(out, PAGE_FMT "Tiling %s %s (%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "Tiling %s %s (%d %d R)\n", glo->pattern[i].page, - pdf_to_num(glo->pattern[i].pageref), - pdf_to_gen(glo->pattern[i].pageref), - painttype[pdf_to_int(glo->pattern[i].u.pattern.paint)], - tilingtype[pdf_to_int(glo->pattern[i].u.pattern.tiling)], - pdf_to_num(glo->pattern[i].u.pattern.obj), - pdf_to_gen(glo->pattern[i].u.pattern.obj)); + pdf_to_num(ctx, glo->pattern[i].pageref), + pdf_to_gen(ctx, glo->pattern[i].pageref), + painttype[pdf_to_int(ctx, glo->pattern[i].u.pattern.paint)], + tilingtype[pdf_to_int(ctx, glo->pattern[i].u.pattern.tiling)], + pdf_to_num(ctx, glo->pattern[i].u.pattern.obj), + pdf_to_gen(ctx, glo->pattern[i].u.pattern.obj)); } else { - fz_printf(out, PAGE_FMT "Shading %d %d R (%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "Shading %d %d R (%d %d R)\n", glo->pattern[i].page, - pdf_to_num(glo->pattern[i].pageref), - pdf_to_gen(glo->pattern[i].pageref), - pdf_to_num(glo->pattern[i].u.pattern.shading), - pdf_to_gen(glo->pattern[i].u.pattern.shading), - pdf_to_num(glo->pattern[i].u.pattern.obj), - pdf_to_gen(glo->pattern[i].u.pattern.obj)); + pdf_to_num(ctx, glo->pattern[i].pageref), + pdf_to_gen(ctx, glo->pattern[i].pageref), + pdf_to_num(ctx, glo->pattern[i].u.pattern.shading), + pdf_to_gen(ctx, glo->pattern[i].u.pattern.shading), + pdf_to_num(ctx, glo->pattern[i].u.pattern.obj), + pdf_to_gen(ctx, glo->pattern[i].u.pattern.obj)); } } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & XOBJS && glo->forms > 0) { - fz_printf(out, "Form xobjects (%d):\n", glo->forms); + fz_printf(ctx, out, "Form xobjects (%d):\n", glo->forms); for (i = 0; i < glo->forms; i++) { - fz_printf(out, PAGE_FMT "Form%s%s%s%s (%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "Form%s%s%s%s (%d %d R)\n", glo->form[i].page, - pdf_to_num(glo->form[i].pageref), - pdf_to_gen(glo->form[i].pageref), + pdf_to_num(ctx, glo->form[i].pageref), + pdf_to_gen(ctx, glo->form[i].pageref), glo->form[i].u.form.groupsubtype ? " " : "", - glo->form[i].u.form.groupsubtype ? pdf_to_name(glo->form[i].u.form.groupsubtype) : "", + glo->form[i].u.form.groupsubtype ? pdf_to_name(ctx, glo->form[i].u.form.groupsubtype) : "", glo->form[i].u.form.groupsubtype ? " Group" : "", glo->form[i].u.form.reference ? " Reference" : "", - pdf_to_num(glo->form[i].u.form.obj), - pdf_to_gen(glo->form[i].u.form.obj)); + pdf_to_num(ctx, glo->form[i].u.form.obj), + pdf_to_gen(ctx, glo->form[i].u.form.obj)); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } if (show & XOBJS && glo->psobjs > 0) { - fz_printf(out, "Postscript xobjects (%d):\n", glo->psobjs); + fz_printf(ctx, out, "Postscript xobjects (%d):\n", glo->psobjs); for (i = 0; i < glo->psobjs; i++) { - fz_printf(out, PAGE_FMT "(%d %d R)\n", + fz_printf(ctx, out, PAGE_FMT "(%d %d R)\n", glo->psobj[i].page, - pdf_to_num(glo->psobj[i].pageref), - pdf_to_gen(glo->psobj[i].pageref), - pdf_to_num(glo->psobj[i].u.form.obj), - pdf_to_gen(glo->psobj[i].u.form.obj)); + pdf_to_num(ctx, glo->psobj[i].pageref), + pdf_to_gen(ctx, glo->psobj[i].pageref), + pdf_to_num(ctx, glo->psobj[i].u.form.obj), + pdf_to_gen(ctx, glo->psobj[i].u.form.obj)); } - fz_printf(out, "\n"); + fz_printf(ctx, out, "\n"); } } static void -showinfo(globals *glo, char *filename, int show, char *pagelist) +showinfo(fz_context *ctx, globals *glo, char *filename, int show, char *pagelist) { int page, spage, epage; char *spec, *dash; @@ -917,7 +917,7 @@ showinfo(globals *glo, char *filename, int show, char *pagelist) allpages = !strcmp(pagelist, "1-"); - pagecount = pdf_count_pages(glo->doc); + pagecount = pdf_count_pages(ctx, glo->doc); spec = fz_strsep(&pagelist, ","); while (spec && pagecount) { @@ -943,15 +943,15 @@ showinfo(globals *glo, char *filename, int show, char *pagelist) epage = fz_clampi(epage, 1, pagecount); if (allpages) - fz_printf(out, "Retrieving info from pages %d-%d...\n", spage, epage); + fz_printf(ctx, out, "Retrieving info from pages %d-%d...\n", spage, epage); for (page = spage; page <= epage; page++) { - gatherpageinfo(glo, page, show); + gatherpageinfo(ctx, glo, page, show); if (!allpages) { - fz_printf(out, "Page %d:\n", page); - printinfo(glo, filename, show, page); - fz_printf(out, "\n"); + fz_printf(ctx, out, "Page %d:\n", page); + printinfo(ctx, glo, filename, show, page); + fz_printf(ctx, out, "\n"); } } @@ -959,7 +959,7 @@ showinfo(globals *glo, char *filename, int show, char *pagelist) } if (allpages) - printinfo(glo, filename, show, -1); + printinfo(ctx, glo, filename, show, -1); } static int arg_is_page_range(const char *arg) @@ -981,7 +981,6 @@ pdfinfo_info(fz_context *ctx, fz_output *out, char *filename, char *password, in int argidx = 0; globals glo = { 0 }; - glo.ctx = ctx; glo.out = out; state = NO_FILE_OPENED; @@ -991,25 +990,25 @@ pdfinfo_info(fz_context *ctx, fz_output *out, char *filename, char *password, in { if (state == NO_INFO_GATHERED) { - showinfo(&glo, filename, show, "1-"); + showinfo(ctx, &glo, filename, show, "1-"); } - closexref(&glo); + closexref(ctx, &glo); filename = argv[argidx]; - fz_printf(out, "%s:\n", filename); + fz_printf(ctx, out, "%s:\n", filename); glo.doc = pdf_open_document_no_run(glo.ctx, filename); - if (pdf_needs_password(glo.doc)) - if (!pdf_authenticate_password(glo.doc, password)) + if (pdf_needs_password(ctx, glo.doc)) + if (!pdf_authenticate_password(ctx, glo.doc, password)) fz_throw(glo.ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); - glo.pagecount = pdf_count_pages(glo.doc); + glo.pagecount = pdf_count_pages(ctx, glo.doc); - showglobalinfo(&glo); + showglobalinfo(ctx, &glo); state = NO_INFO_GATHERED; } else { - showinfo(&glo, filename, show, argv[argidx]); + showinfo(ctx, &glo, filename, show, argv[argidx]); state = INFO_SHOWN; } @@ -1017,9 +1016,9 @@ pdfinfo_info(fz_context *ctx, fz_output *out, char *filename, char *password, in } if (state == NO_INFO_GATHERED) - showinfo(&glo, filename, show, "1-"); + showinfo(ctx, &glo, filename, show, "1-"); - closexref(&glo); + closexref(ctx, &glo); } int pdfinfo_main(int argc, char **argv) @@ -1064,14 +1063,14 @@ int pdfinfo_main(int argc, char **argv) ret = 0; fz_try(ctx) { - out = fz_new_output_with_file(ctx, stdout); + out = fz_new_output_with_file(ctx, stdout, 0); pdfinfo_info(ctx, out, filename, password, show, &argv[fz_optind], argc-fz_optind); } fz_catch(ctx) { ret = 1; } - fz_close_output(out); - fz_free_context(ctx); + fz_drop_output(ctx, out); + fz_drop_context(ctx); return ret; } |