Debian Codegraph @

texk/web2c/window/epsf.c

raw
1 /*
2 * epsf.c -- Encapsulated PostScript window server.
3 * Copyright (C) 1998 Mathias Herberts <[email protected]>
4 *
5 * These functions generate an Encapsulated PostScript File
6 * representing the graphics normally shown online. They are
7 * selected by setting MFTERM to epsf.
8 *
9 * The name of the file defaults to metafont.eps but can be
10 * changed by setting the MFEPSF environment variable.
11 *
12 * The file is closed when the program exits.
13 */
14
15 /*
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 */
30
31
32
33 #define EXTERN extern
34
35 #include "../mfd.h"
36
37 #ifdef EPSFWIN
38
39 #include <stdio.h>
40
41 static FILE * psout = NULL;
42
43 /*
44 * Arrays epsf_{left,right,top,bottom} hold the coordinates of
45 * open windows.
46 *
47 * When a new window is opened, i.e. when blankrectangle is
48 * called, we check the arrays to see if the blank rectangle
49 * clears an open window. If it is the case a showpage and an %%EOF is
50 * appended To the PostScript file and a new header is output thus
51 * making it easy to separate the pages.
52 *
53 * The last page of the file is not terminated by a showpage and
54 * an %%EOF, the user should add them himself.
55 *
56 */
57
58 static screencol epsf_left[16];
59 static screencol epsf_right[16];
60 static screenrow epsf_top[16];
61 static screenrow epsf_bottom[16];
62
63 static short epsf_window = 0;
64 static unsigned int epsf_page = 1;
65
66 void
67 mf_epsf_header ()
68 {
69 fprintf (psout, "%%!PS-Adobe-3.0 EPSF-3.0\n");
70 fprintf (psout, "%%%%BoundingBox: -1 -1 %d %d\n", screenwidth, screendepth);
71 fprintf (psout, "%%%%Creator: METAFONT\n");
72 fprintf (psout, "%%%%Page: %d %d\n\n", epsf_page, epsf_page);
73 fprintf (psout, "1 dup scale\n");
74 fprintf (psout, "1 setlinewidth\n\n");
75
76 epsf_page++;
77 }
78
79 #include <mfdisplay.h>
80
81 int
82 mf_epsf_initscreen (void)
83 {
84 if (getenv ("MFEPSF") != (char *) NULL)
85 {
86 psout = fopen ((char *) getenv ("MFEPSF"), "w");
87 }
88 else
89 {
90 psout = fopen ("metafont.eps", "w");
91 }
92
93 if (psout == (FILE *) NULL)
94 {
95 return 0;
96 }
97 else
98 {
99 mf_epsf_header ();
100 epsf_window = 0;
101 return 1;
102 }
103 }
104
105 void
106 mf_epsf_updatescreen (void)
107 {
108 fflush (psout);
109 }
110
111 void
112 mf_epsf_blankrectangle (screencol left,
113 screencol right,
114 screenrow top,
115 screenrow bottom)
116 {
117 int i;
118
119 for (i = 0; i < epsf_window; i++)
120 {
121 if (! ((right - 1 < epsf_left[i]) || (epsf_right[i] < left)) ) /* new window is neither left nor right of window i */
122 if ( ! ((top > epsf_bottom[i]) || (epsf_top[i] > bottom - 1))) /* new window is neither below nor above window i */
123 {
124 fprintf (psout, "\nshowpage\n%%%%EOF\n");
125 mf_epsf_header ();
126 epsf_window = 0;
127 break;
128 }
129 }
130
131 epsf_left[epsf_window] = left;
132 epsf_right[epsf_window] = right - 1;
133 epsf_top[epsf_window] = top;
134 epsf_bottom[epsf_window] = bottom - 1;
135
136 epsf_window++;
137
138 fprintf (psout, "1 setgray %d %d %d %d rectfill 0 setgray\n", left, screendepth - 1 - bottom, right - left, bottom - top);
139
140 fflush (psout);
141 }
142
143
144 void
145 mf_epsf_paintrow (screenrow row,
146 pixelcolor init_color,
147 transspec transition_vector,
148 screencol vector_size)
149 {
150 int col;
151 int color;
152
153 color = (init_color == 0) ? 1 : 0;
154
155 do
156 {
157 col = *transition_vector++;
158
159 if (!color)
160 {
161 fprintf (psout, "newpath %d %d moveto %d %d lineto stroke\n",
162 col,
163 screendepth - 1 - row,
164 *transition_vector,
165 screendepth - 1 - row);
166 }
167
168 color = (color == 0) ? 1 : 0;
169 }
170 while (--vector_size > 0);
171 }
172
173
174 #else /* !EPSFWIN */
175
176 int epsf_dummy;
177
178 #endif /* !EPSFWIN */