static int ps_hspan(const struct termp *p, const struct roffsu *su) { double r; /* * All of these measurements are derived by converting from the * native measurement to AFM units. */ switch (su->unit) { case SCALE_BU: /* * Traditionally, the default unit is fixed to the * output media. So this would refer to the point. In * mandoc(1), however, we stick to the default terminal * scaling unit so that output is the same regardless * the media. */ r = PNT2AFM(p, su->scale * 72.0 / 240.0); break; case SCALE_CM: r = PNT2AFM(p, su->scale * 72.0 / 2.54); break; case SCALE_EM: r = su->scale * fonts[(int)TERMFONT_NONE].gly[109 - 32].wx; break; case SCALE_EN: r = su->scale * fonts[(int)TERMFONT_NONE].gly[110 - 32].wx; break; case SCALE_IN: r = PNT2AFM(p, su->scale * 72.0); break; case SCALE_MM: r = su->scale * fonts[(int)TERMFONT_NONE].gly[109 - 32].wx / 100.0; break; case SCALE_PC: r = PNT2AFM(p, su->scale * 12.0); break; case SCALE_PT: r = PNT2AFM(p, su->scale * 1.0); break; case SCALE_VS: r = su->scale * p->ps->lineheight; break; default: r = su->scale; break; } return r * 24.0; }
static double ps_hspan(const struct termp *p, const struct roffsu *su) { double r; /* * All of these measurements are derived by converting from the * native measurement to AFM units. */ switch (su->unit) { case (SCALE_CM): r = PNT2AFM(p, su->scale * 28.34); break; case (SCALE_IN): r = PNT2AFM(p, su->scale * 72); break; case (SCALE_PC): r = PNT2AFM(p, su->scale * 12); break; case (SCALE_PT): r = PNT2AFM(p, su->scale * 100); break; case (SCALE_EM): r = su->scale * fonts[(int)TERMFONT_NONE].gly[109 - 32].wx; break; case (SCALE_MM): r = PNT2AFM(p, su->scale * 2.834); break; case (SCALE_EN): r = su->scale * fonts[(int)TERMFONT_NONE].gly[110 - 32].wx; break; case (SCALE_VS): r = su->scale * p->ps->lineheight; break; default: r = su->scale; break; } return(r); }
static struct termp * pspdf_alloc(char *outopts) { struct termp *p; unsigned int pagex, pagey; size_t marginx, marginy, lineheight; const char *toks[2]; const char *pp; char *v; p = mandoc_calloc(1, sizeof(struct termp)); p->enc = TERMENC_ASCII; p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); p->advance = ps_advance; p->begin = ps_begin; p->end = ps_end; p->endline = ps_endline; p->hspan = ps_hspan; p->letter = ps_letter; p->width = ps_width; toks[0] = "paper"; toks[1] = NULL; pp = NULL; while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case (0): pp = v; break; default: break; } /* Default to US letter (millimetres). */ pagex = 216; pagey = 279; /* * The ISO-269 paper sizes can be calculated automatically, but * it would require bringing in -lm for pow() and I'd rather not * do that. So just do it the easy way for now. Since this * only happens once, I'm not terribly concerned. */ if (pp && strcasecmp(pp, "letter")) { if (0 == strcasecmp(pp, "a3")) { pagex = 297; pagey = 420; } else if (0 == strcasecmp(pp, "a4")) { pagex = 210; pagey = 297; } else if (0 == strcasecmp(pp, "a5")) { pagex = 148; pagey = 210; } else if (0 == strcasecmp(pp, "legal")) { pagex = 216; pagey = 356; } else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey)) fprintf(stderr, "%s: Unknown paper\n", pp); } /* * This MUST be defined before any PNT2AFM or AFM2PNT * calculations occur. */ p->ps->scale = 11; /* Remember millimetres -> AFM units. */ pagex = PNT2AFM(p, ((double)pagex * 2.834)); pagey = PNT2AFM(p, ((double)pagey * 2.834)); /* Margins are 1/9 the page x and y. */ marginx = /* LINTED */ (size_t)((double)pagex / 9.0); marginy = /* LINTED */ (size_t)((double)pagey / 9.0); /* Line-height is 1.4em. */ lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4)); p->ps->width = (size_t)pagex; p->ps->height = (size_t)pagey; p->ps->header = pagey - (marginy / 2) - (lineheight / 2); p->ps->top = pagey - marginy; p->ps->footer = (marginy / 2) - (lineheight / 2); p->ps->bottom = marginy; p->ps->left = marginx; p->ps->lineheight = lineheight; p->defrmargin = pagex - (marginx * 2); return(p); }
static struct termp * pspdf_alloc(const struct manoutput *outopts) { struct termp *p; unsigned int pagex, pagey; size_t marginx, marginy, lineheight; const char *pp; p = mandoc_calloc(1, sizeof(struct termp)); p->enc = TERMENC_ASCII; p->fontq = mandoc_reallocarray(NULL, (p->fontsz = 8), sizeof(enum termfont)); p->fontq[0] = p->fontl = TERMFONT_NONE; p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); p->advance = ps_advance; p->begin = ps_begin; p->end = ps_end; p->endline = ps_endline; p->hspan = ps_hspan; p->letter = ps_letter; p->setwidth = ps_setwidth; p->width = ps_width; /* Default to US letter (millimetres). */ pagex = 216; pagey = 279; /* * The ISO-269 paper sizes can be calculated automatically, but * it would require bringing in -lm for pow() and I'd rather not * do that. So just do it the easy way for now. Since this * only happens once, I'm not terribly concerned. */ pp = outopts->paper; if (pp && strcasecmp(pp, "letter")) { if (0 == strcasecmp(pp, "a3")) { pagex = 297; pagey = 420; } else if (0 == strcasecmp(pp, "a4")) { pagex = 210; pagey = 297; } else if (0 == strcasecmp(pp, "a5")) { pagex = 148; pagey = 210; } else if (0 == strcasecmp(pp, "legal")) { pagex = 216; pagey = 356; } else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey)) warnx("%s: Unknown paper", pp); } /* * This MUST be defined before any PNT2AFM or AFM2PNT * calculations occur. */ p->ps->scale = 11; /* Remember millimetres -> AFM units. */ pagex = PNT2AFM(p, ((double)pagex * 2.834)); pagey = PNT2AFM(p, ((double)pagey * 2.834)); /* Margins are 1/9 the page x and y. */ marginx = (size_t)((double)pagex / 9.0); marginy = (size_t)((double)pagey / 9.0); /* Line-height is 1.4em. */ lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4)); p->ps->width = p->ps->lastwidth = (size_t)pagex; p->ps->height = (size_t)pagey; p->ps->header = pagey - (marginy / 2) - (lineheight / 2); p->ps->top = pagey - marginy; p->ps->footer = (marginy / 2) - (lineheight / 2); p->ps->bottom = marginy; p->ps->left = marginx; p->ps->lineheight = lineheight; p->defrmargin = pagex - (marginx * 2); return p; }