summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-01-27 17:37:04 +0000
committerRobin Watts <robin.watts@artifex.com>2014-02-10 15:04:49 +0000
commitee420dddc55381976d5fceab32a4e361877818e5 (patch)
tree1185f086857dc09c196bfe0890b9e76e877f4d0f
parent563fb862e3094f1e2070bc3b975818c226aac154 (diff)
downloadmupdf-ee420dddc55381976d5fceab32a4e361877818e5.tar.xz
Add pdf_output_obj function.
Reuses the same internals as pdf_fprintf_obj etc.
-rw-r--r--include/mupdf/pdf/object.h1
-rw-r--r--source/pdf/pdf-object.c23
2 files changed, 24 insertions, 0 deletions
diff --git a/include/mupdf/pdf/object.h b/include/mupdf/pdf/object.h
index 15886233..77c02382 100644
--- a/include/mupdf/pdf/object.h
+++ b/include/mupdf/pdf/object.h
@@ -109,6 +109,7 @@ int pdf_obj_parent_num(pdf_obj *obj);
int pdf_sprint_obj(char *s, int n, pdf_obj *obj, int tight);
int pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight);
+int pdf_output_obj(fz_output *out, pdf_obj *obj);
#ifndef NDEBUG
void pdf_print_obj(pdf_obj *obj);
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c
index 0ee399c5..b8147970 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -1737,6 +1737,29 @@ pdf_fprint_obj(FILE *fp, pdf_obj *obj, int tight)
return n;
}
+int pdf_output_obj(fz_output *out, pdf_obj *obj)
+{
+ char buf[1024];
+ char *ptr;
+ int n;
+ int tight = 1;
+
+ n = pdf_sprint_obj(NULL, 0, obj, tight);
+ if ((n + 1) < sizeof buf)
+ {
+ pdf_sprint_obj(buf, sizeof buf, obj, tight);
+ fz_printf(out, "%s\n", buf);
+ }
+ else
+ {
+ ptr = fz_malloc(obj->doc->ctx, n + 1);
+ pdf_sprint_obj(ptr, n + 1, obj, tight);
+ fz_printf(out, "%s\n", ptr);
+ fz_free(obj->doc->ctx, ptr);
+ }
+ return n;
+}
+
#ifndef NDEBUG
void
pdf_print_obj(pdf_obj *obj)