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 256
24 #define symbolEncodingSize 256
25 #define zapfDingbatsEncodingSize 256
26 #define macRomanEncodingSize 256
28 extern char *standardEncoding[standardEncodingSize];
29 extern char *symbolEncoding[symbolEncodingSize];
30 extern char *zapfDingbatsEncoding[zapfDingbatsEncodingSize];
31 extern char *macRomanEncoding[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 /* if "all" is given, translate the font names in something more
53 if(!strcmp(fullname, "Nimbus Roman No9 L Regular")) fontname = "Helvetica";
54 if(!strcmp(fullname, "Nimbus Roman No9 L Regular Italic")) fontname = "HelveticaItalic";
55 if(!strcmp(fullname, "Nimbus Roman No9 L Medium")) fontname = "HelveticaBold";
56 if(!strcmp(fullname, "Nimbus Roman No9 L Medium Italic")) fontname = "HelveticaBoldItalic";
57 if(!strcmp(fullname, "Nimbus Sans L Regular")) fontname = "Times";
58 if(!strcmp(fullname, "Nimbus Sans L Regular Italic")) fontname = "TimesItalic";
59 if(!strcmp(fullname, "Nimbus Sans L Bold")) fontname = "TimesBold";
60 if(!strcmp(fullname, "Nimbus Sans L Bold Italic")) fontname = "TimesBoldItalic";
61 if(!strcmp(fullname, "Nimbus Mono L Regular")) fontname = "Courier";
62 if(!strcmp(fullname, "Nimbus Mono L Regular Oblique")) fontname = "CourierItalic";
63 if(!strcmp(fullname, "Nimbus Mono L Bold")) fontname = "CourierBold";
64 if(!strcmp(fullname, "Nimbus Mono L Bold Oblique")) fontname = "CourierBoldItalic";
65 if(!strcmp(fullname, "Standard Symbols L")) fontname = "Symbol";
67 char ** encoding = standardEncoding;
68 int encodingsize = standardEncodingSize;
70 printf("processing \"%s\" (\"%s\")...\n", fullname, fontname);
72 if(strstr(fullname, "Dingbats")) {// Zapf Dingbats
73 encoding = zapfDingbatsEncoding;
74 encodingsize = zapfDingbatsEncodingSize;
76 else if(strstr(fullname, "Symbol")) {// Symbol
77 encoding = symbolEncoding;
78 encodingsize = symbolEncodingSize;
81 SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT));
82 SWFFont * font = new SWFFont("", i, "");
85 wfont->name = (U8*)strdup(fontname);
86 wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT));
87 memset(wfont->layout, 0, sizeof(SWFLAYOUT));
91 for(s=0;s<encodingsize;s++)
94 T1_OUTLINE*outline = font->getOutline(encoding[s]);
95 if(outline && outline->link)
100 wfont->maxascii = encodingsize;
101 wfont->numchars = num;
103 wfont->style = (/*bold*/0?FONT_STYLE_BOLD:0) + (angle>0.05?FONT_STYLE_ITALIC:0);
105 wfont->glyph = (SWFGLYPH*)malloc(num*sizeof(SWFGLYPH));
106 memset(wfont->glyph, 0, num*sizeof(SWFGLYPH));
107 wfont->glyph2ascii = (U16*)malloc(num*sizeof(U16));
108 memset(wfont->glyph2ascii, 0, num*sizeof(U16));
109 wfont->ascii2glyph = (int*)malloc(encodingsize*sizeof(int));
110 memset(wfont->ascii2glyph, -1, encodingsize*sizeof(int));
111 wfont->layout->ascent = (U16)(underline - bbox.lly);
112 wfont->layout->descent = (U16)(bbox.ury - underline);
113 wfont->layout->leading = (U16)(wfont->layout->ascent -
114 wfont->layout->descent -
115 (bbox.lly - bbox.ury));
116 wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*num);
117 memset(wfont->layout->bounds, 0, sizeof(SRECT)*num);
118 wfont->layout->kerningcount = 0;
119 wfont->layout->kerning = 0;
122 for(s=0;s<encodingsize;s++)
125 T1_OUTLINE*outline = font->getOutline(encoding[s]);
126 int width = font->getWidth(encoding[s]);
127 if(outline && outline->link) {
129 wfont->ascii2glyph[s] = num;
130 wfont->glyph2ascii[num] = s;
131 swf_ShapeNew(&wfont->glyph[num].shape);
132 SHAPE*shape = wfont->glyph[num].shape;
133 wfont->glyph[num].advance = width/2;
135 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE);
147 shape->bits.fill = 1;
148 shape->bits.line = 0;
149 swf_ShapeSetStyle(tag,shape,0,1,0);
151 drawpath(tag, outline, &m, log);
153 /*uncomment this to mark the glyph sizes:
154 plotxy p1,p2; p1.x=0; p1.y=0; p2.x=width/8; p2.y=-width/8;
155 moveto(tag, p1); lineto(tag, p2); p1.x += 2; p2.x += 2;
156 lineto(tag, p2); lineto(tag, p1); p1.x -= 2; lineto(tag, p1);// */
158 swf_ShapeSetEnd(tag);
160 wfont->glyph[num].shape->bitlen = (tag->len-1)*8;
161 wfont->glyph[num].shape->data = (U8*)malloc(tag->len-1);
162 memcpy(wfont->glyph[num].shape->data, &tag->data[1], tag->len-1);
165 /* fix bounding box */
168 shape2 = swf_ShapeToShape2(shape);
169 if(!shape2) { fprintf(stderr, "Shape parse error\n");exit(1);}
170 bbox = swf_GetShapeBoundingBox(shape2->lines);
171 swf_Shape2Free(shape2);
172 wfont->layout->bounds[num] = bbox;
181 int main(int argc, char ** argv)
185 printf("Usage: %s font.afm\n", argv[0]);
186 printf("OR: %s all\n", argv[0]);
188 printf("\tIf \"all\" is given instead of font names, all standard fonts\n");
189 printf("\t(Courier, Arial etc.) will be created\n");
192 if(!strcmp(argv[1],"all"))
195 //TODO: use tempnam here. Check if environment already contains a
197 putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp");
198 FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb");
199 fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n", DATADIR);
200 fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR);
201 fprintf(fi, "AFM=%s/fonts:.\n", DATADIR);
202 fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR);
204 fi = fopen("/tmp/FontDataBase", "wb");
207 fprintf(fi, "n021003l.afm\n"); //fixme
208 fprintf(fi, "n021023l.afm\n");
209 fprintf(fi, "n021004l.afm\n");
210 fprintf(fi, "n021024l.afm\n");
211 fprintf(fi, "n019003l.afm\n");
212 fprintf(fi, "n019023l.afm\n");
213 fprintf(fi, "n019004l.afm\n");
214 fprintf(fi, "n019024l.afm\n");
215 fprintf(fi, "n022003l.afm\n");
216 fprintf(fi, "n022023l.afm\n");
217 fprintf(fi, "n022004l.afm\n");
218 fprintf(fi, "n022024l.afm\n");
219 fprintf(fi, "s050000l.afm\n");
220 fprintf(fi, "d050000l.afm\n");
222 fprintf(fi, "%d\n",argc-1);
224 for(t=1;t<argc;t++) {
225 fprintf(fi, "%s\n",argv[t]);
229 /* initialize t1lib */
230 T1_SetBitmapPad( 16);
231 if ((T1_InitLib(NO_LOGFILE)==NULL)){
232 fprintf(stderr, "Initialization of t1lib failed\n");
235 unlink("/tmp/t1lib.config.tmp");
238 for( i=0; i<T1_Get_no_fonts(); i++)
241 SWFFONT * font = t1font2swffont(i);
244 sprintf(filename, "%s.swf", font->name);
245 swf_WriteFont(font, filename);