3 Example for including and using fonts
5 Part of the swftools package.
7 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
9 This file is distributed under the GPL, see file COPYING for details
17 #include "../rfxswf.h"
19 #include "../../pdf2swf/swfoutput.h"
20 #include "../../pdf2swf/spline.h"
22 #define standardEncodingSize 335
23 #define symbolEncodingSize 257
24 #define zapfDingbatsEncodingSize 270
25 #define macRomanEncodingSize 256
27 extern char *standardEncodingNames[standardEncodingSize];
28 extern char *symbolEncodingNames[symbolEncodingSize];
29 extern char *zapfDingbatsEncodingNames[zapfDingbatsEncodingSize];
30 extern char *macRomanEncodingNames[macRomanEncodingSize];
32 char*DATADIR = "/usr/local/share/swftools";
34 extern void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m);
36 SWFFONT * t1font2swffont(int i)
40 float angle = T1_GetItalicAngle(i);
41 char*fontname = T1_GetFontName(i);
42 char*fullname = T1_GetFullName(i);
43 char*familyname = T1_GetFamilyName(i);
44 float underline = T1_GetUnderlinePosition(i);
45 BBox bbox = T1_GetFontBBox(i);
47 char ** encoding = standardEncodingNames;
48 int encodingsize = standardEncodingSize;
50 printf("processing \"%s\"...\n", fullname);
52 if(strstr(fullname, "Dingbats")) {// Zapf Dingbats
53 encoding = zapfDingbatsEncodingNames;
54 encodingsize = zapfDingbatsEncodingSize;
56 else if(strstr(fullname, "Symbol")) {// Symbol
57 encoding = symbolEncodingNames;
58 encodingsize = zapfDingbatsEncodingSize;
61 SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT));
62 SWFFont * font = new SWFFont("", i, "");
65 wfont->name = (U8*)fontname;
66 wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
70 for(s=0;s<encodingsize;s++)
73 T1_OUTLINE*outline = font->getOutline(encoding[s]);
74 if(outline && outline->link)
79 wfont->maxascii = encodingsize;
80 wfont->numchars = num;
81 wfont->flags = /*layout*/0x80 + /*bold*/0?0:1 + /*italic*/(angle>0.05)?2:0;
82 wfont->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
83 memset(wfont->glyph, 0, num*sizeof(SWFGLYPH));
84 wfont->glyph2ascii = (U16*)malloc(num*sizeof(U16));
85 memset(wfont->glyph2ascii, 0, num*sizeof(U16));
86 wfont->ascii2glyph = (int*)malloc(encodingsize*sizeof(int));
87 memset(wfont->ascii2glyph, -1, encodingsize*sizeof(int));
88 wfont->layout->ascent = (U16)(underline - bbox.lly);
89 wfont->layout->descent = (U16)(bbox.ury - underline);
90 wfont->layout->leading = (U16)(wfont->layout->ascent -
91 wfont->layout->descent -
92 (bbox.lly - bbox.ury));
93 wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT));
94 wfont->layout->bounds->xmin = bbox.llx;
95 wfont->layout->bounds->ymin = bbox.lly;
96 wfont->layout->bounds->xmax = bbox.urx;
97 wfont->layout->bounds->ymax = bbox.ury;
98 wfont->layout->kerningcount = 0;
99 wfont->layout->kerning = 0;
102 for(s=0;s<encodingsize;s++)
105 T1_OUTLINE*outline = font->getOutline(encoding[s]);
106 if(outline && outline->link) {
107 wfont->ascii2glyph[s] = num;
108 wfont->glyph2ascii[num] = s;
109 swf_ShapeNew(&wfont->glyph[num].shape);
110 SHAPE*shape = wfont->glyph[num].shape;
111 wfont->glyph[num].advance = font->getCharWidth(num)/8;
113 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE);
125 shape->bits.fill = 1;
126 shape->bits.line = 0;
127 swf_ShapeSetStyle(tag,shape,0,1,0);
128 drawpath(tag, outline, &m);
129 swf_ShapeSetEnd(tag);
131 wfont->glyph[num].shape->data = &tag->data[1];
134 if(tag->writeBit == (0x80>>t)) break;
135 if(tag->writeBit == 0)
137 wfont->glyph[num].shape->bitlen = (tag->len-1)*8;
145 int main(int argc, char ** argv)
147 //TODO: use tempnam here. Check if environment already contains a
149 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
150 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
151 fprintf(fi, "FONTDATABASE=%s/FontDataBase\n", DATADIR);
152 fprintf(fi, "ENCODING=%s:.\n", DATADIR);
153 fprintf(fi, "AFM=%s:.\n", DATADIR);
154 fprintf(fi, "TYPE1=%s:.\n", DATADIR);
156 /* initialize t1lib */
157 T1_SetBitmapPad( 16);
158 if ((T1_InitLib(NO_LOGFILE)==NULL)){
159 fprintf(stderr, "Initialization of t1lib failed\n");
162 unlink("/tmp/t1lib.config.tmp");
165 for( i=0; i<T1_Get_no_fonts(); i++)
168 SWFFONT * font = t1font2swffont(i);
171 sprintf(filename, "%s.swf", font->name);
172 swf_WriteFont(font, filename);