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;
86 wfont->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0);
88 wfont->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
89 memset(wfont->glyph, 0, num*sizeof(SWFGLYPH));
90 wfont->glyph2ascii = (U16*)malloc(num*sizeof(U16));
91 memset(wfont->glyph2ascii, 0, num*sizeof(U16));
92 wfont->ascii2glyph = (int*)malloc(encodingsize*sizeof(int));
93 memset(wfont->ascii2glyph, -1, encodingsize*sizeof(int));
94 wfont->layout->ascent = (U16)(underline - bbox.lly);
95 wfont->layout->descent = (U16)(bbox.ury - underline);
96 wfont->layout->leading = (U16)(wfont->layout->ascent -
97 wfont->layout->descent -
98 (bbox.lly - bbox.ury));
99 wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT));
100 wfont->layout->bounds->xmin = bbox.llx;
101 wfont->layout->bounds->ymin = bbox.lly;
102 wfont->layout->bounds->xmax = bbox.urx;
103 wfont->layout->bounds->ymax = bbox.ury;
104 wfont->layout->kerningcount = 0;
105 wfont->layout->kerning = 0;
108 for(s=0;s<encodingsize;s++)
111 T1_OUTLINE*outline = font->getOutline(encoding[s]);
112 int width = font->getWidth(encoding[s]);
113 if(outline && outline->link) {
115 wfont->ascii2glyph[s] = num;
116 wfont->glyph2ascii[num] = s;
117 swf_ShapeNew(&wfont->glyph[num].shape);
118 SHAPE*shape = wfont->glyph[num].shape;
119 wfont->glyph[num].advance = width/2;
121 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE);
133 shape->bits.fill = 1;
134 shape->bits.line = 0;
135 swf_ShapeSetStyle(tag,shape,0,1,0);
137 drawpath(tag, outline, &m, log);
139 /*uncomment this to mark the glyph sizes:
152 lineto(tag, p1);// */
154 swf_ShapeSetEnd(tag);
156 wfont->glyph[num].shape->bitlen = (tag->len-1)*8;
157 wfont->glyph[num].shape->data = (U8*)malloc(tag->len-1);
158 memcpy(wfont->glyph[num].shape->data, &tag->data[1], tag->len-1);
167 int main(int argc, char ** argv)
169 //TODO: use tempnam here. Check if environment already contains a
171 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
172 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
173 fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n", DATADIR);
174 fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR);
175 fprintf(fi, "AFM=%s/fonts:.\n", DATADIR);
176 fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR);
178 fi = fopen("/tmp/FontDataBase", "wb");
180 fprintf(fi, "n021003l.afm\n"); //fixme
181 fprintf(fi, "n021023l.afm\n");
182 fprintf(fi, "n021004l.afm\n");
183 fprintf(fi, "n021024l.afm\n");
184 fprintf(fi, "n019003l.afm\n");
185 fprintf(fi, "n019023l.afm\n");
186 fprintf(fi, "n019004l.afm\n");
187 fprintf(fi, "n019024l.afm\n");
188 fprintf(fi, "n022003l.afm\n");
189 fprintf(fi, "n022023l.afm\n");
190 fprintf(fi, "n022004l.afm\n");
191 fprintf(fi, "n022024l.afm\n");
192 fprintf(fi, "s050000l.afm\n");
193 fprintf(fi, "d050000l.afm\n");
195 /* initialize t1lib */
196 T1_SetBitmapPad( 16);
197 if ((T1_InitLib(NO_LOGFILE)==NULL)){
198 fprintf(stderr, "Initialization of t1lib failed\n");
201 unlink("/tmp/t1lib.config.tmp");
204 for( i=0; i<T1_Get_no_fonts(); i++)
207 SWFFONT * font = t1font2swffont(i);
210 sprintf(filename, "%s.swf", font->name);
211 swf_WriteFont(font, filename);