+ if(fontname) {
+ this->t1id = searchT1Font(fontname);
+ }
+ if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
+ logf("<fatal> Too many fonts in file.");
+ exit(1);
+ }
+ if(oldname) {
+ substitutesource[substitutepos] = oldname;
+ substitutetarget[substitutepos] = fontname;
+ logf("<verbose> substituting %s -> %s", FIXNULL(oldname), FIXNULL(fontname));
+ substitutepos ++;
+ }
+ return fontname;
+}
+
+void unlinkfont(char* filename)
+{
+ int l;
+ if(!filename)
+ return;
+ l=strlen(filename);
+ unlink(filename);
+ if(!strncmp(&filename[l-4],".afm",4)) {
+ memcpy(&filename[l-4],".pfb",4);
+ unlink(filename);
+ memcpy(&filename[l-4],".pfa",4);
+ unlink(filename);
+ memcpy(&filename[l-4],".afm",4);
+ return;
+ } else
+ if(!strncmp(&filename[l-4],".pfa",4)) {
+ memcpy(&filename[l-4],".afm",4);
+ unlink(filename);
+ memcpy(&filename[l-4],".pfa",4);
+ return;
+ } else
+ if(!strncmp(&filename[l-4],".pfb",4)) {
+ memcpy(&filename[l-4],".afm",4);
+ unlink(filename);
+ memcpy(&filename[l-4],".pfb",4);
+ return;
+ }
+}
+
+void SWFOutputDev::updateFont(GfxState *state)
+{
+ GfxFont*gfxFont = state->getFont();
+ char * fileName = 0;
+
+ if (!gfxFont) {
+ return;
+ }
+ char * fontname = gfxFontName(gfxFont);
+
+ int t;
+ for(t=0;t<substitutepos;t++) {
+ if(!strcmp(fontname, substitutesource[t])) {
+ fontname = substitutetarget[t];
+ break;
+ }
+ }
+
+ if(swfoutput_queryfont(&output, fontname))
+ {
+ swfoutput_setfont(&output, fontname, -1, 0);
+ return;
+ }
+
+ // look for Type 3 font
+ if (!type3Warning && gfxFont->getType() == fontType3) {
+ type3Warning = gTrue;
+ showFontError(gfxFont, 2);
+ }
+ //dumpFontInfo ("<notice>", gfxFont);
+
+ Ref embRef;
+ GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
+ if(embedded) {
+ if (!gfxFont->is16Bit() &&
+ (gfxFont->getType() == fontType1 ||
+ gfxFont->getType() == fontType1C ||
+ gfxFont->getType() == fontTrueType)) {
+
+ fileName = writeEmbeddedFontToFile(gfxFont);
+ if(!fileName) {
+ logf("<error> Couldn't write font to file");
+ showFontError(gfxFont,0);
+ return ;
+ }
+ this->t1id = T1_AddFont(fileName);
+ if(this->t1id<0) {
+ logf("<error> Couldn't load font from file");
+ showFontError(gfxFont,0);
+ unlinkfont(fileName);
+ return ;
+ }
+ }
+ else {
+ showFontError(gfxFont,0);
+ fontname = substituteFont(gfxFont, fontname);
+ }
+ } else {
+ if(fontname) {
+ int newt1id = searchT1Font(fontname);
+ if(newt1id<0) {
+ fontname = substituteFont(gfxFont, fontname);
+ } else
+ this->t1id = newt1id;