3 Example for how to construct an SWF font from another SWF font.
5 Part of the swftools package.
7 Copyright (c) 2004 Matthias Kramm <kramm@quiss.org>
9 This file is distributed under the GPL, see file COPYING for details
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
28 #include "../rfxswf.h"
30 static void write_font(SWFFONT * font, char *filename)
37 int useDefineFont2 = 1;
38 int storeGlyphNames = 1;
40 #define WRITEFONTID 8888
41 font->id = WRITEFONTID;
43 memset(&swf, 0x00, sizeof(SWF));
46 swf.frameRate = 0x4000;
48 t = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
55 t = swf_InsertTag(t, ST_DEFINEFONT3);
56 swf_FontSetDefine2(t, font);
58 t = swf_InsertTag(t, ST_DEFINEFONTALIGNZONES);
59 swf_SetU16(t, font->id);
60 swf_SetU8(t, 0); //thin
64 swf_SetF16(t, 82.0 / 1024.0);
65 swf_SetF16(t, 82.0 / 1024.0);
66 swf_SetF16(t, ((i%16/2)*82.0) / 1024.0);
67 swf_SetF16(t, ((i/16/2)*82.0) / 1024.0);
69 if(i<128 && (i&15)<8) {
72 swf_SetF16(t, 640.0 / 1024.0);
73 swf_SetF16(t, 640.0 / 1024.0);
74 } else if(i<128 && (i&15)>=8) {
75 swf_SetF16(t, 0.0 / 1024.0);
76 swf_SetF16(t, 0.0 / 1024.0);
77 swf_SetF16(t, 330.0 / 1024.0);
78 swf_SetF16(t, 640.0 / 1024.0);
79 } else if(i>=128 && (i&15)<8) {
80 swf_SetF16(t, 0.0 / 1024.0);
81 swf_SetF16(t, 0.0 / 1024.0);
82 swf_SetF16(t, 640.0 / 1024.0);
83 swf_SetF16(t, 330.0 / 1024.0);
85 swf_SetF16(t, 0.0 / 1024.0);
86 swf_SetF16(t, 0.0 / 1024.0);
87 swf_SetF16(t, 330.0 / 1024.0);
88 swf_SetF16(t, 330.0 / 1024.0);
90 swf_SetU8(t, 3); // x and y
99 int range = font->maxascii;
107 swf.movieSize.xmax = xmax * 20;
108 swf.movieSize.ymax = ymax;
110 t = swf_InsertTag(t, ST_DEFINETEXT);
111 swf_SetU16(t, font->id + 1); // ID
114 r.xmax = swf.movieSize.xmax;
115 r.ymax = swf.movieSize.ymax;
117 swf_SetMatrix(t, NULL);
118 abits = swf_CountBits(xmax * 16, 0);
128 int textscale = 1024;
129 for (y = 0; y < ((range + 15) / 16); y++) {
130 for (x = 0; x < 16; x++) {
131 //swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10+(x+y)*20, y*64*20+128*20+10+(x^y)*20);
132 swf_TextSetInfoRecord(t, font, textscale, &rgb, x*64*20+64*20+10, y*64*20+128*20+10);
135 swf_SetBits(t, g, gbits);
136 swf_SetBits(t, 0, abits);
137 swf_ResetWriteBits(t);
142 t = swf_InsertTag(t, ST_CSMTEXTSETTINGS);
143 swf_SetU16(t, font->id + 1);
144 swf_SetU8(t, (1<<3)//grid
147 swf_SetU32(t, 0x20000);//thickness
148 swf_SetU32(t, 0x800000);//sharpness
149 swf_SetU8(t, 0);//reserved
151 t = swf_InsertTag(t, ST_PLACEOBJECT2);
152 swf_ObjectPlace(t, font->id + 1, 1, NULL, NULL, NULL);
154 t = swf_InsertTag(t, ST_SHOWFRAME);
155 t = swf_InsertTag(t, ST_END);
157 f = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644);
159 (swf_WriteSWF(f, &swf)) fprintf(stderr, "WriteSWF() failed in writeFont().\n");
170 memset(&hexfont, 0, sizeof(hexfont));
171 hexfont.name = (U8*)"HexFont";
172 hexfont.layout = malloc(sizeof(SWFLAYOUT));
173 hexfont.numchars = 256;
174 hexfont.maxascii = 256;
175 hexfont.encoding = 32;
176 hexfont.glyph2ascii = malloc(sizeof(U16)*256);
177 hexfont.ascii2glyph = malloc(sizeof(int)*256);
178 hexfont.glyph = malloc(sizeof(SWFGLYPH)*256);
179 hexfont.glyphnames = malloc(sizeof(char*)*256);
180 hexfont.layout->bounds = malloc(sizeof(SRECT)*256);
181 hexfont.layout->kerningcount = 0;
182 hexfont.layout->kerning = 0;
184 int ymax =-0x7fffffff;
185 int ymin = 0x7fffffff;
188 drawer_t _draw,*draw=&_draw;
189 swf_Shape01DrawerInit(draw, 0);
193 int ry = 0;//(t&15)^0x05;
194 #define S {d.x*=20*4+2;d.y*=20*4+2;}
199 d.x=x;d.y=-y; S;draw->moveTo(draw, &d);
200 d.x=x+1;d.y=-y; S;draw->lineTo(draw, &d);
201 d.x=x+1;d.y=-y-1; S;draw->lineTo(draw, &d);
202 d.x=x;d.y=-y-1; S;draw->lineTo(draw, &d);
203 d.x=x;d.y=-y; S;draw->lineTo(draw, &d);
207 d.x=0;d.y=-0; S;draw->moveTo(draw, &d);
208 d.x=0;d.y=-8; S;draw->lineTo(draw, &d);
209 d.x=8;d.y=-8; S;draw->lineTo(draw, &d);
210 d.x=8;d.y=-0; S;draw->lineTo(draw, &d);
211 d.x=0;d.y=-0; S;draw->lineTo(draw, &d);
213 d.x=1;d.y=-1; S;draw->moveTo(draw, &d);
214 d.x=7;d.y=-1; S;draw->lineTo(draw, &d);
215 d.x=7;d.y=-7; S;draw->lineTo(draw, &d);
216 d.x=1;d.y=-7; S;draw->lineTo(draw, &d);
217 d.x=1;d.y=-1; S;draw->lineTo(draw, &d);
220 hexfont.glyph[t].shape = swf_ShapeDrawerToShape(draw);
221 hexfont.layout->bounds[t] = swf_ShapeDrawerGetBBox(draw);
222 hexfont.glyph[t].advance = hexfont.layout->bounds[t].xmax + hexfont.layout->bounds[t].xmin;
225 hexfont.glyph2ascii[t] = t;
226 hexfont.ascii2glyph[t] = t;
227 hexfont.glyphnames[t] = 0;
228 if(hexfont.layout->bounds[t].ymax > ymax)
229 ymax = hexfont.layout->bounds[t].ymax;
230 if(hexfont.layout->bounds[t].ymin < ymin)
231 ymin = hexfont.layout->bounds[t].ymin;
234 /* breaks flashtype, but not (non-flashtype) definefont2 */
235 //hexfont.glyph2ascii[t] = 0;
238 hexfont.layout->ascent = ymin<0?-ymin:0;
239 hexfont.layout->descent = ymax>0?ymax:0;
240 hexfont.layout->leading = hexfont.layout->ascent + hexfont.layout->descent;
242 write_font(&hexfont, "alignzones.swf");