summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-05-30 14:29:08 +0200
committerRobin Watts <robin.watts@artifex.com>2016-05-30 17:49:19 +0100
commite74df981077189c6408be4cdfb1f9dc4738e4ed0 (patch)
treea868de66b31c973876e7036d7fe0bb7a013a035a
parent0b73a8ddf620894112cd212b43f5d4cccec9d90e (diff)
downloadmupdf-e74df981077189c6408be4cdfb1f9dc4738e4ed0.tar.xz
Respect FZ_ENABLE_PDF=0 to allow dropping all PDF specific code in tools.
-rw-r--r--Makefile5
-rw-r--r--source/fitz/document.c12
-rw-r--r--source/fitz/writer.c2
-rw-r--r--source/tools/muconvert.c2
-rw-r--r--source/tools/mudraw.c25
-rw-r--r--source/tools/murun.c454
-rw-r--r--source/tools/mutool.c3
7 files changed, 275 insertions, 228 deletions
diff --git a/Makefile b/Makefile
index 9e155d7b..217afb93 100644
--- a/Makefile
+++ b/Makefile
@@ -62,8 +62,6 @@ ALL_DIR += $(OUT)/pdf $(OUT)/pdf/js
ALL_DIR += $(OUT)/xps
ALL_DIR += $(OUT)/svg
ALL_DIR += $(OUT)/cbz
-ALL_DIR += $(OUT)/img
-ALL_DIR += $(OUT)/tiff
ALL_DIR += $(OUT)/html
ALL_DIR += $(OUT)/gprf
ALL_DIR += $(OUT)/tools
@@ -255,7 +253,8 @@ $(OUT)/cmapdump.o : include/mupdf/pdf/cmap.h source/fitz/context.c source/fitz/e
# --- Tools and Apps ---
MUTOOL := $(addprefix $(OUT)/, mutool)
-MUTOOL_OBJ := $(addprefix $(OUT)/tools/, mutool.o muconvert.o mudraw.o murun.o pdfclean.o pdfcreate.o pdfextract.o pdfinfo.o pdfmerge.o pdfposter.o pdfpages.o pdfshow.o)
+MUTOOL_OBJ := $(addprefix $(OUT)/tools/, mutool.o muconvert.o mudraw.o murun.o)
+MUTOOL_OBJ += $(addprefix $(OUT)/tools/, pdfclean.o pdfcreate.o pdfextract.o pdfinfo.o pdfmerge.o pdfposter.o pdfpages.o pdfshow.o)
$(MUTOOL_OBJ): $(FITZ_HDR) $(PDF_HDR)
$(MUTOOL) : $(MUPDF_LIB) $(THIRD_LIB)
$(MUTOOL) : $(MUTOOL_OBJ)
diff --git a/source/fitz/document.c b/source/fitz/document.c
index 227c93e1..5c913012 100644
--- a/source/fitz/document.c
+++ b/source/fitz/document.c
@@ -70,8 +70,10 @@ fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stre
int best_i, best_score;
fz_document_handler_context *dc;
- if (ctx == NULL || magic == NULL || stream == NULL)
+ if (ctx == NULL)
return NULL;
+ if (magic == NULL || stream == NULL)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "no document to open");
dc = ctx->handler;
if (dc->count == 0)
@@ -92,7 +94,7 @@ fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stre
if (best_i >= 0)
return dc->handler[best_i]->open_with_stream(ctx, stream);
- return NULL;
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find document handler for file type: %s", magic);
}
fz_document *
@@ -102,8 +104,10 @@ fz_open_document(fz_context *ctx, const char *filename)
int best_i, best_score;
fz_document_handler_context *dc;
- if (ctx == NULL || filename == NULL)
+ if (ctx == NULL)
return NULL;
+ if (filename == NULL)
+ fz_throw(ctx, FZ_ERROR_GENERIC, "no document to open");
dc = ctx->handler;
if (dc->count == 0)
@@ -124,7 +128,7 @@ fz_open_document(fz_context *ctx, const char *filename)
if (best_i >= 0)
return dc->handler[best_i]->open(ctx, filename);
- return NULL;
+ fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find document handler for file: '%s'", filename);
}
void *
diff --git a/source/fitz/writer.c b/source/fitz/writer.c
index 94f601b5..2a344e52 100644
--- a/source/fitz/writer.c
+++ b/source/fitz/writer.c
@@ -54,8 +54,10 @@ fz_new_document_writer(fz_context *ctx, const char *path, const char *format, co
if (!fz_strcasecmp(format, "cbz"))
return fz_new_cbz_writer(ctx, path, options);
+#if FZ_ENABLE_PDF
if (!fz_strcasecmp(format, "pdf"))
return fz_new_pdf_writer(ctx, path, options);
+#endif
fz_throw(ctx, FZ_ERROR_GENERIC, "unknown document format: %s", format);
}
diff --git a/source/tools/muconvert.c b/source/tools/muconvert.c
index 6f354b01..926536fa 100644
--- a/source/tools/muconvert.c
+++ b/source/tools/muconvert.c
@@ -44,7 +44,9 @@ static void usage(void)
"\n"
);
fprintf(stderr, "%s\n", fz_cbz_write_options_usage);
+#if FZ_ENABLE_PDF
fprintf(stderr, "%s\n", fz_pdf_write_options_usage);
+#endif
exit(1);
}
diff --git a/source/tools/mudraw.c b/source/tools/mudraw.c
index 8808b02b..85553ea8 100644
--- a/source/tools/mudraw.c
+++ b/source/tools/mudraw.c
@@ -27,7 +27,10 @@ enum {
OUT_PNG, OUT_TGA, OUT_PNM, OUT_PGM, OUT_PPM, OUT_PAM,
OUT_PBM, OUT_PKM, OUT_PWG, OUT_PCL, OUT_PS,
OUT_TEXT, OUT_HTML, OUT_STEXT,
- OUT_TRACE, OUT_SVG, OUT_PDF,
+ OUT_TRACE, OUT_SVG,
+#if FZ_ENABLE_PDF
+ OUT_PDF,
+#endif
OUT_GPROOF
};
@@ -52,7 +55,9 @@ static const suffix_t suffix_table[] =
{ ".pwg", OUT_PWG },
{ ".pcl", OUT_PCL },
{ ".ps", OUT_PS },
+#if FZ_ENABLE_PDF
{ ".pdf", OUT_PDF },
+#endif
{ ".tga", OUT_TGA },
{ ".txt", OUT_TEXT },
@@ -111,7 +116,9 @@ static const format_cs_table_t format_cs_table[] =
{ OUT_TRACE, CS_RGB, { CS_RGB } },
{ OUT_SVG, CS_RGB, { CS_RGB } },
+#if FZ_ENABLE_PDF
{ OUT_PDF, CS_RGB, { CS_RGB } },
+#endif
{ OUT_GPROOF, CS_RGB, { CS_RGB } },
{ OUT_TEXT, CS_RGB, { CS_RGB } },
@@ -131,7 +138,7 @@ static const format_cs_table_t format_cs_table[] =
#define SEMAPHORE HANDLE
#define SEMAPHORE_INIT(A) do { A = CreateSemaphore(NULL, 0, 1, NULL); } while (0)
#define SEMAPHORE_FIN(A) do { CloseHandle(A); } while (0)
-#define SEMAPHORE_TRIGGER(A) do { (void)ReleaseSemaphore(A, 1, NULL); } while (0)
+#define SEMAPHORE_TRIGGER(A) do { (void)ReleaseSemaphore(A, 1, NULL); } while (0)
#define SEMAPHORE_WAIT(A) do { (void)WaitForSingleObject(A, INFINITE); } while (0)
#define THREAD HANDLE
#define THREAD_INIT(A,B,C) do { A = CreateThread(NULL, 0, B, C, 0, NULL); } while (0)
@@ -348,7 +355,9 @@ static size_t memtrace_total = 0;
static int showmemory = 0;
static int showmd5 = 0;
+#if FZ_ENABLE_PDF
static pdf_document *pdfout = NULL;
+#endif
static int ignore_errors = 0;
static int uselist = 1;
@@ -651,6 +660,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
}
}
+#if FZ_ENABLE_PDF
else if (output_format == OUT_PDF)
{
fz_buffer *contents;
@@ -684,6 +694,7 @@ static void dodrawpage(fz_context *ctx, fz_page *page, fz_display_list *list, in
fz_rethrow(ctx);
}
}
+#endif
else if (output_format == OUT_SVG)
{
@@ -1577,11 +1588,14 @@ int mudraw_main(int argc, char **argv)
break;
}
+#if FZ_ENABLE_PDF
if (output_format == OUT_PDF)
{
pdfout = pdf_create_document(ctx);
}
- else if (output_format == OUT_GPROOF)
+ else
+#endif
+ if (output_format == OUT_GPROOF)
{
/* GPROOF files are saved direct. Do not open "output". */
}
@@ -1668,6 +1682,7 @@ int mudraw_main(int argc, char **argv)
if (output_append)
file_level_trailers(ctx);
+#if FZ_ENABLE_PDF
if (output_format == OUT_PDF)
{
if (!output)
@@ -1675,7 +1690,9 @@ int mudraw_main(int argc, char **argv)
pdf_save_document(ctx, pdfout, output, NULL);
pdf_drop_document(ctx, pdfout);
}
- else if (output_format == OUT_GPROOF)
+ else
+#endif
+ if (output_format == OUT_GPROOF)
{
/* No output file to close */
}
diff --git a/source/tools/murun.c b/source/tools/murun.c
index e069bf0d..52df9a79 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -186,24 +186,6 @@ static void ffi_gc_fz_document(js_State *J, void *doc)
fz_drop_document(ctx, doc);
}
-static void ffi_gc_pdf_document(js_State *J, void *doc)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_drop_document(ctx, doc);
-}
-
-static void ffi_gc_pdf_obj(js_State *J, void *obj)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_drop_obj(ctx, obj);
-}
-
-static void ffi_gc_pdf_graft_map(js_State *J, void *map)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_drop_graft_map(ctx, map);
-}
-
static void ffi_gc_fz_page(js_State *J, void *page)
{
fz_context *ctx = js_getcontext(J);
@@ -270,6 +252,28 @@ static void ffi_gc_fz_document_writer(js_State *J, void *wri)
fz_drop_document_writer(ctx, wri);
}
+#if FZ_ENABLE_PDF
+
+static void ffi_gc_pdf_document(js_State *J, void *doc)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_drop_document(ctx, doc);
+}
+
+static void ffi_gc_pdf_obj(js_State *J, void *obj)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_drop_obj(ctx, obj);
+}
+
+static void ffi_gc_pdf_graft_map(js_State *J, void *map)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_drop_graft_map(ctx, map);
+}
+
+#endif /* FZ_ENABLE_PDF */
+
/* type conversions */
struct color {
@@ -540,108 +544,6 @@ static void ffi_pushimage(js_State *J, fz_image *image)
js_newuserdata(J, "fz_image", fz_keep_image(ctx, image), ffi_gc_fz_image);
}
-static pdf_obj *ffi_toobj(js_State *J, pdf_document *pdf, int idx)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_obj *obj;
-
- /* make sure index is absolute */
- if (idx < 0)
- idx += js_gettop(J);
-
- if (js_isuserdata(J, idx, "pdf_obj"))
- return pdf_keep_obj(ctx, js_touserdata(J, idx, "pdf_obj"));
-
- if (js_isnumber(J, idx)) {
- float f = js_tonumber(J, idx);
- fz_try(ctx)
- if (f == (int)f)
- obj = pdf_new_int(ctx, pdf, f);
- else
- obj = pdf_new_real(ctx, pdf, f);
- fz_catch(ctx)
- rethrow(J);
- return obj;
- }
-
- if (js_isstring(J, idx)) {
- const char *s = js_tostring(J, idx);
- fz_try(ctx)
- if (s[0] == '(' && s[1] != 0)
- obj = pdf_new_string(ctx, pdf, s+1, strlen(s)-2);
- else
- obj = pdf_new_name(ctx, pdf, s);
- fz_catch(ctx)
- rethrow(J);
- return obj;
- }
-
- if (js_isboolean(J, idx)) {
- int b = js_toboolean(J, idx);
- fz_try(ctx)
- obj = pdf_new_bool(ctx, pdf, b);
- fz_catch(ctx)
- rethrow(J);
- return obj;
- }
-
- if (js_isnull(J, idx)) {
- fz_try(ctx)
- obj = pdf_new_null(ctx, pdf);
- fz_catch(ctx)
- rethrow(J);
- return obj;
- }
-
- if (js_isarray(J, idx)) {
- pdf_obj *val;
- int i, n = js_getlength(J, idx);
- fz_try(ctx)
- obj = pdf_new_array(ctx, pdf, n);
- fz_catch(ctx)
- rethrow(J);
- for (i = 0; i < n; ++i) {
- js_getindex(J, idx, i);
- val = ffi_toobj(J, pdf, -1);
- fz_try(ctx)
- pdf_array_push(ctx, obj, val);
- fz_always(ctx)
- pdf_drop_obj(ctx, val);
- fz_catch(ctx)
- rethrow(J);
- js_pop(J, 1);
- }
- return obj;
- }
-
- if (js_isobject(J, idx)) {
- const char *key;
- pdf_obj *val;
- fz_try(ctx)
- obj = pdf_new_dict(ctx, pdf, 0);
- fz_catch(ctx)
- rethrow(J);
- js_pushiterator(J, idx, 1);
- while ((key = js_nextiterator(J, -1))) {
- js_getproperty(J, idx, key);
- val = ffi_toobj(J, pdf, -1);
- fz_try(ctx)
- pdf_dict_puts(ctx, obj, key, val);
- fz_always(ctx)
- pdf_drop_obj(ctx, val);
- fz_catch(ctx)
- rethrow(J);
- js_pop(J, 1);
- }
- js_pop(J, 1);
- return obj;
- }
-
- js_error(J, "cannot convert JS type to PDF");
-}
-
-static void ffi_pushobj(js_State *J, pdf_obj *obj);
-
static int is_number(const char *key, int *idx)
{
char *end;
@@ -649,96 +551,6 @@ static int is_number(const char *key, int *idx)
return *end == 0;
}
-static int ffi_pdf_obj_has(js_State *J, void *obj, const char *key)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_obj *val;
- int idx;
-
- if (is_number(key, &idx)) {
- fz_try(ctx)
- val = pdf_array_get(ctx, obj, idx);
- fz_catch(ctx)
- rethrow(J);
- } else {
- fz_try(ctx)
- val = pdf_dict_gets(ctx, obj, key);
- fz_catch(ctx)
- rethrow(J);
- }
- if (val) {
- ffi_pushobj(J, pdf_keep_obj(ctx, val));
- return 1;
- }
- return 0;
-}
-
-static int ffi_pdf_obj_put(js_State *J, void *obj, const char *key)
-{
- fz_context *ctx = js_getcontext(J);
- pdf_document *pdf;
- pdf_obj *val;
- int idx;
-
- fz_try(ctx)
- pdf = pdf_get_bound_document(ctx, obj);
- fz_catch(ctx)
- rethrow(J);
-
- val = ffi_toobj(J, pdf, -1);
-
- if (is_number(key, &idx)) {
- fz_try(ctx)
- if (idx == pdf_array_len(ctx, obj))
- pdf_array_push(ctx, obj, val);
- else
- pdf_array_put(ctx, obj, idx, val);
- fz_always(ctx)
- pdf_drop_obj(ctx, val);
- fz_catch(ctx)
- rethrow(J);
- } else {
- fz_try(ctx)
- pdf_dict_puts(ctx, obj, key, val);
- fz_always(ctx)
- pdf_drop_obj(ctx, val);
- fz_catch(ctx)
- rethrow(J);
- }
- return 1;
-}
-
-static int ffi_pdf_obj_delete(js_State *J, void *obj, const char *key)
-{
- fz_context *ctx = js_getcontext(J);
- int idx;
-
- if (is_number(key, &idx)) {
- fz_try(ctx)
- pdf_array_delete(ctx, obj, idx);
- fz_catch(ctx)
- rethrow(J);
- } else {
- fz_try(ctx)
- pdf_dict_dels(ctx, obj, key);
- fz_catch(ctx)
- rethrow(J);
- }
- return 1;
-}
-
-static void ffi_pushobj(js_State *J, pdf_obj *obj)
-{
- if (obj) {
- js_getregistry(J, "pdf_obj");
- js_newuserdatax(J, "pdf_obj", obj,
- ffi_pdf_obj_has, ffi_pdf_obj_put, ffi_pdf_obj_delete,
- ffi_gc_pdf_obj);
- } else {
- js_pushnull(J);
- }
-}
-
static int ffi_buffer_has(js_State *J, void *buf_, const char *key)
{
fz_buffer *buf = buf_;
@@ -771,6 +583,16 @@ static int ffi_buffer_put(js_State *J, void *buf_, const char *key)
return 0;
}
+static void ffi_pushbuffer(js_State *J, fz_buffer *buf)
+{
+ js_getregistry(J, "fz_buffer");
+ js_newuserdatax(J, "fz_buffer", buf,
+ ffi_buffer_has, ffi_buffer_put, NULL,
+ ffi_gc_fz_buffer);
+}
+
+#if FZ_ENABLE_PDF
+
static fz_buffer *ffi_tobuffer(js_State *J, int idx)
{
fz_context *ctx = js_getcontext(J);
@@ -789,13 +611,7 @@ static fz_buffer *ffi_tobuffer(js_State *J, int idx)
return buf;
}
-static void ffi_pushbuffer(js_State *J, fz_buffer *buf)
-{
- js_getregistry(J, "fz_buffer");
- js_newuserdatax(J, "fz_buffer", buf,
- ffi_buffer_has, ffi_buffer_put, NULL,
- ffi_gc_fz_buffer);
-}
+#endif /* FZ_ENABLE_PDF */
/* device calling into js from c */
@@ -1623,6 +1439,7 @@ static void ffi_Document_layout(js_State *J)
static void ffi_Document_toPDF(js_State *J)
{
+#if FZ_ENABLE_PDF
fz_context *ctx = js_getcontext(J);
fz_document *doc = js_touserdata(J, 0, "fz_document");
pdf_document *pdf;
@@ -1638,6 +1455,9 @@ static void ffi_Document_toPDF(js_State *J)
} else {
js_pushnull(J);
}
+#else
+ js_pushnull(J);
+#endif
}
static void ffi_Page_toPixmap(js_State *J)
@@ -2363,6 +2183,200 @@ static void ffi_DocumentWriter_close(js_State *J)
/* PDF specifics */
+#if FZ_ENABLE_PDF
+
+static pdf_obj *ffi_toobj(js_State *J, pdf_document *pdf, int idx)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_obj *obj;
+
+ /* make sure index is absolute */
+ if (idx < 0)
+ idx += js_gettop(J);
+
+ if (js_isuserdata(J, idx, "pdf_obj"))
+ return pdf_keep_obj(ctx, js_touserdata(J, idx, "pdf_obj"));
+
+ if (js_isnumber(J, idx)) {
+ float f = js_tonumber(J, idx);
+ fz_try(ctx)
+ if (f == (int)f)
+ obj = pdf_new_int(ctx, pdf, f);
+ else
+ obj = pdf_new_real(ctx, pdf, f);
+ fz_catch(ctx)
+ rethrow(J);
+ return obj;
+ }
+
+ if (js_isstring(J, idx)) {
+ const char *s = js_tostring(J, idx);
+ fz_try(ctx)
+ if (s[0] == '(' && s[1] != 0)
+ obj = pdf_new_string(ctx, pdf, s+1, strlen(s)-2);
+ else
+ obj = pdf_new_name(ctx, pdf, s);
+ fz_catch(ctx)
+ rethrow(J);
+ return obj;
+ }
+
+ if (js_isboolean(J, idx)) {
+ int b = js_toboolean(J, idx);
+ fz_try(ctx)
+ obj = pdf_new_bool(ctx, pdf, b);
+ fz_catch(ctx)
+ rethrow(J);
+ return obj;
+ }
+
+ if (js_isnull(J, idx)) {
+ fz_try(ctx)
+ obj = pdf_new_null(ctx, pdf);
+ fz_catch(ctx)
+ rethrow(J);
+ return obj;
+ }
+
+ if (js_isarray(J, idx)) {
+ pdf_obj *val;
+ int i, n = js_getlength(J, idx);
+ fz_try(ctx)
+ obj = pdf_new_array(ctx, pdf, n);
+ fz_catch(ctx)
+ rethrow(J);
+ for (i = 0; i < n; ++i) {
+ js_getindex(J, idx, i);
+ val = ffi_toobj(J, pdf, -1);
+ fz_try(ctx)
+ pdf_array_push(ctx, obj, val);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ rethrow(J);
+ js_pop(J, 1);
+ }
+ return obj;
+ }
+
+ if (js_isobject(J, idx)) {
+ const char *key;
+ pdf_obj *val;
+ fz_try(ctx)
+ obj = pdf_new_dict(ctx, pdf, 0);
+ fz_catch(ctx)
+ rethrow(J);
+ js_pushiterator(J, idx, 1);
+ while ((key = js_nextiterator(J, -1))) {
+ js_getproperty(J, idx, key);
+ val = ffi_toobj(J, pdf, -1);
+ fz_try(ctx)
+ pdf_dict_puts(ctx, obj, key, val);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ rethrow(J);
+ js_pop(J, 1);
+ }
+ js_pop(J, 1);
+ return obj;
+ }
+
+ js_error(J, "cannot convert JS type to PDF");
+}
+
+static void ffi_pushobj(js_State *J, pdf_obj *obj);
+
+static int ffi_pdf_obj_has(js_State *J, void *obj, const char *key)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_obj *val;
+ int idx;
+
+ if (is_number(key, &idx)) {
+ fz_try(ctx)
+ val = pdf_array_get(ctx, obj, idx);
+ fz_catch(ctx)
+ rethrow(J);
+ } else {
+ fz_try(ctx)
+ val = pdf_dict_gets(ctx, obj, key);
+ fz_catch(ctx)
+ rethrow(J);
+ }
+ if (val) {
+ ffi_pushobj(J, pdf_keep_obj(ctx, val));
+ return 1;
+ }
+ return 0;
+}
+
+static int ffi_pdf_obj_put(js_State *J, void *obj, const char *key)
+{
+ fz_context *ctx = js_getcontext(J);
+ pdf_document *pdf;
+ pdf_obj *val;
+ int idx;
+
+ fz_try(ctx)
+ pdf = pdf_get_bound_document(ctx, obj);
+ fz_catch(ctx)
+ rethrow(J);
+
+ val = ffi_toobj(J, pdf, -1);
+
+ if (is_number(key, &idx)) {
+ fz_try(ctx)
+ if (idx == pdf_array_len(ctx, obj))
+ pdf_array_push(ctx, obj, val);
+ else
+ pdf_array_put(ctx, obj, idx, val);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ rethrow(J);
+ } else {
+ fz_try(ctx)
+ pdf_dict_puts(ctx, obj, key, val);
+ fz_always(ctx)
+ pdf_drop_obj(ctx, val);
+ fz_catch(ctx)
+ rethrow(J);
+ }
+ return 1;
+}
+
+static int ffi_pdf_obj_delete(js_State *J, void *obj, const char *key)
+{
+ fz_context *ctx = js_getcontext(J);
+ int idx;
+
+ if (is_number(key, &idx)) {
+ fz_try(ctx)
+ pdf_array_delete(ctx, obj, idx);
+ fz_catch(ctx)
+ rethrow(J);
+ } else {
+ fz_try(ctx)
+ pdf_dict_dels(ctx, obj, key);
+ fz_catch(ctx)
+ rethrow(J);
+ }
+ return 1;
+}
+
+static void ffi_pushobj(js_State *J, pdf_obj *obj)
+{
+ if (obj) {
+ js_getregistry(J, "pdf_obj");
+ js_newuserdatax(J, "pdf_obj", obj,
+ ffi_pdf_obj_has, ffi_pdf_obj_put, ffi_pdf_obj_delete,
+ ffi_gc_pdf_obj);
+ } else {
+ js_pushnull(J);
+ }
+}
+
static void ffi_new_PDFDocument(js_State *J)
{
fz_context *ctx = js_getcontext(J);
@@ -3022,6 +3036,8 @@ static void ffi_PDFObject_forEach(js_State *J)
}
}
+#endif /* FZ_ENABLE_PDF */
+
int murun_main(int argc, char **argv)
{
fz_context *ctx;
@@ -3236,6 +3252,7 @@ int murun_main(int argc, char **argv)
}
js_setregistry(J, "fz_document_writer");
+#if FZ_ENABLE_PDF
js_newobject(J);
{
jsB_propfun(J, "PDFDocument.toDocument", ffi_PDFDocument_toDocument, 0);
@@ -3295,10 +3312,13 @@ int murun_main(int argc, char **argv)
js_newobject(J);
js_setregistry(J, "pdf_graft_map");
+#endif
js_pushglobal(J);
{
+#if FZ_ENABLE_PDF
jsB_propcon(J, "pdf_document", "PDFDocument", ffi_new_PDFDocument, 1);
+#endif
jsB_propcon(J, "fz_buffer", "Buffer", ffi_new_Buffer, 1);
jsB_propcon(J, "fz_document", "Document", ffi_new_Document, 1);
diff --git a/source/tools/mutool.c b/source/tools/mutool.c
index 3ba45ea0..95c49fa1 100644
--- a/source/tools/mutool.c
+++ b/source/tools/mutool.c
@@ -11,6 +11,7 @@
int muconvert_main(int argc, char *argv[]);
int mudraw_main(int argc, char *argv[]);
int murun_main(int argc, char *argv[]);
+
int pdfclean_main(int argc, char *argv[]);
int pdfextract_main(int argc, char *argv[]);
int pdfinfo_main(int argc, char *argv[]);
@@ -28,6 +29,7 @@ static struct {
{ muconvert_main, "convert", "convert document" },
{ mudraw_main, "draw", "convert document" },
{ murun_main, "run", "run javascript" },
+#if FZ_ENABLE_PDF
{ pdfclean_main, "clean", "rewrite pdf file" },
{ pdfextract_main, "extract", "extract font and image resources" },
{ pdfinfo_main, "info", "show information about pdf resources" },
@@ -36,6 +38,7 @@ static struct {
{ pdfshow_main, "show", "show internal pdf objects" },
{ pdfcreate_main, "create", "create pdf document" },
{ pdfmerge_main, "merge", "merge pages from multiple pdf sources into a new pdf" },
+#endif
};
static int