applied MSVC compatibility patch from Dwight Kelly
[swftools.git] / lib / devices / bbox.c
1 /* bbox.c
2
3    Part of the swftools package.
4
5    Copyright (c) 2006 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     gfxbbox_t bbox;
33     int do_graphics;
34     int do_text;
35 } internal_t;
36
37 void measuregfxline(internal_t*i, gfxline_t*line)
38 {
39     gfxbbox_t b = gfxline_getbbox(line);
40     if(b.xmin==0 && b.ymin==0 && b.xmax==0 && b.ymax==0) {
41         return;
42     }
43     i->bbox = gfxbbox_expand_to_point(i->bbox, b.xmin, b.ymin);
44     i->bbox = gfxbbox_expand_to_point(i->bbox, b.xmax, b.ymax);
45 }
46
47 int bbox_setparameter(gfxdevice_t*dev, const char*key, const char*value)
48 {
49     internal_t*i = (internal_t*)dev->internal;
50     if(!strcmp(key, "graphics")) {
51         i->do_graphics = atoi(value);
52         return 1;
53     } else if(!strcmp(key, "text")) {
54         i->do_text = atoi(value);
55         return 1;
56     }
57     return 0;
58 }
59
60 void bbox_startpage(gfxdevice_t*dev, int width, int height)
61 {
62     internal_t*i = (internal_t*)dev->internal;
63     i->bbox.xmin = 0;
64     i->bbox.ymin = 0;
65     i->bbox.xmax = 0;
66     i->bbox.ymax = 0;
67 }
68
69 void bbox_startclip(gfxdevice_t*dev, gfxline_t*line)
70 {
71     internal_t*i = (internal_t*)dev->internal;
72 }
73
74 void bbox_endclip(gfxdevice_t*dev)
75 {
76     internal_t*i = (internal_t*)dev->internal;
77 }
78
79 void bbox_stroke(gfxdevice_t*dev, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit)
80 {
81     internal_t*i = (internal_t*)dev->internal;
82     if(i->do_graphics)
83         measuregfxline(i, line);
84 }
85
86 void bbox_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
87 {
88     internal_t*i = (internal_t*)dev->internal;
89     if(i->do_graphics)
90         measuregfxline(i, line);
91 }
92
93 void bbox_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
94 {
95     internal_t*i = (internal_t*)dev->internal;
96     if(i->do_graphics)
97         measuregfxline(i, line);
98 }
99
100 void bbox_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
101 {
102     internal_t*i = (internal_t*)dev->internal;
103     if(i->do_graphics)
104         measuregfxline(i, line);
105 }
106
107 void bbox_addfont(gfxdevice_t*dev, gfxfont_t*font)
108 {
109     internal_t*i = (internal_t*)dev->internal;
110 }
111
112 void bbox_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
113 {
114     internal_t*i = (internal_t*)dev->internal;
115     if(!font)
116         return;
117
118     if(i->do_text) {
119         gfxglyph_t*glyph = &font->glyphs[glyphnr];
120         gfxline_t*line2 = gfxline_clone(glyph->line);
121         gfxline_transform(line2, matrix);
122         measuregfxline(i, line2);
123         gfxline_free(line2);
124     }
125 }
126
127 void bbox_drawlink(gfxdevice_t*dev, gfxline_t*line, const char*action)
128 {
129     internal_t*i = (internal_t*)dev->internal;
130 }
131
132 void bbox_endpage(gfxdevice_t*dev)
133 {
134     internal_t*i = (internal_t*)dev->internal;
135 }
136
137 gfxresult_t* bbox_finish(gfxdevice_t*dev)
138 {
139     free(dev->internal);dev->internal = 0;
140     return 0;
141 }
142
143 gfxbbox_t gfxdevice_bbox_getbbox(gfxdevice_t*dev)
144 {
145     internal_t*i = (internal_t*)dev->internal;
146     return i->bbox;
147 }
148
149 void gfxdevice_bbox_init(gfxdevice_t*dev)
150 {
151     internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
152     memset(dev, 0, sizeof(gfxdevice_t));
153
154     dev->name = "bbox";
155
156     dev->internal = i;
157
158     dev->setparameter = bbox_setparameter;
159     dev->startpage = bbox_startpage;
160     dev->startclip = bbox_startclip;
161     dev->endclip = bbox_endclip;
162     dev->stroke = bbox_stroke;
163     dev->fill = bbox_fill;
164     dev->fillbitmap = bbox_fillbitmap;
165     dev->fillgradient = bbox_fillgradient;
166     dev->addfont = bbox_addfont;
167     dev->drawchar = bbox_drawchar;
168     dev->drawlink = bbox_drawlink;
169     dev->endpage = bbox_endpage;
170     dev->finish = bbox_finish;
171
172     i->do_graphics = 1;
173     i->do_text = 1;
174 }
175