summaryrefslogtreecommitdiff
path: root/source/tools/murun.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-06-19 13:15:31 +0200
committerRobin Watts <robin.watts@artifex.com>2018-06-22 16:48:50 +0100
commitf7ace61076d0ab3c71e1d2bd70967ddb0b86f220 (patch)
tree8bd8b4fe4d7414685d162f66911e9951ea3dce16 /source/tools/murun.c
parent148b0934370336fc8b260e8c3aef83daf4d80ba4 (diff)
downloadmupdf-f7ace61076d0ab3c71e1d2bd70967ddb0b86f220.tar.xz
Keep copy of decoded utf8 text string in pdf_obj.
Removes the need to alloc/free text strings in the API, allowing for simple functions like pdf_dict_get_text_string.
Diffstat (limited to 'source/tools/murun.c')
-rw-r--r--source/tools/murun.c40
1 files changed, 10 insertions, 30 deletions
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 3ed840fb..c74e4bbc 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3837,19 +3837,14 @@ static void ffi_PDFObject_asString(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_obj *obj = js_touserdata(J, 0, "pdf_obj");
- char *string = NULL;
+ const char *string = NULL;
fz_try(ctx)
- string = pdf_to_utf8(ctx, obj);
+ string = pdf_to_text_string(ctx, obj);
fz_catch(ctx)
rethrow(J);
- if (js_try(J)) {
- fz_free(ctx, string);
- js_throw(J);
- }
js_pushstring(J, string);
- fz_free(ctx, string);
js_endtry(J);
}
@@ -3858,12 +3853,11 @@ static void ffi_PDFObject_asByteString(js_State *J)
fz_context *ctx = js_getcontext(J);
pdf_obj *obj = js_touserdata(J, 0, "pdf_obj");
const char *buf;
- int i, len = 0;
+ size_t i, len = 0;
- fz_try(ctx) {
- buf = pdf_to_str_buf(ctx, obj);
- len = pdf_to_str_len(ctx, obj);
- } fz_catch(ctx)
+ fz_try(ctx)
+ buf = pdf_to_string(ctx, obj, &len);
+ fz_catch(ctx)
rethrow(J);
js_newarray(J);
@@ -4076,21 +4070,14 @@ static void ffi_PDFAnnotation_getContents(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
- char *contents = NULL;
+ const char *contents = NULL;
fz_try(ctx)
- contents = pdf_copy_annot_contents(ctx, annot);
+ contents = pdf_get_annot_contents(ctx, annot);
fz_catch(ctx)
rethrow(J);
- if (js_try(J)) {
- fz_free(ctx, contents);
- js_throw(J);
- }
js_pushstring(J, contents);
- js_endtry(J);
-
- fz_free(ctx, contents);
}
static void ffi_PDFAnnotation_setContents(js_State *J)
@@ -4375,21 +4362,14 @@ static void ffi_PDFAnnotation_getAuthor(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_annot *annot = js_touserdata(J, 0, "pdf_annot");
- char *author = NULL;
+ const char *author = NULL;
fz_try(ctx)
- author = pdf_copy_annot_author(ctx, annot);
+ author = pdf_get_annot_author(ctx, annot);
fz_catch(ctx)
rethrow(J);
- if (js_try(J)) {
- fz_free(ctx, author);
- js_throw(J);
- }
js_pushstring(J, author);
- js_endtry(J);
-
- fz_free(ctx, author);
}
static void ffi_PDFAnnotation_setAuthor(js_State *J)