From 17c71b41790ba139de121fb3e987532ce3979dff Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 21 Sep 2004 18:09:35 +0000 Subject: [PATCH] Replace the hardcoded instances of "4096" and "4096.0" in the paper backends with a macro. halibut.ps and halibut.pdf are identical (modulo dates) over this change. git-svn-id: svn://svn.tartarus.org/sgt/halibut@4564 cda61777-01e9-0310-a592-d414129be87e --- bk_paper.c | 94 +++++++++++++++++++++++++++++++------------------------------- bk_pdf.c | 21 ++++++++------ bk_ps.c | 22 ++++++++------- paper.h | 4 +++ 4 files changed, 75 insertions(+), 66 deletions(-) diff --git a/bk_paper.c b/bk_paper.c index eb3caf0..cab3a11 100644 --- a/bk_paper.c +++ b/bk_paper.c @@ -199,31 +199,31 @@ static paper_conf paper_configure(paragraph *source, font_list *fontlist) { /* * Defaults. */ - ret.paper_width = 595 * 4096; - ret.paper_height = 841 * 4096; - ret.left_margin = 72 * 4096; - ret.top_margin = 72 * 4096; - ret.right_margin = 72 * 4096; - ret.bottom_margin = 108 * 4096; - ret.indent_list_bullet = 6 * 4096; - ret.indent_list_after = 18 * 4096; - ret.indent_quote = 18 * 4096; - ret.base_leading = 4096; - ret.base_para_spacing = 10 * 4096; - ret.chapter_top_space = 72 * 4096; - ret.sect_num_left_space = 12 * 4096; - ret.chapter_underline_depth = 14 * 4096; - ret.chapter_underline_thickness = 3 * 4096; - ret.rule_thickness = 1 * 4096; + ret.paper_width = 595 * UNITS_PER_PT; + ret.paper_height = 841 * UNITS_PER_PT; + ret.left_margin = 72 * UNITS_PER_PT; + ret.top_margin = 72 * UNITS_PER_PT; + ret.right_margin = 72 * UNITS_PER_PT; + ret.bottom_margin = 108 * UNITS_PER_PT; + ret.indent_list_bullet = 6 * UNITS_PER_PT; + ret.indent_list_after = 18 * UNITS_PER_PT; + ret.indent_quote = 18 * UNITS_PER_PT; + ret.base_leading = UNITS_PER_PT; + ret.base_para_spacing = 10 * UNITS_PER_PT; + ret.chapter_top_space = 72 * UNITS_PER_PT; + ret.sect_num_left_space = 12 * UNITS_PER_PT; + ret.chapter_underline_depth = 14 * UNITS_PER_PT; + ret.chapter_underline_thickness = 3 * UNITS_PER_PT; + ret.rule_thickness = 1 * UNITS_PER_PT; ret.base_font_size = 12; - ret.contents_indent_step = 24 * 4096; - ret.contents_margin = 84 * 4096; - ret.leader_separation = 12 * 4096; - ret.index_gutter = 36 * 4096; + ret.contents_indent_step = 24 * UNITS_PER_PT; + ret.contents_margin = 84 * UNITS_PER_PT; + ret.leader_separation = 12 * UNITS_PER_PT; + ret.index_gutter = 36 * UNITS_PER_PT; ret.index_cols = 2; - ret.index_minsep = 18 * 4096; + ret.index_minsep = 18 * UNITS_PER_PT; ret.pagenum_fontsize = 12; - ret.footer_distance = 32 * 4096; + ret.footer_distance = 32 * UNITS_PER_PT; ret.lquote = L"\x2018\0\x2019\0'\0'\0\0"; ret.rquote = uadv(ret.lquote); ret.bullet = L"\x2022\0-\0\0"; @@ -257,70 +257,70 @@ static paper_conf paper_configure(paragraph *source, font_list *fontlist) { ret.bullet = uadv(p->keyword); } else if (!ustricmp(p->keyword, L"paper-page-width")) { ret.paper_width = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-page-height")) { ret.paper_height = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-left-margin")) { ret.left_margin = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-top-margin")) { ret.top_margin = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-right-margin")) { ret.right_margin = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-bottom-margin")) { ret.bottom_margin = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-list-indent")) { ret.indent_list_bullet = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-listitem-indent")) { ret.indent_list = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-quote-indent")) { ret.indent_quote = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-base-leading")) { ret.base_leading = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-base-para-spacing")) { ret.base_para_spacing = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-chapter-top-space")) { ret.chapter_top_space = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-sect-num-left-space")) { ret.sect_num_left_space = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-chapter-underline-depth")) { ret.chapter_underline_depth = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-chapter-underline-thickness")) { ret.chapter_underline_thickness = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-rule-thickness")) { ret.rule_thickness = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-contents-indent-step")) { ret.contents_indent_step = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-contents-margin")) { ret.contents_margin = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-leader-separation")) { ret.leader_separation = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-index-gutter")) { ret.index_gutter = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-index-minsep")) { ret.index_minsep = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-footer-distance")) { ret.footer_distance = - (int) 0.5 + 4096.0 * utof(uadv(p->keyword)); + (int) 0.5 + FUNITS_PER_PT * utof(uadv(p->keyword)); } else if (!ustricmp(p->keyword, L"paper-base-font-size")) { ret.base_font_size = utoi(uadv(p->keyword)); @@ -1433,7 +1433,7 @@ static void wrap_paragraph(para_data *pdata, word *words, for (i = 0; i < NFONTS; i++) if (line_height < pdata->sizes[i]) line_height = pdata->sizes[i]; - line_height *= 4096; + line_height *= UNITS_PER_PT; } spacewidth = (pdata->sizes[FONT_NORMAL] * @@ -1444,7 +1444,7 @@ static void wrap_paragraph(para_data *pdata, word *words, * comes up, but I'll make a random guess anyway and set my * space width to half the point size. */ - spacewidth = pdata->sizes[FONT_NORMAL] * 4096 / 2; + spacewidth = pdata->sizes[FONT_NORMAL] * UNITS_PER_PT / 2; } /* @@ -2314,7 +2314,7 @@ static para_data *code_paragraph(int indent, word *words, paper_conf *conf) ldata->pdata = pdata; ldata->first = lhead; ldata->end = NULL; - ldata->line_height = conf->base_font_size * 4096; + ldata->line_height = conf->base_font_size * UNITS_PER_PT; ldata->xpos = indent; diff --git a/bk_pdf.c b/bk_pdf.c index b679875..75d1f83 100644 --- a/bk_pdf.c +++ b/bk_pdf.c @@ -150,7 +150,7 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, width = 0.0; else width = fe->font->widths[fe->indices[i]]; - sprintf(buf, "%g\n", 1000.0 * width / 4096.0); + sprintf(buf, "%g\n", 1000.0 * width / FUNITS_PER_PT); objtext(widths, buf); } objtext(widths, "]\n"); @@ -203,7 +203,8 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, * So we don't need a /Resources entry here. */ sprintf(buf, "/MediaBox [0 0 %g %g]\n", - doc->paper_width / 4096.0, doc->paper_height / 4096.0); + doc->paper_width / FUNITS_PER_PT, + doc->paper_height / FUNITS_PER_PT); objtext(opage, buf); /* @@ -220,8 +221,9 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, */ for (r = page->first_rect; r; r = r->next) { char buf[512]; - sprintf(buf, "%g %g %g %g re f\n", r->x / 4096.0, - r->y / 4096.0, r->w / 4096.0, r->h / 4096.0); + sprintf(buf, "%g %g %g %g re f\n", + r->x / FUNITS_PER_PT, r->y / FUNITS_PER_PT, + r->w / FUNITS_PER_PT, r->h / FUNITS_PER_PT); objstream(cstr, buf); } @@ -265,10 +267,11 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, */ if (lx < 0) { sprintf(buf, "1 0 0 1 %g %g Tm ", - frag->x/4096.0, frag->y/4096.0); + frag->x/FUNITS_PER_PT, frag->y/FUNITS_PER_PT); } else { sprintf(buf, "%g %g Td ", - (frag->x - lx)/4096.0, (frag->y - ly)/4096.0); + (frag->x - lx)/FUNITS_PER_PT, + (frag->y - ly)/FUNITS_PER_PT); } objstream(cstr, buf); lx = x = frag->x; @@ -291,7 +294,7 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, if (frag->x != x) { sprintf(buf, "%g", (x - frag->x) * 1000.0 / - (4096.0 * frag->fontsize)); + (FUNITS_PER_PT * frag->fontsize)); objstream(cstr, buf); } pdf_string(objstream, cstr, frag->text); @@ -330,8 +333,8 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, objtext(annot, "<<\n/Type /Annot\n/Subtype /Link\n/Rect ["); sprintf(buf, "%g %g %g %g", - xr->lx / 4096.0, xr->by / 4096.0, - xr->rx / 4096.0, xr->ty / 4096.0); + xr->lx / FUNITS_PER_PT, xr->by / FUNITS_PER_PT, + xr->rx / FUNITS_PER_PT, xr->ty / FUNITS_PER_PT); objtext(annot, buf); objtext(annot, "]\n/Border [0 0 0]\n"); diff --git a/bk_ps.c b/bk_ps.c index 9f81ffe..8ae49c4 100644 --- a/bk_ps.c +++ b/bk_ps.c @@ -113,13 +113,14 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, fprintf(fp, "{1 index /FID ne {def} {pop pop} ifelse} forall\n"); fprintf(fp, "/Encoding [\n"); for (i = 0; i < 256; i++) - fprintf(fp, "/%s\n", fe->vector[i] ? fe->vector[i] : ".notdef"); + fprintf(fp, "/%s%c", fe->vector[i] ? fe->vector[i] : ".notdef", + i % 4 == 3 ? '\n' : ' '); fprintf(fp, "] def /Metrics 256 dict dup begin\n"); for (i = 0; i < 256; i++) { if (fe->indices[i] >= 0) { double width = fe->font->widths[fe->indices[i]]; fprintf(fp, "/%s %g def\n", fe->vector[i], - 1000.0 * width / 4096.0); + 1000.0 * width / FUNITS_PER_PT); } } fprintf(fp, "end def currentdict end\n"); @@ -150,12 +151,12 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, */ for (xr = page->first_xref; xr; xr = xr->next) { fprintf(fp, "gsave 0.7 setgray %g %g moveto", - xr->lx/4096.0, xr->ty/4096.0); + xr->lx/FUNITS_PER_PT, xr->ty/FUNITS_PER_PT); fprintf(fp, " %g %g lineto %g %g lineto", - xr->lx/4096.0, xr->by/4096.0, - xr->rx/4096.0, xr->by/4096.0); + xr->lx/FUNITS_PER_PT, xr->by/FUNITS_PER_PT, + xr->rx/FUNITS_PER_PT, xr->by/FUNITS_PER_PT); fprintf(fp, " %g %g lineto closepath fill grestore\n", - xr->rx/4096.0, xr->ty/4096.0); + xr->rx/FUNITS_PER_PT, xr->ty/FUNITS_PER_PT); } } #endif @@ -163,8 +164,9 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, for (r = page->first_rect; r; r = r->next) { fprintf(fp, "%g %g moveto %g 0 rlineto 0 %g rlineto " "-%g 0 rlineto closepath fill\n", - r->x / 4096.0, r->y / 4096.0, r->w / 4096.0, - r->h / 4096.0, r->w / 4096.0); + r->x / FUNITS_PER_PT, r->y / FUNITS_PER_PT, + r->w / FUNITS_PER_PT, r->h / FUNITS_PER_PT, + r->w / FUNITS_PER_PT); } frag = page->first_text; @@ -181,7 +183,7 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, frag_end && frag_end->y == frag->y; frag_end = frag_end->next); - fprintf(fp, "%g[", frag->y / 4096.0); + fprintf(fp, "%g[", frag->y / FUNITS_PER_PT); fe = NULL; fs = -1; @@ -193,7 +195,7 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, fe = frag->fe; fs = frag->fontsize; - fprintf(fp, "%g(", frag->x/4096.0); + fprintf(fp, "%g(", frag->x/FUNITS_PER_PT); for (c = frag->text; *c; c++) { if (*c == '(' || *c == ')' || *c == '\\') fputc('\\', fp); diff --git a/paper.h b/paper.h index d6f34b9..5976a67 100644 --- a/paper.h +++ b/paper.h @@ -8,6 +8,10 @@ #ifndef HALIBUT_PAPER_H #define HALIBUT_PAPER_H +/* Number of internal units per PostScript point. */ +#define UNITS_PER_PT 4096 +#define FUNITS_PER_PT 4096.0 + typedef struct document_Tag document; typedef struct font_data_Tag font_data; typedef struct font_encoding_Tag font_encoding; -- 2.11.0