summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2006-05-10 12:55:16 +0000
committerBen Harris <bjh21@bjh21.me.uk>2006-05-10 12:55:16 +0000
commit2685a444105ca14ea8653d81945abc9509b245a0 (patch)
treedb98f522a71eb5c5210d05ca0a4184ae25995706
parentb5945e9cec63ac9b990074805095d4e82c2d9a9b (diff)
downloadhalibut-2685a444105ca14ea8653d81945abc9509b245a0.zip
halibut-2685a444105ca14ea8653d81945abc9509b245a0.tar.gz
halibut-2685a444105ca14ea8653d81945abc9509b245a0.tar.bz2
halibut-2685a444105ca14ea8653d81945abc9509b245a0.tar.xz
A page's MediaBox, like its Resources, is inheritable, so rather than
putting one in each page, put a single one in the top-level page tree node. This saves us all a few kilobytes in the Halibut manual. [originally from svn r6671]
-rw-r--r--bk_pdf.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/bk_pdf.c b/bk_pdf.c
index 75d1f83..bd705eb 100644
--- a/bk_pdf.c
+++ b/bk_pdf.c
@@ -40,7 +40,8 @@ static void pdf_string_len(void (*add)(object *, char const *),
static void objref(object *o, object *dest);
static void make_pages_node(object *node, object *parent, page_data *first,
- page_data *last, object *resources);
+ page_data *last, object *resources,
+ object *mediabox);
static int make_outline(object *parent, outline_element *start, int n,
int open);
static int pdf_versionid(FILE *fp, word *words);
@@ -56,7 +57,7 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords,
char *filename;
paragraph *p;
objlist olist;
- object *o, *cat, *outlines, *pages, *resources;
+ object *o, *cat, *outlines, *pages, *resources, *mediabox;
int fileoff;
IGNORE(keywords);
@@ -160,6 +161,15 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords,
}
objtext(resources, ">>\n>>\n");
+ {
+ char buf[255];
+ mediabox = new_object(&olist);
+ sprintf(buf, "[0 0 %g %g]\n",
+ doc->paper_width / FUNITS_PER_PT,
+ doc->paper_height / FUNITS_PER_PT);
+ objtext(mediabox, buf);
+ }
+
/*
* Define the page objects for each page, and get each one
* ready to have a `Parent' specification added to it.
@@ -175,7 +185,7 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords,
/*
* Recursively build the page tree.
*/
- make_pages_node(pages, NULL, doc->pages, NULL, resources);
+ make_pages_node(pages, NULL, doc->pages, NULL, resources, mediabox);
/*
* Create and render the individual pages.
@@ -200,12 +210,9 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords,
* that it's inheritable and may be omitted if it's present
* in a Pages node. In our case it is: it's present in the
* topmost /Pages node because we carefully put it there.
- * So we don't need a /Resources entry here.
+ * So we don't need a /Resources entry here. The same applies
+ * to /MediaBox.
*/
- sprintf(buf, "/MediaBox [0 0 %g %g]\n",
- doc->paper_width / FUNITS_PER_PT,
- doc->paper_height / FUNITS_PER_PT);
- objtext(opage, buf);
/*
* Now we're ready to define a content stream containing
@@ -509,7 +516,8 @@ static void objref(object *o, object *dest)
}
static void make_pages_node(object *node, object *parent, page_data *first,
- page_data *last, object *resources)
+ page_data *last, object *resources,
+ object *mediabox)
{
int count;
page_data *page;
@@ -557,7 +565,8 @@ static void make_pages_node(object *node, object *parent, page_data *first,
objtext((object *)thisfirst->spare, "\n");
} else {
object *newnode = new_object(node->list);
- make_pages_node(newnode, node, thisfirst, thislast, NULL);
+ make_pages_node(newnode, node, thisfirst, thislast,
+ NULL, NULL);
objref(node, newnode);
}
objtext(node, "\n");
@@ -584,6 +593,11 @@ static void make_pages_node(object *node, object *parent, page_data *first,
objref(node, resources);
objtext(node, "\n");
}
+ if (mediabox) {
+ objtext(node, "/MediaBox ");
+ objref(node, mediabox);
+ objtext(node, "\n");
+ }
objtext(node, ">>\n");
}