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 */
153 void outrotate(int deg
)
158 outf("%d %d %d rot\n", -o_rdeg
, o_rh
, o_rv
);
162 outf("%d %d %d rot\n", deg
, o_h
, o_v
);
165 static int draw_path
; /* number of path segments */
166 static int draw_point
; /* point was set for postscript newpath */
168 static void drawmv(void)
171 outf("%d %d m ", o_h
, o_v
);
175 /* start a multi-segment path */
176 void drawmbeg(char *s
)
181 outf("gsave newpath %s\n", s
);
184 /* end a multi-segment path */
185 void drawmend(char *s
)
189 outf("%s grestore\n", s
);
201 void drawend(int close
, int fill
)
214 void drawl(int h
, int v
)
218 outf("%d %d drawl ", o_h
, o_v
);
225 outf("%d %d drawe ", c
, c
);
228 void drawe(int h
, int v
)
232 outf("%d %d drawe ", h
, v
);
235 void drawa(int h1
, int v1
, int h2
, int v2
)
238 outf("%d %d %d %d drawa ", h1
, v1
, h2
, v2
);
239 outrel(h1
+ h2
, v1
+ v2
);
242 void draws(int h1
, int v1
, int h2
, int v2
)
245 outf("%d %d %d %d %d %d draws ", o_h
, o_v
, o_h
+ h1
, o_v
+ v1
,
246 o_h
+ h1
+ h2
, o_v
+ v1
+ v2
);
250 void outeps(char *spec
)
254 int llx
, lly
, urx
, ury
;
258 if ((nspec
= sscanf(spec
, "%s %d %d", eps
, &hwid
, &vwid
)) < 1)
264 if (!(filp
= fopen(eps
, "r")))
266 if (!fgets(buf
, sizeof(buf
), filp
) ||
267 (strcmp(buf
, "%!PS-Adobe-2.0 EPSF-2.0\n") &&
268 strcmp(buf
, "%!PS-Adobe-3.0 EPSF-3.0\n"))) {
273 while (fgets(buf
, sizeof(buf
), filp
))
274 if (!strncmp(buf
, "%%BoundingBox: ", 15))
275 if ((nbb
= sscanf(buf
+ 15, "%d %d %d %d",
276 &llx
, &lly
, &urx
, &ury
)) == 4)
279 if (nbb
< 4) /* no BoundingBox comment */
281 if (hwid
<= 0 && vwid
<= 0)
284 vwid
= (ury
- lly
) * hwid
/ (urx
- llx
);
286 hwid
= (urx
- llx
) * vwid
/ (ury
- lly
);
287 /* output the EPS file */
290 outf("%d %d %d %d %d %d %d %d EPSFBEG\n",
291 llx
, lly
, hwid
, urx
- llx
, vwid
, ury
- lly
, o_h
, o_v
);
292 outf("%%%%BeginDocument: %s\n", eps
);
293 filp
= fopen(eps
, "r");
294 while (fgets(buf
, sizeof(buf
), filp
))
297 outf("%%%%EndDocument\n");