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
17 #include "../lib/rfxswf.h"
18 #include "swfoutput.h"
21 #define standardEncodingSize 256
22 #define symbolEncodingSize 256
23 #define zapfDingbatsEncodingSize 256
24 #define macRomanEncodingSize 256
26 extern char *standardEncoding[standardEncodingSize];
27 extern char *symbolEncoding[symbolEncodingSize];
28 extern char *zapfDingbatsEncoding[zapfDingbatsEncodingSize];
29 extern char *macRomanEncoding[macRomanEncodingSize];
31 extern void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log);
32 extern void resetdrawer();
33 extern void moveto(TAG*tag, plotxy p0);
34 extern void lineto(TAG*tag, plotxy p0);
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 /* if "all" is given, translate the font names in something more
49 if(!strcmp(fullname, "Nimbus Roman No9 L Regular")) fontname = "Helvetica";
50 if(!strcmp(fullname, "Nimbus Roman No9 L Regular Italic")) fontname = "HelveticaItalic";
51 if(!strcmp(fullname, "Nimbus Roman No9 L Medium")) fontname = "HelveticaBold";
52 if(!strcmp(fullname, "Nimbus Roman No9 L Medium Italic")) fontname = "HelveticaBoldItalic";
53 if(!strcmp(fullname, "Nimbus Sans L Regular")) fontname = "Times";
54 if(!strcmp(fullname, "Nimbus Sans L Regular Italic")) fontname = "TimesItalic";
55 if(!strcmp(fullname, "Nimbus Sans L Bold")) fontname = "TimesBold";
56 if(!strcmp(fullname, "Nimbus Sans L Bold Italic")) fontname = "TimesBoldItalic";
57 if(!strcmp(fullname, "Nimbus Mono L Regular")) fontname = "Courier";
58 if(!strcmp(fullname, "Nimbus Mono L Regular Oblique")) fontname = "CourierItalic";
59 if(!strcmp(fullname, "Nimbus Mono L Bold")) fontname = "CourierBold";
60 if(!strcmp(fullname, "Nimbus Mono L Bold Oblique")) fontname = "CourierBoldItalic";
61 if(!strcmp(fullname, "Standard Symbols L")) fontname = "Symbol";
63 char ** encoding = standardEncoding;
64 int encodingsize = standardEncodingSize;
66 printf("processing \"%s\" (\"%s\")...\n", fullname, fontname);
68 if(strstr(fullname, "Dingbats")) {// Zapf Dingbats
69 encoding = zapfDingbatsEncoding;
70 encodingsize = zapfDingbatsEncodingSize;
72 else if(strstr(fullname, "Symbol")) {// Symbol
73 encoding = symbolEncoding;
74 encodingsize = symbolEncodingSize;
77 SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT));
78 SWFFont * font = new SWFFont("", i, "");
81 wfont->name = (U8*)strdup(fontname);
82 wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
83 memset(wfont->layout, 0, sizeof(SWFLAYOUT));
87 for(s=0;s<encodingsize;s++)
90 T1_OUTLINE*outline = font->getOutline(encoding[s], 0);
91 if(outline && outline->link)
96 wfont->maxascii = encodingsize;
97 wfont->numchars = num;
99 wfont->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0);
101 wfont->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
102 memset(wfont->glyph, 0, num*sizeof(SWFGLYPH));
103 wfont->glyph2ascii = (U16*)malloc(num*sizeof(U16));
104 memset(wfont->glyph2ascii, 0, num*sizeof(U16));
105 wfont->ascii2glyph = (int*)malloc(encodingsize*sizeof(int));
106 memset(wfont->ascii2glyph, -1, encodingsize*sizeof(int));
107 wfont->layout->ascent = (U16)(underline - bbox.lly);
108 wfont->layout->descent = (U16)(bbox.ury - underline);
109 wfont->layout->leading = (U16)(wfont->layout->ascent -
110 wfont->layout->descent -
111 (bbox.lly - bbox.ury));
112 wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*num);
113 memset(wfont->layout->bounds, 0, sizeof(SRECT)*num);
114 wfont->layout->kerningcount = 0;
115 wfont->layout->kerning = 0;
118 for(s=0;s<encodingsize;s++)
121 T1_OUTLINE*outline = font->getOutline(encoding[s],0);
122 int width = font->getWidth(encoding[s]);
123 if(outline && outline->link) {
125 wfont->ascii2glyph[s] = num;
126 wfont->glyph2ascii[num] = s;
127 swf_ShapeNew(&wfont->glyph[num].shape);
128 SHAPE*shape = wfont->glyph[num].shape;
130 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE);
142 shape->bits.fill = 1;
143 shape->bits.line = 0;
144 swf_ShapeSetStyle(tag,shape,0,1,0);
146 drawpath(tag, outline, &m, log);
148 /*uncomment this to mark the glyph sizes:
149 plotxy p1,p2; p1.x=0; p1.y=0; p2.x=width/8; p2.y=-width/8;
150 moveto(tag, p1); lineto(tag, p2); p1.x += 2; p2.x += 2;
151 lineto(tag, p2); lineto(tag, p1); p1.x -= 2; lineto(tag, p1);// */
153 swf_ShapeSetEnd(tag);
155 wfont->glyph[num].shape->bitlen = (tag->len-1)*8;
156 wfont->glyph[num].shape->data = (U8*)malloc(tag->len-1);
157 memcpy(wfont->glyph[num].shape->data, &tag->data[1], tag->len-1);
160 /* fix bounding box */
163 shape2 = swf_ShapeToShape2(shape);
164 if(!shape2) { fprintf(stderr, "Shape parse error\n");exit(1);}
165 bbox = swf_GetShapeBoundingBox(shape2->lines);
166 swf_Shape2Free(shape2);
167 wfont->layout->bounds[num] = bbox;
168 //wfont->glyph[num].advance = (int)(width/6.4); // 128/20
169 wfont->glyph[num].advance = bbox.xmax/20;
178 int main(int argc, char ** argv)
182 printf("Usage: %s font.afm\n", argv[0]);
183 printf("OR: %s all\n", argv[0]);
185 printf("\tIf \"all\" is given instead of font names, all standard fonts\n");
186 printf("\t(Courier, Arial etc.) will be created\n");
189 if(!strcmp(argv[1],"all"))
192 //TODO: use tempnam here. Check if environment already contains a
194 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
195 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
196 fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n", DATADIR);
197 fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR);
198 fprintf(fi, "AFM=%s/fonts:.\n", DATADIR);
199 fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR);
201 fi = fopen("/tmp/FontDataBase", "wb");
204 fprintf(fi, "n021003l.afm\n"); //fixme
205 fprintf(fi, "n021023l.afm\n");
206 fprintf(fi, "n021004l.afm\n");
207 fprintf(fi, "n021024l.afm\n");
208 fprintf(fi, "n019003l.afm\n");
209 fprintf(fi, "n019023l.afm\n");
210 fprintf(fi, "n019004l.afm\n");
211 fprintf(fi, "n019024l.afm\n");
212 fprintf(fi, "n022003l.afm\n");
213 fprintf(fi, "n022023l.afm\n");
214 fprintf(fi, "n022004l.afm\n");
215 fprintf(fi, "n022024l.afm\n");
216 fprintf(fi, "s050000l.afm\n");
217 fprintf(fi, "d050000l.afm\n");
219 fprintf(fi, "%d\n",argc-1);
221 for(t=1;t<argc;t++) {
222 fprintf(fi, "%s\n",argv[t]);
226 /* initialize t1lib */
227 T1_SetBitmapPad( 16);
228 if ((T1_InitLib(NO_LOGFILE)==NULL)){
229 fprintf(stderr, "Initialization of t1lib failed\n");
232 unlink("/tmp/t1lib.config.tmp");
235 for( i=0; i<T1_Get_no_fonts(); i++)
238 SWFFONT * font = t1font2swffont(i);
241 sprintf(filename, "%s.swf", font->name);
242 swf_WriteFont(font, filename);