summaryrefslogtreecommitdiff
path: root/src/page.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2018-02-03 22:24:59 +0000
committerVincent Sanders <vince@kyllikki.org>2018-02-03 22:24:59 +0000
commite6af9e997df381f053f3f8c85a678ad07677c791 (patch)
tree9608ed7de269e5d2536201551678340c45433463 /src/page.c
parent1ca90f384d4f2311cbf0abd44d8e4e5b7a4abb37 (diff)
downloadlibnspdf-e6af9e997df381f053f3f8c85a678ad07677c791.tar.gz
libnspdf-e6af9e997df381f053f3f8c85a678ad07677c791.tar.bz2
correctly extract the page boundaries from the page tree
Diffstat (limited to 'src/page.c')
-rw-r--r--src/page.c82
1 files changed, 79 insertions, 3 deletions
diff --git a/src/page.c b/src/page.c
index e4bbae4..d55a92f 100644
--- a/src/page.c
+++ b/src/page.c
@@ -22,8 +22,13 @@
/** page entry */
struct page_table_entry {
struct cos_object *resources;
- struct cos_object *mediabox;
struct cos_object *contents;
+ struct cos_rectangle mediabox; /* extent of media - required */
+ struct cos_rectangle cropbox; /* default is mediabox */
+ struct cos_rectangle bleedbox; /* default is crop box */
+ struct cos_rectangle trimbox; /* default is crop box */
+ struct cos_rectangle artbox; /* default is crop box */
+
};
/**
@@ -90,6 +95,7 @@ nspdf__decode_page_tree(struct nspdf_doc *doc,
} else if (strcmp(type, "Page") == 0) {
struct page_table_entry *page;
+ struct cos_object *rect_array;
page = doc->page_table + (*page_index);
@@ -106,11 +112,68 @@ nspdf__decode_page_tree(struct nspdf_doc *doc,
res = cos_heritable_dictionary_array(doc,
page_tree_node,
"MediaBox",
- &(page->mediabox));
+ &rect_array);
+ if (res != NSPDFERROR_OK) {
+ return res;
+ }
+
+ res = cos_get_rectangle(doc, rect_array, &page->mediabox);
if (res != NSPDFERROR_OK) {
return res;
}
+ /* optional heritable crop box */
+ res = cos_heritable_dictionary_array(doc,
+ page_tree_node,
+ "CropBox",
+ &rect_array);
+ if (res == NSPDFERROR_OK) {
+ res = cos_get_rectangle(doc, rect_array, &page->cropbox);
+ }
+ if (res != NSPDFERROR_OK) {
+ /* default is mediabox */
+ page->cropbox = page->mediabox;
+ }
+
+ /* optional bleed box */
+ res = cos_get_dictionary_array(doc,
+ page_tree_node,
+ "BleedBox",
+ &rect_array);
+ if (res == NSPDFERROR_OK) {
+ res = cos_get_rectangle(doc, rect_array, &page->bleedbox);
+ }
+ if (res != NSPDFERROR_OK) {
+ /* default is cropbox */
+ page->bleedbox = page->cropbox;
+ }
+
+ /* optional trim box */
+ res = cos_get_dictionary_array(doc,
+ page_tree_node,
+ "TrimBox",
+ &rect_array);
+ if (res == NSPDFERROR_OK) {
+ res = cos_get_rectangle(doc, rect_array, &page->trimbox);
+ }
+ if (res != NSPDFERROR_OK) {
+ /* default is cropbox */
+ page->trimbox = page->cropbox;
+ }
+
+ /* optional art box */
+ res = cos_get_dictionary_array(doc,
+ page_tree_node,
+ "ArtBox",
+ &rect_array);
+ if (res == NSPDFERROR_OK) {
+ res = cos_get_rectangle(doc, rect_array, &page->artbox);
+ }
+ if (res != NSPDFERROR_OK) {
+ /* default is cropbox */
+ page->artbox = page->cropbox;
+ }
+
/* optional page contents */
res = cos_get_dictionary_value(doc,
page_tree_node,
@@ -323,7 +386,6 @@ nspdf_page_render(struct nspdf_doc *doc,
nspdferror res;
struct content_operation *operation;
unsigned int idx;
-
struct graphics_state gs;
page_entry = doc->page_table + page_number;
@@ -406,3 +468,17 @@ nspdf_page_render(struct nspdf_doc *doc,
return res;
}
+
+
+nspdferror
+nspdf_get_page_dimensions(struct nspdf_doc *doc,
+ unsigned int page_number,
+ float *width,
+ float *height)
+{
+ struct page_table_entry *page_entry;
+ page_entry = doc->page_table + page_number;
+ *width = page_entry->cropbox.urx - page_entry->cropbox.llx;
+ *height = page_entry->cropbox.ury - page_entry->cropbox.lly;
+ return NSPDFERROR_OK;
+}