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 */
13 static int o_gname
; /* use glyphshow for all glyphs */
15 char o_fonts
[FNLEN
* NFONTS
] = " ";
17 static void outvf(char *s
, va_list ap
)
19 vfprintf(stdout
, s
, ap
);
22 static void outf(char *s
, ...)
30 static void o_flush(void)
33 outf(") %d %d w\n", o_qh
, o_qv
);
35 outf("] %d %d g\n", o_qh
, o_qv
);
55 static void o_queue(struct glyph
*g
)
57 int type
= 1 + (g
->pos
<= 0 || o_gname
);
58 if (o_qtype
!= type
|| o_qend
!= o_h
|| o_qv
!= o_v
) {
63 outf(type
== 1 ? "(" : "[");
66 if (g
->pos
>= ' ' && g
->pos
<= '~')
67 outf("%s%c", strchr("()\\", g
->pos
) ? "\\" : "", g
->pos
);
69 outf("\\%d%d%d", (g
->pos
>> 6) & 7,
70 (g
->pos
>> 3) & 7, g
->pos
& 7);
74 o_qend
= o_h
+ font_wid(g
->font
, o_s
, g
->wid
);
77 /* calls o_flush() if necessary */
78 void out(char *s
, ...)
87 static void out_fontup(int fid
)
92 out("%d %d %d rgb\n", CLR_R(o_m
), CLR_G(o_m
), CLR_B(o_m
));
95 if (fid
!= p_f
|| o_s
!= p_s
) {
97 out("%d /%s f\n", o_s
, font_name(fn
));
100 sprintf(fnname
, " %s ", font_name(fn
));
101 if (!strstr(o_fonts
, fnname
))
102 sprintf(strchr(o_fonts
, '\0'), "%s ", font_name(fn
));
110 g
= dev_glyph(c
, o_f
);
111 fn
= g
? g
->font
: dev_font(o_f
);
113 outrel(*c
== ' ' && fn
? font_swid(fn
, o_s
) : 1, 0);
116 out_fontup(dev_fontid(fn
));
130 void outrel(int h
, int v
)
142 /* a font was mounted at pos f */
160 void outrotate(int deg
)
165 outf("%d %d %d rot\n", -o_rdeg
, o_rh
, o_rv
);
169 outf("%d %d %d rot\n", deg
, o_h
, o_v
);
172 static int draw_path
; /* number of path segments */
173 static int draw_point
; /* point was set for postscript newpath */
175 static void drawmv(void)
178 outf("%d %d m ", o_h
, o_v
);
182 /* start a multi-segment path */
183 void drawmbeg(char *s
)
188 outf("gsave newpath %s\n", s
);
191 /* end a multi-segment path */
192 void drawmend(char *s
)
196 outf("%s grestore\n", s
);
208 void drawend(int close
, int fill
)
221 void drawl(int h
, int v
)
225 outf("%d %d drawl ", o_h
, o_v
);
232 outf("%d %d drawe ", c
, c
);
235 void drawe(int h
, int v
)
239 outf("%d %d drawe ", h
, v
);
242 void drawa(int h1
, int v1
, int h2
, int v2
)
245 outf("%d %d %d %d drawa ", h1
, v1
, h2
, v2
);
246 outrel(h1
+ h2
, v1
+ v2
);
249 void draws(int h1
, int v1
, int h2
, int v2
)
252 outf("%d %d %d %d %d %d draws ", o_h
, o_v
, o_h
+ h1
, o_v
+ v1
,
253 o_h
+ h1
+ h2
, o_v
+ v1
+ v2
);
257 void outeps(char *spec
)
261 int llx
, lly
, urx
, ury
;
265 if ((nspec
= sscanf(spec
, "%s %d %d", eps
, &hwid
, &vwid
)) < 1)
271 if (!(filp
= fopen(eps
, "r")))
273 if (!fgets(buf
, sizeof(buf
), filp
) ||
274 (strcmp(buf
, "%!PS-Adobe-2.0 EPSF-1.2\n") &&
275 strcmp(buf
, "%!PS-Adobe-2.0 EPSF-2.0\n") &&
276 strcmp(buf
, "%!PS-Adobe-3.0 EPSF-3.0\n"))) {
281 while (fgets(buf
, sizeof(buf
), filp
))
282 if (!strncmp(buf
, "%%BoundingBox: ", 15))
283 if ((nbb
= sscanf(buf
+ 15, "%d %d %d %d",
284 &llx
, &lly
, &urx
, &ury
)) == 4)
287 if (nbb
< 4) /* no BoundingBox comment */
289 if (hwid
<= 0 && vwid
<= 0)
290 hwid
= (urx
- llx
) * dev_res
/ 72;
292 vwid
= (ury
- lly
) * hwid
/ (urx
- llx
);
294 hwid
= (urx
- llx
) * vwid
/ (ury
- lly
);
295 /* output the EPS file */
298 outf("%d %d %d %d %d %d %d %d EPSFBEG\n",
299 llx
, lly
, hwid
, urx
- llx
, vwid
, ury
- lly
, o_h
, o_v
);
300 outf("%%%%BeginDocument: %s\n", eps
);
301 filp
= fopen(eps
, "r");
302 while (fgets(buf
, sizeof(buf
), filp
))
305 outf("%%%%EndDocument\n");