summaryrefslogtreecommitdiff
path: root/bk_ps.c
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2004-04-16 10:56:31 +0000
committerSimon Tatham <anakin@pobox.com>2004-04-16 10:56:31 +0000
commitf2cf240dc050f1eb376dfd1d952b3a255893be6f (patch)
tree776e434dd7ca5b86616e3a024b2915b2838f92bb /bk_ps.c
parent046a6dc8493e42e9e9c7f0fec5a454730f6f689b (diff)
downloadhalibut-f2cf240dc050f1eb376dfd1d952b3a255893be6f.zip
halibut-f2cf240dc050f1eb376dfd1d952b3a255893be6f.tar.gz
halibut-f2cf240dc050f1eb376dfd1d952b3a255893be6f.tar.bz2
halibut-f2cf240dc050f1eb376dfd1d952b3a255893be6f.tar.xz
Compacted PS and PDF output files by removing redundant reiterations
of the same font and position designations. Reduced the size of the Halibut manual PDF to less than half what it started out as, and the PS one to more like a third of its original size. [originally from svn r4083]
Diffstat (limited to 'bk_ps.c')
-rw-r--r--bk_ps.c65
1 files changed, 55 insertions, 10 deletions
diff --git a/bk_ps.c b/bk_ps.c
index c9f4223..7a59ac0 100644
--- a/bk_ps.c
+++ b/bk_ps.c
@@ -73,6 +73,27 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords,
fprintf(fp, "%%%%EndComments\n");
fprintf(fp, "%%%%BeginProlog\n");
+ /*
+ * Supply a prologue function which allows a reasonably
+ * compressed representation of the text on the pages.
+ *
+ * Expects two arguments: a y-coordinate, and then an array.
+ * Elements of the array are processed sequentially as follows:
+ *
+ * - a number is treated as an x-coordinate
+ * - an array is treated as a (font, size) pair
+ * - a string is shown
+ */
+ fprintf(fp,
+ "/t {\n"
+ " exch /y exch def {\n"
+ " /x exch def\n"
+ " x type [] type eq {x aload pop scalefont setfont} if\n"
+ " x type dup 1 type eq exch 1.0 type eq or {x y moveto} if\n"
+ " x type () type eq {x show} if\n"
+ " } forall\n"
+ "} def\n");
+
fprintf(fp, "%%%%EndProlog\n");
fprintf(fp, "%%%%BeginSetup\n");
@@ -119,7 +140,7 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords,
*/
pageno = 0;
for (page = doc->pages; page; page = page->next) {
- text_fragment *frag;
+ text_fragment *frag, *frag_end;
rect *r;
pageno++;
@@ -154,20 +175,44 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords,
r->h / 4096.0, r->w / 4096.0);
}
- for (frag = page->first_text; frag; frag = frag->next) {
+ frag = page->first_text;
+ while (frag) {
+ font_encoding *fe;
+ int fs;
char *c;
- fprintf(fp, "%s %d scalefont setfont %g %g moveto (",
- frag->fe->name, frag->fontsize,
- frag->x/4096.0, frag->y/4096.0);
+ /*
+ * Collect all the adjacent text fragments with the
+ * same y-coordinate.
+ */
+ for (frag_end = frag;
+ frag_end && frag_end->y == frag->y;
+ frag_end = frag_end->next);
+
+ fprintf(fp, "%g[", frag->y / 4096.0);
+
+ fe = NULL;
+ fs = -1;
+
+ while (frag && frag != frag_end) {
+
+ if (frag->fe != fe || frag->fontsize != fs)
+ fprintf(fp, "[%s %d]", frag->fe->name, frag->fontsize);
+ fe = frag->fe;
+ fs = frag->fontsize;
+
+ fprintf(fp, "%g(", frag->x/4096.0);
+ for (c = frag->text; *c; c++) {
+ if (*c == '(' || *c == ')' || *c == '\\')
+ fputc('\\', fp);
+ fputc(*c, fp);
+ }
+ fprintf(fp, ")");
- for (c = frag->text; *c; c++) {
- if (*c == '(' || *c == ')' || *c == '\\')
- fputc('\\', fp);
- fputc(*c, fp);
+ frag = frag->next;
}
- fprintf(fp, ") show\n");
+ fprintf(fp, "]t\n");
}
fprintf(fp, "showpage\n");