version 1.10, 2010/06/19 20:46:28 |
version 1.15, 2010/06/28 23:26:09 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <time.h> |
|
|
#include "out.h" |
#include "out.h" |
#include "main.h" |
#include "main.h" |
#include "term.h" |
#include "term.h" |
|
|
#define PS_CHAR_WIDTH 6 |
/* TODO: all this will go away with different paper sizes. */ |
#define PS_CHAR_HEIGHT 12 |
#define PS_CHAR_HEIGHT 12 |
#define PS_CHAR_TOPMARG (792 - 24) |
#define PS_CHAR_TOPMARG (792 - 24) |
#define PS_CHAR_TOP (PS_CHAR_TOPMARG - 36) |
#define PS_CHAR_TOP (PS_CHAR_TOPMARG - 36) |
|
|
#define PS_CHAR_BOTMARG 24 |
#define PS_CHAR_BOTMARG 24 |
#define PS_CHAR_BOT (PS_CHAR_BOTMARG + 36) |
#define PS_CHAR_BOT (PS_CHAR_BOTMARG + 36) |
|
|
|
struct glyph { |
|
int wx; /* WX in AFM */ |
|
}; |
|
|
|
struct font { |
|
const char *name; /* FontName in AFM */ |
|
#define MAXCHAR 95 /* total characters we can handle */ |
|
struct glyph gly[MAXCHAR]; /* glyph metrics */ |
|
}; |
|
|
|
/* |
|
* We define, for the time being, three fonts: bold, oblique/italic, and |
|
* normal (roman). The following table hard-codes the font metrics for |
|
* ASCII, i.e., 32--127. |
|
*/ |
|
|
|
static const struct font fonts[3] = { |
|
{ "Courier", { |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
} }, |
|
{ "Courier-Bold", { |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
} }, |
|
{ "Courier-Oblique", { |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
{ 600 }, |
|
} }, |
|
}; |
|
|
|
/* These work the buffer used by the header and footer. */ |
#define PS_BUFSLOP 128 |
#define PS_BUFSLOP 128 |
#define PS_GROWBUF(p, sz) \ |
#define PS_GROWBUF(p, sz) \ |
do if ((p)->engine.ps.psmargcur + (sz) > \ |
do if ((p)->engine.ps.psmargcur + (sz) > \ |
Line 60 static void ps_end(struct termp *); |
|
Line 372 static void ps_end(struct termp *); |
|
static void ps_advance(struct termp *, size_t); |
static void ps_advance(struct termp *, size_t); |
static void ps_endline(struct termp *); |
static void ps_endline(struct termp *); |
static void ps_fclose(struct termp *); |
static void ps_fclose(struct termp *); |
|
static size_t ps_width(const struct termp *, char); |
static void ps_pclose(struct termp *); |
static void ps_pclose(struct termp *); |
static void ps_pletter(struct termp *, char); |
static void ps_pletter(struct termp *, int); |
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); |
|
|
if (NULL == (p = term_alloc(TERMENC_ASCII))) |
if (NULL == (p = term_alloc(TERMENC_ASCII))) |
return(NULL); |
return(NULL); |
|
|
|
p->defrmargin = 612 - (PS_CHAR_LEFT * 2); |
|
|
p->type = TERMTYPE_PS; |
p->type = TERMTYPE_PS; |
p->letter = ps_letter; |
p->letter = ps_letter; |
p->begin = ps_begin; |
p->begin = ps_begin; |
p->end = ps_end; |
p->end = ps_end; |
p->advance = ps_advance; |
p->advance = ps_advance; |
p->endline = ps_endline; |
p->endline = ps_endline; |
|
p->width = ps_width; |
return(p); |
return(p); |
} |
} |
|
|
Line 178 ps_end(struct termp *p) |
|
Line 494 ps_end(struct termp *p) |
|
static void |
static void |
ps_begin(struct termp *p) |
ps_begin(struct termp *p) |
{ |
{ |
|
time_t t; |
|
|
/* |
/* |
* Print margins into margin buffer. Nothing gets output to the |
* Print margins into margin buffer. Nothing gets output to the |
Line 216 ps_begin(struct termp *p) |
|
Line 533 ps_begin(struct termp *p) |
|
* stuff gets printed to the screen, so make sure we're sane. |
* stuff gets printed to the screen, so make sure we're sane. |
*/ |
*/ |
|
|
printf("%s\n", "%!PS"); |
t = time(NULL); |
|
|
|
printf("%%!PS\n"); |
|
printf("%%%%Creator: mandoc-%s\n", VERSION); |
|
printf("%%%%CreationDate: %s", ctime(&t)); |
|
printf("%%%%PageOrder: Ascend\n"); |
|
printf("%%%%Orientation: Portrait\n"); |
|
printf("%%%%EndComments\n"); |
|
|
ps_setfont(p, TERMFONT_NONE); |
ps_setfont(p, TERMFONT_NONE); |
p->engine.ps.pscol = PS_CHAR_LEFT; |
p->engine.ps.pscol = PS_CHAR_LEFT; |
p->engine.ps.psrow = PS_CHAR_TOP; |
p->engine.ps.psrow = PS_CHAR_TOP; |
Line 224 ps_begin(struct termp *p) |
|
Line 549 ps_begin(struct termp *p) |
|
|
|
|
|
static void |
static void |
ps_pletter(struct termp *p, char c) |
ps_pletter(struct termp *p, int c) |
{ |
{ |
|
int f; |
|
|
/* |
/* |
* If we're not in a PostScript "word" context, then open one |
* If we're not in a PostScript "word" context, then open one |
Line 260 ps_pletter(struct termp *p, char c) |
|
Line 586 ps_pletter(struct termp *p, char c) |
|
|
|
/* Write the character and adjust where we are on the page. */ |
/* Write the character and adjust where we are on the page. */ |
|
|
|
f = (int)p->engine.ps.lastf; |
|
|
|
if (c <= 32 || (c - 32 > MAXCHAR)) { |
|
ps_putchar(p, ' '); |
|
p->engine.ps.pscol += (fonts[f].gly[0].wx / 100); |
|
return; |
|
} |
|
|
ps_putchar(p, c); |
ps_putchar(p, c); |
p->engine.ps.pscol += PS_CHAR_WIDTH; |
c -= 32; |
|
p->engine.ps.pscol += (fonts[f].gly[c].wx / 100); |
} |
} |
|
|
|
|
Line 371 ps_advance(struct termp *p, size_t len) |
|
Line 706 ps_advance(struct termp *p, size_t len) |
|
*/ |
*/ |
|
|
ps_fclose(p); |
ps_fclose(p); |
p->engine.ps.pscol += len ? len * PS_CHAR_WIDTH : 0; |
p->engine.ps.pscol += len; |
} |
} |
|
|
|
|
|
|
ps_setfont(struct termp *p, enum termfont f) |
ps_setfont(struct termp *p, enum termfont f) |
{ |
{ |
|
|
if (TERMFONT_BOLD == f) |
ps_printf(p, "/%s 10 selectfont\n", fonts[(int)f].name); |
ps_printf(p, "/Courier-Bold\n"); |
|
else if (TERMFONT_UNDER == f) |
|
ps_printf(p, "/Courier-Oblique\n"); |
|
else |
|
ps_printf(p, "/Courier\n"); |
|
|
|
ps_printf(p, "10 selectfont\n"); |
|
p->engine.ps.lastf = f; |
p->engine.ps.lastf = f; |
} |
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static size_t |
|
ps_width(const struct termp *p, char c) |
|
{ |
|
|
|
if (c <= 32 || c - 32 >= MAXCHAR) |
|
return(fonts[(int)TERMFONT_NONE].gly[0].wx / 100); |
|
|
|
c -= 32; |
|
return(fonts[(int)TERMFONT_NONE].gly[(int)c].wx / 100); |
|
} |