fixed bug in SWFOutputDev::getDimensions().
[swftools.git] / pdf2swf / SWFOutputDev.cc
index 75d19e6..52f00d0 100644 (file)
@@ -126,6 +126,8 @@ public:
   void setClip(int x1,int y1,int x2,int y2);
   
   int save(char*filename);
+  void  pagefeed();
+  void* getSWF();
 
   void getDimensions(int*x1,int*y1,int*x2,int*y2);
 
@@ -353,10 +355,7 @@ void SWFOutputDev::setClip(int x1,int y1,int x2,int y2)
 }
 void SWFOutputDev::getDimensions(int*x1,int*y1,int*x2,int*y2)
 {
-    if(x1) *x1 = output.swf.movieSize.xmin/20;
-    if(y1) *y1 = output.swf.movieSize.ymin/20;
-    if(x2) *x2 = output.swf.movieSize.xmax/20;
-    if(y2) *y2 = output.swf.movieSize.ymax/20;
+    return swfoutput_getdimensions(&output, x1,y1,x2,y2);
 }
 
 static char*getFontID(GfxFont*font)
@@ -799,10 +798,20 @@ void SWFOutputDev::eoClip(GfxState *state)
     clipping[clippos] ++;
     free_outline(outline);
 }
+
+/* pass through functions for swf_output */
 int SWFOutputDev::save(char*filename)
 {
     return swfoutput_save(&output, filename);
 }
+void SWFOutputDev::pagefeed()
+{
+    swfoutput_pagefeed(&output);
+}
+void* SWFOutputDev::getSWF()
+{
+    return (void*)swfoutput_get(&output);
+}
 
 SWFOutputDev::~SWFOutputDev() 
 {
@@ -846,7 +855,7 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
     // check for invisible text -- this is used by Acrobat Capture
     if ((state->getRender() & 3) == 3)
        return;
-
+    Gushort *CIDToGIDMap = 0;
     GfxFont*font = state->getFont();
 
     if(font->getType() == fontType3) {
@@ -859,20 +868,29 @@ void SWFOutputDev::drawChar(GfxState *state, double x, double y,
     state->transform(x, y, &x1, &y1);
     
     Unicode u=0;
-    if(_u && uLen) 
+    char*name=0;
+
+    if(_u && uLen) {
        u = *_u;
+       if (u) {
+           int t;
+           /* find out char name from unicode index 
+              TODO: should be precomputed
+            */
+           for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
+               if(nameToUnicodeTab[t].u == u) {
+                   name = nameToUnicodeTab[t].name;
+                   break;
+               }
+           }
+       }
+    }
 
-    /* find out the character name */
-    char*name=0;
-    if(font->isCIDFont() && u) {
+    if(font->isCIDFont()) {
        GfxCIDFont*cfont = (GfxCIDFont*)font;
-       int t;
-       for(t=0;t<sizeof(nameToUnicodeTab)/sizeof(nameToUnicodeTab[0]);t++) {
-           /* todo: should be precomputed */
-           if(nameToUnicodeTab[t].u == u) {
-               name = nameToUnicodeTab[t].name;
-               break;
-           }
+
+       if(font->getType() == fontCIDType2) {
+           CIDToGIDMap = cfont->getCIDToGID();
        }
     } else {
        Gfx8BitFont*font8;
@@ -881,13 +899,14 @@ 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",x,y,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name));
-
-    /*x1 = (int)(x1+0.5);
-    y1 = (int)(y1+0.5);*/
-    
-    int ret = swfoutput_drawchar(&output, x1, y1, name, c, u);
+    if (CIDToGIDMap) {
+       msg("<debug> drawChar(%f, %f, c='%c' (%d), GID=%d, u=%d <%d>) CID=%d name=\"%s\"\n", x, y, (c&127)>=32?c:'?', c, CIDToGIDMap[c], u, uLen, font->isCIDFont(), FIXNULL(name));
+       swfoutput_drawchar(&output, x1, y1, name, CIDToGIDMap[c], u);
+    } else {
+       msg("<debug> drawChar(%f,%f,c='%c' (%d), u=%d <%d>) CID=%d name=\"%s\"\n",x,y,(c&127)>=32?c:'?',c,u, uLen, font->isCIDFont(), FIXNULL(name));
+       swfoutput_drawchar(&output, x1, y1, name, c, u);
+    }
 }
 
 void SWFOutputDev::endString(GfxState *state) { 
@@ -937,10 +956,10 @@ void SWFOutputDev::startPage(int pageNum, GfxState *state, double crop_x1, doubl
 
     /* apply user clip box */
     if(user_clipx1|user_clipy1|user_clipx2|user_clipy2) {
-        if(user_clipx1 > x1) x1 = user_clipx1;
-        if(user_clipx2 < x2) x2 = user_clipx2;
-        if(user_clipy1 > y1) y1 = user_clipy1;
-        if(user_clipy2 < y2) y2 = user_clipy2;
+        /*if(user_clipx1 > x1)*/ x1 = user_clipx1;
+        /*if(user_clipx2 < x2)*/ x2 = user_clipx2;
+        /*if(user_clipy1 > y1)*/ y1 = user_clipy1;
+        /*if(user_clipy2 < y2)*/ y2 = user_clipy2;
     }
 
     if(!outputstarted) {
@@ -2203,6 +2222,13 @@ void swf_output_setparameter(swf_output_t*swf_output, char*name, char*value)
     pdfswf_setparameter(name, value);
 }
 
+void swf_output_pagefeed(swf_output_t*swf)
+{
+    swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+    i->outputDev->pagefeed();
+    i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2);
+}
+
 int swf_output_save(swf_output_t*swf, char*filename)
 {
     swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
@@ -2211,6 +2237,14 @@ int swf_output_save(swf_output_t*swf, char*filename)
     return ret;
 }
 
+void* swf_output_get(swf_output_t*swf)
+{
+    swf_output_internal_t*i= (swf_output_internal_t*)swf->internal;
+    void* ret = i->outputDev->getSWF();
+    i->outputDev->getDimensions(&swf->x1, &swf->y1, &swf->x2, &swf->y2);
+    return ret;
+}
+
 void swf_output_destroy(swf_output_t*output)
 {
     swf_output_internal_t*i = (swf_output_internal_t*)output->internal;