+ /* 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() == fontCIDType0C ||
+ 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 %s", fileName);
+ 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) {
+ msg("<error> Couldn't find any suitable replacement for %s",fontname);
+ 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);
+ }
+ }
+
+ if(t1id<0) {
+ msg("<error> Current font's t1id is %d", t1id);
+ //showFontError(gfxFont,0);
+ return;
+ }
+
+ /* we may have done some substitutions here, so check
+ again if this font is cached. */
+ if(swfoutput_queryfont(&output, fontname))
+ {
+ swfoutput_setfont(&output, fontname, -1, 0);
+ return;
+ }
+
+ msg("<verbose> Creating new SWF font: t1id: %d, filename: %s name:%s", this->t1id, FIXNULL(fileName), FIXNULL(fontname));
+ swfoutput_setfont(&output, fontname, this->t1id, fileName);