X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fswfoutput.cc;h=62850815a6ae3001b17990b77c45f955a152dc91;hb=06aa9dc1fe16b6965b7ea00dbcfaeb8209cdf1bc;hp=f0d43e764fdb7fd7e7c6e4e96c8ce60dfba1915f;hpb=813c13d3a6050b4f081356b3f4b7edc3282c1162;p=swftools.git diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index f0d43e7..6285081 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -29,9 +29,7 @@ #else #define assert(a) #endif -#define logf logarithmf // logf is also used by ../lib/log.h #include -#undef logf #include "swfoutput.h" #include "spline.h" extern "C" { @@ -222,7 +220,7 @@ void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log) tag->id != ST_DEFINESHAPE2 && tag->id != ST_DEFINESHAPE3) { - logf(" internal error: drawpath needs a shape tag, not %d\n",tag->id); + msg(" internal error: drawpath needs a shape tag, not %d\n",tag->id); exit(1); } double x=0,y=0; @@ -283,7 +281,7 @@ void drawpath(TAG*tag, T1_OUTLINE*outline, struct swfmatrix*m, int log) spline(tag,p0,p1,p2,p3,m); } else { - logf(" drawpath: unknown outline type:%d\n", outline->type); + msg(" drawpath: unknown outline type:%d\n", outline->type); } lastx=x; lasty=y; @@ -661,7 +659,7 @@ void drawpath2poly(struct swfoutput *output, T1_OUTLINE*outline, struct swfmatri tag->id != ST_DEFINESHAPE && tag->id != ST_DEFINESHAPE2 && tag->id != ST_DEFINESHAPE3) { - logf(" internal error: drawpath needs a shape tag, not %d\n",tag->id); + msg(" internal error: drawpath needs a shape tag, not %d\n",tag->id); exit(1); } assert(shapeid>=0); @@ -753,11 +751,11 @@ static void putcharacters(TAG*tag) if(tag->id != ST_DEFINETEXT && tag->id != ST_DEFINETEXT2) { - logf(" internal error: putcharacters needs an text tag, not %d\n",tag->id); + msg(" internal error: putcharacters needs an text tag, not %d\n",tag->id); exit(1); } if(!chardatapos) { - logf(" putcharacters called with zero characters"); + msg(" putcharacters called with zero characters"); } for(pass = 0; pass < 2; pass++) @@ -819,8 +817,12 @@ static void putcharacters(TAG*tag) if(lastx != chardata[t].x || lasty != chardata[t].y) { - newx=chardata[t].x; - newy=chardata[t].y; + newx = chardata[t].x; + newy = chardata[t].y; + if(newx == 0) + newx = SET_TO_ZERO; + if(newy == 0) + newy = SET_TO_ZERO; } if(!colorcompare(&color, &chardata[t].color)) { @@ -890,9 +892,18 @@ static void drawchar(struct swfoutput*obj, SWFFont*font, char*character, int cha if(m->m11 != m->m22) usefonts=0; + if(!font) { + msg(" Font is NULL"); + } + if(usefonts && ! drawonlyshapes) { int charid = font->getSWFCharID(character, charnr); + if(charid<0) { + msg(" Didn't find character '%s' (%d) in current charset (%s)", + FIXNULL(character),charnr, FIXNULL(font->getName())); + return; + } if(shapeid>=0) endshape(); if(textid<0) @@ -906,8 +917,8 @@ static void drawchar(struct swfoutput*obj, SWFFont*font, char*character, int cha char* charname = character; if(!outline) { - logf(" Didn't find %s in current charset (%s)", - FIXNULL(character),FIXNULL(font->getName())); + msg(" Didn't find character '%s' (%d) in current charset (%s)", + FIXNULL(character),charnr,FIXNULL(font->getName())); return; } @@ -980,18 +991,24 @@ SWFFont::SWFFont(char*name, int id, char*filename) this->fontid = strdup(name); this->t1id = id; - char**a= T1_GetAllCharNames(id); + char**charnamebase= T1_GetAllCharNames(id); + char**a= charnamebase; int t, outlinepos=0; char*map[256]; + char*null = 0; + if(!a) + a=&null; + t=0; while(a[t]) t++; this->charnum = t; - if(!charnum) - return; - logf(" Font %s(%d): Storing %d outlines.\n", FIXNULL(name), id, charnum); + if(!charnum) { + this->standardtablesize = 0; + } + msg(" Font %s(%d): Storing %d outlines.\n", FIXNULL(name), id, charnum); this->standardtablesize = 256; if(this->charnum < this->standardtablesize) @@ -1000,9 +1017,18 @@ SWFFont::SWFFont(char*name, int id, char*filename) for(t = 0; t < this->standardtablesize; t++) { char*name = T1_GetCharName(id,t); - if(!name) - name = ""; + char chh[2] = ""; + chh[0] = t; + if(!name || !strstr(name, "notdef")) { + if(t + } + } standardtable[t] = strdup(name); + msg(" Char %d is named %s\n", t, name); } outline = (T1_OUTLINE**)malloc(charnum*sizeof(T1_OUTLINE*)); @@ -1022,7 +1048,7 @@ SWFFont::SWFFont(char*name, int id, char*filename) t=0; while(*a) { - map[t] = *a; + map[t] = strdup(*a); a++; t++; if(t==256 || !*a) { @@ -1037,6 +1063,12 @@ SWFFont::SWFFont(char*name, int id, char*filename) int ret = T1_ReencodeFont(id, map); if(ret) fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret); + /* Deleting the font invalidates the charname array, + so we have to ask for it again now. + We continue at the position we were, hoping the font + didn't shrink in the meantime or something. + */ + a = T1_GetAllCharNames(id) + (a - charnamebase); } // parsecharacters @@ -1049,6 +1081,9 @@ SWFFont::SWFFont(char*name, int id, char*filename) this->charname[outlinepos] = strdup(name); outlinepos++; } + + for(s=0;s Font %s has %d used characters",FIXNULL(fontid), usednum); + msg(" Font %s has %d used characters",FIXNULL(fontid), usednum); TAG*ftag = swf_InsertTag(swf.firstTag,ST_DEFINEFONT); swf_SetU16(ftag, this->swfid); int initpos = swf_GetTagLen(ftag); @@ -1136,7 +1171,8 @@ SWFFont::~SWFFont() } free(ptr); - free(outline); + if(outline) + free(outline); for(t=0;tstandardtable && charnr>=0 && charnr < this->standardtablesize) { - return getOutline(this->standardtable[charnr], -1); + T1_OUTLINE*ret = getOutline(this->standardtable[charnr], -1); + if(ret) return ret; } - logf(" Didn't find character '%s' in font '%s'", FIXNULL(name), this->name); return 0; } @@ -1209,10 +1245,10 @@ int SWFFont::getSWFCharID(char*name, int charnr) /* if we didn't find it by name, use the names of the first 256 (or so) characters of the font to try a new name based on charnr */ if(this->standardtable && charnr>=0 && charnr < this->standardtablesize) { - return getSWFCharID(this->standardtable[charnr], -1); + int ret = getSWFCharID(this->standardtable[charnr], -1); + if(ret) return ret; } - logf(" Didn't find character '%s' in font '%s'", FIXNULL(name), this->name); - return 0; + return -1; } int SWFFont::getWidth(char*name) @@ -1258,7 +1294,7 @@ void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filenam } if(t1id<0) { - logf(" internal error: t1id:%d, fontid:%s\n", t1id,FIXNULL(fontid)); + msg(" internal error: t1id:%d, fontid:%s\n", t1id,FIXNULL(fontid)); } SWFFont*font = new SWFFont(fontid, t1id, filename); @@ -1316,17 +1352,17 @@ void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character, } /* initialize the swf writer */ -void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _sizey) +void swfoutput_init(struct swfoutput* obj, char*_filename, int x1, int y1, int x2, int y2) { GLYPH *glyph; RGBA rgb; SRECT r; memset(obj, 0, sizeof(struct swfoutput)); filename = _filename; - sizex = _sizex; - sizey = _sizey; + sizex = x2; + sizey = y2; - logf(" initializing swf output for size %d*%d\n", sizex,sizey); + msg(" initializing swf output for size %d*%d\n", sizex,sizey); obj->font = 0; @@ -1334,8 +1370,10 @@ void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _size swf.fileVersion = flashversion; swf.frameRate = 0x0040; // 1 frame per 4 seconds - swf.movieSize.xmax = 20*sizex; - swf.movieSize.ymax = 20*sizey; + swf.movieSize.xmin = 20*x1; + swf.movieSize.ymin = 20*y1; + swf.movieSize.xmax = 20*x2; + swf.movieSize.ymax = 20*y2; swf.firstTag = swf_InsertTag(NULL,ST_SETBACKGROUNDCOLOR); tag = swf.firstTag; @@ -1343,8 +1381,10 @@ void swfoutput_init(struct swfoutput* obj, char*_filename, int _sizex, int _size rgb.g = 0xff; rgb.b = 0xff; swf_SetRGB(tag,&rgb); - if(flag_protected) // good practice! /r + + if(flag_protected) tag = swf_InsertTag(tag, ST_PROTECT); + depth = 1; startdepth = depth; } @@ -1494,7 +1534,7 @@ void swfoutput_destroy(struct swfoutput* obj) fi = 1; // stdout if(fi<=0) { - logf(" Could not create \"%s\". ", FIXNULL(filename)); + msg(" Could not create \"%s\". ", FIXNULL(filename)); exit(1); } @@ -1502,15 +1542,15 @@ void swfoutput_destroy(struct swfoutput* obj) if(enablezlib) { if FAILED(swf_WriteSWC(fi,&swf)) - logf(" WriteSWC() failed.\n"); + msg(" WriteSWC() failed.\n"); } else { if FAILED(swf_WriteSWF(fi,&swf)) - logf(" WriteSWF() failed.\n"); + msg(" WriteSWF() failed.\n"); } if(filename) close(fi); - logf(" SWF written\n"); + msg(" SWF written\n"); } void swfoutput_setdrawmode(swfoutput* obj, int mode) @@ -1578,7 +1618,7 @@ void swfoutput_startclip(swfoutput*obj, T1_OUTLINE*outline, struct swfmatrix*m) if(clippos >= 127) { - logf(" Too many clip levels."); + msg(" Too many clip levels."); clippos --; } @@ -1605,7 +1645,7 @@ void swfoutput_endclip(swfoutput*obj) endshape(); if(!clippos) { - logf(" Invalid end of clipping region"); + msg(" Invalid end of clipping region"); return; } clippos--;