version 1.51, 2011/05/17 14:38:34 |
version 1.57, 2014/03/30 19:47:48 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
|
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "mandoc_aux.h" |
#include "out.h" |
#include "out.h" |
#include "main.h" |
#include "main.h" |
#include "term.h" |
#include "term.h" |
Line 74 struct termp_ps { |
|
Line 76 struct termp_ps { |
|
size_t bottom; /* body bottom (AFM units) */ |
size_t bottom; /* body bottom (AFM units) */ |
size_t height; /* page height (AFM units */ |
size_t height; /* page height (AFM units */ |
size_t width; /* page width (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 left; /* body left (AFM units) */ |
size_t header; /* header pos (AFM units) */ |
size_t header; /* header pos (AFM units) */ |
size_t footer; /* footer pos (AFM units) */ |
size_t footer; /* footer pos (AFM units) */ |
Line 97 static void ps_growbuf(struct termp *, size_t); |
|
Line 100 static void ps_growbuf(struct termp *, size_t); |
|
static void ps_letter(struct termp *, int); |
static void ps_letter(struct termp *, int); |
static void ps_pclose(struct termp *); |
static void ps_pclose(struct termp *); |
static void ps_pletter(struct termp *, int); |
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_printf(struct termp *, const char *, ...); |
static void ps_putchar(struct termp *, char); |
static void ps_putchar(struct termp *, char); |
static void ps_setfont(struct termp *, enum termfont); |
static void ps_setfont(struct termp *, enum termfont); |
|
static void ps_setwidth(struct termp *, size_t); |
static struct termp *pspdf_alloc(char *); |
static struct termp *pspdf_alloc(char *); |
static void pdf_obj(struct termp *, size_t); |
static void pdf_obj(struct termp *, size_t); |
|
|
Line 429 static struct termp * |
|
Line 436 static struct termp * |
|
pspdf_alloc(char *outopts) |
pspdf_alloc(char *outopts) |
{ |
{ |
struct termp *p; |
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 *toks[2]; |
const char *pp; |
const char *pp; |
char *v; |
char *v; |
Line 444 pspdf_alloc(char *outopts) |
|
Line 452 pspdf_alloc(char *outopts) |
|
p->endline = ps_endline; |
p->endline = ps_endline; |
p->hspan = ps_hspan; |
p->hspan = ps_hspan; |
p->letter = ps_letter; |
p->letter = ps_letter; |
|
p->setwidth = ps_setwidth; |
p->width = ps_width; |
p->width = ps_width; |
|
|
toks[0] = "paper"; |
toks[0] = "paper"; |
Line 485 pspdf_alloc(char *outopts) |
|
Line 494 pspdf_alloc(char *outopts) |
|
} else if (0 == strcasecmp(pp, "legal")) { |
} else if (0 == strcasecmp(pp, "legal")) { |
pagex = 216; |
pagex = 216; |
pagey = 356; |
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); |
fprintf(stderr, "%s: Unknown paper\n", pp); |
} else if (NULL == pp) |
} |
pp = "letter"; |
|
|
|
/* |
/* |
* This MUST be defined before any PNT2AFM or AFM2PNT |
* This MUST be defined before any PNT2AFM or AFM2PNT |
Line 513 pspdf_alloc(char *outopts) |
|
Line 521 pspdf_alloc(char *outopts) |
|
|
|
lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4)); |
lineheight = PNT2AFM(p, ((double)p->ps->scale * 1.4)); |
|
|
p->ps->width = pagex; |
p->ps->width = p->ps->lastwidth = (size_t)pagex; |
p->ps->height = pagey; |
p->ps->height = (size_t)pagey; |
p->ps->header = pagey - (marginy / 2) - (lineheight / 2); |
p->ps->header = pagey - (marginy / 2) - (lineheight / 2); |
p->ps->top = pagey - marginy; |
p->ps->top = pagey - marginy; |
p->ps->footer = (marginy / 2) - (lineheight / 2); |
p->ps->footer = (marginy / 2) - (lineheight / 2); |
Line 527 pspdf_alloc(char *outopts) |
|
Line 535 pspdf_alloc(char *outopts) |
|
} |
} |
|
|
|
|
|
static void |
|
ps_setwidth(struct termp *p, size_t width) |
|
{ |
|
size_t lastwidth; |
|
|
|
lastwidth = p->ps->width; |
|
p->ps->width = width ? width : p->ps->lastwidth; |
|
p->ps->lastwidth = lastwidth; |
|
} |
|
|
|
|
void |
void |
pspdf_free(void *arg) |
pspdf_free(void *arg) |
{ |
{ |
Line 575 ps_printf(struct termp *p, const char *fmt, ...) |
|
Line 594 ps_printf(struct termp *p, const char *fmt, ...) |
|
ps_growbuf(p, PS_BUFSLOP); |
ps_growbuf(p, PS_BUFSLOP); |
|
|
pos = (int)p->ps->psmargcur; |
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); |
va_end(ap); |
|
|
Line 824 ps_begin(struct termp *p) |
|
Line 843 ps_begin(struct termp *p) |
|
ps_printf(p, "<<\n"); |
ps_printf(p, "<<\n"); |
ps_printf(p, "/Type /Font\n"); |
ps_printf(p, "/Type /Font\n"); |
ps_printf(p, "/Subtype /Type1\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, "/BaseFont /%s\n", fonts[i].name); |
ps_printf(p, ">>\n"); |
ps_printf(p, ">>\n"); |
} |
} |