8 static int o_f
, o_s
, o_m
; /* font and size */
9 static int o_h
, o_v
; /* current user position */
10 static int p_f
, p_s
, p_m
; /* output postscript font */
11 static int o_qtype
; /* queued character type */
12 static int o_qv
, o_qh
, o_qend
; /* queued character position */
13 static int o_rh
, o_rv
, o_rdeg
; /* previous rotation position and degree */
14 static int o_gname
; /* use glyphshow for all glyphs */
16 char o_fonts
[FNLEN
* NFONTS
] = " ";
18 static void outvf(char *s
, va_list ap
)
20 vfprintf(stdout
, s
, ap
);
23 static void outf(char *s
, ...)
31 static void o_flush(void)
34 outf(") %d %d w\n", o_qh
, o_qv
);
36 outf("] %d %d g\n", o_qh
, o_qv
);
56 static void o_queue(struct glyph
*g
)
58 int type
= 1 + (g
->pos
<= 0 || o_gname
);
59 if (o_qtype
!= type
|| o_qend
!= o_h
|| o_qv
!= o_v
) {
64 outf(type
== 1 ? "(" : "[");
67 if (g
->pos
>= ' ' && g
->pos
<= '~')
68 outf("%s%c", strchr("()\\", g
->pos
) ? "\\" : "", g
->pos
);
70 outf("\\%d%d%d", (g
->pos
>> 6) & 7,
71 (g
->pos
>> 3) & 7, g
->pos
& 7);
75 o_qend
= o_h
+ font_wid(g
->font
, o_s
, g
->wid
);
78 /* calls o_flush() if necessary */
79 void out(char *s
, ...)
88 static void out_fontup(int fid
)
93 out("%d %d %d rgb\n", CLR_R(o_m
), CLR_G(o_m
), CLR_B(o_m
));
96 if (fid
!= p_f
|| o_s
!= p_s
) {
98 out("%d /%s f\n", o_s
, font_name(fn
));
101 sprintf(fnname
, " %s ", font_name(fn
));
102 if (!strstr(o_fonts
, fnname
))
103 sprintf(strchr(o_fonts
, '\0'), "%s ", font_name(fn
));
111 g
= dev_glyph(c
, o_f
);
112 fn
= g
? g
->font
: dev_font(o_f
);
114 outrel(*c
== ' ' && fn
? font_swid(fn
, o_s
) : 1, 0);
117 out_fontup(dev_fontid(fn
));
131 void outrel(int h
, int v
)
143 /* a font was mounted at pos f */
161 void outrotate(int deg
)
166 outf("%d %d %d rot\n", -o_rdeg
, o_rh
, o_rv
);
170 outf("%d %d %d rot\n", deg
, o_h
, o_v
);
173 static int draw_path
; /* number of path segments */
174 static int draw_point
; /* point was set for postscript newpath */
176 static void drawmv(void)
179 outf("%d %d m ", o_h
, o_v
);
183 /* start a multi-segment path */
184 void drawmbeg(char *s
)
189 outf("gsave newpath %s\n", s
);
192 /* end a multi-segment path */
193 void drawmend(char *s
)
197 outf("%s grestore\n", s
);
209 void drawend(int close
, int fill
)
222 void drawl(int h
, int v
)
226 outf("%d %d drawl ", o_h
, o_v
);
233 outf("%d %d drawe ", c
, c
);
236 void drawe(int h
, int v
)
240 outf("%d %d drawe ", h
, v
);
243 void drawa(int h1
, int v1
, int h2
, int v2
)
246 outf("%d %d %d %d drawa ", h1
, v1
, h2
, v2
);
247 outrel(h1
+ h2
, v1
+ v2
);
250 void draws(int h1
, int v1
, int h2
, int v2
)
253 outf("%d %d %d %d %d %d draws ", o_h
, o_v
, o_h
+ h1
, o_v
+ v1
,
254 o_h
+ h1
+ h2
, o_v
+ v1
+ v2
);
258 void outeps(char *spec
)
262 int llx
, lly
, urx
, ury
;
266 if ((nspec
= sscanf(spec
, "%s %d %d", eps
, &hwid
, &vwid
)) < 1)
272 if (!(filp
= fopen(eps
, "r")))
274 if (!fgets(buf
, sizeof(buf
), filp
) ||
275 (strcmp(buf
, "%!PS-Adobe-2.0 EPSF-1.2\n") &&
276 strcmp(buf
, "%!PS-Adobe-2.0 EPSF-2.0\n") &&
277 strcmp(buf
, "%!PS-Adobe-3.0 EPSF-3.0\n"))) {
282 while (fgets(buf
, sizeof(buf
), filp
))
283 if (!strncmp(buf
, "%%BoundingBox: ", 15))
284 if ((nbb
= sscanf(buf
+ 15, "%d %d %d %d",
285 &llx
, &lly
, &urx
, &ury
)) == 4)
288 if (nbb
< 4) /* no BoundingBox comment */
290 if (hwid
<= 0 && vwid
<= 0)
291 hwid
= (urx
- llx
) * dev_res
/ 72;
293 vwid
= (ury
- lly
) * hwid
/ (urx
- llx
);
295 hwid
= (urx
- llx
) * vwid
/ (ury
- lly
);
296 /* output the EPS file */
299 outf("%d %d %d %d %d %d %d %d EPSFBEG\n",
300 llx
, lly
, hwid
, urx
- llx
, vwid
, ury
- lly
, o_h
, o_v
);
301 outf("%%%%BeginDocument: %s\n", eps
);
302 filp
= fopen(eps
, "r");
303 while (fgets(buf
, sizeof(buf
), filp
))
306 outf("%%%%EndDocument\n");
310 void outlink(char *spec
)
315 if ((nspec
= sscanf(spec
, "%s %d %d", lnk
, &hwid
, &vwid
)) != 3)
318 if (isdigit((unsigned char) lnk
[0])) {
319 outf("[ /Rect [ %d %d t %d %d t ] /Page %s"
320 "/Subtype /Link /LNK pdfmark\n",
321 o_h
, o_v
, o_h
+ hwid
, o_v
+ vwid
, lnk
);
323 outf("[ /Rect [ %d %d t %d %d t ]"
324 "/Action << /Subtype /URI /URI (%s) >> /Open true "
325 "/Subtype /Link /LNK pdfmark\n",
326 o_h
, o_v
, o_h
+ hwid
, o_v
+ vwid
, lnk
);