3 Part of the swftools package.
5 Copyright (c) 2006 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 */
28 #include "../gfxdevice.h"
29 #include "../gfxtools.h"
31 typedef struct _internal {
39 static int verbose = 1;
40 static void dbg(char*format, ...)
47 va_start(arglist, format);
48 vsprintf(buf, format, arglist);
51 while(l && buf[l-1]=='\n') {
55 printf("(device-rescale) %s\n", buf);
59 gfxline_t*transformgfxline(internal_t*i, gfxline_t*line)
61 gfxline_t*line2 = gfxline_clone(line);
62 gfxline_transform(line2, &i->matrix);
66 int rescale_setparameter(gfxdevice_t*dev, const char*key, const char*value)
68 internal_t*i = (internal_t*)dev->internal;
69 return i->out->setparameter(i->out,key,value);
72 void rescale_startpage(gfxdevice_t*dev, int width, int height)
74 internal_t*i = (internal_t*)dev->internal;
75 i->matrix.m00 = (double)i->targetwidth / (double)width;
76 i->matrix.m11 = (double)i->targetheight / (double)height;
77 i->out->startpage(i->out,i->targetwidth,i->targetheight);
80 void rescale_startclip(gfxdevice_t*dev, gfxline_t*line)
82 internal_t*i = (internal_t*)dev->internal;
83 gfxline_t*line2 = transformgfxline(i, line);
84 i->out->startclip(i->out,line2);
88 void rescale_endclip(gfxdevice_t*dev)
90 internal_t*i = (internal_t*)dev->internal;
91 i->out->endclip(i->out);
94 void rescale_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
96 internal_t*i = (internal_t*)dev->internal;
97 gfxline_t*line2 = transformgfxline(i, line);
98 i->out->stroke(i->out, line2, width*i->zoomwidth, color, cap_style, joint_style, miterLimit);
102 void rescale_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
104 internal_t*i = (internal_t*)dev->internal;
105 gfxline_t*line2 = transformgfxline(i, line);
106 i->out->fill(i->out, line2, color);
110 void rescale_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
112 internal_t*i = (internal_t*)dev->internal;
113 gfxline_t*line2 = transformgfxline(i, line);
115 gfxmatrix_multiply(&i->matrix, matrix, &m2);
116 i->out->fillbitmap(i->out, line2, img, &m2, cxform);
120 void rescale_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
122 internal_t*i = (internal_t*)dev->internal;
123 gfxline_t*line2 = transformgfxline(i, line);
124 i->out->fillgradient(i->out, line, gradient, type, matrix);
128 void rescale_addfont(gfxdevice_t*dev, gfxfont_t*font)
130 internal_t*i = (internal_t*)dev->internal;
131 i->out->addfont(i->out, font);
134 void rescale_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
136 internal_t*i = (internal_t*)dev->internal;
138 gfxmatrix_multiply(&i->matrix, matrix, &m2);
139 i->out->drawchar(i->out, font, glyphnr, color, &m2);
142 void rescale_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action)
144 internal_t*i = (internal_t*)dev->internal;
145 gfxline_t*line2 = transformgfxline(i, line);
146 i->out->drawlink(i->out, line, action);
150 void rescale_endpage(gfxdevice_t*dev)
152 internal_t*i = (internal_t*)dev->internal;
153 i->out->endpage(i->out);
156 gfxresult_t* rescale_finish(gfxdevice_t*dev)
158 internal_t*i = (internal_t*)dev->internal;
159 gfxdevice_t*out = i->out;
160 free(dev->internal);dev->internal = 0;i=0;
161 return out->finish(out);
164 void gfxdevice_rescale_init(gfxdevice_t*dev, gfxdevice_t*out, int width, int height)
166 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
167 memset(dev, 0, sizeof(gfxdevice_t));
169 dev->name = "rescale";
173 dev->setparameter = rescale_setparameter;
174 dev->startpage = rescale_startpage;
175 dev->startclip = rescale_startclip;
176 dev->endclip = rescale_endclip;
177 dev->stroke = rescale_stroke;
178 dev->fill = rescale_fill;
179 dev->fillbitmap = rescale_fillbitmap;
180 dev->fillgradient = rescale_fillgradient;
181 dev->addfont = rescale_addfont;
182 dev->drawchar = rescale_drawchar;
183 dev->drawlink = rescale_drawlink;
184 dev->endpage = rescale_endpage;
185 dev->finish = rescale_finish;
187 gfxmatrix_unit(&i->matrix);
188 i->targetwidth = width;
189 i->targetheight = height;