+ if(fontname) {
+ this->t1id = searchT1Font(fontname);
+ }
+ if(substitutepos>=sizeof(substitutesource)/sizeof(char*)) {
+ msg("<fatal> Too many fonts in file.");
+ exit(1);
+ }
+ if(oldname) {
+ substitutesource[substitutepos] = oldname;
+ substitutetarget[substitutepos] = fontname;
+ msg("<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::startDoc(XRef *xref)
+{
+ this->xref = xref;
+}
+
+
+void SWFOutputDev::updateFont(GfxState *state)
+{
+ GfxFont*gfxFont = state->getFont();
+ char * fileName = 0;
+
+ if (!gfxFont) {
+ return;
+ }
+ char * fontname = gfxFontName(gfxFont);
+
+ int t;
+ /* first, look if we substituted this font before-
+ this way, we don't initialize the T1 Fonts
+ too often */
+ for(t=0;t<substitutepos;t++) {
+ if(!strcmp(fontname, substitutesource[t])) {
+ fontname = substitutetarget[t];
+ break;
+ }
+ }
+
+ /* second, see if swfoutput already has this font
+ cached- if so, we are done */
+
+ 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);
+ }
+
+ /* now either load the font, or find a substitution */
+
+ Ref embRef;
+ GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
+ if(embedded) {
+ if (gfxFont->getType() == fontType1 ||
+ gfxFont->getType() == fontType1C ||
+ gfxFont->getType() == fontTrueType ||
+ gfxFont->getType() == fontCIDType2)
+ {
+ fileName = writeEmbeddedFontToFile(xref, gfxFont);
+ if(!fileName) {
+ msg("<error> Couldn't write font to file");
+ showFontError(gfxFont,0);
+ return ;
+ }
+ this->t1id = T1_AddFont(fileName);
+ if(this->t1id<0) {
+ msg("<error> Couldn't load font from file");
+ showFontError(gfxFont,0);
+ unlinkfont(fileName);
+ return ;
+ }
+ }
+ else {
+ /* in case the font is embedded, but has an
+ unsupported format, we just look through the
+ font directories */
+ int newt1id = searchT1Font(fontname);
+ if(newt1id<0) {
+ showFontError(gfxFont,0);
+ fontname = substituteFont(gfxFont, fontname);
+ } else
+ this->t1id = newt1id;
+ }
+ } else {
+ if(fontname) {
+ int newt1id = searchT1Font(fontname);
+ if(newt1id<0) {
+ showFontError(gfxFont,1);
+ fontname = substituteFont(gfxFont, fontname);
+ } else
+ this->t1id = newt1id;
+ }
+ else {
+ showFontError(gfxFont,1);
+ fontname = substituteFont(gfxFont, fontname);