X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=pdf2swf%2Ffont2swf.cc;h=894b7ab713079f103a9587db3202d42298cdf4a0;hp=cc6b5ce6df7cc00646004468dc4e3eca4b8cc280;hb=f9cd3d326142683da50bf7095a8b8985c01b13e2;hpb=4685b0c5ad48b7ae65bb84c26923a4843fb5aed9 diff --git a/pdf2swf/font2swf.cc b/pdf2swf/font2swf.cc index cc6b5ce..894b7ab 100644 --- a/pdf2swf/font2swf.cc +++ b/pdf2swf/font2swf.cc @@ -1,28 +1,104 @@ /* makefonts.cc - Utility for generating the standard fonts (arial, courier, etc.) in swf-format. + Utility for converting Type 1 fonts to SWF. Part of the swftools package. Copyright (c) 2001 Matthias Kramm - This file is distributed under the GPL, see file COPYING for details + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -*/ + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include #include "../lib/rfxswf.h" +#include "../lib/args.h" #include "swfoutput.h" #include "spline.h" +static char * filenames[256]; +static int filenum; +static char * destfilename = "output.swf"; +int all=0; +int verbose=0; + +struct options_t options[] = +{ + {"o","output"}, + {"v","verbose"}, + {"V","version"}, + {0,0} +}; +int args_callback_option(char*name,char*val) +{ + if(!strcmp(name, "V")) { + printf("font2swf - part of %s %s\n", PACKAGE, VERSION); + exit(0); + } + else if(!strcmp(name, "o")) { + destfilename = val; + return 1; + } + else if(!strcmp(name, "v")) { + verbose ++; + return 0; + } + else { + printf("Unknown option: -%s\n", name); + exit(1); + } + return 0; +} +int args_callback_longoption(char*name,char*val) +{ + return args_long2shortoption(options, name, val); +} +void args_callback_usage(char*name) +{ + printf("Usage: %s file.afm [...]\n", name); + printf(" OR: %s all\n", name); + printf("\n"); + printf("\tIf \"all\" is given instead of font names, all standard fonts\n"); + printf("\t(Courier, Arial etc.) will be created\n"); + printf("\n"); + printf("Options:\n"); + printf("\n"); + printf("\t-h , --help\t\t Print help and exit\n"); + printf("\t-o , --output filename\t set output filename\n"); + printf("\t-v , --verbose\t\t Be more verbose\n"); + printf("\t-V , --version\t\t Print program version and exit\n"); +} +int args_callback_command(char*name,char*val) +{ + if(!strcmp(name, "all")) + all = 1; + else { + filenames[filenum++] = strdup(name); + } + return 0; +} + + #define standardEncodingSize 256 #define symbolEncodingSize 256 #define zapfDingbatsEncodingSize 256 #define macRomanEncodingSize 256 +#define winAnsiEncodingSize 256 +extern char *winAnsiEncoding[winAnsiEncodingSize]; extern char *standardEncoding[standardEncodingSize]; extern char *symbolEncoding[symbolEncodingSize]; extern char *zapfDingbatsEncoding[zapfDingbatsEncodingSize]; @@ -60,8 +136,8 @@ SWFFONT * t1font2swffont(int i) if(!strcmp(fullname, "Nimbus Mono L Bold Oblique")) fontname = "CourierBoldItalic"; if(!strcmp(fullname, "Standard Symbols L")) fontname = "Symbol"; - char ** encoding = standardEncoding; - int encodingsize = standardEncodingSize; + char ** encoding = winAnsiEncoding; + int encodingsize = winAnsiEncodingSize; printf("processing \"%s\" (\"%s\")...\n", fullname, fontname); @@ -77,6 +153,8 @@ SWFFONT * t1font2swffont(int i) SWFFONT * wfont = (SWFFONT*)malloc(sizeof(SWFFONT)); SWFFont * font = new SWFFont("", i, ""); + memset(wfont, 0, sizeof(SWFFONT)); + wfont->version = 2; wfont->name = (U8*)strdup(fontname); wfont->layout = (SWFLAYOUT*)malloc(sizeof(SWFLAYOUT)); @@ -86,11 +164,15 @@ SWFFONT * t1font2swffont(int i) num = 0; for(s=0;sgetOutline(encoding[s], 0); - if(outline && outline->link) - num++; + if(outline) {num++;charinfont=1;} } + /*if(charinfont) printf("x"); + else printf("."); + if((s&15) == 15) + printf("\n");*/ } wfont->maxascii = encodingsize; @@ -120,12 +202,14 @@ SWFFONT * t1font2swffont(int i) if(encoding[s]) { T1_OUTLINE*outline = font->getOutline(encoding[s],0); int width = font->getWidth(encoding[s]); - if(outline && outline->link) { + + if(outline) { int log = 0; wfont->ascii2glyph[s] = num; wfont->glyph2ascii[num] = s; swf_ShapeNew(&wfont->glyph[num].shape); SHAPE*shape = wfont->glyph[num].shape; + int firstx = outline->dest.x/0xffff; TAG*tag = swf_InsertTag(0,ST_DEFINESHAPE); @@ -143,8 +227,9 @@ SWFFONT * t1font2swffont(int i) shape->bits.line = 0; swf_ShapeSetStyle(tag,shape,0,1,0); resetdrawer(); + 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; @@ -156,17 +241,20 @@ 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); + bbox = swf_GetShapeBoundingBox(shape2); swf_Shape2Free(shape2); wfont->layout->bounds[num] = bbox; //wfont->glyph[num].advance = (int)(width/6.4); // 128/20 wfont->glyph[num].advance = bbox.xmax/20; + if(!wfont->glyph[num].advance) { + wfont->glyph[num].advance = firstx; + } num++; } @@ -177,49 +265,51 @@ 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; + char cwd[128]; + getcwd(cwd, 128); + processargs(argc, argv); + if(!all && !filenum) { + fprintf(stderr, "You must supply a filename.\n"); + exit(1); } //TODO: use tempnam here. Check if environment already contains a //T1LIB_CONFIG. putenv( "T1LIB_CONFIG=/tmp/t1lib.config.tmp"); FILE*fi = fopen("/tmp/t1lib.config.tmp", "wb"); - fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n", DATADIR); - fprintf(fi, "ENCODING=%s/fonts:.\n", DATADIR); - fprintf(fi, "AFM=%s/fonts:.\n", DATADIR); - fprintf(fi, "TYPE1=%s/fonts:.\n", DATADIR); + if(all) { + fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n"); + fprintf(fi, "ENCODING=%s/fonts:.\n", SWFTOOLS_DATADIR); + fprintf(fi, "AFM=%s/fonts:.\n", SWFTOOLS_DATADIR); + fprintf(fi, "TYPE1=%s/fonts:.\n", SWFTOOLS_DATADIR); + } else { + fprintf(fi, "FONTDATABASE=/tmp/FontDataBase\n"); + fprintf(fi, "ENCODING=%s:.\n", cwd); + fprintf(fi, "AFM=%s:.\n", cwd); + fprintf(fi, "TYPE1=%s:.\n", cwd); + } fclose(fi); fi = fopen("/tmp/FontDataBase", "wb"); 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"); + fprintf(fi, "%s/fonts/n021003l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n021023l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n021004l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n021024l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n019003l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n019023l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n019004l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n019024l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n022003l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n022023l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n022004l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/n022024l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/s050000l.afm\n", SWFTOOLS_DATADIR); + fprintf(fi, "%s/fonts/d050000l.afm\n", SWFTOOLS_DATADIR); } else { - fprintf(fi, "%d\n",argc-1); + fprintf(fi, "%d\n", filenum); int t; - for(t=1;t