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 */
26 #include "../gfxdevice.h"
27 #include "../gfxtools.h"
28 #include "../art/libart.h"
29 #include "artsutils.c"
31 typedef struct _clip {
36 typedef struct _internal {
41 int arts_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
43 internal_t*i = (internal_t*)dev->internal;
44 return i->out->setparameter(i->out,key,value);
47 void arts_startpage(struct _gfxdevice*dev, int width, int height)
49 internal_t*i = (internal_t*)dev->internal;
50 i->out->startpage(i->out,width,height);
53 void arts_startclip(struct _gfxdevice*dev, gfxline_t*line)
55 internal_t*i = (internal_t*)dev->internal;
56 ArtSVP* svp = gfxfillToSVP(line, 1);
58 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
61 ArtSVP*old = i->clip->svp;
63 i->clip = (clip_t*)rfx_calloc(sizeof(clip_t));
65 i->clip->svp = art_svp_intersect(svp, old);
68 i->clip = rfx_calloc(sizeof(clip_t));
73 void arts_endclip(struct _gfxdevice*dev)
75 internal_t*i = (internal_t*)dev->internal;
79 i->clip = i->clip->next;
80 art_svp_free(old->svp);old->svp = 0;
81 old->next = 0;free(old);
83 fprintf(stderr, "Error: endclip without startclip\n");
87 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)
89 internal_t*i = (internal_t*)dev->internal;
90 //i->out->stroke(i->out, line, width, color, cap_style, joint_style, miterLimit);
91 ArtSVP* svp = gfxstrokeToSVP(line, width, cap_style, joint_style, miterLimit);
94 svp = art_svp_intersect(svp, i->clip->svp);
97 gfxline_t*gfxline = SVPtogfxline(svp);
98 i->out->fill(i->out, gfxline, color);
103 void arts_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
105 internal_t*i = (internal_t*)dev->internal;
106 ArtSVP* svp = gfxfillToSVP(line, 1);
108 svp = art_svp_rewind_uncrossed(art_svp_uncross(svp),ART_WIND_RULE_ODDEVEN); /*FIXME*/
112 svp = art_svp_intersect(svp, i->clip->svp);
115 gfxline_t*gfxline = SVPtogfxline(svp);
116 i->out->fill(i->out, gfxline, color);
121 void arts_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
123 internal_t*i = (internal_t*)dev->internal;
124 ArtSVP* svp = gfxfillToSVP(line, 1);
127 svp = art_svp_intersect(svp, i->clip->svp);
130 gfxline_t*gfxline = SVPtogfxline(svp);
131 i->out->fillbitmap(i->out, gfxline, img, matrix, cxform);
136 void arts_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
138 internal_t*i = (internal_t*)dev->internal;
139 ArtSVP* svp = gfxfillToSVP(line, 1);
142 svp = art_svp_intersect(svp, i->clip->svp);
145 gfxline_t*gfxline = SVPtogfxline(svp);
146 i->out->fillgradient(i->out, gfxline, gradient, type, matrix);
151 void arts_addfont(struct _gfxdevice*dev, gfxfont_t*font)
153 internal_t*i = (internal_t*)dev->internal;
154 i->out->addfont(i->out, font);
157 void arts_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
159 internal_t*i = (internal_t*)dev->internal;
160 gfxline_t*glyph = gfxline_clone(font->glyphs[glyphnr].line);
161 gfxline_transform(glyph, matrix);
164 gfxbbox_t bbox = gfxline_getbbox(glyph);
165 ArtSVP*dummybox = boxToSVP(bbox.xmin,bbox.ymin,bbox.xmax,bbox.ymax);
166 ArtSVP*svp = art_svp_intersect(dummybox, i->clip->svp);
167 gfxline_t*gfxline = SVPtogfxline(svp);
168 gfxbbox_t bbox2 = gfxline_getbbox(gfxline);
169 double w = bbox2.xmax - bbox2.xmin;
170 double h = bbox2.ymax - bbox2.ymin;
171 if(w < 0.001 || h < 0.001) /* character was clipped completely */ {
172 } else if(fabs((bbox.xmax - bbox.xmin) - w) > 0.05 ||
173 fabs((bbox.ymax - bbox.ymin) - h) > 0.05) {
174 /* notable change in character size: character was clipped
175 TODO: handle diagonal cuts
177 arts_fill(dev, glyph, color);
179 i->out->drawchar(i->out, font, glyphnr, color, matrix);
182 i->out->drawchar(i->out, font, glyphnr, color, matrix);
188 void arts_drawlink(struct _gfxdevice*dev, gfxline_t*line, char*action)
190 internal_t*i = (internal_t*)dev->internal;
191 i->out->drawlink(i->out, line, action);
194 void arts_endpage(struct _gfxdevice*dev)
196 internal_t*i = (internal_t*)dev->internal;
197 i->out->endpage(i->out);
200 gfxresult_t* arts_finish(struct _gfxdevice*dev)
202 internal_t*i = (internal_t*)dev->internal;
203 return i->out->finish(i->out);
206 void gfxdevice_arts_init(gfxdevice_t*dev, gfxdevice_t*out)
208 internal_t*i = rfx_calloc(sizeof(internal_t));
209 memset(dev, 0, sizeof(gfxdevice_t));
212 dev->setparameter = arts_setparameter;
213 dev->startpage = arts_startpage;
214 dev->startclip = arts_startclip;
215 dev->endclip = arts_endclip;
216 dev->stroke = arts_stroke;
217 dev->fill = arts_fill;
218 dev->fillbitmap = arts_fillbitmap;
219 dev->fillgradient = arts_fillgradient;
220 dev->addfont = arts_addfont;
221 dev->drawchar = arts_drawchar;
222 dev->drawlink = arts_drawlink;
223 dev->endpage = arts_endpage;
224 dev->finish = arts_finish;