7 static int o_f
, o_s
, o_m
; /* font and size */
8 static int o_h
, o_v
; /* current user position */
9 static int p_f
, p_s
, p_m
; /* output postscript font */
10 static int o_qtype
; /* queued character type */
11 static int o_qv
, o_qh
, o_qend
; /* queued character position */
12 static int o_rh
, o_rv
, o_rdeg
; /* previous rotation position and degree */
14 char o_fonts
[FNLEN
* NFONTS
] = " ";
16 static void outvf(char *s
, va_list ap
)
18 vfprintf(stdout
, s
, ap
);
21 static void outf(char *s
, ...)
29 static void o_flush(void)
32 outf(") %d %d w\n", o_qh
, o_qv
);
34 outf("] %d %d g\n", o_qh
, o_qv
);
49 static void o_queue(struct glyph
*g
)
51 int type
= 1 + (g
->pos
<= 0);
52 if (o_qtype
!= type
|| o_qend
!= o_h
|| o_qv
!= o_v
) {
57 outf(type
== 1 ? "(" : "[");
60 if (g
->pos
>= ' ' && g
->pos
<= '~')
61 outf("%s%c", strchr("()\\", g
->pos
) ? "\\" : "", g
->pos
);
63 outf("\\%d%d%d", (g
->pos
>> 6) & 7,
64 (g
->pos
>> 3) & 7, g
->pos
& 7);
68 o_qend
= o_h
+ font_wid(g
->font
, o_s
, g
->wid
);
71 /* calls o_flush() if necessary */
72 void out(char *s
, ...)
81 static void out_fontup(int fid
)
86 out("%d %d %d rgb\n", CLR_R(o_m
), CLR_G(o_m
), CLR_B(o_m
));
89 if (fid
!= p_f
|| o_s
!= p_s
) {
91 out("%d /%s f\n", o_s
, font_name(fn
));
94 sprintf(fnname
, " %s ", font_name(fn
));
95 if (!strstr(o_fonts
, fnname
))
96 sprintf(strchr(o_fonts
, '\0'), "%s ", font_name(fn
));
104 g
= dev_glyph(c
, o_f
);
105 fn
= g
? g
->font
: dev_font(o_f
);
107 outrel(*c
== ' ' && fn
? font_swid(fn
, o_s
) : 1, 0);
110 out_fontup(dev_fontid(fn
));
124 void outrel(int h
, int v
)
136 /* a font was mounted at pos f */
154 void outrotate(int deg
)
159 outf("%d %d %d rot\n", -o_rdeg
, o_rh
, o_rv
);
163 outf("%d %d %d rot\n", deg
, o_h
, o_v
);
166 static int draw_path
; /* number of path segments */
167 static int draw_point
; /* point was set for postscript newpath */
169 static void drawmv(void)
172 outf("%d %d m ", o_h
, o_v
);
176 /* start a multi-segment path */
177 void drawmbeg(char *s
)
182 outf("gsave newpath %s\n", s
);
185 /* end a multi-segment path */
186 void drawmend(char *s
)
190 outf("%s grestore\n", s
);
202 void drawend(int close
, int fill
)
215 void drawl(int h
, int v
)
219 outf("%d %d drawl ", o_h
, o_v
);
226 outf("%d %d drawe ", c
, c
);
229 void drawe(int h
, int v
)
233 outf("%d %d drawe ", h
, v
);
236 void drawa(int h1
, int v1
, int h2
, int v2
)
239 outf("%d %d %d %d drawa ", h1
, v1
, h2
, v2
);
240 outrel(h1
+ h2
, v1
+ v2
);
243 void draws(int h1
, int v1
, int h2
, int v2
)
246 outf("%d %d %d %d %d %d draws ", o_h
, o_v
, o_h
+ h1
, o_v
+ v1
,
247 o_h
+ h1
+ h2
, o_v
+ v1
+ v2
);
251 void outeps(char *spec
)
255 int llx
, lly
, urx
, ury
;
259 if ((nspec
= sscanf(spec
, "%s %d %d", eps
, &hwid
, &vwid
)) < 1)
265 if (!(filp
= fopen(eps
, "r")))
267 if (!fgets(buf
, sizeof(buf
), filp
) ||
268 (strcmp(buf
, "%!PS-Adobe-2.0 EPSF-2.0\n") &&
269 strcmp(buf
, "%!PS-Adobe-3.0 EPSF-3.0\n"))) {
274 while (fgets(buf
, sizeof(buf
), filp
))
275 if (!strncmp(buf
, "%%BoundingBox: ", 15))
276 if ((nbb
= sscanf(buf
+ 15, "%d %d %d %d",
277 &llx
, &lly
, &urx
, &ury
)) == 4)
280 if (nbb
< 4) /* no BoundingBox comment */
282 if (hwid
<= 0 && vwid
<= 0)
285 vwid
= (ury
- lly
) * hwid
/ (urx
- llx
);
287 hwid
= (urx
- llx
) * vwid
/ (ury
- lly
);
288 /* output the EPS file */
291 outf("%d %d %d %d %d %d %d %d EPSFBEG\n",
292 llx
, lly
, hwid
, urx
- llx
, vwid
, ury
- lly
, o_h
, o_v
);
293 outf("%%%%BeginDocument: %s\n", eps
);
294 filp
= fopen(eps
, "r");
295 while (fgets(buf
, sizeof(buf
), filp
))
298 outf("%%%%EndDocument\n");