added some log messages about fonts.
[swftools.git] / pdf2swf / SWFOutputDev.cc
index f6274bb..23f1258 100644 (file)
@@ -386,35 +386,35 @@ void dumpFontInfo(char*loglevel, GfxFont*font)
 
   GString*gstr  = font->getTag();
    
-  msg("%sTag: %s\n", loglevel, name);
+  msg("%s| Tag: %s\n", loglevel, name);
   
-  if(font->isCIDFont()) msg("%sis CID font\n", loglevel);
+  if(font->isCIDFont()) msg("%s| is CID font\n", loglevel);
 
   GfxFontType type=font->getType();
   switch(type) {
     case fontUnknownType:
-     msg("%sType: unknown\n",loglevel);
+     msg("%s| Type: unknown\n",loglevel);
     break;
     case fontType1:
-     msg("%sType: 1\n",loglevel);
+     msg("%s| Type: 1\n",loglevel);
     break;
     case fontType1C:
-     msg("%sType: 1C\n",loglevel);
+     msg("%s| Type: 1C\n",loglevel);
     break;
     case fontType3:
-     msg("%sType: 3\n",loglevel);
+     msg("%s| Type: 3\n",loglevel);
     break;
     case fontTrueType:
-     msg("%sType: TrueType\n",loglevel);
+     msg("%s| Type: TrueType\n",loglevel);
     break;
     case fontCIDType0:
-     msg("%sType: CIDType0\n",loglevel);
+     msg("%s| Type: CIDType0\n",loglevel);
     break;
     case fontCIDType0C:
-     msg("%sType: CIDType0C\n",loglevel);
+     msg("%s| Type: CIDType0C\n",loglevel);
     break;
     case fontCIDType2:
-     msg("%sType: CIDType2\n",loglevel);
+     msg("%s| Type: CIDType2\n",loglevel);
     break;
   }
   
@@ -423,18 +423,18 @@ void dumpFontInfo(char*loglevel, GfxFont*font)
   if(font->getEmbeddedFontName())
     name = font->getEmbeddedFontName()->getCString();
   if(embedded)
-   msg("%sEmbedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
+   msg("%s| Embedded name: %s id: %d\n",loglevel, FIXNULL(name), embRef.num);
 
   gstr = font->getExtFontFile();
   if(gstr)
-   msg("%sExternal Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
+   msg("%s| External Font file: %s\n", loglevel, FIXNULL(gstr->getCString()));
 
   // Get font descriptor flags.
-  if(font->isFixedWidth()) msg("%sis fixed width\n", loglevel);
-  if(font->isSerif()) msg("%sis serif\n", loglevel);
-  if(font->isSymbolic()) msg("%sis symbolic\n", loglevel);
-  if(font->isItalic()) msg("%sis italic\n", loglevel);
-  if(font->isBold()) msg("%sis bold\n", loglevel);
+  if(font->isFixedWidth()) msg("%s| is fixed width\n", loglevel);
+  if(font->isSerif()) msg("%s| is serif\n", loglevel);
+  if(font->isSymbolic()) msg("%s| is symbolic\n", loglevel);
+  if(font->isItalic()) msg("%s| is italic\n", loglevel);
+  if(font->isBold()) msg("%s| is bold\n", loglevel);
 }
 
 //void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) {printf("void SWFOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str, int width, int height, GBool invert, GBool inlineImg) \n");}
@@ -617,12 +617,11 @@ SWFOutputDev::~SWFOutputDev()
 };
 GBool SWFOutputDev::upsideDown() 
 {
-    msg("<debug> upsidedown?");
+    msg("<debug> upsidedown? yes");
     return gTrue;
 };
 GBool SWFOutputDev::useDrawChar() 
 {
-    msg("<debug> usedrawchar?");
     return gTrue;
 }
 
@@ -660,8 +659,6 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
     if(_u) 
        u = *_u;
     
-    msg("<debug> drawChar(%f,%f,%f,%f,c='%c' (%d),u=%d <%d>) CID=%d\n",x,y,dx,dy,c,c,u, uLen, font->isCIDFont());
-
     /* find out the character name */
     char*name=0;
     if(font->isCIDFont() && u) {
@@ -681,13 +678,13 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
        if(enc && enc[c])
           name = enc[c];
     }
+    
+    msg("<debug> drawChar(%f,%f,c='%c' (%d),u=%d <%d>) CID=%d name=\"%s\"\n",x1,y1,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name));
 
     int ret = swfoutput_drawchar(&output, x1, y1, name, c, u);
 }
 
-void SWFOutputDev::endString(GfxState *state) 
-{ 
-    msg("<debug> endstring\n");
+void SWFOutputDev::endString(GfxState *state) { 
 }    
 
  
@@ -710,18 +707,25 @@ void SWFOutputDev::endType3Char(GfxState *state)
 void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, double crop_y1, double crop_x2, double crop_y2) 
 {
   double x1,y1,x2,y2;
+  int rot = doc->getPageRotate(1);
   laststate = state;
   msg("<verbose> startPage %d (%f,%f,%f,%f)\n", pageNum, crop_x1, crop_y1, crop_x2, crop_y2);
+  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
   */
-  x1 = crop_x1;
+  
+  /*x1 = crop_x1;
   y1 = crop_y1;
   x2 = crop_x2;
-  y2 = crop_y2;
+  y2 = crop_y2;*/
+  state->transform(crop_x1,crop_y1,&x1,&y1);
+  state->transform(crop_x2,crop_y2,&x2,&y2);
 
   if(x2<x1) {double x3=x1;x1=x2;x2=x3;}
   if(y2<y1) {double y3=y1;y1=y2;y2=y3;}
@@ -922,7 +926,7 @@ char* SWFOutputDev::searchFont(char*name)
     /* look in all font files */
     for(i=0;i<fontnum;i++) 
     {
-       if(!strstr(fonts[i], name))
+       if(strstr(fonts[i], name))
        {
            return fonts[i];
        }
@@ -1156,7 +1160,7 @@ void SWFOutputDev::updateFont(GfxState *state)
     int del = 0;
     if(embedded &&
        (gfxFont->getType() == fontType1 ||
-       gfxFont->getType() == fontCIDType0C ||
+       //gfxFont->getType() == fontCIDType0C ||
        gfxFont->getType() == fontType1C ||
        gfxFont->getType() == fontTrueType ||
        gfxFont->getType() == fontCIDType2
@@ -1178,9 +1182,10 @@ void SWFOutputDev::updateFont(GfxState *state)
     }
        
     msg("<verbose> updateFont(%s) -> %s", fontname, fileName);
+    dumpFontInfo("<verbose>", gfxFont);
 
     swfoutput_setfont(&output, fontname, fileName);
-    
+   
     if(fileName && del)
        unlinkfont(fileName);
 }
@@ -1609,15 +1614,9 @@ void pdfswf_init(char*filename, char*userPassword)
     }
   }
   info.free();
-
+                
   numpages = doc->getNumPages();
   if (doc->isEncrypted()) {
-       /*ERROR: This pdf is encrypted, and disallows copying.
-         Due to the DMCA, paragraph 1201, (2) A-C, circumventing
-         a technological measure that efficively controls access to
-         a protected work is violating American law. 
-         See www.eff.org for more information about DMCA issues.
-        */
        if(!doc->okToCopy()) {
            printf("PDF disallows copying. Bailing out.\n");
            exit(1); //bail out