summaryrefslogtreecommitdiff
path: root/apps/pdfinfo.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2009-06-30 02:23:57 +0200
committerTor Andersson <tor@ghostscript.com>2009-06-30 02:23:57 +0200
commit0f66fa12ec2b514459e5f456b016ef719f041fc0 (patch)
tree68d7a4ec805a27c61b0b544fab038831978b731e /apps/pdfinfo.c
parentd8706a2cd98b373f45efcbb6a1753551984dc43c (diff)
downloadmupdf-0f66fa12ec2b514459e5f456b016ef719f041fc0.tar.xz
Move dynamic objects (fz_obj) out of fitz and into mupdf conceptually. Make all fz_obj functions automatically and invisibly resolve indirect references before use.
Diffstat (limited to 'apps/pdfinfo.c')
-rw-r--r--apps/pdfinfo.c223
1 files changed, 4 insertions, 219 deletions
diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c
index e9f9a77d..215d5ddf 100644
--- a/apps/pdfinfo.c
+++ b/apps/pdfinfo.c
@@ -95,20 +95,10 @@ void opensrc(char *filename, char *password, int loadpages)
/* TODO: move into mupdf lib, see pdfapp_open in pdfapp.c */
obj = fz_dictgets(src->trailer, "Root");
- if (!obj)
- die(error);
-
- error = pdf_loadindirect(&src->root, src, obj);
- if (error)
- die(error);
+ src->root = fz_resolveindirect(obj);
obj = fz_dictgets(src->trailer, "Info");
- if (obj)
- {
- error = pdf_loadindirect(&src->info, src, obj);
- if (error)
- die(error);
- }
+ src->info = fz_resolveindirect(obj);
error = pdf_loadnametrees(src);
if (error)
@@ -227,19 +217,12 @@ gatherglobalinfo()
fz_error
gatherdimensions(int page, fz_obj *pageref, fz_obj *pageobj)
{
- fz_error error;
fz_obj *ref;
fz_rect bbox;
fz_obj *obj;
int j;
obj = ref = fz_dictgets(pageobj, "MediaBox");
- if (obj)
- {
- error = pdf_resolve(&obj, src);
- if (error)
- return error;
- }
if (!fz_isarray(obj))
return fz_throw("cannot find page bounds (%d %d R)", fz_tonum(ref), fz_togen(ref));
@@ -290,43 +273,24 @@ gatherfonts(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
fontdict = ref = fz_dictgetval(dict, i);
- if (fontdict)
- {
- error = pdf_resolve(&fontdict, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect font dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(fontdict))
return fz_throw("not a font dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
subtype = fz_dictgets(fontdict, "Subtype");
- if (subtype)
- {
- error = pdf_resolve(&subtype, src);
- if (error)
- return fz_rethrow(error, "cannot find font dict subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isname(subtype))
return fz_throw("not a font dict subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
basefont = fz_dictgets(fontdict, "BaseFont");
if (basefont)
{
- error = pdf_resolve(&basefont, src);
- if (error)
- return fz_rethrow(error, "cannot find font dict basefont (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (!fz_isname(basefont))
return fz_throw("not a font dict basefont (%d %d R)", fz_tonum(ref), fz_togen(ref));
}
else
{
name = fz_dictgets(fontdict, "Name");
- if (name)
- error = pdf_resolve(&name, src);
- else
+ if (!name)
error = fz_newnull(&name);
- if (error)
- return fz_rethrow(error, "cannot find font dict name (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (!fz_isnull(name) && !fz_isname(name))
return fz_throw("not a font dict name (%d %d R)", fz_tonum(ref), fz_togen(ref));
}
@@ -380,35 +344,17 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
imagedict = ref = fz_dictgetval(dict, i);
- if (imagedict)
- {
- error = pdf_resolve(&imagedict, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(imagedict))
return fz_throw("not an image dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
type = fz_dictgets(imagedict, "Subtype");
- if (type)
- {
- error = pdf_resolve(&type, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isname(type))
return fz_throw("not an image subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (strcmp(fz_toname(type), "Image"))
continue;
filter = fz_dictgets(imagedict, "Filter");
- if (filter)
- {
- error = pdf_resolve(&filter, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image filter (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
- else
+ if (!filter)
{
error = fz_newname(&filter, "Raw");
if (error)
@@ -418,53 +364,19 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
return fz_throw("not an image filter (%d %d R)", fz_tonum(ref), fz_togen(ref));
mask = fz_dictgets(imagedict, "ImageMask");
- if (mask)
- {
- error = pdf_resolve(&mask, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image mask (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
altcs = nil;
cs = fz_dictgets(imagedict, "ColorSpace");
- if (cs)
- {
- error = pdf_resolve(&cs, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image colorspace (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (fz_isarray(cs))
{
fz_obj *cses = cs;
cs = fz_arrayget(cses, 0);
- if (cs)
- {
- error = pdf_resolve(&cs, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image colorspace name (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
-
if (fz_isname(cs) && (!strcmp(fz_toname(cs), "DeviceN") || !strcmp(fz_toname(cs), "Separation")))
{
altcs = fz_arrayget(cses, 2);
- if (altcs)
- {
- error = pdf_resolve(&altcs, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image alternate colorspace name (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
-
if (fz_isarray(altcs))
- {
altcs = fz_arrayget(altcs, 0);
- if (altcs)
- {
- error = pdf_resolve(&altcs, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image alternate colorspace name (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
- }
}
}
@@ -482,32 +394,14 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
return fz_throw("not an image alternate colorspace (%d %d R)", fz_tonum(ref), fz_togen(ref));
width = fz_dictgets(imagedict, "Width");
- if (width)
- {
- error = pdf_resolve(&width, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image width (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(width))
return fz_throw("not an image width (%d %d R)", fz_tonum(ref), fz_togen(ref));
height = fz_dictgets(imagedict, "Height");
- if (height)
- {
- error = pdf_resolve(&height, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image height (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(height))
return fz_throw("not an image height (%d %d R)", fz_tonum(ref), fz_togen(ref));
bpc = fz_dictgets(imagedict, "BitsPerComponent");
- if (bpc)
- {
- error = pdf_resolve(&bpc, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image bits per component (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_tobool(mask) && !fz_isint(bpc))
return fz_throw("not an image bits per component (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (fz_tobool(mask) && fz_isint(bpc) && fz_toint(bpc) != 1)
@@ -554,7 +448,6 @@ gatherimages(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_error
gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
- fz_error error;
int i;
for (i = 0; i < fz_dictlen(dict); i++)
@@ -568,56 +461,26 @@ gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
xobjdict = ref = fz_dictgetval(dict, i);
- if (xobjdict)
- {
- error = pdf_resolve(&xobjdict, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(xobjdict))
return fz_throw("not a xobject dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
type = fz_dictgets(xobjdict, "Subtype");
- if (type)
- {
- error = pdf_resolve(&type, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect xobject type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isname(type))
return fz_throw("not a xobject type (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (strcmp(fz_toname(type), "Form"))
return fz_okay;
subtype = fz_dictgets(xobjdict, "Subtype2");
- if (subtype)
- {
- error = pdf_resolve(&subtype, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect xobject subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (subtype && !fz_isname(subtype))
return fz_throw("not a xobject subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (strcmp(fz_toname(subtype), "PS"))
return fz_okay;
group = fz_dictgets(xobjdict, "Group");
- if (group)
- {
- error = pdf_resolve(&group, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect form xobject group dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (group && !fz_isdict(group))
return fz_throw("not a form xobject group dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
reference = fz_dictgets(xobjdict, "Ref");
- if (reference)
- {
- error = pdf_resolve(&reference, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect form xobject reference dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (reference && !fz_isdict(reference))
return fz_throw("not a form xobject reference dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
@@ -652,7 +515,6 @@ gatherforms(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_error
gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
- fz_error error;
int i;
for (i = 0; i < fz_dictlen(dict); i++)
@@ -664,34 +526,16 @@ gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
xobjdict = ref = fz_dictgetval(dict, i);
- if (xobjdict)
- {
- error = pdf_resolve(&xobjdict, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect image dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(xobjdict))
return fz_throw("not a xobject dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
type = fz_dictgets(xobjdict, "Subtype");
- if (type)
- {
- error = pdf_resolve(&type, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect xobject type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isname(type))
return fz_throw("not a xobject type (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (strcmp(fz_toname(type), "Form"))
return fz_okay;
subtype = fz_dictgets(xobjdict, "Subtype2");
- if (subtype)
- {
- error = pdf_resolve(&subtype, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect xobject subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (subtype && !fz_isname(subtype))
return fz_throw("not a xobject subtype (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (strcmp(fz_toname(type), "PS") &&
@@ -727,7 +571,6 @@ gatherpsobjs(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
fz_error
gathershadings(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
{
- fz_error error;
int i;
for (i = 0; i < fz_dictlen(dict); i++)
@@ -738,22 +581,10 @@ gathershadings(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
shade = ref = fz_dictgetval(dict, i);
- if (shade)
- {
- error = pdf_resolve(&shade, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect shading dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(shade))
return fz_throw("not a shading dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
type = fz_dictgets(shade, "ShadingType");
- if (type)
- {
- error = pdf_resolve(&type, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect shading type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(type) || fz_toint(type) < 1 || fz_toint(type) > 7)
return fz_throw("not a shading type (%d %d R)", fz_tonum(ref), fz_togen(ref));
@@ -800,44 +631,20 @@ gatherpatterns(int page, fz_obj *pageref, fz_obj *pageobj, fz_obj *dict)
int k;
patterndict = ref = fz_dictgetval(dict, i);
- if (patterndict)
- {
- error = pdf_resolve(&patterndict, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect pattern dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isdict(patterndict))
return fz_throw("not a pattern dict (%d %d R)", fz_tonum(ref), fz_togen(ref));
type = fz_dictgets(patterndict, "PatternType");
- if (type)
- {
- error = pdf_resolve(&type, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect pattern type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(type) || fz_toint(type) < 1 || fz_toint(type) > 2)
return fz_throw("not a pattern type (%d %d R)", fz_tonum(ref), fz_togen(ref));
if (fz_toint(type) == 1)
{
paint = fz_dictgets(patterndict, "PaintType");
- if (paint)
- {
- error = pdf_resolve(&paint, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect pattern paint type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(paint) || fz_toint(paint) < 1 || fz_toint(paint) > 2)
return fz_throw("not a pattern paint type (%d %d R)", fz_tonum(ref), fz_togen(ref));
tiling = fz_dictgets(patterndict, "TilingType");
- if (tiling)
- {
- error = pdf_resolve(&tiling, src);
- if (error)
- return fz_rethrow(error, "cannot resolve indirect pattern tiling type (%d %d R)", fz_tonum(ref), fz_togen(ref));
- }
if (!fz_isint(tiling) || fz_toint(tiling) < 1 || fz_toint(tiling) > 3)
return fz_throw("not a pattern tiling type (%d %d R)", fz_tonum(ref), fz_togen(ref));
}
@@ -906,22 +713,12 @@ gatherinfo(int show, int page)
}
rsrc = fz_dictgets(pageobj, "Resources");
- if (rsrc)
- {
- error = pdf_resolve(&rsrc, src);
- if (error)
- die(fz_rethrow(error, "retrieving resources at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
- }
if (show & FONTS)
{
font = fz_dictgets(rsrc, "Font");
if (font)
{
- error = pdf_resolve(&font, src);
- if (error)
- die(fz_rethrow(error, "resolving font dict at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
-
error = gatherfonts(page, pageref, pageobj, font);
if (error)
die(fz_rethrow(error, "gathering fonts at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
@@ -933,10 +730,6 @@ gatherinfo(int show, int page)
xobj = fz_dictgets(rsrc, "XObject");
if (xobj)
{
- error = pdf_resolve(&xobj, src);
- if (error)
- die(fz_rethrow(error, "resolving xobject dict at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
-
error = gatherimages(page, pageref, pageobj, xobj);
if (error)
die(fz_rethrow(error, "gathering images at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
@@ -954,10 +747,6 @@ gatherinfo(int show, int page)
shade = fz_dictgets(rsrc, "Shading");
if (shade)
{
- error = pdf_resolve(&shade, src);
- if (error)
- die(fz_rethrow(error, "resolving shading dict at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
-
error = gathershadings(page, pageref, pageobj, shade);
if (error)
die(fz_rethrow(error, "gathering shadings at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
@@ -969,10 +758,6 @@ gatherinfo(int show, int page)
pattern = fz_dictgets(rsrc, "Pattern");
if (pattern)
{
- error = pdf_resolve(&pattern, src);
- if (error)
- die(fz_rethrow(error, "resolving pattern dict at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));
-
error = gathershadings(page, pageref, pageobj, shade);
if (error)
die(fz_rethrow(error, "gathering shadings at page %d (%d %d R)", page, fz_tonum(pageref), fz_togen(pageref)));