3 Utility for generating the standard fonts (arial, courier, etc.) in swf-format.
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
18 #include "../rfxswf.h"
20 #include "../../pdf2swf/swfoutput.h"
21 #include "../../pdf2swf/spline.h"
23 #define standardEncodingSize 335
24 #define symbolEncodingSize 257
25 #define zapfDingbatsEncodingSize 270
26 #define macRomanEncodingSize 256
28 extern char *standardEncodingNames[standardEncodingSize];
29 extern char *symbolEncodingNames[symbolEncodingSize];
30 extern char *zapfDingbatsEncodingNames[zapfDingbatsEncodingSize];
31 extern char *macRomanEncodingNames[macRomanEncodingSize];
33 char*DATADIR = "/usr/local/share/swftools";
35 extern void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log);
36 extern void resetdrawer();
37 extern void moveto(TAG*tag, plotxy p0);
38 extern void lineto(TAG*tag, plotxy p0);
40 SWFFONT * t1font2swffont(int i)
44 float angle = T1_GetItalicAngle(i);
45 char*fontname = T1_GetFontName(i);
46 char*fullname = T1_GetFullName(i);
47 char*familyname = T1_GetFamilyName(i);
48 float underline = T1_GetUnderlinePosition(i);
49 BBox bbox = T1_GetFontBBox(i);
51 char ** encoding = standardEncodingNames;
52 int encodingsize = standardEncodingSize;
54 printf("processing \"%s\"...\n", fullname);
56 if(strstr(fullname, "Dingbats")) {// Zapf Dingbats
57 encoding = zapfDingbatsEncodingNames;
58 encodingsize = zapfDingbatsEncodingSize;
60 else if(strstr(fullname, "Symbol")) {// Symbol
61 encoding = symbolEncodingNames;
62 encodingsize = zapfDingbatsEncodingSize;
65 SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT));
66 SWFFont * font = new SWFFont("", i, "");
69 wfont->name = (U8*)strdup(fontname);
70 wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
74 for(s=0;s<encodingsize;s++)
77 T1_OUTLINE*outline = font->getOutline(encoding[s]);
78 if(outline && outline->link)
83 wfont->maxascii = encodingsize;
84 wfont->numchars = num;
85 wfont->flags = /*layout*/0x80 + /*bold*/0?1:0 + /*italic*/(angle>0.05)?2:0;
86 wfont->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
87 memset(wfont->glyph, 0, num*sizeof(SWFGLYPH));
88 wfont->glyph2ascii = (U16*)malloc(num*sizeof(U16));
89 memset(wfont->glyph2ascii, 0, num*sizeof(U16));
90 wfont->ascii2glyph = (int*)malloc(encodingsize*sizeof(int));
91 memset(wfont->ascii2glyph, -1, encodingsize*sizeof(int));
92 wfont->layout->ascent = (U16)(underline - bbox.lly);
93 wfont->layout->descent = (U16)(bbox.ury - underline);
94 wfont->layout->leading = (U16)(wfont->layout->ascent -
95 wfont->layout->descent -
96 (bbox.lly - bbox.ury));
97 wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT));
98 wfont->layout->bounds->xmin = bbox.llx;
99 wfont->layout->bounds->ymin = bbox.lly;
100 wfont->layout->bounds->xmax = bbox.urx;
101 wfont->layout->bounds->ymax = bbox.ury;
102 wfont->layout->kerningcount = 0;
103 wfont->layout->kerning = 0;
106 for(s=0;s<encodingsize;s++)
109 T1_OUTLINE*outline = font->getOutline(encoding[s]);
110 int width = font->getWidth(encoding[s]);
111 if(outline && outline->link) {
113 wfont->ascii2glyph[s] = num;
114 wfont->glyph2ascii[num] = s;
115 swf_ShapeNew(&wfont->glyph[num].shape);
116 SHAPE*shape = wfont->glyph[num].shape;
117 wfont->glyph[num].advance = width/2;
119 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE);
131 shape->bits.fill = 1;
132 shape->bits.line = 0;
133 swf_ShapeSetStyle(tag,shape,0,1,0);
135 drawpath(tag, outline, &m, log);
137 /*uncomment this to mark the glyph sizes:
150 lineto(tag, p1);// */
152 swf_ShapeSetEnd(tag);
154 wfont->glyph[num].shape->bitlen = (tag->len-1)*8;
155 wfont->glyph[num].shape->data = (U8*)malloc(tag->len-1);
156 memcpy(wfont->glyph[num].shape->data, &tag->data[1], tag->len-1);
165 int main(int argc, char ** argv)
167 //TODO: use tempnam here. Check if environment already contains a
169 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
170 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
171 fprintf(fi, "FONTDATABASE=%s/FontDataBase\n", DATADIR);
172 fprintf(fi, "ENCODING=%s:.\n", DATADIR);
173 fprintf(fi, "AFM=%s:.\n", DATADIR);
174 fprintf(fi, "TYPE1=%s:.\n", DATADIR);
176 /* initialize t1lib */
177 T1_SetBitmapPad( 16);
178 if ((T1_InitLib(NO_LOGFILE)==NULL)){
179 fprintf(stderr, "Initialization of t1lib failed\n");
182 unlink("/tmp/t1lib.config.tmp");
185 for( i=0; i<T1_Get_no_fonts(); i++)
188 SWFFONT * font = t1font2swffont(i);
191 sprintf(filename, "%s.swf", font->name);
192 swf_WriteFont(font, filename);