fixed a few bugs in remove_font_transforms filter
[swftools.git] / lib / devices / dummy.c
1 /* dummy.c
2
3    Part of the swftools package.
4
5    Copyright (c) 2007 Matthias Kramm <kramm@quiss.org> 
6  
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.
11
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.
16
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 */
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <unistd.h>
25 #include <memory.h>
26 #include "../types.h"
27 #include "../mem.h"
28 #include "../gfxdevice.h"
29 #include "../gfxtools.h"
30
31 typedef struct _internal {
32     gfxdevice_t*out;
33 } internal_t;
34
35 int dummy_setparameter(gfxdevice_t*dev, const char*key, const char*value)
36 {
37     internal_t*i = (internal_t*)dev->internal;
38     if(i->out) {
39         return i->out->setparameter(i->out,key,value);
40     } else {
41         return 0;
42     }
43 }
44
45 void dummy_startpage(gfxdevice_t*dev, int width, int height)
46 {
47     internal_t*i = (internal_t*)dev->internal;
48     if(i->out)
49         i->out->startpage(i->out,width,height);
50 }
51 void dummy_startclip(gfxdevice_t*dev, gfxline_t*line)
52 {
53     internal_t*i = (internal_t*)dev->internal;
54     if(i->out)
55         i->out->startclip(i->out,line);
56 }
57 void dummy_endclip(gfxdevice_t*dev)
58 {
59     internal_t*i = (internal_t*)dev->internal;
60     if(i->out)
61         i->out->endclip(i->out);
62 }
63 void dummy_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
64 {
65     internal_t*i = (internal_t*)dev->internal;
66     if(i->out)
67         i->out->stroke(i->out, line, width, color, cap_style, joint_style, miterLimit);
68 }
69
70 void dummy_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
71 {
72     internal_t*i = (internal_t*)dev->internal;
73     if(i->out)
74         i->out->fill(i->out, line, color);
75 }
76
77 void dummy_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
78 {
79     internal_t*i = (internal_t*)dev->internal;
80     if(i->out)
81         i->out->fillbitmap(i->out, line, img, matrix, cxform);
82 }
83
84 void dummy_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
85 {
86     internal_t*i = (internal_t*)dev->internal;
87     if(i->out)
88         i->out->fillgradient(i->out, line, gradient, type, matrix);
89 }
90
91 void dummy_addfont(gfxdevice_t*dev, gfxfont_t*font)
92 {
93     internal_t*i = (internal_t*)dev->internal;
94     if(i->out)
95         i->out->addfont(i->out, font);
96 }
97
98 void dummy_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
99 {
100     internal_t*i = (internal_t*)dev->internal;
101     if(i->out)
102         i->out->drawchar(i->out, font, glyphnr, color, matrix);
103 }
104
105 void dummy_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action)
106 {
107     internal_t*i = (internal_t*)dev->internal;
108     if(i->out)
109         i->out->drawlink(i->out, line, action);
110 }
111
112 void dummy_endpage(gfxdevice_t*dev)
113 {
114     internal_t*i = (internal_t*)dev->internal;
115     if(i->out)
116         i->out->endpage(i->out);
117 }
118
119 gfxresult_t* dummy_finish(gfxdevice_t*dev)
120 {
121     internal_t*i = (internal_t*)dev->internal;
122     if(i->out) {
123         gfxdevice_t*out = i->out;
124         free(dev->internal);dev->internal = 0;i=0;
125         return out->finish(out);
126     } else {
127         free(dev->internal);dev->internal = 0;i=0;
128         return 0;
129     }
130 }
131
132 void gfxdevice_dummy_init(gfxdevice_t*dev, gfxdevice_t*out)
133 {
134     internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
135     memset(dev, 0, sizeof(gfxdevice_t));
136
137     dev->name = "dummy";
138
139     dev->internal = i;
140
141     dev->setparameter = dummy_setparameter;
142     dev->startpage = dummy_startpage;
143     dev->startclip = dummy_startclip;
144     dev->endclip = dummy_endclip;
145     dev->stroke = dummy_stroke;
146     dev->fill = dummy_fill;
147     dev->fillbitmap = dummy_fillbitmap;
148     dev->fillgradient = dummy_fillgradient;
149     dev->addfont = dummy_addfont;
150     dev->drawchar = dummy_drawchar;
151     dev->drawlink = dummy_drawlink;
152     dev->endpage = dummy_endpage;
153     dev->finish = dummy_finish;
154
155     i->out = out;
156 }
157