added fontCIDType0C support.
[swftools.git] / pdf2swf / SWFOutputDev.cc
index 04676e1..2809efc 100644 (file)
@@ -624,8 +624,6 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
                        double originX, double originY,
                        CharCode c, Unicode *_u, int uLen)
 {
-    msg("<debug> drawChar(%f,%f,%f,%f,'%c')\n",x,y,dx,dy,c);
-    
     // check for invisible text -- this is used by Acrobat Capture
     if ((state->getRender() & 3) == 3)
        return;
@@ -640,13 +638,16 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
     x1 = x;
     y1 = y;
     state->transform(x, y, &x1, &y1);
+       
+    Unicode u=0;
+    if(_u) 
+       u = *_u;
+    
+    msg("<debug> drawChar(%f,%f,%f,%f,'%c',%d) CID=%d\n",x,y,dx,dy,c,u, font->isCIDFont());
 
     if(font->isCIDFont()) {
        GfxCIDFont*cfont = (GfxCIDFont*)font;
-       Unicode u=0;
        char*name=0;
-       if(_u) 
-           u = *_u;
        if(u) {
            int t;
            for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++)
@@ -656,14 +657,13 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
                    break;
                }
        }
-/*        printf("%02x %04x/%04x-%d \"%s\" %s %d\n", c,u, *_u, uLen, name, cfont->getName()->getCString(),
-               cfont->getType());*/
 
        if(name)
           swfoutput_drawchar(&output, x1, y1, name, c);
-       else
+       else {
           msg("<warning> couldn't get name for CID character %02x from Encoding", c);
           swfoutput_drawchar(&output, x1, y1, "<unknown>", c);
+       }
     } else {
        Gfx8BitFont*font8;
        font8 = (Gfx8BitFont*)font;
@@ -983,10 +983,10 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
       int c;
       char *fontBuf;
       int fontLen;
-      Type1CFontFile *cvt;
       Ref embRef;
       Object refObj, strObj;
-      tmpFileName = "/tmp/tmpfont";
+      char namebuf[512];
+      tmpFileName = mktmpname(namebuf);
       int ret;
 
       ret = font->getEmbeddedFontID(&embRef);
@@ -1002,16 +1002,28 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
        msg("<error> Couldn't create temporary Type 1 font file");
          return 0;
       }
-      if (font->getType() == fontType1C) {
+      if (font->getType() == fontType1C ||
+         font->getType() == fontCIDType0C) {
        if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
          fclose(f);
          msg("<error> Couldn't read embedded font file");
          return 0;
        }
-       cvt = new Type1CFontFile(fontBuf, fontLen);
+       Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
        cvt->convertToType1(f);
        delete cvt;
        gfree(fontBuf);
+      } else if(font->getType() == fontTrueType) {
+       msg("<verbose> writing font using TrueTypeFontFile::writeTTF");
+       if (!(fontBuf = font->readEmbFontFile(xref, &fontLen))) {
+         fclose(f);
+         msg("<error> Couldn't read embedded font file");
+         return 0;
+       }
+       TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
+       cvt->writeTTF(f);
+       delete cvt;
+       gfree(fontBuf);
       } else {
        font->getEmbeddedFontID(&embRef);
        refObj.initRef(embRef.num, embRef.gen);
@@ -1055,25 +1067,25 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
              msg("<notice> File contains TrueType fonts");
              ttfinfo = 1;
          }
-         char name2[80];
+         char name2[512];
          char*tmp;
          tmp = strdup(mktmpname((char*)name2));
          sprintf(name2, "%s", tmp);
-         char*a[] = {"./ttf2pt1", "-W0",
+         char*a[] = {"./ttf2pt1", "-W", "0",
 #ifndef USE_FREETYPE
-             "-pttf",
+             "-p", "ttf",
 #else
-             "-pft",
+             "-p", "ft",
 #endif
              "-b", tmpFileName, name2};
-         msg("<verbose> Invoking %s %s %s %s %s %s",a[0],a[1],a[2],a[3],a[4],a[5]);
-         ttf2pt1_main(6,a);
+         msg("<verbose> Invoking %s %s %s %s %s %s %s %s",a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);
+         ttf2pt1_main(8,a);
          unlink(tmpFileName);
          sprintf(name2,"%s.pfb",tmp);
          tmpFileName = strdup(name2);
       }
 
-    return tmpFileName;
+    return strdup(tmpFileName);
 }
 
 char* gfxFontName(GfxFont* gfxFont)
@@ -1280,9 +1292,11 @@ void SWFOutputDev::updateFont(GfxState *state)
   GBool embedded = gfxFont->getEmbeddedFontID(&embRef);
   if(embedded) {
     if (gfxFont->getType() == fontType1 ||
+       gfxFont->getType() == fontCIDType0C ||
        gfxFont->getType() == fontType1C ||
        gfxFont->getType() == fontTrueType ||
-       gfxFont->getType() == fontCIDType2)
+       gfxFont->getType() == fontCIDType2
+       )
     {
        fileName = writeEmbeddedFontToFile(xref, gfxFont);
        if(!fileName) {
@@ -1292,7 +1306,7 @@ void SWFOutputDev::updateFont(GfxState *state)
        }
        this->t1id = T1_AddFont(fileName);
        if(this->t1id<0) {
-         msg("<error> Couldn't load font from file");
+         msg("<error> Couldn't load font from file %s", fileName);
          showFontError(gfxFont,0);
          unlinkfont(fileName);
          return ;
@@ -1304,6 +1318,7 @@ void SWFOutputDev::updateFont(GfxState *state)
           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
@@ -1325,7 +1340,8 @@ void SWFOutputDev::updateFont(GfxState *state)
   }
 
   if(t1id<0) {
-      showFontError(gfxFont,0);
+      msg("<error> Current font's t1id is %d", t1id);
+      //showFontError(gfxFont,0);
       return;
   }