3 Part of the swftools package.
5 Copyright (c) 2005 Matthias Kramm <kramm@quiss.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
27 #include "../gfxdevice.h"
28 #include "../gfxtools.h"
29 #include "../art/libart.h"
30 #include "artsutils.c"
32 typedef struct _clip {
37 typedef struct _internal {
43 static int verbose = 0;
44 static void dbg(char*format, ...)
51 va_start(arglist, format);
52 vsprintf(buf, format, arglist);
55 while(l && buf[l-1]=='\n') {
59 printf("(device-arts) %s\n", buf);
63 int arts_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
65 dbg("arts_setparameter");
66 internal_t*i = (internal_t*)dev->internal;
67 if(i->out) return i->out->setparameter(i->out,key,value);
71 void arts_startpage(struct _gfxdevice*dev, int width, int height)
73 dbg("arts_startpage");
74 internal_t*i = (internal_t*)dev->internal;
75 if(i->out) i->out->startpage(i->out,width,height);
78 void arts_startclip(struct _gfxdevice*dev, gfxline_t*line)
80 dbg("arts_startclip");
81 internal_t*i = (internal_t*)dev->internal;
82 ArtSVP* svp = gfxfillToSVP(line, 1);
84 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
87 ArtSVP*old = i->clip->svp;
89 i->clip = (clip_t*)rfx_calloc(sizeof(clip_t));
91 i->clip->svp = art_svp_intersect(svp, old);
94 i->clip = (clip_t*)rfx_calloc(sizeof(clip_t));
99 void arts_endclip(struct _gfxdevice*dev)
102 internal_t*i = (internal_t*)dev->internal;
105 clip_t*old = i->clip;
106 i->clip = i->clip->next;
107 art_svp_free(old->svp);old->svp = 0;
108 old->next = 0;free(old);
110 fprintf(stderr, "Error: endclip without startclip\n");
114 void addtounion(struct _gfxdevice*dev, ArtSVP*svp)
116 internal_t*i = (internal_t*)dev->internal;
118 ArtSVP*old = i->svpunion;
119 i->svpunion = art_svp_union(svp,i->svpunion);
124 void arts_stroke(struct _gfxdevice*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
127 internal_t*i = (internal_t*)dev->internal;
128 //i->out->stroke(i->out, line, width, color, cap_style, joint_style, miterLimit);
129 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
132 svp = art_svp_intersect(svp, i->clip->svp);
136 gfxline_t*gfxline = SVPtogfxline(svp);
137 if(i->out) i->out->fill(i->out, gfxline, color);
142 void arts_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
145 internal_t*i = (internal_t*)dev->internal;
146 ArtSVP* svp = gfxfillToSVP(line, 1);
148 if (svp->n_segs > 500)
151 gfxline_t* lineCursor = line;
152 while(lineCursor != NULL)
154 if(lineCursor->type != gfx_moveTo) ++lineParts;
155 lineCursor = lineCursor->next;
157 fprintf(stderr, "arts_fill abandonning shape with %d segments (%d line parts)\n", svp->n_segs, lineParts);
162 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
166 svp = art_svp_intersect(svp, i->clip->svp);
170 gfxline_t*gfxline = SVPtogfxline(svp);
171 if(i->out) i->out->fill(i->out, gfxline, color);
176 void arts_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
178 dbg("arts_fillbitmap");
179 internal_t*i = (internal_t*)dev->internal;
180 ArtSVP* svp = gfxfillToSVP(line, 1);
184 svp = art_svp_intersect(svp, i->clip->svp);
188 gfxline_t*gfxline = SVPtogfxline(svp);
189 if(i->out) i->out->fillbitmap(i->out, gfxline, img, matrix, cxform);
194 void arts_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
196 dbg("arts_fillgradient");
197 internal_t*i = (internal_t*)dev->internal;
198 ArtSVP* svp = gfxfillToSVP(line, 1);
201 svp = art_svp_intersect(svp, i->clip->svp);
205 gfxline_t*gfxline = SVPtogfxline(svp);
206 if(i->out) i->out->fillgradient(i->out, gfxline, gradient, type, matrix);
211 void arts_addfont(struct _gfxdevice*dev, gfxfont_t*font)
214 internal_t*i = (internal_t*)dev->internal;
215 if(i->out) i->out->addfont(i->out, font);
218 void arts_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
220 dbg("arts_drawchar");
223 internal_t*i = (internal_t*)dev->internal;
224 gfxline_t*glyph = gfxline_clone(font->glyphs[glyphnr].line);
225 gfxline_transform(glyph, matrix);
228 gfxbbox_t bbox = gfxline_getbbox(glyph);
229 ArtSVP*dummybox = boxToSVP(bbox.xmin,bbox.ymin,bbox.xmax,bbox.ymax);
230 ArtSVP*svp = art_svp_intersect(dummybox, i->clip->svp);
231 gfxline_t*gfxline = SVPtogfxline(svp);
232 gfxbbox_t bbox2 = gfxline_getbbox(gfxline);
233 double w = bbox2.xmax - bbox2.xmin;
234 double h = bbox2.ymax - bbox2.ymin;
236 addtounion(dev, svp); // TODO: use the whole char, not just the bbox
238 if(w < 0.001 || h < 0.001) /* character was clipped completely */ {
239 } else if(fabs((bbox.xmax - bbox.xmin) - w) > 0.05 ||
240 fabs((bbox.ymax - bbox.ymin) - h) > 0.05) {
241 /* notable change in character size: character was clipped
242 TODO: handle diagonal cuts
244 arts_fill(dev, glyph, color);
246 if(i->out) i->out->drawchar(i->out, font, glyphnr, color, matrix);
249 if(i->out) i->out->drawchar(i->out, font, glyphnr, color, matrix);
255 void arts_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action)
257 dbg("arts_drawlink");
258 internal_t*i = (internal_t*)dev->internal;
259 if(i->out) i->out->drawlink(i->out, line, action);
262 void arts_endpage(struct _gfxdevice*dev)
265 internal_t*i = (internal_t*)dev->internal;
266 if(i->out) i->out->endpage(i->out);
269 gfxresult_t* arts_finish(struct _gfxdevice*dev)
272 internal_t*i = (internal_t*)dev->internal;
274 return i->out->finish(i->out);
280 gfxline_t*gfxdevice_union_getunion(struct _gfxdevice*dev)
282 internal_t*i = (internal_t*)dev->internal;
283 return SVPtogfxline(i->svpunion);
286 void gfxdevice_removeclippings_init(gfxdevice_t*dev, gfxdevice_t*out)
288 dbg("gfxdevice_removeclippings_init");
289 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
290 memset(dev, 0, sizeof(gfxdevice_t));
292 dev->name = "removeclippings";
296 dev->setparameter = arts_setparameter;
297 dev->startpage = arts_startpage;
298 dev->startclip = arts_startclip;
299 dev->endclip = arts_endclip;
300 dev->stroke = arts_stroke;
301 dev->fill = arts_fill;
302 dev->fillbitmap = arts_fillbitmap;
303 dev->fillgradient = arts_fillgradient;
304 dev->addfont = arts_addfont;
305 dev->drawchar = arts_drawchar;
306 dev->drawlink = arts_drawlink;
307 dev->endpage = arts_endpage;
308 dev->finish = arts_finish;
314 void gfxdevice_union_init(gfxdevice_t*dev,gfxdevice_t*out)
316 dbg("gfxdevice_getunion_init");
317 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
318 memset(dev, 0, sizeof(gfxdevice_t));
324 dev->setparameter = arts_setparameter;
325 dev->startpage = arts_startpage;
326 dev->startclip = arts_startclip;
327 dev->endclip = arts_endclip;
328 dev->stroke = arts_stroke;
329 dev->fill = arts_fill;
330 dev->fillbitmap = arts_fillbitmap;
331 dev->fillgradient = arts_fillgradient;
332 dev->addfont = arts_addfont;
333 dev->drawchar = arts_drawchar;
334 dev->drawlink = arts_drawlink;
335 dev->endpage = arts_endpage;
336 dev->finish = arts_finish;
339 i->svpunion = gfxstrokeToSVP(0, 0, 0, 0, 0);