From: kramm Date: Sat, 20 Oct 2001 18:53:01 +0000 (+0000) Subject: Font characters are now addressed by full name, not charcode X-Git-Tag: release-0-0-2~44 X-Git-Url: http://git.asbjorn.it/?a=commitdiff_plain;h=e795670a7843a35bd56065c9c6bd8405f4b18566;p=swftools.git Font characters are now addressed by full name, not charcode --- diff --git a/pdf2swf/SWFOutputDev.cc b/pdf2swf/SWFOutputDev.cc index b2573d8..17eecb2 100644 --- a/pdf2swf/SWFOutputDev.cc +++ b/pdf2swf/SWFOutputDev.cc @@ -21,6 +21,7 @@ #include #include #include +#include //xpdf header files #include "GString.h" #include "gmem.h" @@ -45,7 +46,7 @@ extern "C" { #include "../lib/log.h" } -static char* filename = 0; +static char* swffilename = 0; static void printInfoString(Dict *infoDict, char *key, char *fmt); static void printInfoDate(Dict *infoDict, char *key, char *fmt); @@ -220,7 +221,6 @@ public: int clippos; int setT1Font(char*name,FontEncoding*enc); - int initT1Font(int id, FontEncoding*encoding); int t1id; }; @@ -365,7 +365,7 @@ void dumpFontInfo(char*loglevel, GfxFont*font) char*name; gstr = font->getName(); Ref r=font->getID(); - logf("%s=========== %s (ID:%d) ==========\n", loglevel, gstr?gstr->getCString():"(unknown font)", r.num); + logf("%s=========== %s (ID:%d,%d) ==========\n", loglevel, gstr?gstr->getCString():"(unknown font)", r.num,r.gen); gstr = font->getTag(); if(gstr) @@ -582,7 +582,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y, double dx, doub y1 = y; state->transform(x, y, &x1, &y1); - swfoutput_drawchar(&output, x1, y1, c); + swfoutput_drawchar(&output, x1, y1, enc->getCharName(c)); } } @@ -606,7 +606,7 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state) state->transform(state->getX1(),state->getY1(),&x1,&y1); state->transform(state->getX2(),state->getY2(),&x2,&y2); if(!outputstarted) { - swfoutput_init(&output, filename, abs((int)(x2-x1)),abs((int)(y2-y1))); + swfoutput_init(&output, swffilename, abs((int)(x2-x1)),abs((int)(y2-y1))); outputstarted = 1; } else @@ -725,51 +725,7 @@ int SWFOutputDev::setT1Font(char*name, FontEncoding*encoding) if(id<0) return 0; - /* T1 allows us to recode only once. Therefore, remove - and reload the font to reset it */ - T1_DeleteFont(id); - T1_LoadFont(id); - initT1Font(id, encoding); -} - -int SWFOutputDev::initT1Font(int id, FontEncoding*encoding) -{ - int encStrSize; - char *encPtr; - int i; - - if(!T1_GetFontName(id)) - T1_LoadFont(id); - - /* reencode the font: - * This is the only way to get the unmapped characters - * from t1lib - */ - encStrSize = 0; - for (i = 0; i < 256 && i < encoding->getSize(); ++i) { - if (encoding->getCharName(i)) { - encStrSize += strlen(encoding->getCharName(i)) + 1; - } - } - char**enc = (char **)gmalloc(257 * sizeof(char *)); - char*encStr = (char *)gmalloc(encStrSize * sizeof(char)); - encPtr = encStr; - for (i = 0; i < 256 && i < encoding->getSize(); ++i) { - if (encoding->getCharName(i)) { - strcpy(encPtr, encoding->getCharName(i)); - enc[i] = encPtr; - encPtr += strlen(encPtr) + 1; - } else { - enc[i] = ".notdef"; - } - } - for (; i < 256; ++i) { - enc[i] = ".notdef"; - } - enc[256] = "custom"; - int ret=T1_ReencodeFont(id, enc); - t1id = id; - return 1; + this->t1id = id; } void SWFOutputDev::updateLineWidth(GfxState *state) @@ -853,19 +809,35 @@ int embeddedt1ids[128]; int embedded_mappos = 0; int embedded_maxpos = 128; +char* gfxFontName(GfxFont* gfxFont) +{ + GString *gstr; + gstr = gfxFont->getName(); + if(gstr) { + return gstr->getCString(); + } + else { + char buf[32]; + Ref r=gfxFont->getID(); + sprintf(buf, "UFONT%d", r.num); + return strdup(buf); + } +} + void SWFOutputDev::updateFont(GfxState *state) { double m11, m12, m21, m22; char * fontname = 0; GfxFont*gfxFont = state->getFont(); + char * fileName = 0; if (!gfxFont) { return; } - if(swfoutput_queryfont(&output, gfxFont->getID().num)) + if(swfoutput_queryfont(&output, gfxFontName(gfxFont))) { - swfoutput_setfont(&output, gfxFont->getID().num, -1); + swfoutput_setfont(&output, gfxFontName(gfxFont), -1, 0); return; } @@ -883,9 +855,8 @@ void SWFOutputDev::updateFont(GfxState *state) for(t=0;tis16Bit() && (gfxFont->getType() == fontType1 || gfxFont->getType() == fontType1C)) { @@ -898,6 +869,7 @@ void SWFOutputDev::updateFont(GfxState *state) showFontError(gfxFont,0); return ; } + t1id = T1_AddFont(fileName); embeddedids[embedded_mappos] = embRef.num; embeddedt1ids[embedded_mappos] = t1id; @@ -908,7 +880,6 @@ void SWFOutputDev::updateFont(GfxState *state) { t1id = embeddedt1ids[t]; } - initT1Font(t1id, gfxFont->getEncoding()); } else { fontname = NULL; if(gfxFont->getName()) { @@ -980,7 +951,9 @@ void SWFOutputDev::updateFont(GfxState *state) } } - swfoutput_setfont(&output,gfxFont->getID().num,t1id); + swfoutput_setfont(&output,gfxFontName(gfxFont),t1id, fileName); + if(fileName) + unlink(fileName); } void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, @@ -1008,6 +981,7 @@ void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, fputc(c, fi); fclose(fi); swfoutput_drawimagefile(&output, fileName, width, height, x1,y1,x2,y2,x3,y3,x4,y4); + unlink(fileName); } else { logf(" File contains pbm pictures."); } @@ -1039,6 +1013,7 @@ void SWFOutputDev::drawImage(GfxState *state, Object *ref, Stream *str, fputc(c, fi); fclose(fi); swfoutput_drawimagefile(&output, fileName, width, height, x1,y1,x2,y2,x3,y3,x4,y4); + unlink(fileName); } else { logf(" File contains pbm pictures."); } @@ -1124,7 +1099,7 @@ void pdfswf_init(char*filename, char*userPassword) void pdfswf_setoutputfilename(char*_filename) { - filename = _filename; + swffilename = _filename; } void pdfswf_convertpage(int page) diff --git a/pdf2swf/swfoutput.cc b/pdf2swf/swfoutput.cc index 2993ffc..074f28b 100644 --- a/pdf2swf/swfoutput.cc +++ b/pdf2swf/swfoutput.cc @@ -201,23 +201,14 @@ void drawpath(T1_OUTLINE*outline, struct swfmatrix*m, char*namehint) //char*charname = T1_GetCharName(t1fontindex, character); /* process a character. */ -void drawchar(struct swfoutput*obj, SWFFont*font, char character, swfmatrix*m) +void drawchar(struct swfoutput*obj, SWFFont*font, char*character, swfmatrix*m) { T1_OUTLINE*outline = font->getOutline(character); - char* charname = font->getCharName(character); + char* charname = character; if(!outline) - { - /* for newline, we don't print an error. FIXME: We shouldn't get newlines here - in the first place - */ - if(character != '\n') { - logf(" Char to set is not defined!"); - logf(" - font file is %s\n", font->getName()); - logf(" - char 0x%02x is named %s\n",character, charname); - } return; - } + swfmatrix m2=*m; m2.m11/=100; m2.m21/=100; @@ -254,38 +245,69 @@ void swfoutput_drawpath(swfoutput*output, T1_OUTLINE*outline, struct swfmatrix*m drawpath(outline,m, 0); } -SWFFont::SWFFont(int t1fontindex) +SWFFont::SWFFont(char*name, int id, char*filename) { - int t; - for(t=0;t<256;t++) - { - int width = T1_GetCharWidth(t1fontindex, t); - BBox bbox = T1_GetCharBBox(t1fontindex, t); - T1_OUTLINE*outline = T1_GetCharOutline(t1fontindex,t,100.0,0); + if(!T1_GetFontName(id)) + T1_LoadFont(id); - char*name; - this->outline[t] = T1_CopyOutline(outline); + this->name = strdup(T1_GetFontFileName(id)); + this->fontid = name; + this->t1id = id; - name = T1_GetCharName(t1fontindex, t); - if(!name || name[0]=='.') - { - this->charname[t] = 0; - this->outline[t] = 0; + char**a= T1_GetAllCharNames(id); + int t=0, outlinepos=0; + char*map[256]; + while(a[t]) + t++; + + this->charnum = t; + if(!t) + return; + logf(" Font %s(%d): Storing %d outlines.\n", name, id, t); + + outline = (T1_OUTLINE**)malloc(t*sizeof(T1_OUTLINE*)); + charname = (char**)malloc(t*sizeof(char*)); + + t=0; + while(*a) + { + map[t] = *a; + a++; + t++; + if(t==256 || !*a) { + int s; + for(s=t;s<256;s++) + map[s] = ".notdef"; + + int ret = T1_ReencodeFont(id, map); + if(ret) { + T1_DeleteFont(id); + T1_LoadFont(id); + int ret = T1_ReencodeFont(id, map); + if(ret) + fprintf(stderr,"Can't reencode font: (%s) ret:%d\n",filename, ret); + } + + // parsecharacters + for(s=0;soutline[outlinepos] = T1_CopyOutline(T1_GetCharOutline(id, s, 100.0, 0)); + this->charname[outlinepos] = strdup(T1_GetCharName(id, s)); + outlinepos++; + } + t=0; } - else - this->charname[t] = strdup(name); } - this->name = strdup(T1_GetFontFileName(t1fontindex)); -} - -T1_OUTLINE*SWFFont::getOutline(unsigned char nr) -{ - return outline[nr]; } -char*SWFFont::getCharName(int t) +T1_OUTLINE*SWFFont::getOutline(char*name) { - return this->charname[t]; + int t; + for(t=0;tcharnum;t++) { + if(!strcmp(this->charname[t],name)) + return outline[t]; + } + return 0; } char*SWFFont::getName() @@ -300,15 +322,15 @@ struct fontlist_t } *fontlist = 0; /* set's the t1 font index of the font to use for swfoutput_drawchar(). */ -void swfoutput_setfont(struct swfoutput*obj, int fontid, int t1id) +void swfoutput_setfont(struct swfoutput*obj, char*fontid, int t1id, char*filename) { fontlist_t*last=0,*iterator; - if(obj->font && obj->font->id == fontid) + if(obj->font && !strcmp(obj->font->fontid,fontid)) return; iterator = fontlist; while(iterator) { - if(iterator->font->id == fontid) + if(!strcmp(iterator->font->fontid,fontid)) break; last = iterator; iterator = iterator->next; @@ -320,10 +342,10 @@ void swfoutput_setfont(struct swfoutput*obj, int fontid, int t1id) } if(t1id<0) { - logf(" internal error: t1id:%d, fontid:%d\n", t1id,fontid); + logf(" internal error: t1id:%d, fontid:%s\n", t1id,fontid); } - SWFFont*font = new SWFFont(t1id); + SWFFont*font = new SWFFont(fontid, t1id, filename); iterator = new fontlist_t; iterator->font = font; iterator->next = 0; @@ -335,11 +357,11 @@ void swfoutput_setfont(struct swfoutput*obj, int fontid, int t1id) obj->font = font; } -int swfoutput_queryfont(struct swfoutput*obj, int fontid) +int swfoutput_queryfont(struct swfoutput*obj, char*fontid) { fontlist_t *iterator = fontlist; while(iterator) { - if(iterator->font->id == fontid) + if(!strcmp(iterator->font->fontid,fontid)) return 1; iterator = iterator->next; } @@ -358,7 +380,7 @@ void swfoutput_setfontmatrix(struct swfoutput*obj,double m11,double m12, } /* draws a character at x,y. */ -void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char character) +void swfoutput_drawchar(struct swfoutput* obj,double x,double y,char*character) { swfmatrix m; m.m11 = obj->fontm11; diff --git a/pdf2swf/swfoutput.h b/pdf2swf/swfoutput.h index 8db8f3a..2b1e742 100644 --- a/pdf2swf/swfoutput.h +++ b/pdf2swf/swfoutput.h @@ -28,16 +28,18 @@ struct swfcoord { class SWFFont { - T1_OUTLINE*(outline[256]); - char*(charname[256]); + T1_OUTLINE**outline; + char**charname; char*name; + int charnum; public: - int id; + int t1id; + char*fontid; - SWFFont(int t1id); - T1_OUTLINE*getOutline(unsigned char nr); + SWFFont(char*name, int t1id, char*filename); + T1_OUTLINE*getOutline(char*charname); char*getName(); char*getCharName(int t); }; @@ -63,15 +65,15 @@ void swfoutput_setprotected(); //write PROTECT tag void swfoutput_newpage(struct swfoutput*); -void swfoutput_setfont(struct swfoutput*, int fontid, int t1font); -int swfoutput_queryfont(struct swfoutput*, int fontid); +void swfoutput_setfont(struct swfoutput*, char*fontid, int t1font, char*filename); +int swfoutput_queryfont(struct swfoutput*, char*fontid); void swfoutput_setdrawmode(struct swfoutput*, int drawmode); void swfoutput_setfillcolor(struct swfoutput*, unsigned char r, unsigned char g, unsigned char b, unsigned char a); void swfoutput_setstrokecolor(struct swfoutput*, unsigned char r, unsigned char g, unsigned char b, unsigned char a); void swfoutput_setfontmatrix(struct swfoutput*,double,double,double,double); void swfoutput_setlinewidth(struct swfoutput*, double linewidth); -void swfoutput_drawchar(struct swfoutput*,double x,double y,char a); +void swfoutput_drawchar(struct swfoutput*,double x,double y,char*a); void swfoutput_drawpath(struct swfoutput*, T1_OUTLINE*outline, struct swfmatrix*m); void swfoutput_startclip(struct swfoutput*, T1_OUTLINE*outline, struct swfmatrix*m); void swfoutput_endclip(struct swfoutput*);