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
69 SWFFONT * font = Font_Demo_Font(ID_FONT); // change font name here
71 /* adding layout to a font has the side effect that the
72 advance information is stored in the font itself, not
73 in accompanying textfields- this is needed e.g. for
76 swf_FontAddLayout(font,0,0,0);
78 swf_FontInitUsage(&use);
79 swf_FontUse(&use,BANNER_TEXT); // SWF reduces font information to the used glyphs
80 swf_FontReduce(font,&use);
82 memset(&swf,0x00,sizeof(SWF));
85 swf.frameRate = 0x4000;
86 swf.movieSize.xmax = 20*width;
87 swf.movieSize.ymax = 20*height;
89 swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
98 t = swf_InsertTag(t,ST_DEFINEFONT2);
99 swf_FontSetDefine2(t, font);
101 t = swf_InsertTag(t,ST_DEFINEFONT);
102 swf_FontSetDefine(t, font);
103 t = swf_InsertTag(t,ST_DEFINEFONTINFO);
104 swf_FontSetInfo(t, font);
107 t = swf_InsertTag(t,ST_DEFINETEXT);
109 swf_SetU16(t,ID_BANNER); // ID
113 r.xmax = swf_TextGetWidth(font,BANNER_TEXT,textscale);
118 swf_SetMatrix(t,NULL);
120 swf_TextCountBits(font,BANNER_TEXT,textscale,&gbits,&abits);
129 swf_TextSetInfoRecord(t,font,textsize,&rgb,0,textsize);
130 swf_TextSetCharRecord(t,font,BANNER_TEXT,textscale,gbits,abits);
135 t = swf_InsertTag(t,ST_PLACEOBJECT2);
137 swf_ObjectPlace(t,ID_BANNER,1,NULL,NULL,NULL);
139 t = swf_InsertTag(t,ST_SHOWFRAME);
141 t = swf_InsertTag(t,ST_END);
143 // swf_WriteCGI(&swf);
146 f = open("text.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
147 if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
151 // swf_FontFree(font);
154 system("start ..\\text.swf");