summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-04-01 16:02:09 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-04-01 16:02:09 +0200
commitd2250034a7e629455b9bfbf735473ea39638a701 (patch)
tree5d5cedf0e6447a75162d9ef1b89309e911740227
parent6192f4c4fdec838fd5ef86a17517d615d7ff16ca (diff)
downloadmupdf-d2250034a7e629455b9bfbf735473ea39638a701.tar.xz
Use a function pointer for resolveindirect.
This removes a static dependency between fitz and mupdf. Fitz should now be link time independent of mupdf again.
-rw-r--r--fitz/fitz.h6
-rw-r--r--fitz/obj_simple.c32
-rw-r--r--mupdf/pdf_xref.c28
-rw-r--r--xps/xpstop.c6
4 files changed, 39 insertions, 33 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index f8bef4c3..d4ab8ff4 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -406,13 +406,15 @@ struct fz_obj_s
} u;
};
+extern fz_obj* (*fz_resolveindirect)(fz_obj*);
+
fz_obj *fz_newnull(void);
fz_obj *fz_newbool(int b);
fz_obj *fz_newint(int i);
fz_obj *fz_newreal(float f);
fz_obj *fz_newname(char *str);
fz_obj *fz_newstring(char *str, int len);
-fz_obj *fz_newindirect(int num, int gen, struct pdf_xref_s *xref);
+fz_obj *fz_newindirect(int num, int gen, void *xref);
fz_obj *fz_newarray(int initialcap);
fz_obj *fz_newdict(int initialcap);
@@ -435,8 +437,6 @@ int fz_isindirect(fz_obj *obj);
int fz_objcmp(fz_obj *a, fz_obj *b);
-fz_obj *fz_resolveindirect(fz_obj *obj);
-
/* silent failure, no error reporting */
int fz_tobool(fz_obj *obj);
int fz_toint(fz_obj *obj);
diff --git a/fitz/obj_simple.c b/fitz/obj_simple.c
index f279bd55..b629974e 100644
--- a/fitz/obj_simple.c
+++ b/fitz/obj_simple.c
@@ -1,9 +1,15 @@
#include "fitz.h"
-#include "mupdf.h" /* for pdf_loadobject */
extern void fz_freearray(fz_obj *array);
extern void fz_freedict(fz_obj *dict);
+static fz_obj *fz_resolve_indirect_null(fz_obj *ref)
+{
+ return ref;
+}
+
+fz_obj* (*fz_resolveindirect)(fz_obj*) = fz_resolve_indirect_null;
+
fz_obj *
fz_newnull(void)
{
@@ -66,7 +72,7 @@ fz_newname(char *str)
}
fz_obj *
-fz_newindirect(int num, int gen, pdf_xref *xref)
+fz_newindirect(int num, int gen, void *xref)
{
fz_obj *o = fz_malloc(sizeof(fz_obj));
o->refs = 1;
@@ -219,28 +225,6 @@ int fz_togen(fz_obj *obj)
return 0;
}
-fz_obj *fz_resolveindirect(fz_obj *ref)
-{
- if (fz_isindirect(ref))
- {
- pdf_xref *xref = ref->u.r.xref;
- int num = fz_tonum(ref);
- int gen = fz_togen(ref);
- if (xref)
- {
- fz_error error = pdf_cacheobject(xref, num, gen);
- if (error)
- {
- fz_catch(error, "cannot load object (%d %d R) into cache", num, gen);
- return ref;
- }
- if (xref->table[num].obj)
- return xref->table[num].obj;
- }
- }
- return ref;
-}
-
int
fz_objcmp(fz_obj *a, fz_obj *b)
{
diff --git a/mupdf/pdf_xref.c b/mupdf/pdf_xref.c
index 7174cfc5..4ec23a30 100644
--- a/mupdf/pdf_xref.c
+++ b/mupdf/pdf_xref.c
@@ -1,6 +1,8 @@
#include "fitz.h"
#include "mupdf.h"
+static fz_obj *pdf_resolveindirect(fz_obj *ref);
+
static inline int iswhite(int ch)
{
return
@@ -535,6 +537,9 @@ pdf_openxrefwithstream(pdf_xref **xrefp, fz_stream *file, char *password)
fz_obj *dict, *obj;
int i, repaired = 0;
+ /* install pdf specific callback */
+ fz_resolveindirect = pdf_resolveindirect;
+
xref = fz_malloc(sizeof(pdf_xref));
memset(xref, 0, sizeof(pdf_xref));
@@ -893,6 +898,29 @@ pdf_loadobject(fz_obj **objp, pdf_xref *xref, int num, int gen)
return fz_okay;
}
+static fz_obj *
+pdf_resolveindirect(fz_obj *ref)
+{
+ if (fz_isindirect(ref))
+ {
+ pdf_xref *xref = ref->u.r.xref;
+ int num = fz_tonum(ref);
+ int gen = fz_togen(ref);
+ if (xref)
+ {
+ fz_error error = pdf_cacheobject(xref, num, gen);
+ if (error)
+ {
+ fz_catch(error, "cannot load object (%d %d R) into cache", num, gen);
+ return ref;
+ }
+ if (xref->table[num].obj)
+ return xref->table[num].obj;
+ }
+ }
+ return ref;
+}
+
/* Replace numbered object -- for use by pdfclean and similar tools */
void
pdf_updateobject(pdf_xref *xref, int num, int gen, fz_obj *newobj)
diff --git a/xps/xpstop.c b/xps/xpstop.c
index 2ae1d585..921d677a 100644
--- a/xps/xpstop.c
+++ b/xps/xpstop.c
@@ -21,12 +21,6 @@ fz_colorspace *colorspace;
fz_glyphcache *glyphcache;
char *filename;
-/* stub function for automatic resolution of indirect objects in obj_simple.c */
-int pdf_cacheobject(struct pdf_xref_s *xref, int num, int gen)
-{
- return fz_throw("not a pdf");
-}
-
struct {
int count, total;
int min, max;