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"
32 typedef struct _internal {
37 static int verbose = 1;
38 static void dbg(char*format, ...)
45 va_start(arglist, format);
46 vsprintf(buf, format, arglist);
49 while(l && buf[l-1]=='\n') {
53 printf("(device-ops) %s\n", buf);
57 inline gfxcolor_t transform_color(internal_t*i, gfxcolor_t*col)
60 /*col2.r = (col->r * i->alpha)>>8;
61 col2.g = (col->g * i->alpha)>>8;
62 col2.b = (col->b * i->alpha)>>8;*/
66 col2.a = (col->a * i->alpha)>>8;
70 int ops_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
72 internal_t*i = (internal_t*)dev->internal;
73 return i->out->setparameter(i->out,key,value);
76 void ops_startpage(struct _gfxdevice*dev, int width, int height)
78 internal_t*i = (internal_t*)dev->internal;
79 i->out->startpage(i->out,width,height);
82 void ops_startclip(struct _gfxdevice*dev, gfxline_t*line)
84 internal_t*i = (internal_t*)dev->internal;
85 i->out->startclip(i->out,line);
88 void ops_endclip(struct _gfxdevice*dev)
90 internal_t*i = (internal_t*)dev->internal;
91 i->out->endclip(i->out);
94 void ops_stroke(struct _gfxdevice*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 gfxcolor_t color2 = transform_color(i, color);
98 i->out->stroke(i->out, line, width, &color2, cap_style, joint_style, miterLimit);
101 void ops_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
103 internal_t*i = (internal_t*)dev->internal;
104 gfxcolor_t color2 = transform_color(i, color);
105 i->out->fill(i->out, line, &color2);
108 void ops_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
110 internal_t*i = (internal_t*)dev->internal;
112 img2.width = img->width;
113 img2.height = img->height;
114 img2.data = (gfxcolor_t*)malloc(img->width*img->height*4);
116 for(y=0;y<img->height;y++) {
117 gfxcolor_t*in = &img->data[y*img->width];
118 gfxcolor_t*out = &img2.data[y*img->width];
119 for(x=0;x<img->width;x++) {
120 out[x] = transform_color(i, &in[x]);
123 i->out->fillbitmap(i->out, line, &img2, matrix, cxform);
127 void ops_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
129 internal_t*i = (internal_t*)dev->internal;
130 i->out->fillgradient(i->out, line, gradient, type, matrix);
133 void ops_addfont(struct _gfxdevice*dev, gfxfont_t*font)
135 internal_t*i = (internal_t*)dev->internal;
136 i->out->addfont(i->out, font);
139 void ops_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
141 internal_t*i = (internal_t*)dev->internal;
142 gfxcolor_t color2 = transform_color(i, color);
143 i->out->drawchar(i->out, font, glyphnr, color, matrix);
146 void ops_drawlink(struct _gfxdevice*dev, gfxline_t*line, const char*action)
148 internal_t*i = (internal_t*)dev->internal;
149 i->out->drawlink(i->out, line, action);
152 void ops_endpage(struct _gfxdevice*dev)
154 internal_t*i = (internal_t*)dev->internal;
155 i->out->endpage(i->out);
158 gfxresult_t* ops_finish(struct _gfxdevice*dev)
160 free(dev->internal);dev->internal = 0;
164 void gfxdevice_ops_init(gfxdevice_t*dev, gfxdevice_t*out, U8 alpha)
166 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
167 memset(dev, 0, sizeof(gfxdevice_t));
173 dev->setparameter = ops_setparameter;
174 dev->startpage = ops_startpage;
175 dev->startclip = ops_startclip;
176 dev->endclip = ops_endclip;
177 dev->stroke = ops_stroke;
178 dev->fill = ops_fill;
179 dev->fillbitmap = ops_fillbitmap;
180 dev->fillgradient = ops_fillgradient;
181 dev->addfont = ops_addfont;
182 dev->drawchar = ops_drawchar;
183 dev->drawlink = ops_drawlink;
184 dev->endpage = ops_endpage;
185 dev->finish = ops_finish;