1 /* libwmf ("ipa/x/draw.h"): library for wmf conversion
2 Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources
3
4 The libwmf Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 The libwmf Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the libwmf Library; see the file COPYING. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
18
19
wmf_x_flood_interior(wmfAPI * API,wmfFlood_t * flood)20 static void wmf_x_flood_interior (wmfAPI* API,wmfFlood_t* flood)
21 { (void)flood;
22 /* wmf_x_t* ddata = WMF_X_GetData (API); */
23
24 WMF_DEBUG (API,"wmf_[x_]flood_interior");
25
26 /* TODO */
27 }
28
wmf_x_flood_exterior(wmfAPI * API,wmfFlood_t * flood)29 static void wmf_x_flood_exterior (wmfAPI* API,wmfFlood_t* flood)
30 { (void)flood;
31 /* wmf_x_t* ddata = WMF_X_GetData (API); */
32
33 WMF_DEBUG (API,"wmf_[x_]flood_exterior");
34
35 /* TODO */
36 }
37
wmf_x_draw_pixel(wmfAPI * API,wmfDrawPixel_t * draw_pixel)38 static void wmf_x_draw_pixel (wmfAPI* API,wmfDrawPixel_t* draw_pixel)
39 { wmf_x_t* ddata = WMF_X_GetData (API);
40
41 XPoint pt;
42
43 WMF_DEBUG (API,"wmf_[x_]draw_pixel");
44
45 pt = x_translate (API,draw_pixel->pt);
46
47 setdefaultstyle (API);
48
49 XSetForeground (ddata->display,ddata->gc,get_color (API,&(draw_pixel->color)));
50
51 if (ddata->window != None)
52 { XDrawPoint (ddata->display,ddata->window,ddata->gc,pt.x,pt.y);
53 }
54 if (ddata->pixmap != None)
55 { XDrawPoint (ddata->display,ddata->pixmap,ddata->gc,pt.x,pt.y);
56 }
57 }
58
wmf_x_draw_pie(wmfAPI * API,wmfDrawArc_t * draw_arc)59 static void wmf_x_draw_pie (wmfAPI* API,wmfDrawArc_t* draw_arc)
60 { /* wmf_x_t* ddata = WMF_X_GetData (API); */
61
62 WMF_DEBUG (API,"wmf_[x_]draw_pie");
63
64 x_draw_arc (API,draw_arc,x_arc_pie);
65 }
66
wmf_x_draw_chord(wmfAPI * API,wmfDrawArc_t * draw_arc)67 static void wmf_x_draw_chord (wmfAPI* API,wmfDrawArc_t* draw_arc)
68 { /* wmf_x_t* ddata = WMF_X_GetData (API); */
69
70 WMF_DEBUG (API,"wmf_[x_]draw_chord");
71
72 x_draw_arc (API,draw_arc,x_arc_chord);
73 }
74
wmf_x_draw_arc(wmfAPI * API,wmfDrawArc_t * draw_arc)75 static void wmf_x_draw_arc (wmfAPI* API,wmfDrawArc_t* draw_arc)
76 { /* wmf_x_t* ddata = WMF_X_GetData (API); */
77
78 WMF_DEBUG (API,"wmf_[x_]draw_arc");
79
80 x_draw_arc (API,draw_arc,x_arc_open);
81 }
82
wmf_x_draw_ellipse(wmfAPI * API,wmfDrawArc_t * draw_arc)83 static void wmf_x_draw_ellipse (wmfAPI* API,wmfDrawArc_t* draw_arc)
84 { /* wmf_x_t* ddata = WMF_X_GetData (API); */
85
86 WMF_DEBUG (API,"wmf_[x_]draw_ellipse");
87
88 x_draw_arc (API,draw_arc,x_arc_ellipse);
89 }
90
x_draw_arc(wmfAPI * API,wmfDrawArc_t * draw_arc,x_arc_t finish)91 static void x_draw_arc (wmfAPI* API,wmfDrawArc_t* draw_arc,x_arc_t finish) /* TODO !! */
92 { wmf_x_t* ddata = WMF_X_GetData (API);
93
94 XPoint TL;
95 XPoint BR;
96
97 XPoint s_pt;
98 XPoint e_pt;
99
100 int Ox;
101 int Oy;
102 int w;
103 int h;
104 int start = 0;
105 int end = 64 * 360;
106
107 WMF_DEBUG (API,"~~~~~~~~x_draw_arc");
108
109 TL = x_translate (API,draw_arc->TL);
110 BR = x_translate (API,draw_arc->BR);
111
112 Ox = (BR.x + TL.x) / 2; /* origin of ellipse */
113 Oy = (BR.y + TL.y) / 2;
114
115 w = (BR.x - TL.x); /* axes of ellipse */
116 h = (BR.y - TL.y);
117
118 if (finish != x_arc_ellipse)
119 { start = (int) (atan2 (draw_arc->end.y ,draw_arc->end.x ) * 64 * 180 / PI);
120 end = (int) (atan2 (draw_arc->start.y,draw_arc->start.x) * 64 * 180 / PI);
121
122 start = (64 * 360) - start;
123 end = (64 * 360) - end;
124
125 while (start < 0)
126 { start += 64 * 360;
127 end += 64 * 360;
128 }
129 while (end <= start) end += 64 * 360;
130
131 end -= start;
132
133 if (finish != x_arc_open)
134 { s_pt = x_translate (API,draw_arc->start);
135 s_pt.x += Ox;
136 s_pt.y += Oy;
137 e_pt = x_translate (API,draw_arc->end);
138 e_pt.x += Ox;
139 e_pt.y += Oy;
140 }
141 }
142
143 if (TO_FILL (draw_arc) && (finish != x_arc_open))
144 { setbrushstyle (API,draw_arc->dc);
145
146 if (finish == x_arc_ellipse)
147 { XSetArcMode (ddata->display,ddata->gc,ArcChord);
148 }
149 else if (finish == x_arc_pie)
150 { XSetArcMode (ddata->display,ddata->gc,ArcPieSlice);
151 }
152 else if (finish == x_arc_chord)
153 { XSetArcMode (ddata->display,ddata->gc,ArcChord);
154 }
155
156 if (ddata->window != None)
157 { XFillArc (ddata->display,ddata->window,ddata->gc,TL.x,TL.y,w,h,start,end);
158 }
159 if (ddata->pixmap != None)
160 { XFillArc (ddata->display,ddata->pixmap,ddata->gc,TL.x,TL.y,w,h,start,end);
161 }
162 }
163 if (TO_DRAW (draw_arc))
164 { setlinestyle (API,draw_arc->dc);
165
166 if (ddata->window != None)
167 { XDrawArc (ddata->display,ddata->window,ddata->gc,TL.x,TL.y,w,h,start,end);
168 }
169 if (ddata->pixmap != None)
170 { XDrawArc (ddata->display,ddata->pixmap,ddata->gc,TL.x,TL.y,w,h,start,end);
171 }
172
173 if (finish == x_arc_ellipse)
174 { /* Do nothing */
175 }
176 else if (finish == x_arc_open)
177 { /* Do nothing */
178 }
179 else if (finish == x_arc_pie)
180 { if (ddata->window != None)
181 { XDrawLine (ddata->display,ddata->window,ddata->gc,e_pt.x,e_pt.y,Ox,Oy);
182 XDrawLine (ddata->display,ddata->window,ddata->gc,Ox,Oy,s_pt.x,s_pt.y);
183 }
184 if (ddata->pixmap != None)
185 { XDrawLine (ddata->display,ddata->pixmap,ddata->gc,e_pt.x,e_pt.y,Ox,Oy);
186 XDrawLine (ddata->display,ddata->pixmap,ddata->gc,Ox,Oy,s_pt.x,s_pt.y);
187 }
188 }
189 else if (finish == x_arc_chord)
190 { if (ddata->window != None)
191 { XDrawLine (ddata->display,ddata->window,ddata->gc,e_pt.x,e_pt.y,s_pt.x,s_pt.y);
192 }
193 if (ddata->pixmap != None)
194 { XDrawLine (ddata->display,ddata->pixmap,ddata->gc,e_pt.x,e_pt.y,s_pt.x,s_pt.y);
195 }
196 }
197 }
198 }
199
wmf_x_draw_line(wmfAPI * API,wmfDrawLine_t * draw_line)200 static void wmf_x_draw_line (wmfAPI* API,wmfDrawLine_t* draw_line)
201 { wmf_x_t* ddata = WMF_X_GetData (API);
202
203 XPoint from;
204 XPoint to;
205
206 WMF_DEBUG (API,"wmf_[x_]draw_line");
207
208 if (TO_DRAW (draw_line))
209 { setlinestyle (API,draw_line->dc);
210
211 from = x_translate (API,draw_line->from);
212 to = x_translate (API,draw_line->to );
213
214 if (ddata->window != None)
215 { XDrawLine (ddata->display,ddata->window,ddata->gc,from.x,from.y,to.x,to.y);
216 }
217 if (ddata->pixmap != None)
218 { XDrawLine (ddata->display,ddata->pixmap,ddata->gc,from.x,from.y,to.x,to.y);
219 }
220 }
221 }
222
wmf_x_poly_line(wmfAPI * API,wmfPolyLine_t * poly_line)223 static void wmf_x_poly_line (wmfAPI* API,wmfPolyLine_t* poly_line)
224 { wmf_x_t* ddata = WMF_X_GetData (API);
225
226 XPoint* pt;
227
228 U16 i;
229
230 WMF_DEBUG (API,"wmf_[x_]poly_line");
231
232 if (poly_line->count < 2) return;
233
234 pt = (XPoint*) wmf_malloc (API,poly_line->count * sizeof (XPoint));
235
236 if (ERR (API))
237 { WMF_DEBUG (API,"bailing...");
238 return;
239 }
240
241 for (i = 0; i < poly_line->count; i++)
242 { pt[i] = x_translate (API,poly_line->pt[i]);
243 }
244
245 if (TO_DRAW (poly_line))
246 { setlinestyle (API,poly_line->dc);
247
248 if (ddata->window != None)
249 { XDrawLines (ddata->display,ddata->window,ddata->gc,
250 pt,poly_line->count,CoordModeOrigin);
251 }
252 if (ddata->pixmap != None)
253 { XDrawLines (ddata->display,ddata->pixmap,ddata->gc,
254 pt,poly_line->count,CoordModeOrigin);
255 }
256 }
257
258 wmf_free (API,pt);
259 }
260
wmf_x_draw_polygon(wmfAPI * API,wmfPolyLine_t * poly_line)261 static void wmf_x_draw_polygon (wmfAPI* API,wmfPolyLine_t* poly_line)
262 { wmf_x_t* ddata = WMF_X_GetData (API);
263
264 XPoint* pt;
265
266 U16 i;
267
268 WMF_DEBUG (API,"wmf_[x_]draw_polygon");
269
270 if (poly_line->count < 2) return;
271
272 pt = (XPoint*) wmf_malloc (API,(poly_line->count + 1) * sizeof (XPoint));
273
274 if (ERR (API))
275 { WMF_DEBUG (API,"bailing...");
276 return;
277 }
278
279 for (i = 0; i < poly_line->count; i++)
280 { pt[i] = x_translate (API,poly_line->pt[i]);
281 }
282 pt[poly_line->count] = pt[0];
283
284 if (TO_FILL (poly_line))
285 { setbrushstyle (API,poly_line->dc);
286
287 if (ddata->window != None)
288 { XFillPolygon (ddata->display,ddata->window,ddata->gc,
289 pt,poly_line->count+1,Complex,CoordModeOrigin);
290 }
291 if (ddata->pixmap != None)
292 { XFillPolygon (ddata->display,ddata->pixmap,ddata->gc,
293 pt,poly_line->count+1,Complex,CoordModeOrigin);
294 }
295 }
296 if (TO_DRAW (poly_line))
297 { setlinestyle (API,poly_line->dc);
298
299 if (ddata->window != None)
300 { XDrawLines (ddata->display,ddata->window,ddata->gc,
301 pt,poly_line->count+1,CoordModeOrigin);
302 }
303 if (ddata->pixmap != None)
304 { XDrawLines (ddata->display,ddata->pixmap,ddata->gc,
305 pt,poly_line->count+1,CoordModeOrigin);
306 }
307 }
308
309 wmf_free (API,pt);
310 }
311
wmf_x_draw_rectangle(wmfAPI * API,wmfDrawRectangle_t * draw_rectangle)312 static void wmf_x_draw_rectangle (wmfAPI* API,wmfDrawRectangle_t* draw_rectangle)
313 { wmf_x_t* ddata = WMF_X_GetData (API);
314
315 XPoint TL;
316 XPoint BR;
317
318 WMF_DEBUG (API,"wmf_[x_]draw_rectangle");
319
320 TL = x_translate (API,draw_rectangle->TL);
321 BR = x_translate (API,draw_rectangle->BR);
322
323 BR.x -= TL.x;
324 BR.y -= TL.y;
325
326 if (TO_FILL (draw_rectangle))
327 { setbrushstyle (API,draw_rectangle->dc);
328
329 if (ddata->window != None)
330 { XFillRectangle (ddata->display,ddata->window,ddata->gc,TL.x,TL.y,BR.x,BR.y);
331 }
332 if (ddata->pixmap != None)
333 { XFillRectangle (ddata->display,ddata->pixmap,ddata->gc,TL.x,TL.y,BR.x,BR.y);
334 }
335 }
336 if (TO_DRAW (draw_rectangle))
337 { setlinestyle (API,draw_rectangle->dc);
338
339 if (ddata->window != None)
340 { XDrawRectangle (ddata->display,ddata->window,ddata->gc,TL.x,TL.y,BR.x,BR.y);
341 }
342 if (ddata->pixmap != None)
343 { XDrawRectangle (ddata->display,ddata->pixmap,ddata->gc,TL.x,TL.y,BR.x,BR.y);
344 }
345 }
346 }
347