1 /*----------------------------------------------------------------------------
2 gdi.cc (generate tpv data)
3 This file is a part of topaz systems
4 Copyright: Hisao Kawaura, All rights reserved
5 1997 - 98
6
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 ----------------------------------------------------------------------------*/
23
24 #include <stdio.h>
25 #include "vectdefs.h"
26 #include "pointdefs.h"
27 #include "filepoint.h"
28 #include "graph.h"
29 #include <time.h>
30 #include "topazvalues.h"
31
32 extern graph *gra;
33 extern FileHandleArray *fhvuff;
34 extern intpoint RotatePoint(intpoint P, intpoint OrgP, double Theta);
35
36 // following flag true:paint false:getrect
37 bool movelineflag = false;
38 int prevx, prevy;
39 intrect bb;
40 int linew = 0;
41 int lineno = 0;
42
updateBB(int x,int y)43 void updateBB(int x, int y)
44 {
45 if (x < bb.left)
46 bb.left = x;
47 if (x > bb.right)
48 bb.right = x;
49 if (y < bb.top)
50 bb.top = y;
51 if (y > bb.bottom)
52 bb.bottom = y;
53 }
54
psetmag(bool flag,FILE * f)55 void psetmag(bool flag, FILE *f)
56 {
57 if (flag)
58 {
59 fprintf(f, "/MAG\n");
60 fprintf(f, "%f\n", gra->mag);
61 }
62 }
63
psetshift(bool flag,FILE * f)64 void psetshift(bool flag, FILE *f)
65 {
66 if (flag)
67 {
68 fprintf(f, "/SFT\n");
69 fprintf(f, "%d,%d\n", gra->offset.x, gra->offset.y);
70 }
71 }
72
pmoveto(bool flag,FILE * f,int x,int y)73 void pmoveto(bool flag, FILE *f, int x, int y)
74 {
75 if (flag)
76 {
77 if (movelineflag)
78 {
79 fprintf(f, "/SRP\n");
80 fprintf(f, "/BGP\n");
81 }
82 movelineflag = false;
83 prevx = x; prevy = y;
84 }
85 else
86 {
87 movelineflag = false;
88 prevx = x; prevy = y;
89 }
90 }
91
plineto(bool flag,FILE * f,int x,int y)92 void plineto(bool flag, FILE *f, int x, int y)
93 {
94 if (flag)
95 {
96 if (movelineflag == false)
97 {
98 fprintf(f, "/MVT\n");
99 fprintf(f, "%d,%d\n", prevx, prevy);
100 }
101
102 fprintf(f, "/LNT\n");
103 fprintf(f, "%d,%d\n", x, y);
104 movelineflag = true;
105 lineno++;
106
107 if (lineno > 1000)
108 {
109 fprintf(f, "/SRP\n");
110 fprintf(f, "/BGP\n");
111 movelineflag = false;
112 prevx = x; prevy = y;
113 lineno = 0;
114 }
115 }
116 else
117 {
118 if (movelineflag == false)
119 {
120 updateBB(prevx - gra->scale(linew / 2), prevy - gra->scale(linew / 2));
121 updateBB(prevx + gra->scale(linew / 2), prevy + gra->scale(linew / 2));
122 }
123
124 updateBB(x - gra->scale(linew / 2), y - gra->scale(linew / 2));
125 updateBB(x + gra->scale(linew / 2), y + gra->scale(linew / 2));
126 movelineflag = true;
127 }
128 }
129
130
pstroke(bool flag,FILE * f)131 void pstroke(bool flag, FILE *f)
132 {
133 if (flag)
134 {
135 fprintf(f, "/SRP\n");
136 }
137 }
138
pbeginpath(bool flag,FILE * f)139 void pbeginpath(bool flag, FILE *f)
140 {
141 if (flag)
142 fprintf(f, "/BGP\n");
143 }
144
pclosepath(bool flag,FILE * f)145 void pclosepath(bool flag, FILE *f)
146 {
147 if (flag)
148 {
149 fprintf(f, "/CSP\n");
150 }
151 }
152
plinestyle(bool flag,FILE * f,int width,int cap,int join,int style)153 void plinestyle(bool flag, FILE *f, int width, int cap, int join, int style)
154 {
155 if (flag)
156 {
157 fprintf(f, "/LSY\n");
158 fprintf(f, "%d\n", width);
159 linew = width;
160 fprintf(f, "%d\n", cap);
161 fprintf(f, "%d\n", join);
162 fprintf(f, "%d\n", style);
163 }
164 else
165 linew = width;
166 }
167
pfillstyle(bool flag,FILE * f,int fillrule,int style)168 void pfillstyle(bool flag, FILE *f, int fillrule, int style)
169 {
170 if (flag)
171 {
172 fprintf(f, "/FSY\n");
173 fprintf(f, "%d\n", fillrule);
174 fprintf(f, "%d\n", style);
175 }
176 }
177
ppolygon(bool flag,FILE * f,intpointarray * ia)178 void ppolygon(bool flag, FILE *f, intpointarray *ia)
179 {
180 if (ia->getarraylength() > 1000)
181 return;
182
183 if (flag)
184 {
185 fprintf(f, "/PLY\n");
186 fprintf(f, "%d\n", ia->getarraylength());
187 for (int i = 0; i < ia->getarraylength(); i++)
188 fprintf(f, "%d,%d\n", (*ia)[i].x, (*ia)[i].y);
189 }
190 else
191 {
192 for (int i = 0; i < ia->getarraylength(); i++)
193 {
194 updateBB((*ia)[i].x - gra->scale(linew / 2), (*ia)[i].y - gra->scale(linew / 2));
195 updateBB((*ia)[i].x + gra->scale(linew / 2), (*ia)[i].y + gra->scale(linew / 2));
196 }
197 }
198 }
199
pellipse(bool flag,FILE * f,int x1,int y1,int x2,int y2)200 void pellipse(bool flag, FILE *f, int x1, int y1, int x2, int y2)
201 {
202 if (flag)
203 {
204 fprintf(f, "/ELP\n");
205 fprintf(f, "%d,%d\n", x1, y1);
206 fprintf(f, "%d,%d\n", x2, y2);
207 }
208 else
209 {
210 updateBB(x1 - gra->scale(linew / 2), y1 - gra->scale(linew / 2));
211 updateBB(x1 + gra->scale(linew / 2), y1 + gra->scale(linew / 2));
212 updateBB(x2 - gra->scale(linew / 2), y2 - gra->scale(linew / 2));
213 updateBB(x2 + gra->scale(linew / 2), y2 + gra->scale(linew / 2));
214 }
215 }
216
psetforecolor(bool flag,FILE * f,unsigned int red,unsigned int green,unsigned int blue)217 void psetforecolor(bool flag, FILE *f, unsigned int red, unsigned int green, unsigned int blue)
218 {
219 if (flag)
220 {
221 fprintf(f, "/FCL\n");
222 fprintf(f, "%u,%u,%u\n",red, green, blue);
223 }
224 }
225
psetbackcolor(bool flag,FILE * f,unsigned int red,unsigned int green,unsigned int blue)226 void psetbackcolor(bool flag, FILE *f, unsigned int red, unsigned int green, unsigned int blue)
227 {
228 if (flag)
229 {
230 fprintf(f, "/BCL\n");
231 fprintf(f, "%u,%u,%u\n",red, green, blue);
232 }
233 }
234
psetpaintmode(bool flag,FILE * f,int mode)235 void psetpaintmode(bool flag, FILE *f, int mode)
236 {
237 if (flag)
238 {
239 fprintf(f, "/PMD\n");
240 fprintf(f, "%d\n", mode);
241 }
242 }
243
psavegdc(bool flag,FILE * f)244 void psavegdc(bool flag, FILE *f)
245 {
246 if (flag)
247 fprintf(f, "\n");
248 }
249
presoregdc(bool flag,FILE * f)250 void presoregdc(bool flag, FILE *f)
251 {
252 if (flag)
253 fprintf(f, "\n");
254 }
255
psetcliprect(bool flag,FILE * f,intrect * rect)256 void psetcliprect(bool flag, FILE *f, intrect *rect)
257 {
258 if (flag)
259 {
260 fprintf(f, "/CRT\n");
261 fprintf(f, "%d,%d\n", rect->left, rect->top);
262 fprintf(f, "%d,%d\n", rect->right, rect->bottom);
263 }
264 }
265
pinitcliprect(bool flag,FILE * f)266 void pinitcliprect(bool flag, FILE *f)
267 {
268 if (flag)
269 {
270 fprintf(f, "/RCP\n");
271 }
272 }
273
ploadfont(bool flag,FILE * f,int face,int size,double angle)274 void ploadfont(bool flag, FILE *f, int face, int size, double angle)
275 {
276 if (flag)
277 {
278 fprintf(f, "/LFT\n");
279 fprintf(f, "%d,%d,%f\n", face, size, angle);
280 }
281 }
282
pdrawtext(bool flag,FILE * f,int x,int y,const char * text,int size,int width,double angle,int ascend)283 void pdrawtext(bool flag, FILE *f, int x, int y, const char *text, int size, int width, double angle, int ascend)
284 {
285 intpoint lt, lb, rt, rb;
286
287 if (flag)
288 {
289 fprintf(f, "/DTX\n");
290 fprintf(f, "%d,%d\n", x, y);
291 fprintf(f, "%s\n", text);
292 }
293 else
294 {
295 lt = RotatePoint(intpoint(x, y - ascend), intpoint (x, y), angle);
296 rt = RotatePoint(intpoint(x + width, y - ascend), intpoint (x, y), angle);
297 rb = RotatePoint(intpoint(x + width, y - ascend + size), intpoint (x, y), angle);
298 lb = RotatePoint(intpoint(x, y - ascend + size), intpoint (x, y), angle);
299
300 updateBB(lt.x, lt.y);
301 updateBB(rt.x, rt.y);
302 updateBB(rb.x, rb.y);
303 updateBB(lb.x, lb.y);
304 }
305 }
306
psettempdashline(bool flag,FILE * f)307 void psettempdashline(bool flag, FILE *f)
308 {
309 if (flag)
310 fprintf(f, "/STD\n");
311 }
312
prestorelinestyle(bool flag,FILE * f)313 void prestorelinestyle(bool flag, FILE *f)
314 {
315 if (flag)
316 fprintf(f, "/RLS\n");
317 }
318
poutBBox(FILE * f)319 void poutBBox(FILE *f)
320 {
321 fprintf(f, "/PAR\n");
322 fprintf(f, "%d,%d\n", gra->papersize.x, gra->papersize.y);
323 fprintf(f, "/BBX\n");
324 fprintf(f, "%d,%d\n", bb.left, bb.top);
325 fprintf(f, "%d,%d\n", bb.right, bb.bottom);
326 }
327
pbegin(bool flag,FILE * f)328 void pbegin(bool flag, FILE *f)
329 {
330 time_t timeval;
331 if (flag)
332 {
333 (void)time(&timeval);
334 fprintf(f, "# topaz primitive vector format\n");
335 fprintf(f, "# created by topaz %s", ctime(&timeval));
336 fprintf(f, "# Date : %s", ctime(&timeval));
337 poutBBox(f);
338 psetmag(flag, f);
339 psetshift(flag, f);
340 fprintf(f, "BGN\n");
341 }
342 else
343 {
344 bb.left = MAXINT;
345 bb.top = MAXINT;
346 bb.right = -MAXINT;
347 bb.bottom = -MAXINT;
348 }
349 }
350
ppaint(bool flag,FILE * f)351 void ppaint(bool flag, FILE *f)
352 {
353 if (flag)
354 fprintf(f, "PNT\n");
355 }
356
pclearviewer(bool flag,FILE * f)357 void pclearviewer(bool flag, FILE *f)
358 {
359 if (flag)
360 fprintf(f, "/CLR\n");
361 }
362
pflush(bool flag,FILE * f)363 void pflush(bool flag, FILE *f)
364 {
365 if (flag)
366 fflush(f);
367 }
368
369
370
371
372
373
374
375
376
377
378