diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-03-03 12:36:14 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2016-03-14 17:08:28 +0100 |
commit | 27d73f2043e72dc146f543bbc871dbf820f9900e (patch) | |
tree | 2fa7d7a3e1ca281a3602eb9b1ce91edff9b9c0fc /source/tools | |
parent | e2b8c1638eec8aee44291074414fa161f9e2213f (diff) | |
download | mupdf-27d73f2043e72dc146f543bbc871dbf820f9900e.tar.xz |
js: Add obj.readStream and obj.readRawStream.
Diffstat (limited to 'source/tools')
-rw-r--r-- | source/tools/murun.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c index d4a68b79..9eef2d02 100644 --- a/source/tools/murun.c +++ b/source/tools/murun.c @@ -2498,6 +2498,52 @@ static void ffi_PDFObject_valueOf(js_State *J) js_copy(J, 0); } +static void ffi_PDFObject_isStream(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + pdf_obj *obj = js_touserdata(J, 0, "pdf_obj"); + int b = 0; + fz_try(ctx) + b = pdf_is_stream(ctx, obj); + fz_catch(ctx) + rethrow(J); + js_pushboolean(J, b); +} + +static void ffi_PDFObject_readStream(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + pdf_obj *obj = js_touserdata(J, 0, "pdf_obj"); + pdf_document *pdf; + fz_buffer *buf; + + fz_try(ctx) { + if (!pdf_is_stream(ctx, obj)) + fz_throw(ctx, FZ_ERROR_GENERIC, "not a stream"); + pdf = pdf_get_indirect_document(ctx, obj); + buf = pdf_load_stream(ctx, pdf, pdf_to_num(ctx, obj), pdf_to_gen(ctx, obj)); + } fz_catch(ctx) + rethrow(J); + ffi_pushbuffer(J, buf); +} + +static void ffi_PDFObject_readRawStream(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + pdf_obj *obj = js_touserdata(J, 0, "pdf_obj"); + pdf_document *pdf; + fz_buffer *buf; + + fz_try(ctx) { + if (!pdf_is_stream(ctx, obj)) + fz_throw(ctx, FZ_ERROR_GENERIC, "not a stream"); + pdf = pdf_get_indirect_document(ctx, obj); + buf = pdf_load_raw_stream(ctx, pdf, pdf_to_num(ctx, obj), pdf_to_gen(ctx, obj)); + } fz_catch(ctx) + rethrow(J); + ffi_pushbuffer(J, buf); +} + static void ffi_PDFObject_forEach(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -2789,6 +2835,9 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "PDFObject.resolve", ffi_PDFObject_resolve, 0); jsB_propfun(J, "PDFObject.toString", ffi_PDFObject_toString, 1); jsB_propfun(J, "PDFObject.valueOf", ffi_PDFObject_valueOf, 0); + jsB_propfun(J, "PDFObject.isStream", ffi_PDFObject_isStream, 0); + jsB_propfun(J, "PDFObject.readStream", ffi_PDFObject_readStream, 0); + jsB_propfun(J, "PDFObject.readRawStream", ffi_PDFObject_readRawStream, 0); jsB_propfun(J, "PDFObject.forEach", ffi_PDFObject_forEach, 1); } js_setregistry(J, "pdf_obj"); |