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 */
31 #include "../gfxdevice.h"
32 #include "../gfxtools.h"
35 typedef struct _internal {
40 static int verbose = 1;
41 static void dbg(char*format, ...)
48 va_start(arglist, format);
49 vsprintf(buf, format, arglist);
52 while(l && buf[l-1]=='\n') {
56 printf("(device-ops) %s\n", buf);
60 inline gfxcolor_t transform_color(internal_t*i, gfxcolor_t*col)
63 /*col2.r = (col->r * i->alpha)>>8;
64 col2.g = (col->g * i->alpha)>>8;
65 col2.b = (col->b * i->alpha)>>8;*/
69 col2.a = (col->a * i->alpha)>>8;
73 int ops_setparameter(struct _gfxdevice*dev, const char*key, const char*value)
75 internal_t*i = (internal_t*)dev->internal;
76 return i->out->setparameter(i->out,key,value);
79 void ops_startpage(struct _gfxdevice*dev, int width, int height)
81 internal_t*i = (internal_t*)dev->internal;
82 i->out->startpage(i->out,width,height);
85 void ops_startclip(struct _gfxdevice*dev, gfxline_t*line)
87 internal_t*i = (internal_t*)dev->internal;
88 i->out->startclip(i->out,line);
91 void ops_endclip(struct _gfxdevice*dev)
93 internal_t*i = (internal_t*)dev->internal;
94 i->out->endclip(i->out);
97 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)
99 internal_t*i = (internal_t*)dev->internal;
100 gfxcolor_t color2 = transform_color(i, color);
101 i->out->stroke(i->out, line, width, &color2, cap_style, joint_style, miterLimit);
104 void ops_fill(struct _gfxdevice*dev, gfxline_t*line, gfxcolor_t*color)
106 internal_t*i = (internal_t*)dev->internal;
107 gfxcolor_t color2 = transform_color(i, color);
108 i->out->fill(i->out, line, &color2);
111 void ops_fillbitmap(struct _gfxdevice*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
113 internal_t*i = (internal_t*)dev->internal;
115 img2.width = img->width;
116 img2.height = img->height;
117 img2.data = (gfxcolor_t*)malloc(img->width*img->height*4);
119 for(y=0;y<img->height;y++) {
120 gfxcolor_t*in = &img->data[y*img->width];
121 gfxcolor_t*out = &img2.data[y*img->width];
122 for(x=0;x<img->width;x++) {
123 out[x] = transform_color(i, &in[x]);
126 i->out->fillbitmap(i->out, line, &img2, matrix, cxform);
130 void ops_fillgradient(struct _gfxdevice*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
132 internal_t*i = (internal_t*)dev->internal;
133 i->out->fillgradient(i->out, line, gradient, type, matrix);
136 void ops_addfont(struct _gfxdevice*dev, gfxfont_t*font)
138 internal_t*i = (internal_t*)dev->internal;
139 i->out->addfont(i->out, font);
142 void ops_drawchar(struct _gfxdevice*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
144 internal_t*i = (internal_t*)dev->internal;
145 gfxcolor_t color2 = transform_color(i, color);
146 i->out->drawchar(i->out, font, glyphnr, color, matrix);
149 void ops_drawlink(struct _gfxdevice*dev, gfxline_t*line, const char*action)
151 internal_t*i = (internal_t*)dev->internal;
152 i->out->drawlink(i->out, line, action);
155 void ops_endpage(struct _gfxdevice*dev)
157 internal_t*i = (internal_t*)dev->internal;
158 i->out->endpage(i->out);
161 gfxresult_t* ops_finish(struct _gfxdevice*dev)
169 void gfxdevice_ops_init(gfxdevice_t*dev, gfxdevice_t*out, U8 alpha)
171 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
172 memset(dev, 0, sizeof(gfxdevice_t));
178 dev->setparameter = ops_setparameter;
179 dev->startpage = ops_startpage;
180 dev->startclip = ops_startclip;
181 dev->endclip = ops_endclip;
182 dev->stroke = ops_stroke;
183 dev->fill = ops_fill;
184 dev->fillbitmap = ops_fillbitmap;
185 dev->fillgradient = ops_fillgradient;
186 dev->addfont = ops_addfont;
187 dev->drawchar = ops_drawchar;
188 dev->drawlink = ops_drawlink;
189 dev->endpage = ops_endpage;
190 dev->finish = ops_finish;