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 {
42 static int verbose = 1;
43 static void dbg(char*format, ...)
50 va_start(arglist, format);
51 vsprintf(buf, format, arglist);
54 while(l && buf[l-1]=='\n') {
58 printf("(device-arts) %s\n", buf);
62 int arts_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
64 dbg("arts_setparameter");
65 internal_t*i = (internal_t*)dev->internal;
66 return i->out->setparameter(i->out,key,value);
69 void arts_startpage(struct _gfxdevice*dev, int width, int height)
71 dbg("arts_startpage");
72 internal_t*i = (internal_t*)dev->internal;
73 i->out->startpage(i->out,width,height);
76 void arts_startclip(struct _gfxdevice*dev, gfxline_t*line)
78 dbg("arts_startclip");
79 internal_t*i = (internal_t*)dev->internal;
80 ArtSVP* svp = gfxfillToSVP(line, 1);
82 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
85 ArtSVP*old = i->clip->svp;
87 i->clip = (clip_t*)rfx_calloc(sizeof(clip_t));
89 i->clip->svp = art_svp_intersect(svp, old);
92 i->clip = rfx_calloc(sizeof(clip_t));
97 void arts_endclip(struct _gfxdevice*dev)
100 internal_t*i = (internal_t*)dev->internal;
103 clip_t*old = i->clip;
104 i->clip = i->clip->next;
105 art_svp_free(old->svp);old->svp = 0;
106 old->next = 0;free(old);
108 fprintf(stderr, "Error: endclip without startclip\n");
112 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)
115 internal_t*i = (internal_t*)dev->internal;
116 //i->out->stroke(i->out, line, width, color, cap_style, joint_style, miterLimit);
117 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
120 svp = art_svp_intersect(svp, i->clip->svp);
123 gfxline_t*gfxline = SVPtogfxline(svp);
124 i->out->fill(i->out, gfxline, color);
129 void arts_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
132 internal_t*i = (internal_t*)dev->internal;
133 ArtSVP* svp = gfxfillToSVP(line, 1);
135 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
139 svp = art_svp_intersect(svp, i->clip->svp);
142 gfxline_t*gfxline = SVPtogfxline(svp);
143 i->out->fill(i->out, gfxline, color);
148 void arts_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
150 dbg("arts_fillbitmap");
151 internal_t*i = (internal_t*)dev->internal;
152 ArtSVP* svp = gfxfillToSVP(line, 1);
155 svp = art_svp_intersect(svp, i->clip->svp);
158 gfxline_t*gfxline = SVPtogfxline(svp);
159 i->out->fillbitmap(i->out, gfxline, img, matrix, cxform);
164 void arts_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
166 dbg("arts_fillgradient");
167 internal_t*i = (internal_t*)dev->internal;
168 ArtSVP* svp = gfxfillToSVP(line, 1);
171 svp = art_svp_intersect(svp, i->clip->svp);
174 gfxline_t*gfxline = SVPtogfxline(svp);
175 i->out->fillgradient(i->out, gfxline, gradient, type, matrix);
180 void arts_addfont(struct _gfxdevice*dev, gfxfont_t*font)
183 internal_t*i = (internal_t*)dev->internal;
184 i->out->addfont(i->out, font);
187 void arts_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
189 dbg("arts_drawchar");
190 internal_t*i = (internal_t*)dev->internal;
191 gfxline_t*glyph = gfxline_clone(font->glyphs[glyphnr].line);
192 gfxline_transform(glyph, matrix);
195 gfxbbox_t bbox = gfxline_getbbox(glyph);
196 ArtSVP*dummybox = boxToSVP(bbox.xmin,bbox.ymin,bbox.xmax,bbox.ymax);
197 ArtSVP*svp = art_svp_intersect(dummybox, i->clip->svp);
198 gfxline_t*gfxline = SVPtogfxline(svp);
199 gfxbbox_t bbox2 = gfxline_getbbox(gfxline);
200 double w = bbox2.xmax - bbox2.xmin;
201 double h = bbox2.ymax - bbox2.ymin;
202 if(w < 0.001 || h < 0.001) /* character was clipped completely */ {
203 } else if(fabs((bbox.xmax - bbox.xmin) - w) > 0.05 ||
204 fabs((bbox.ymax - bbox.ymin) - h) > 0.05) {
205 /* notable change in character size: character was clipped
206 TODO: handle diagonal cuts
208 arts_fill(dev, glyph, color);
210 i->out->drawchar(i->out, font, glyphnr, color, matrix);
213 i->out->drawchar(i->out, font, glyphnr, color, matrix);
219 void arts_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action)
221 dbg("arts_drawlink");
222 internal_t*i = (internal_t*)dev->internal;
223 i->out->drawlink(i->out, line, action);
226 void arts_endpage(struct _gfxdevice*dev)
229 internal_t*i = (internal_t*)dev->internal;
230 i->out->endpage(i->out);
233 gfxresult_t* arts_finish(struct _gfxdevice*dev)
236 internal_t*i = (internal_t*)dev->internal;
237 return i->out->finish(i->out);
240 void gfxdevice_arts_init(gfxdevice_t*dev, gfxdevice_t*out)
242 dbg("gfxdevice_arts_init");
243 internal_t*i = rfx_calloc(sizeof(internal_t));
244 memset(dev, 0, sizeof(gfxdevice_t));
247 dev->setparameter = arts_setparameter;
248 dev->startpage = arts_startpage;
249 dev->startclip = arts_startclip;
250 dev->endclip = arts_endclip;
251 dev->stroke = arts_stroke;
252 dev->fill = arts_fill;
253 dev->fillbitmap = arts_fillbitmap;
254 dev->fillgradient = arts_fillgradient;
255 dev->addfont = arts_addfont;
256 dev->drawchar = arts_drawchar;
257 dev->drawlink = arts_drawlink;
258 dev->endpage = arts_endpage;
259 dev->finish = arts_finish;