3 Example for including and using fonts
5 Part of the swftools package.
7 Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
26 #include "../rfxswf.h"
28 #include "demofont.c" // five glyphs only: f, l, o, s, w
31 Due to copyright reasons we don't include full typesets into
32 the swftools package. But you can easily create fontdumps
35 * Create a swf file with all characters of your desired fonts
36 (with any tool that can output swf files)
38 * use the dumpfont example in this directory to dump font code
40 * include dump code and adjust Font_<Fontname>() calls.
42 Note: pdf2swf (Version 0.1.0) doesn't write ST_DEFINEFONTINFO tags,
43 so you can't extract fonts out of documents made with pdf2swf.
47 #define BANNER_TEXT "swftools"
49 #define ID_BANNER 2001
51 int main(int argc, char ** argv)
63 int points = 50; // <- change global text size here
65 int textsize = points*20; // adjust height
66 int textscale = points*10; // adjust spacing
68 SWFFONT * font = Font_Demo_Font(ID_FONT); // change font name here
70 /* adding layout to a font has the side effect that the
71 advance information is stored in the font itself, not
72 in accompanying textfields- this is needed e.g. for
75 swf_FontAddLayout(font,0,0,0);
77 swf_FontInitUsage(font);
78 swf_FontUse(font,BANNER_TEXT); // SWF reduces font information to the used glyphs
81 memset(&swf,0x00,sizeof(SWF));
84 swf.frameRate = 0x4000;
85 swf.movieSize.xmax = 20*width;
86 swf.movieSize.ymax = 20*height;
88 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
97 t = swf_InsertTag(t,ST_DEFINEFONT2);
98 swf_FontSetDefine2(t, font);
100 t = swf_InsertTag(t,ST_DEFINEFONT);
101 swf_FontSetDefine(t, font);
102 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
103 swf_FontSetInfo(t, font);
106 t = swf_InsertTag(t,ST_DEFINETEXT);
108 swf_SetU16(t,ID_BANNER); // ID
112 r.xmax = swf_TextGetWidth(font,BANNER_TEXT,textscale);
117 swf_SetMatrix(t,NULL);
119 swf_TextCountBits(font,BANNER_TEXT,textscale,&gbits,&abits);
128 swf_TextSetInfoRecord(t,font,textsize,&rgb,0,textsize);
129 swf_TextSetCharRecord(t,font,BANNER_TEXT,textscale,gbits,abits);
134 t = swf_InsertTag(t,ST_PLACEOBJECT2);
136 swf_ObjectPlace(t,ID_BANNER,1,NULL,NULL,NULL);
138 t = swf_InsertTag(t,ST_SHOWFRAME);
140 t = swf_InsertTag(t,ST_END);
142 // swf_WriteCGI(&swf);
145 f = open("text.swf",O_RDWR|O_CREAT|O_TRUNC|O_BINARY,0644);
146 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
150 // swf_FontFree(font);
153 system("start ..\\text.swf");