=================================================================== RCS file: /cvs/mandoc/term_ps.c,v retrieving revision 1.50 retrieving revision 1.58 diff -u -p -r1.50 -r1.58 --- mandoc/term_ps.c 2011/05/15 00:58:48 1.50 +++ mandoc/term_ps.c 2014/03/30 21:28:01 1.58 @@ -1,6 +1,7 @@ -/* $Id: term_ps.c,v 1.50 2011/05/15 00:58:48 kristaps Exp $ */ +/* $Id: term_ps.c,v 1.58 2014/03/30 21:28:01 schwarze Exp $ */ /* - * Copyright (c) 2010 Kristaps Dzonsons + * Copyright (c) 2010, 2011 Kristaps Dzonsons + * Copyright (c) 2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -30,6 +31,7 @@ #include #include "mandoc.h" +#include "mandoc_aux.h" #include "out.h" #include "main.h" #include "term.h" @@ -74,6 +76,7 @@ struct termp_ps { size_t bottom; /* body bottom (AFM units) */ size_t height; /* page height (AFM units */ size_t width; /* page width (AFM units) */ + size_t lastwidth; /* page width before last ll */ size_t left; /* body left (AFM units) */ size_t header; /* header pos (AFM units) */ size_t footer; /* footer pos (AFM units) */ @@ -97,9 +100,13 @@ static void ps_growbuf(struct termp *, size_t); static void ps_letter(struct termp *, int); static void ps_pclose(struct termp *); static void ps_pletter(struct termp *, int); +#if __GNUC__ - 0 >= 4 +__attribute__((__format__ (__printf__, 2, 3))) +#endif static void ps_printf(struct termp *, const char *, ...); static void ps_putchar(struct termp *, char); static void ps_setfont(struct termp *, enum termfont); +static void ps_setwidth(struct termp *, int, size_t); static struct termp *pspdf_alloc(char *); static void pdf_obj(struct termp *, size_t); @@ -429,12 +436,14 @@ static struct termp * pspdf_alloc(char *outopts) { struct termp *p; - size_t pagex, pagey, marginx, marginy, lineheight; + unsigned int pagex, pagey; + size_t marginx, marginy, lineheight; const char *toks[2]; const char *pp; char *v; - p = term_alloc(TERMENC_ASCII); + p = mandoc_calloc(1, sizeof(struct termp)); + p->enc = TERMENC_ASCII; p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); p->advance = ps_advance; @@ -443,6 +452,7 @@ pspdf_alloc(char *outopts) p->endline = ps_endline; p->hspan = ps_hspan; p->letter = ps_letter; + p->setwidth = ps_setwidth; p->width = ps_width; toks[0] = "paper"; @@ -484,10 +494,9 @@ pspdf_alloc(char *outopts) } else if (0 == strcasecmp(pp, "legal")) { pagex = 216; pagey = 356; - } else if (2 != sscanf(pp, "%zux%zu", &pagex, &pagey)) + } else if (2 != sscanf(pp, "%ux%u", &pagex, &pagey)) fprintf(stderr, "%s: Unknown paper\n", pp); - } else if (NULL == pp) - pp = "letter"; + } /* * This MUST be defined before any PNT2AFM or AFM2PNT @@ -512,8 +521,8 @@ pspdf_alloc(char *outopts) lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4)); - p->ps->width = pagex; - p->ps->height = pagey; + 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); @@ -526,6 +535,22 @@ pspdf_alloc(char *outopts) } +static void +ps_setwidth(struct termp *p, int iop, size_t width) +{ + size_t lastwidth; + + lastwidth = p->ps->width; + if (0 < iop) + p->ps->width += width; + else if (0 > iop) + p->ps->width -= width; + else + p->ps->width = width ? width : p->ps->lastwidth; + p->ps->lastwidth = lastwidth; +} + + void pspdf_free(void *arg) { @@ -574,7 +599,7 @@ ps_printf(struct termp *p, const char *fmt, ...) ps_growbuf(p, PS_BUFSLOP); pos = (int)p->ps->psmargcur; - len = vsnprintf(&p->ps->psmarg[pos], PS_BUFSLOP, fmt, ap); + vsnprintf(&p->ps->psmarg[pos], PS_BUFSLOP, fmt, ap); va_end(ap); @@ -823,7 +848,7 @@ ps_begin(struct termp *p) ps_printf(p, "<<\n"); ps_printf(p, "/Type /Font\n"); ps_printf(p, "/Subtype /Type1\n"); - ps_printf(p, "/Name /F%zu\n", i); + ps_printf(p, "/Name /F%d\n", i); ps_printf(p, "/BaseFont /%s\n", fonts[i].name); ps_printf(p, ">>\n"); }