added gradient warning.
[swftools.git] / pdf2swf / SWFOutputDev.cc
index 0b79336..08b3c7c 100644 (file)
 #include "GfxFont.h"
 #include "CharCodeToUnicode.h"
 #include "NameToUnicodeTable.h"
-#include "FontFile.h"
 #include "GlobalParams.h"
+//#define XPDF_101
+#ifdef XPDF_101
+#include "FontFile.h"
+#else
+#include "FoFiType1C.h"
+#include "FoFiTrueType.h"
+#endif
+#include "SWFOutputDev.h"
+
 //swftools header files
 #include "swfoutput.h"
-#include "SWFOutputDev.h"
 #include "../lib/log.h"
 
 #include <math.h>
@@ -150,6 +157,9 @@ public:
   // Does this device use drawChar() or drawString()?
   virtual GBool useDrawChar();
   
+  // Can this device draw gradients?
+  virtual GBool useGradients();
+  
   virtual GBool interpretType3Chars() {return gTrue;}
 
   //----- initialization and control
@@ -231,6 +241,7 @@ public:
   int pbminfo; // did we write "File contains jpegs" yet?
   int linkinfo; // did we write "File contains links" yet?
   int ttfinfo; // did we write "File contains TrueType Fonts" yet?
+  int gradientinfo; // did we write "File contains Gradients yet?
 
   int type3active; // are we between beginType3()/endType3()?
 
@@ -641,6 +652,15 @@ GBool SWFOutputDev::useDrawChar()
 {
     return gTrue;
 }
+GBool SWFOutputDev::useGradients()
+{
+    if(!gradientinfo)
+    {
+       msg("<notice> File contains gradients");
+       gradientinfo = 1;
+    }
+    return gTrue;
+}
 
 void SWFOutputDev::beginString(GfxState *state, GString *s) 
 { 
@@ -650,9 +670,6 @@ void SWFOutputDev::beginString(GfxState *state, GString *s)
     m11 *= state->getHorizScaling();
     m21 *= state->getHorizScaling();
     swfoutput_setfontmatrix(&output, m11, -m21, m12, -m22);
-    
-    msg("<debug> fontmatrix %7.3f %7.3f\n", m11,-m21);
-    msg("<debug> fontmatrix %7.3f %7.3f\n", m12,-m22);
 }
 
 void SWFOutputDev::drawChar(GfxState *state, double x, double y,
@@ -736,8 +753,6 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl
   if(rot!=0)
     msg("<verbose> page is rotated %d degrees\n", rot);
 
-  msg("<notice> processing page %d", pageNum);
-
   /* state->transform(state->getX1(),state->getY1(),&x1,&y1);
   state->transform(state->getX2(),state->getY2(),&x2,&y2);
   Use CropBox, not MediaBox, as page size
@@ -755,11 +770,11 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl
 
   if(!outputstarted) {
     msg("<verbose> Bounding box is (%f,%f)-(%f,%f)", x1,y1,x2,y2);
-    swfoutput_init(&output, swffilename,(int)x1,(int)y1,(int)x2,(int)y2);
+    swfoutput_init(&output, swffilename);
     outputstarted = 1;
   }
-  else
-    swfoutput_newpage(&output);
+    
+  swfoutput_newpage(&output, pageNum, (int)x1, (int)y1, (int)x2, (int)y2);
 }
 
 void SWFOutputDev::drawLink(Link *link, Catalog *catalog) 
@@ -770,7 +785,11 @@ void SWFOutputDev::drawLink(Link *link, Catalog *catalog)
   swfcoord points[5];
   int x, y;
 
+#ifdef XPDF_101
   link->getBorder(&x1, &y1, &x2, &y2, &w);
+#else
+  link->getRect(&x1, &y1, &x2, &y2);
+#endif
 //  if (w > 0) 
   {
     rgb.r = 0;
@@ -1001,6 +1020,11 @@ void SWFOutputDev::updateStrokeColor(GfxState *state)
                                      (char)(rgb.b*255), (char)(opaq*255));
 }
 
+void FoFiWrite(void *stream, char *data, int len)
+{
+   fwrite(data, len, 1, (FILE*)stream);
+}
+
 char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
 {
     char*tmpFileName = NULL;
@@ -1041,8 +1065,13 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
        msg("<error> Couldn't read embedded font file");
        return 0;
       }
+#ifdef XPDF_101
       Type1CFontFile *cvt = new Type1CFontFile(fontBuf, fontLen);
       cvt->convertToType1(f);
+#else
+      FoFiType1C *cvt = FoFiType1C::make(fontBuf, fontLen);
+      cvt->convertToType1(NULL, gTrue, FoFiWrite, f);
+#endif
       //cvt->convertToCIDType0("test", f);
       //cvt->convertToType0("test", f);
       delete cvt;
@@ -1054,8 +1083,13 @@ char*SWFOutputDev::writeEmbeddedFontToFile(XRef*ref, GfxFont*font)
        msg("<error> Couldn't read embedded font file");
        return 0;
       }
+#ifdef XPDF_101
       TrueTypeFontFile *cvt = new TrueTypeFontFile(fontBuf, fontLen);
       cvt->writeTTF(f);
+#else
+      FoFiTrueType *cvt = FoFiTrueType::make(fontBuf, fontLen);
+      cvt->writeTTF(FoFiWrite, f);
+#endif
       delete cvt;
       gfree(fontBuf);
     } else {
@@ -1819,7 +1853,11 @@ void pdfswf_performconversion()
     for(t=0;t<pagepos;t++)
     {
        currentpage = pages[t];
+#ifdef XPDF_101
        doc->displayPage((OutputDev*)output, currentpage, /*zoom*/zoom, /*rotate*/0, /*doLinks*/(int)1);
+#else
+       doc->displayPage((OutputDev*)output, currentpage, zoom, zoom, /*rotate*/0, true, /*doLinks*/(int)1);
+#endif
     }
 }
 int pdfswf_numpages()