15c9e512ee3363b31cfd44b91ffd58b522d4aab6
[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 } internal_t;
34
35 void measuregfxline(internal_t*i, gfxline_t*line)
36 {
37     gfxbbox_t b = gfxline_getbbox(line);
38     i->bbox = gfxbbox_expand_to_point(i->bbox, b.xmin, b.ymin);
39     i->bbox = gfxbbox_expand_to_point(i->bbox, b.xmax, b.ymax);
40 }
41
42 int bbox_setparameter(gfxdevice_t*dev, const char*key, const char*value)
43 {
44     internal_t*i = (internal_t*)dev->internal;
45     return 0;
46 }
47
48 void bbox_startpage(gfxdevice_t*dev, int width, int height)
49 {
50     internal_t*i = (internal_t*)dev->internal;
51     i->bbox.xmin = 0;
52     i->bbox.ymin = 0;
53     i->bbox.xmax = 0;
54     i->bbox.ymax = 0;
55 }
56
57 void bbox_startclip(gfxdevice_t*dev, gfxline_t*line)
58 {
59     internal_t*i = (internal_t*)dev->internal;
60 }
61
62 void bbox_endclip(gfxdevice_t*dev)
63 {
64     internal_t*i = (internal_t*)dev->internal;
65 }
66
67 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)
68 {
69     internal_t*i = (internal_t*)dev->internal;
70     measuregfxline(i, line);
71 }
72
73 void bbox_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
74 {
75     internal_t*i = (internal_t*)dev->internal;
76     measuregfxline(i, line);
77 }
78
79 void bbox_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform)
80 {
81     internal_t*i = (internal_t*)dev->internal;
82     measuregfxline(i, line);
83 }
84
85 void bbox_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
86 {
87     internal_t*i = (internal_t*)dev->internal;
88     measuregfxline(i, line);
89 }
90
91 void bbox_addfont(gfxdevice_t*dev, gfxfont_t*font)
92 {
93     internal_t*i = (internal_t*)dev->internal;
94 }
95
96 void bbox_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix)
97 {
98     internal_t*i = (internal_t*)dev->internal;
99
100     gfxglyph_t*glyph = &font->glyphs[glyphnr];
101     gfxline_t*line2 = gfxline_clone(glyph->line);
102     gfxline_transform(line2, matrix);
103     measuregfxline(i, line2);
104     gfxline_free(line2);
105 }
106
107 void bbox_drawlink(gfxdevice_t*dev, gfxline_t*line, char*action)
108 {
109     internal_t*i = (internal_t*)dev->internal;
110 }
111
112 void bbox_endpage(gfxdevice_t*dev)
113 {
114     internal_t*i = (internal_t*)dev->internal;
115 }
116
117 gfxresult_t* bbox_finish(gfxdevice_t*dev)
118 {
119     free(dev->internal);dev->internal = 0;
120     return 0;
121 }
122
123 gfxbbox_t gfxdevice_bbox_getbbox(gfxdevice_t*dev)
124 {
125     internal_t*i = (internal_t*)dev->internal;
126     return i->bbox;
127 }
128
129 void gfxdevice_bbox_init(gfxdevice_t*dev)
130 {
131     internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
132     memset(dev, 0, sizeof(gfxdevice_t));
133
134     dev->name = "bbox";
135
136     dev->internal = i;
137
138     dev->setparameter = bbox_setparameter;
139     dev->startpage = bbox_startpage;
140     dev->startclip = bbox_startclip;
141     dev->endclip = bbox_endclip;
142     dev->stroke = bbox_stroke;
143     dev->fill = bbox_fill;
144     dev->fillbitmap = bbox_fillbitmap;
145     dev->fillgradient = bbox_fillgradient;
146     dev->addfont = bbox_addfont;
147     dev->drawchar = bbox_drawchar;
148     dev->drawlink = bbox_drawlink;
149     dev->endpage = bbox_endpage;
150     dev->finish = bbox_finish;
151 }
152