summaryrefslogtreecommitdiff
path: root/source/tools/murun.c
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2017-06-03 21:27:33 -0700
committerRobin Watts <Robin.Watts@artifex.com>2017-06-03 21:27:33 -0700
commit7f0a9b9f4448f7f2e87313e9e147b631b687e81b (patch)
tree5259a54b29e55d19fe65d75ac35cbb56022e591c /source/tools/murun.c
parent876f1fe8aaa9b110b3211fedbe5decbd67cf8c45 (diff)
downloadmupdf-7f0a9b9f4448f7f2e87313e9e147b631b687e81b.tar.xz
Tweak pdf_graft_map API.
Passing a pdf_document to pdf_graft_object to specify the source document is redundant, as if we need to know the document, it will be pickled into the object we are copying. Similarly, repeatedly having to pass the destination document seems silly when we can just pickle it into the map too (and this removes the possibility of people using a different destination document part way through). This leaves to simplifying the pdf_graft_object call, at the expense of splitting it into 2 calls - one with a map, and one without. Also, we can delay the creation of the mapping table until we are first asked to copy an object that requires deep copying. This avoids us ever having to manually pass in the source document. This has knock-on effects in the java and javascript classes, but with the advantage of being clearer in the end (IMHO). Conflicts: include/mupdf/pdf/document.h
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r--source/tools/murun.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index cbfd2a78..205e8f91 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3425,11 +3425,21 @@ static void ffi_PDFDocument_graftObject(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_document *dst = js_touserdata(J, 0, "pdf_document");
- pdf_document *src = js_touserdata(J, 1, "pdf_document");
- pdf_obj *obj = js_touserdata(J, 2, "pdf_obj");
- pdf_graft_map *map = js_iscoercible(J, 3) ? js_touserdata(J, 3, "pdf_graft_map") : NULL;
+ pdf_obj *obj = js_touserdata(J, 1, "pdf_obj");
fz_try(ctx)
- obj = pdf_graft_object(ctx, dst, src, obj, map);
+ obj = pdf_graft_object(ctx, dst, obj);
+ fz_catch(ctx)
+ rethrow(J);
+ ffi_pushobj(J, obj);
+}
+
+static void ffi_PDFGraftMap_graftObject(js_State *J)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_graft_map *map = js_touserdata(J, 0, "pdf_graft_map");
+ pdf_obj *obj = js_touserdata(J, 1, "pdf_obj");
+ fz_try(ctx)
+ obj = pdf_graft_mapped_object(ctx, map, obj);
fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, obj);
@@ -4493,10 +4503,17 @@ int murun_main(int argc, char **argv)
jsB_propfun(J, "PDFDocument.newDictionary", ffi_PDFDocument_newDictionary, 1);
jsB_propfun(J, "PDFDocument.newGraftMap", ffi_PDFDocument_newGraftMap, 0);
- jsB_propfun(J, "PDFDocument.graftObject", ffi_PDFDocument_graftObject, 3);
+ jsB_propfun(J, "PDFDocument.graftObject", ffi_PDFDocument_graftObject, 1);
}
js_setregistry(J, "pdf_document");
+ js_getregistry(J, "pdf_graft_map");
+ js_newobjectx(J);
+ {
+ jsB_propfun(J, "PDFGraftMap.graftObject", ffi_PDFGraftMap_graftObject, 1);
+ }
+ js_setregistry(J, "pdf_graft_map");
+
js_getregistry(J, "fz_page");
js_newobjectx(J);
{
@@ -4563,6 +4580,9 @@ int murun_main(int argc, char **argv)
js_setregistry(J, "pdf_obj");
js_newobject(J);
+ {
+ jsB_propfun(J, "PDFGraftMap.graftObject", ffi_PDFGraftMap_graftObject, 1);
+ }
js_setregistry(J, "pdf_graft_map");
#endif