summaryrefslogtreecommitdiff
path: root/pdf/pdf_page.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-03-13 20:25:38 +0000
committerRobin Watts <robin.watts@artifex.com>2012-03-13 20:59:19 +0000
commit3212863288c4ad6396482b8fdb14db2af27c123f (patch)
tree9d7c7efe3a585c538f6e8d0edd5e3a77b5b8b6b5 /pdf/pdf_page.c
parentb6e9b2f8fe172d7175cea3d14d89f986688639af (diff)
parent33dc06b61c0816854193f006c35a9e797f098a22 (diff)
downloadmupdf-3212863288c4ad6396482b8fdb14db2af27c123f.tar.xz
Merge master and pg_android branches
Bring up to date with current APIs, including text device changes.
Diffstat (limited to 'pdf/pdf_page.c')
-rw-r--r--pdf/pdf_page.c199
1 files changed, 100 insertions, 99 deletions
diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c
index f2bf713e..c4083d20 100644
--- a/pdf/pdf_page.c
+++ b/pdf/pdf_page.c
@@ -1,128 +1,128 @@
-#include "fitz.h"
-#include "mupdf.h"
+#include "fitz-internal.h"
+#include "mupdf-internal.h"
struct info
{
- fz_obj *resources;
- fz_obj *mediabox;
- fz_obj *cropbox;
- fz_obj *rotate;
+ pdf_obj *resources;
+ pdf_obj *mediabox;
+ pdf_obj *cropbox;
+ pdf_obj *rotate;
};
static void
-put_marker_bool(fz_context *ctx, fz_obj *rdb, char *marker, int val)
+put_marker_bool(fz_context *ctx, pdf_obj *rdb, char *marker, int val)
{
- fz_obj *tmp;
+ pdf_obj *tmp;
- tmp = fz_new_bool(ctx, val);
+ tmp = pdf_new_bool(ctx, val);
fz_try(ctx)
{
- fz_dict_puts(rdb, marker, tmp);
+ pdf_dict_puts(rdb, marker, tmp);
}
fz_catch(ctx)
{
- fz_drop_obj(tmp);
+ pdf_drop_obj(tmp);
fz_rethrow(ctx);
}
- fz_drop_obj(tmp);
+ pdf_drop_obj(tmp);
}
static void
-pdf_load_page_tree_node(pdf_document *xref, fz_obj *node, struct info info)
+pdf_load_page_tree_node(pdf_document *xref, pdf_obj *node, struct info info)
{
- fz_obj *dict, *kids, *count;
- fz_obj *obj;
+ pdf_obj *dict, *kids, *count;
+ pdf_obj *obj;
int i, n;
fz_context *ctx = xref->ctx;
/* prevent infinite recursion */
- if (!node || fz_dict_mark(node))
+ if (!node || pdf_dict_mark(node))
return;
fz_try(ctx)
{
- kids = fz_dict_gets(node, "Kids");
- count = fz_dict_gets(node, "Count");
+ kids = pdf_dict_gets(node, "Kids");
+ count = pdf_dict_gets(node, "Count");
- if (fz_is_array(kids) && fz_is_int(count))
+ if (pdf_is_array(kids) && pdf_is_int(count))
{
- obj = fz_dict_gets(node, "Resources");
+ obj = pdf_dict_gets(node, "Resources");
if (obj)
info.resources = obj;
- obj = fz_dict_gets(node, "MediaBox");
+ obj = pdf_dict_gets(node, "MediaBox");
if (obj)
info.mediabox = obj;
- obj = fz_dict_gets(node, "CropBox");
+ obj = pdf_dict_gets(node, "CropBox");
if (obj)
info.cropbox = obj;
- obj = fz_dict_gets(node, "Rotate");
+ obj = pdf_dict_gets(node, "Rotate");
if (obj)
info.rotate = obj;
- n = fz_array_len(kids);
+ n = pdf_array_len(kids);
for (i = 0; i < n; i++)
{
- obj = fz_array_get(kids, i);
+ obj = pdf_array_get(kids, i);
pdf_load_page_tree_node(xref, obj, info);
}
}
- else if ((dict = fz_to_dict(node)) != NULL)
+ else if ((dict = pdf_to_dict(node)) != NULL)
{
- if (info.resources && !fz_dict_gets(dict, "Resources"))
- fz_dict_puts(dict, "Resources", info.resources);
- if (info.mediabox && !fz_dict_gets(dict, "MediaBox"))
- fz_dict_puts(dict, "MediaBox", info.mediabox);
- if (info.cropbox && !fz_dict_gets(dict, "CropBox"))
- fz_dict_puts(dict, "CropBox", info.cropbox);
- if (info.rotate && !fz_dict_gets(dict, "Rotate"))
- fz_dict_puts(dict, "Rotate", info.rotate);
+ if (info.resources && !pdf_dict_gets(dict, "Resources"))
+ pdf_dict_puts(dict, "Resources", info.resources);
+ if (info.mediabox && !pdf_dict_gets(dict, "MediaBox"))
+ pdf_dict_puts(dict, "MediaBox", info.mediabox);
+ if (info.cropbox && !pdf_dict_gets(dict, "CropBox"))
+ pdf_dict_puts(dict, "CropBox", info.cropbox);
+ if (info.rotate && !pdf_dict_gets(dict, "Rotate"))
+ pdf_dict_puts(dict, "Rotate", info.rotate);
if (xref->page_len == xref->page_cap)
{
fz_warn(ctx, "found more pages than expected");
xref->page_cap ++;
- xref->page_refs = fz_resize_array(ctx, xref->page_refs, xref->page_cap, sizeof(fz_obj*));
- xref->page_objs = fz_resize_array(ctx, xref->page_objs, xref->page_cap, sizeof(fz_obj*));
+ xref->page_refs = fz_resize_array(ctx, xref->page_refs, xref->page_cap, sizeof(pdf_obj*));
+ xref->page_objs = fz_resize_array(ctx, xref->page_objs, xref->page_cap, sizeof(pdf_obj*));
}
- xref->page_refs[xref->page_len] = fz_keep_obj(node);
- xref->page_objs[xref->page_len] = fz_keep_obj(dict);
+ xref->page_refs[xref->page_len] = pdf_keep_obj(node);
+ xref->page_objs[xref->page_len] = pdf_keep_obj(dict);
xref->page_len ++;
}
}
fz_catch(ctx)
{
- fz_dict_unmark(node);
+ pdf_dict_unmark(node);
fz_rethrow(ctx);
}
- fz_dict_unmark(node);
+ pdf_dict_unmark(node);
}
static void
pdf_load_page_tree(pdf_document *xref)
{
fz_context *ctx = xref->ctx;
- fz_obj *catalog;
- fz_obj *pages;
- fz_obj *count;
+ pdf_obj *catalog;
+ pdf_obj *pages;
+ pdf_obj *count;
struct info info;
if (xref->page_len)
return;
- catalog = fz_dict_gets(xref->trailer, "Root");
- pages = fz_dict_gets(catalog, "Pages");
- count = fz_dict_gets(pages, "Count");
+ catalog = pdf_dict_gets(xref->trailer, "Root");
+ pages = pdf_dict_gets(catalog, "Pages");
+ count = pdf_dict_gets(pages, "Count");
- if (!fz_is_dict(pages))
+ if (!pdf_is_dict(pages))
fz_throw(ctx, "missing page tree");
- if (!fz_is_int(count))
+ if (!pdf_is_int(count))
fz_throw(ctx, "missing page count");
- xref->page_cap = fz_to_int(count);
+ xref->page_cap = pdf_to_int(count);
xref->page_len = 0;
- xref->page_refs = fz_malloc_array(ctx, xref->page_cap, sizeof(fz_obj*));
- xref->page_objs = fz_malloc_array(ctx, xref->page_cap, sizeof(fz_obj*));
+ xref->page_refs = fz_malloc_array(ctx, xref->page_cap, sizeof(pdf_obj*));
+ xref->page_objs = fz_malloc_array(ctx, xref->page_cap, sizeof(pdf_obj*));
info.resources = NULL;
info.mediabox = NULL;
@@ -140,84 +140,84 @@ pdf_count_pages(pdf_document *xref)
}
int
-pdf_find_page_number(pdf_document *xref, fz_obj *page)
+pdf_lookup_page_number(pdf_document *xref, pdf_obj *page)
{
- int i, num = fz_to_num(page);
+ int i, num = pdf_to_num(page);
pdf_load_page_tree(xref);
for (i = 0; i < xref->page_len; i++)
- if (num == fz_to_num(xref->page_refs[i]))
+ if (num == pdf_to_num(xref->page_refs[i]))
return i;
return -1;
}
/* We need to know whether to install a page-level transparency group */
-static int pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb);
+static int pdf_resources_use_blending(fz_context *ctx, pdf_obj *rdb);
static int
-pdf_extgstate_uses_blending(fz_context *ctx, fz_obj *dict)
+pdf_extgstate_uses_blending(fz_context *ctx, pdf_obj *dict)
{
- fz_obj *obj = fz_dict_gets(dict, "BM");
- if (fz_is_name(obj) && strcmp(fz_to_name(obj), "Normal"))
+ pdf_obj *obj = pdf_dict_gets(dict, "BM");
+ if (pdf_is_name(obj) && strcmp(pdf_to_name(obj), "Normal"))
return 1;
return 0;
}
static int
-pdf_pattern_uses_blending(fz_context *ctx, fz_obj *dict)
+pdf_pattern_uses_blending(fz_context *ctx, pdf_obj *dict)
{
- fz_obj *obj;
- obj = fz_dict_gets(dict, "Resources");
+ pdf_obj *obj;
+ obj = pdf_dict_gets(dict, "Resources");
if (pdf_resources_use_blending(ctx, obj))
return 1;
- obj = fz_dict_gets(dict, "ExtGState");
+ obj = pdf_dict_gets(dict, "ExtGState");
return pdf_extgstate_uses_blending(ctx, obj);
}
static int
-pdf_xobject_uses_blending(fz_context *ctx, fz_obj *dict)
+pdf_xobject_uses_blending(fz_context *ctx, pdf_obj *dict)
{
- fz_obj *obj = fz_dict_gets(dict, "Resources");
+ pdf_obj *obj = pdf_dict_gets(dict, "Resources");
return pdf_resources_use_blending(ctx, obj);
}
static int
-pdf_resources_use_blending(fz_context *ctx, fz_obj *rdb)
+pdf_resources_use_blending(fz_context *ctx, pdf_obj *rdb)
{
- fz_obj *obj;
+ pdf_obj *obj;
int i, n, useBM = 0;
if (!rdb)
return 0;
/* Have we been here before and stashed an answer? */
- obj = fz_dict_gets(rdb, ".useBM");
+ obj = pdf_dict_gets(rdb, ".useBM");
if (obj)
- return fz_to_bool(obj);
+ return pdf_to_bool(obj);
/* stop on cyclic resource dependencies */
- if (fz_dict_mark(rdb))
+ if (pdf_dict_mark(rdb))
return 0;
fz_try(ctx)
{
- obj = fz_dict_gets(rdb, "ExtGState");
- n = fz_dict_len(obj);
+ obj = pdf_dict_gets(rdb, "ExtGState");
+ n = pdf_dict_len(obj);
for (i = 0; i < n; i++)
- if (pdf_extgstate_uses_blending(ctx, fz_dict_get_val(obj, i)))
+ if (pdf_extgstate_uses_blending(ctx, pdf_dict_get_val(obj, i)))
goto found;
- obj = fz_dict_gets(rdb, "Pattern");
- n = fz_dict_len(obj);
+ obj = pdf_dict_gets(rdb, "Pattern");
+ n = pdf_dict_len(obj);
for (i = 0; i < n; i++)
- if (pdf_pattern_uses_blending(ctx, fz_dict_get_val(obj, i)))
+ if (pdf_pattern_uses_blending(ctx, pdf_dict_get_val(obj, i)))
goto found;
- obj = fz_dict_gets(rdb, "XObject");
- n = fz_dict_len(obj);
+ obj = pdf_dict_gets(rdb, "XObject");
+ n = pdf_dict_len(obj);
for (i = 0; i < n; i++)
- if (pdf_xobject_uses_blending(ctx, fz_dict_get_val(obj, i)))
+ if (pdf_xobject_uses_blending(ctx, pdf_dict_get_val(obj, i)))
goto found;
if (0)
{
@@ -227,10 +227,10 @@ found:
}
fz_catch(ctx)
{
- fz_dict_unmark(rdb);
+ pdf_dict_unmark(rdb);
fz_rethrow(ctx);
}
- fz_dict_unmark(rdb);
+ pdf_dict_unmark(rdb);
put_marker_bool(ctx, rdb, ".useBM", useBM);
return useBM;
@@ -239,7 +239,7 @@ found:
/* we need to combine all sub-streams into one for the content stream interpreter */
static fz_buffer *
-pdf_load_page_contents_array(pdf_document *xref, fz_obj *list)
+pdf_load_page_contents_array(pdf_document *xref, pdf_obj *list)
{
fz_buffer *big;
fz_buffer *one;
@@ -248,14 +248,14 @@ pdf_load_page_contents_array(pdf_document *xref, fz_obj *list)
big = fz_new_buffer(ctx, 32 * 1024);
- n = fz_array_len(list);
+ n = pdf_array_len(list);
fz_var(i); /* Workaround Mac compiler bug */
for (i = 0; i < n; i++)
{
- fz_obj *stm = fz_array_get(list, i);
+ pdf_obj *stm = pdf_array_get(list, i);
fz_try(ctx)
{
- one = pdf_load_stream(xref, fz_to_num(stm), fz_to_gen(stm));
+ one = pdf_load_stream(xref, pdf_to_num(stm), pdf_to_gen(stm));
}
fz_catch(ctx)
{
@@ -277,24 +277,25 @@ pdf_load_page_contents_array(pdf_document *xref, fz_obj *list)
fz_drop_buffer(ctx, big);
fz_throw(ctx, "cannot load content stream");
}
+ fz_trim_buffer(ctx, big);
return big;
}
static fz_buffer *
-pdf_load_page_contents(pdf_document *xref, fz_obj *obj)
+pdf_load_page_contents(pdf_document *xref, pdf_obj *obj)
{
fz_context *ctx = xref->ctx;
- if (fz_is_array(obj))
+ if (pdf_is_array(obj))
{
return pdf_load_page_contents_array(xref, obj);
/* RJW: "cannot load content stream array" */
}
- else if (pdf_is_stream(xref, fz_to_num(obj), fz_to_gen(obj)))
+ else if (pdf_is_stream(xref, pdf_to_num(obj), pdf_to_gen(obj)))
{
- return pdf_load_stream(xref, fz_to_num(obj), fz_to_gen(obj));
- /* RJW: "cannot load content stream (%d 0 R)", fz_to_num(obj) */
+ return pdf_load_stream(xref, pdf_to_num(obj), pdf_to_gen(obj));
+ /* RJW: "cannot load content stream (%d 0 R)", pdf_to_num(obj) */
}
fz_warn(ctx, "page contents missing, leaving page blank");
@@ -307,7 +308,7 @@ pdf_load_page(pdf_document *xref, int number)
fz_context *ctx = xref->ctx;
pdf_page *page;
pdf_annot *annot;
- fz_obj *pageobj, *pageref, *obj;
+ pdf_obj *pageobj, *pageref, *obj;
fz_rect mediabox, cropbox, realbox;
fz_matrix ctm;
@@ -325,7 +326,7 @@ pdf_load_page(pdf_document *xref, int number)
page->links = NULL;
page->annots = NULL;
- mediabox = pdf_to_rect(ctx, fz_dict_gets(pageobj, "MediaBox"));
+ mediabox = pdf_to_rect(ctx, pdf_dict_gets(pageobj, "MediaBox"));
if (fz_is_empty_rect(mediabox))
{
fz_warn(ctx, "cannot find page size for page %d", number + 1);
@@ -335,7 +336,7 @@ pdf_load_page(pdf_document *xref, int number)
mediabox.y1 = 792;
}
- cropbox = pdf_to_rect(ctx, fz_dict_gets(pageobj, "CropBox"));
+ cropbox = pdf_to_rect(ctx, pdf_dict_gets(pageobj, "CropBox"));
if (!fz_is_empty_rect(cropbox))
mediabox = fz_intersect_rect(mediabox, cropbox);
@@ -350,24 +351,24 @@ pdf_load_page(pdf_document *xref, int number)
page->mediabox = fz_unit_rect;
}
- page->rotate = fz_to_int(fz_dict_gets(pageobj, "Rotate"));
+ page->rotate = pdf_to_int(pdf_dict_gets(pageobj, "Rotate"));
ctm = fz_concat(fz_rotate(-page->rotate), fz_scale(1, -1));
realbox = fz_transform_rect(ctm, page->mediabox);
page->ctm = fz_concat(ctm, fz_translate(-realbox.x0, -realbox.y0));
- obj = fz_dict_gets(pageobj, "Annots");
+ obj = pdf_dict_gets(pageobj, "Annots");
if (obj)
{
page->links = pdf_load_link_annots(xref, obj, page->ctm);
page->annots = pdf_load_annots(xref, obj);
}
- page->resources = fz_dict_gets(pageobj, "Resources");
+ page->resources = pdf_dict_gets(pageobj, "Resources");
if (page->resources)
- fz_keep_obj(page->resources);
+ pdf_keep_obj(page->resources);
- obj = fz_dict_gets(pageobj, "Contents");
+ obj = pdf_dict_gets(pageobj, "Contents");
fz_try(ctx)
{
page->contents = pdf_load_page_contents(xref, obj);
@@ -382,7 +383,7 @@ pdf_load_page(pdf_document *xref, int number)
fz_catch(ctx)
{
pdf_free_page(xref, page);
- fz_throw(ctx, "cannot load page %d contents (%d 0 R)", number + 1, fz_to_num(pageref));
+ fz_throw(ctx, "cannot load page %d contents (%d 0 R)", number + 1, pdf_to_num(pageref));
}
return page;
@@ -408,7 +409,7 @@ void
pdf_free_page(pdf_document *xref, pdf_page *page)
{
if (page->resources)
- fz_drop_obj(page->resources);
+ pdf_drop_obj(page->resources);
if (page->contents)
fz_drop_buffer(xref->ctx, page->contents);
if (page->links)