1 /* remove_font_transform.c
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 */
23 #include "../gfxfilter.h"
24 #include "../gfxtools.h"
25 #include "../gfxfont.h"
29 typedef struct _internal {
35 typedef struct _fontdata {
40 static void pass1_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
42 internal_t*i = (internal_t*)f->internal;
43 fontdata_t*d = gfxfontlist_getuserdata(i->fonts, font->id);
45 d = rfx_calloc(sizeof(fontdata_t));
47 d->start = i->num_glyphs;
48 i->num_glyphs += font->num_glyphs;
49 i->fonts = gfxfontlist_addfont2(i->fonts, font, d);
51 out->drawchar(out, font, glyphnr, color, matrix);
53 static gfxresult_t*pass1_finish(gfxfilter_t*f, gfxdevice_t*out)
55 internal_t*i = (internal_t*)f->internal;
56 gfxfont_t*font = i->font = rfx_calloc(sizeof(gfxfont_t));
57 font->id = strdup("onebigfont");
58 font->num_glyphs = i->num_glyphs;
59 font->glyphs = rfx_calloc(sizeof(gfxglyph_t)*i->num_glyphs);
60 gfxfontlist_t*l = i->fonts;
62 gfxfont_t*old = l->font;
63 fontdata_t*d = l->user;
64 memcpy(font->glyphs + d->start, old->glyphs, sizeof(gfxglyph_t)*old->num_glyphs);
65 if(old->ascent > font->ascent)
66 font->ascent = old->ascent;
67 if(old->descent > font->descent)
68 font->descent = old->descent;
71 gfxfont_fix_unicode(font);
72 return out->finish(out);
75 static void pass2_addfont(gfxfilter_t*f, gfxfont_t*font, gfxdevice_t*out)
77 internal_t*i = (internal_t*)f->internal;
78 out->addfont(out, i->font);
80 static void pass2_drawchar(gfxfilter_t*f, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix, gfxdevice_t*out)
82 internal_t*i = (internal_t*)f->internal;
83 fontdata_t*d = gfxfontlist_getuserdata(i->fonts, font->id);
84 out->drawchar(out, i->font, glyphnr + d->start, color, matrix);
86 static gfxresult_t*pass2_finish(gfxfilter_t*f, gfxdevice_t*out)
88 internal_t*i = (internal_t*)f->internal;
90 gfxfontlist_t*l = i->fonts;
92 free(l->user);l->user=0;
95 gfxfontlist_free(i->fonts, 0);i->fonts=0;
96 return out->finish(out);
99 void gfxtwopassfilter_one_big_font_init(gfxtwopassfilter_t*f)
101 internal_t*i = (internal_t*)rfx_calloc(sizeof(internal_t));
103 memset(f, 0, sizeof(gfxtwopassfilter_t));
104 f->type = gfxfilter_twopass;
106 f->pass1.name = "filter \"one big font\" pass 1";
107 f->pass1.drawchar = pass1_drawchar;
108 f->pass1.finish = pass1_finish;
109 f->pass1.internal = i;
111 f->pass2.name = "filter \"one big font\" pass 2";
112 f->pass2.addfont = pass2_addfont;
113 f->pass2.drawchar = pass2_drawchar;
114 f->pass2.finish = pass2_finish;
115 f->pass2.internal = i;