Generated from configure.in
[swftools.git] / lib / example / text.c
1 /* text.c
2
3    Example for including and using fonts 
4    
5    Part of the swftools package.
6
7    Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
8  
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.
13
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.
18
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 */
22
23 #include <stdio.h>
24 #include <fcntl.h>
25 #include <math.h>
26 #include "../rfxswf.h"
27
28 #include "demofont.c"  // five glyphs only:  f, l, o, s, w
29
30 /*
31     Due to copyright reasons we don't include full typesets into
32     the swftools package. But you can easily create fontdumps
33     of your desired typo:
34
35     * Create a swf file with all characters of your desired fonts
36       (with any tool that can output swf files)
37
38     * use the dumpfont example in this directory to dump font code
39
40     * include dump code and adjust Font_<Fontname>() calls.
41
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. 
44    
45 */
46
47 #define BANNER_TEXT     "swftools" 
48 #define ID_FONT         2000
49 #define ID_BANNER       2001
50
51 int main(int argc, char ** argv)
52 { SWF swf;
53   TAG * t;
54   SRECT r;
55   RGBA rgb;
56   U8 abits, gbits;
57   int definefont2 = 1;
58
59   int f;
60   int width = 170;
61   int height = 60;
62
63   int points = 50; // <- change global text size here
64   
65   int textsize = points*20;   // adjust height
66   int textscale = points*10;  // adjust spacing
67   
68   FONTUSAGE use;
69   SWFFONT * font = Font_Demo_Font(ID_FONT); // change font name here
70
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
74      edittext tags */
75   if(definefont2)
76       swf_FontAddLayout(font,0,0,0);
77
78   swf_FontInitUsage(&use);
79   swf_FontUse(&use,BANNER_TEXT);        // SWF reduces font information to the used glyphs
80   swf_FontReduce(font,&use);  
81     
82   memset(&swf,0x00,sizeof(SWF));
83
84   swf.fileVersion    = 4;
85   swf.frameRate      = 0x4000;
86   swf.movieSize.xmax = 20*width;
87   swf.movieSize.ymax = 20*height;
88
89   swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR);
90   t = swf.firstTag;
91
92         rgb.r = 0xff;
93         rgb.g = 0xff;
94         rgb.b = 0xff;
95         swf_SetRGB(t,&rgb);
96   
97   if(definefont2) {
98       t = swf_InsertTag(t,ST_DEFINEFONT2);
99             swf_FontSetDefine2(t, font);
100   } else {
101       t = swf_InsertTag(t,ST_DEFINEFONT);
102             swf_FontSetDefine(t, font);
103       t = swf_InsertTag(t,ST_DEFINEFONTINFO);
104             swf_FontSetInfo(t, font);
105   }
106
107   t = swf_InsertTag(t,ST_DEFINETEXT);
108
109         swf_SetU16(t,ID_BANNER);            // ID
110
111         r.xmin = 0;
112         r.ymin = 0;
113         r.xmax = swf_TextGetWidth(font,BANNER_TEXT,textscale);
114         r.ymax = textsize;
115         
116         swf_SetRect(t,&r);
117
118         swf_SetMatrix(t,NULL);
119
120         swf_TextCountBits(font,BANNER_TEXT,textscale,&gbits,&abits);
121         
122         swf_SetU8(t,gbits);
123         swf_SetU8(t,abits);
124
125         rgb.r = 0x00;
126         rgb.g = 0x00;
127         rgb.b = 0x00;
128
129         swf_TextSetInfoRecord(t,font,textsize,&rgb,0,textsize);
130         swf_TextSetCharRecord(t,font,BANNER_TEXT,textscale,gbits,abits);
131
132         swf_SetU8(t,0);
133         
134       
135     t = swf_InsertTag(t,ST_PLACEOBJECT2);
136
137         swf_ObjectPlace(t,ID_BANNER,1,NULL,NULL,NULL);
138  
139     t = swf_InsertTag(t,ST_SHOWFRAME);
140   
141     t = swf_InsertTag(t,ST_END);
142  
143 //  swf_WriteCGI(&swf);
144  
145
146   f = open("text.swf",O_RDWR|O_CREAT|O_TRUNC,0644);
147   if FAILED(swf_WriteSWF(f,&swf)) fprintf(stderr,"WriteSWF() failed.\n");
148   close(f);
149
150   swf_FreeTags(&swf);
151 //  swf_FontFree(font);
152
153 #ifdef __NT__
154   system("start ..\\text.swf");
155 #endif
156   
157   return 0;
158 }
159
160