X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fexample%2Fmakefonts.cc;h=0f64799c1844cf7de133b6bc732b6533385aa17e;hb=08413f49a157383b76b52520bd9d69e13250901e;hp=ffd99f7ccfb6542799a7bcb356c51c0bb1a5e37a;hpb=d4af216aee2d07affc044ef8a9f7fb4c408c44cd;p=swftools.git diff --git a/lib/example/makefonts.cc b/lib/example/makefonts.cc index ffd99f7..0f64799 100644 --- a/lib/example/makefonts.cc +++ b/lib/example/makefonts.cc @@ -48,10 +48,26 @@ SWFFONT * t1font2swffont(int i) float underline = T1_GetUnderlinePosition(i); BBox bbox = T1_GetFontBBox(i); + /* if "all" is given, translate the font names in something more + readable */ + if(!strcmp(fullname, "Nimbus Roman No9 L Regular")) fontname = "Helvetica"; + if(!strcmp(fullname, "Nimbus Roman No9 L Regular Italic")) fontname = "HelveticaItalic"; + if(!strcmp(fullname, "Nimbus Roman No9 L Medium")) fontname = "HelveticaBold"; + if(!strcmp(fullname, "Nimbus Roman No9 L Medium Italic")) fontname = "HelveticaBoldItalic"; + if(!strcmp(fullname, "Nimbus Sans L Regular")) fontname = "Times"; + if(!strcmp(fullname, "Nimbus Sans L Regular Italic")) fontname = "TimesItalic"; + if(!strcmp(fullname, "Nimbus Sans L Bold")) fontname = "TimesBold"; + if(!strcmp(fullname, "Nimbus Sans L Bold Italic")) fontname = "TimesBoldItalic"; + if(!strcmp(fullname, "Nimbus Mono L Regular")) fontname = "Courier"; + if(!strcmp(fullname, "Nimbus Mono L Regular Oblique")) fontname = "CourierItalic"; + if(!strcmp(fullname, "Nimbus Mono L Bold")) fontname = "CourierBold"; + if(!strcmp(fullname, "Nimbus Mono L Bold Oblique")) fontname = "CourierBoldItalic"; + if(!strcmp(fullname, "Standard Symbols L")) fontname = "Symbol"; + char ** encoding = standardEncoding; int encodingsize = standardEncodingSize; - printf("processing \"%s\"...\n", fullname); + printf("processing \"%s\" (\"%s\")...\n", fullname, fontname); if(strstr(fullname, "Dingbats")) {// Zapf Dingbats encoding = zapfDingbatsEncoding; @@ -59,7 +75,7 @@ SWFFONT * t1font2swffont(int i) } else if(strstr(fullname, "Symbol")) {// Symbol encoding = symbolEncoding; - encodingsize = zapfDingbatsEncodingSize; + encodingsize = symbolEncodingSize; } SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT)); @@ -68,13 +84,14 @@ SWFFONT * t1font2swffont(int i) wfont->version = 2; wfont->name = (U8*)strdup(fontname); wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT)); + memset(wfont->layout, 0, sizeof(SWFLAYOUT)); int s,num; num = 0; for(s=0;sgetOutline(encoding[s]); + T1_OUTLINE*outline = font->getOutline(encoding[s], 0); if(outline && outline->link) num++; } @@ -96,11 +113,8 @@ SWFFONT * t1font2swffont(int i) wfont->layout->leading = (U16)(wfont->layout->ascent - wfont->layout->descent - (bbox.lly - bbox.ury)); - wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT)); - wfont->layout->bounds->xmin = bbox.llx; - wfont->layout->bounds->ymin = bbox.lly; - wfont->layout->bounds->xmax = bbox.urx; - wfont->layout->bounds->ymax = bbox.ury; + wfont->layout->bounds = (SRECT*)malloc(sizeof(SRECT)*num); + memset(wfont->layout->bounds, 0, sizeof(SRECT)*num); wfont->layout->kerningcount = 0; wfont->layout->kerning = 0; @@ -108,7 +122,7 @@ SWFFONT * t1font2swffont(int i) for(s=0;sgetOutline(encoding[s]); + T1_OUTLINE*outline = font->getOutline(encoding[s],0); int width = font->getWidth(encoding[s]); if(outline && outline->link) { int log = 0; @@ -116,7 +130,7 @@ SWFFONT * t1font2swffont(int i) wfont->glyph2ascii[num] = s; swf_ShapeNew(&wfont->glyph[num].shape); SHAPE*shape = wfont->glyph[num].shape; - wfont->glyph[num].advance = width/2; + wfont->glyph[num].advance = (int)(width/6.4); // 128/20 TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE); @@ -137,19 +151,9 @@ SWFFONT * t1font2swffont(int i) drawpath(tag, outline, &m, log); /*uncomment this to mark the glyph sizes: - plotxy p1,p2; - p1.x=0; - p1.y=0; - p2.x=width/8; - p2.y=-width/8; - moveto(tag, p1); - lineto(tag, p2); - p1.x += 2; - p2.x += 2; - lineto(tag, p2); - lineto(tag, p1); - p1.x -= 2; - lineto(tag, p1);// */ + plotxy p1,p2; p1.x=0; p1.y=0; p2.x=width/8; p2.y=-width/8; + moveto(tag, p1); lineto(tag, p2); p1.x += 2; p2.x += 2; + lineto(tag, p2); lineto(tag, p1); p1.x -= 2; lineto(tag, p1);// */ swf_ShapeSetEnd(tag); @@ -157,6 +161,16 @@ SWFFONT * t1font2swffont(int i) wfont->glyph[num].shape->data = (U8*)malloc(tag->len-1); memcpy(wfont->glyph[num].shape->data, &tag->data[1], tag->len-1); swf_DeleteTag(tag); + + /* fix bounding box */ + SHAPE2*shape2; + SRECT bbox; + shape2 = swf_ShapeToShape2(shape); + if(!shape2) { fprintf(stderr, "Shape parse error\n");exit(1);} + bbox = swf_GetShapeBoundingBox(shape2->lines); + swf_Shape2Free(shape2); + wfont->layout->bounds[num] = bbox; + num++; } } @@ -166,6 +180,18 @@ SWFFONT * t1font2swffont(int i) int main(int argc, char ** argv) { + int all=0; + if(argc<=1) { + printf("Usage: %s font.afm\n", argv[0]); + printf("OR: %s all\n", argv[0]); + printf("\n"); + printf("\tIf \"all\" is given instead of font names, all standard fonts\n"); + printf("\t(Courier, Arial etc.) will be created\n"); + return 0; + } else { + if(!strcmp(argv[1],"all")) + all=1; + } //TODO: use tempnam here. Check if environment already contains a //T1LIB_CONFIG. putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp"); @@ -176,21 +202,29 @@ int main(int argc, char ** argv) fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR); fclose(fi); fi = fopen("/tmp/FontDataBase", "wb"); - fprintf(fi, "14\n"); - fprintf(fi, "n021003l.afm\n"); //fixme - fprintf(fi, "n021023l.afm\n"); - fprintf(fi, "n021004l.afm\n"); - fprintf(fi, "n021024l.afm\n"); - fprintf(fi, "n019003l.afm\n"); - fprintf(fi, "n019023l.afm\n"); - fprintf(fi, "n019004l.afm\n"); - fprintf(fi, "n019024l.afm\n"); - fprintf(fi, "n022003l.afm\n"); - fprintf(fi, "n022023l.afm\n"); - fprintf(fi, "n022004l.afm\n"); - fprintf(fi, "n022024l.afm\n"); - fprintf(fi, "s050000l.afm\n"); - fprintf(fi, "d050000l.afm\n"); + if(all) { + fprintf(fi, "14\n"); + fprintf(fi, "n021003l.afm\n"); //fixme + fprintf(fi, "n021023l.afm\n"); + fprintf(fi, "n021004l.afm\n"); + fprintf(fi, "n021024l.afm\n"); + fprintf(fi, "n019003l.afm\n"); + fprintf(fi, "n019023l.afm\n"); + fprintf(fi, "n019004l.afm\n"); + fprintf(fi, "n019024l.afm\n"); + fprintf(fi, "n022003l.afm\n"); + fprintf(fi, "n022023l.afm\n"); + fprintf(fi, "n022004l.afm\n"); + fprintf(fi, "n022024l.afm\n"); + fprintf(fi, "s050000l.afm\n"); + fprintf(fi, "d050000l.afm\n"); + } else { + fprintf(fi, "%d\n",argc-1); + int t; + for(t=1;t