[poppler] utils/HtmlOutputDev.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Mar 15 16:08:26 PDT 2012


 utils/HtmlOutputDev.cc |   50 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

New commits:
commit 4a9238441a5317c3304296e4e6430cccefe8322c
Author: Ihar Filipau <thephilips at gmail.com>
Date:   Fri Mar 16 00:07:45 2012 +0100

    Flip images if they need to
    
    Bug 32340

diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 82464df..3d8836b 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -777,6 +777,42 @@ void HtmlPage::dumpAsXML(FILE* f,int page){
   fputs("</page>\n",f);
 }
 
+static void printCSS(FILE *f)
+{
+  // Image flip/flop CSS
+  // Source:
+  // http://stackoverflow.com/questions/1309055/cross-browser-way-to-flip-html-image-via-javascript-css
+  // tested in Chrome, Fx (Linux) and IE9 (W7)
+  static const char css[] = 
+    "<STYLE type=\"text/css\">" "\n"
+    "<!--" "\n"
+    ".xflip {" "\n"
+    "    -moz-transform: scaleX(-1);" "\n"
+    "    -webkit-transform: scaleX(-1);" "\n"
+    "    -o-transform: scaleX(-1);" "\n"
+    "    transform: scaleX(-1);" "\n"
+    "    filter: fliph;" "\n"
+    "}" "\n"
+    ".yflip {" "\n"
+    "    -moz-transform: scaleY(-1);" "\n"
+    "    -webkit-transform: scaleY(-1);" "\n"
+    "    -o-transform: scaleY(-1);" "\n"
+    "    transform: scaleY(-1);" "\n"
+    "    filter: flipv;" "\n"
+    "}" "\n"
+    ".xyflip {" "\n"
+    "    -moz-transform: scaleX(-1) scaleY(-1);" "\n"
+    "    -webkit-transform: scaleX(-1) scaleY(-1);" "\n"
+    "    -o-transform: scaleX(-1) scaleY(-1);" "\n"
+    "    transform: scaleX(-1) scaleY(-1);" "\n"
+    "    filter: fliph + flipv;" "\n"
+    "}" "\n"
+    "-->" "\n"
+    "</STYLE>" "\n";
+
+  fwrite( css, sizeof(css)-1, 1, f );
+}
+
 int HtmlPage::dumpComplexHeaders(FILE * const file, FILE *& pageFile, int page) {
   GooString* tmp;
 
@@ -905,7 +941,14 @@ void HtmlPage::dump(FILE *f, int pageNum)
     int listlen=imgList->getLength();
     for (int i = 0; i < listlen; i++) {
       HtmlImage *img = (HtmlImage*)imgList->del(0);
-      fprintf(f,"<IMG src=\"%s\"/><br/>\n",img->fName->getCString());
+
+      // see printCSS() for class names
+      const char *styles[4] = { "", " class=\"xflip\"", " class=\"yflip\"", " class=\"xyflip\"" };
+      int style_index=0;
+      if (img->xMin > img->xMax) style_index += 1; // xFlip
+      if (img->yMin > img->yMax) style_index += 2; // yFlip
+
+      fprintf(f,"<IMG%s src=\"%s\"/><br/>\n",styles[style_index],img->fName->getCString());
       delete img;
     }
 
@@ -1124,7 +1167,9 @@ HtmlOutputDev::HtmlOutputDev(Catalog *catalogA, char *fileName, char *title,
        }
        delete right;
        fputs(DOCTYPE, page);
-       fputs("<HTML>\n<HEAD>\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n",page);
+       fputs("<HTML>\n<HEAD>\n<TITLE></TITLE>\n",page);
+       printCSS(page);
+       fputs("</HEAD>\n<BODY>\n",page);
      }
   }
 
@@ -1156,6 +1201,7 @@ HtmlOutputDev::HtmlOutputDev(Catalog *catalogA, char *fileName, char *title,
       fprintf(page, "<META http-equiv=\"Content-Type\" content=\"text/html; charset=%s\"/>\n", htmlEncoding->getCString());
       
       dumpMetaVars(page);
+      printCSS(page);
       fprintf(page,"</HEAD>\n");
       fprintf(page,"<BODY bgcolor=\"#A0A0A0\" vlink=\"blue\" link=\"blue\">\n");
     }


More information about the poppler mailing list