3 Part of the swftools package.
5 Copyright (c) 2010 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 */
24 #include "../gfxfilter.h"
25 #include "../gfxtools.h"
26 #include "../gfxpoly.h"
27 #include "../gfxfont.h"
32 typedef struct _vglyph {
37 typedef struct _internal {
45 #define FONT_SIZE 1024.0
47 static void pass1_fill(gfxfilter_t*f, gfxline_t*line, gfxcolor_t*color, gfxdevice_t*out)
49 internal_t*i = (internal_t*)f->internal;
50 gfxbbox_t bbox = gfxline_getbbox(line);
51 double height = bbox.ymax - bbox.ymin;
52 double width = bbox.xmax - bbox.xmin;
53 double size = fmax(width,height);
54 if(fabs(size) < 1e-3) return;
55 double scale = FONT_SIZE/size;
56 gfxmatrix_t m = {scale, 0, -bbox.xmin*scale,
57 0, scale, -bbox.ymax*scale};
58 line = gfxline_clone(line);
59 gfxline_transform(line, &m);
60 line = gfxline_restitch(line);
61 vglyph_t*v = rfx_calloc(sizeof(vglyph_t));
63 v->glyph.advance = width*scale;
64 v->glyph.unicode = 32+i->glyph_nr;
66 i->last_glyph->next = v;
69 gfxmatrix_t m2 = {1.0/scale, 0, bbox.xmin,
70 0, 1.0/scale, bbox.ymax};
71 out->drawchar(out, 0, i->glyph_nr, color, &m2);
75 static void pass1_stroke(gfxfilter_t*f, gfxline_t*line, gfxcoord_t width, gfxcolor_t*color, gfx_capType cap_style, gfx_joinType joint_style, gfxcoord_t miterLimit, gfxdevice_t*out)
78 internal_t*i = (internal_t*)f->internal;
79 gfxpoly_t*poly = gfxpoly_from_stroke(line, width, cap_style, joint_style, miterLimit, DEFAULT_GRID);
80 gfxline_t*line2 = gfxline_from_gfxpoly_with_direction(poly);
81 pass1_fill(f, line2, color, out);
83 gfxpoly_destroy(poly);
86 static void make_font(internal_t*i)
88 i->font = rfx_calloc(sizeof(gfxfont_t));
89 i->font->id = "SWFTools-Vector-Magic";
90 i->font->num_glyphs = i->glyph_nr;
91 i->font->glyphs = malloc(sizeof(gfxglyph_t)*i->font->num_glyphs);
92 i->font->ascent = FONT_SIZE;
95 vglyph_t*g = i->first_glyph;
97 i->font->glyphs[pos] = g->glyph;
101 gfxfont_fix_unicode(i->font);
104 static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
106 internal_t*i = (internal_t*)f->internal;
109 out->addfont(out, i->font);
115 gfxcolor_t red = {255,254,1,1};
117 gfxmatrix_t m = {1.0, 0,0,
119 out->drawchar(out, font, 1, &red, &m);
121 /*gfxmatrix_t m2 = {1.0, 0,600,
123 out->drawchar(out, font, 1, &red, &m2);*/
124 gfxline_t*line = gfxline_makerectangle(0, 0, 1, 1);
129 out->fillbitmap(out, line, &img, &m, 0);
131 out->drawchar(out, font, glyphnr, color, matrix);
134 void gfxtwopassfilter_vectors_to_glyphs_init(gfxtwopassfilter_t*f)
136 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
138 memset(f, 0, sizeof(gfxtwopassfilter_t));
139 f->type = gfxfilter_twopass;
141 f->pass1.name = "vectors to glyphs pass 1";
142 f->pass1.fill = pass1_fill;
143 f->pass1.stroke = pass1_stroke;
144 f->pass1.internal = i;
146 f->pass2.name = "vectors to glyphs pass 2";
147 f->pass2.drawchar = pass2_drawchar;
148 f->pass2.internal = i;
152 i->first_glyph = rfx_calloc(sizeof(vglyph_t));
153 i->first_glyph->glyph.line = 0;
154 i->first_glyph->glyph.advance = FONT_SIZE;
155 i->first_glyph->glyph.unicode = 32;
156 i->last_glyph = rfx_calloc(sizeof(vglyph_t));
158 i->first_glyph->next = i->last_glyph;
159 i->last_glyph->glyph.line = 0;
160 i->last_glyph->glyph.advance = FONT_SIZE/8;
161 i->last_glyph->glyph.unicode = 33;