compile pdf2swf with xpdf's wordlist support
authorMatthias Kramm <kramm@quiss.org>
Thu, 8 Oct 2009 00:23:27 +0000 (17:23 -0700)
committerMatthias Kramm <kramm@quiss.org>
Thu, 8 Oct 2009 00:23:27 +0000 (17:23 -0700)
lib/pdf/Makefile.in
lib/pdf/XMLOutputDev.cc [new file with mode: 0644]
lib/pdf/XMLOutputDev.h [new file with mode: 0644]
lib/pdf/aconf.h
lib/pdf/xpdf-changes.patch
lib/rfxswf.c

index ea86f9b..55393a2 100644 (file)
@@ -8,7 +8,7 @@ all: ../libpdf$(A) pdf2swf$(E)
 
 libpdf: ../libpdf$(A)
 
-libpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) pdf.$(O) fonts.$(O)
+libpdf_objects = GFXOutputDev.$(O) InfoOutputDev.$(O) BitmapOutputDev.$(O) FullBitmapOutputDev.$(O) XMLOutputDev.$(O) pdf.$(O) fonts.$(O)
 
 xpdf_in_source = @xpdf_in_source@
 
@@ -21,7 +21,9 @@ xpdf_objects =  xpdf/GHash.$(O) xpdf/GList.$(O) xpdf/GString.$(O) xpdf/gmem.$(O)
                  xpdf/JArithmeticDecoder.$(O) xpdf/Gfx.$(O) xpdf/GfxFont.$(O) xpdf/CMap.$(O) xpdf/CharCodeToUnicode.$(O) \
                  xpdf/PSTokenizer.$(O) xpdf/FontEncodingTables.$(O) xpdf/BuiltinFont.$(O) xpdf/BuiltinFontTables.$(O) \
                  xpdf/GfxState.$(O) xpdf/Function.$(O) xpdf/Annot.$(O) xpdf/NameToCharCode.$(O) xpdf/UnicodeMap.$(O) \
-                 xpdf/SecurityHandler.$(O) #xpdf/OptionalContent.$(O)
+                 xpdf/SecurityHandler.$(O) xpdf/TextOutputDev.$(O) xpdf/UnicodeTypeTable.$(O)
+                 #xpdf/OptionalContent.$(O)
+
 
 splash_in_source = @splash_in_source@
 splash_objects = xpdf/SplashOutputDev.$(O) xpdf/SplashFont.$(O) xpdf/SplashState.$(O) xpdf/Splash.$(O) \
@@ -40,6 +42,8 @@ InfoOutputDev.$(O): InfoOutputDev.cc InfoOutputDev.h
        $(CC) -I ./ -I xpdf InfoOutputDev.cc -o $@
 BitmapOutputDev.$(O): BitmapOutputDev.cc BitmapOutputDev.h CommonOutputDev.h InfoOutputDev.h
        $(CC) -I ./ -I xpdf BitmapOutputDev.cc -o $@
+XMLOutputDev.$(O): XMLOutputDev.cc XMLOutputDev.h xpdf/TextOutputDev.h
+       $(CC) -I ./ -I xpdf XMLOutputDev.cc -o $@
 FullBitmapOutputDev.$(O): FullBitmapOutputDev.cc FullBitmapOutputDev.h CommonOutputDev.h InfoOutputDev.h
        $(CC) -I ./ -I xpdf FullBitmapOutputDev.cc -o $@
 DummyOutputDev.$(O): DummyOutputDev.cc DummyOutputDev.h InfoOutputDev.h
@@ -47,6 +51,11 @@ DummyOutputDev.$(O): DummyOutputDev.cc DummyOutputDev.h InfoOutputDev.h
 pdf.$(O): pdf.cc GFXOutputDev.h InfoOutputDev.h CommonOutputDev.h BitmapOutputDev.h FullBitmapOutputDev.h InfoOutputDev.h
        $(CC) -I ./ -I xpdf pdf.cc -o $@
 
+XPDFOK = xpdf/Gfx.cc
+$(XPDFOK): Makefile.in inject-xpdf.pl xpdf-*tar.gz xpdf*patch
+       @if test xpdf-changes.patch -nt $(XPDFOK);then perl inject-xpdf.pl xpdf-3.02.tar.gz;fi
+       @if test '!' -d xpdf;then perl inject-xpdf.pl xpdf-3.02.tar.gz;fi
+
 xpdf/UnicodeMap.$(O): xpdf/UnicodeMap.cc
        $(CC) -I ./ -I xpdf xpdf/UnicodeMap.cc -o $@
 xpdf/NameToCharCode.$(O): xpdf/NameToCharCode.cc
@@ -140,12 +149,10 @@ xpdf/%.$(O): xpdf/%.cc
        $(CC) -I ./ -I xpdf $< -o $@
 
 
-../libpdf$(A): $(libpdf_objects) $(xpdf_in_source) $(splash_in_source)
+../libpdf$(A): $(XPDFOK) $(libpdf_objects) $(xpdf_in_source) $(splash_in_source)
        $(AR) r ../libpdf$(A) $(libpdf_objects) $(xpdf_in_source) $(splash_in_source)
        $(RANLIB) ../libpdf$(A)
 
-
-
 xpdfapp_sources=xpdf/XPDFApp.cc xpdf/XPDFCore.cc xpdf/XPDFTree.cc xpdf/XPDFViewer.cc xpdf/PDFCore.cc xpdf/TextOutputDev.cc xpdf/xpdf.cc xpdf/CoreOutputDev.cc xpdf/UnicodeTypeTable.cc xpdf/PSOutputDev.cc
 splash_sources=xpdf/Splash.cc xpdf/SplashBitmap.cc xpdf/SplashClip.cc xpdf/SplashFTFont.cc xpdf/SplashFTFontEngine.cc xpdf/SplashFTFontFile.cc xpdf/SplashFont.cc xpdf/SplashFontEngine.cc xpdf/SplashFontFile.cc xpdf/SplashFontFileID.cc xpdf/SplashOutputDev.cc xpdf/SplashPath.cc xpdf/SplashPattern.cc xpdf/SplashScreen.cc xpdf/SplashState.cc xpdf/SplashT1Font.cc xpdf/SplashT1FontEngine.cc xpdf/SplashT1FontFile.cc xpdf/SplashXPath.cc xpdf/SplashXPathScanner.cc
 xpdfapp_objects=xpdf/XPDFApp.$(O) xpdf/XPDFCore.$(O) xpdf/XPDFTree.$(O) xpdf/XPDFViewer.$(O) xpdf/PDFCore.$(O) xpdf/TextOutputDev.$(O) xpdf/xpdf.$(O) xpdf/CoreOutputDev.$(O) xpdf/UnicodeTypeTable.$(O) xpdf/PSOutputDev.$(O)
@@ -154,26 +161,31 @@ xpdfapp_objects=xpdf/XPDFApp.$(O) xpdf/XPDFCore.$(O) xpdf/XPDFTree.$(O) xpdf/XPD
 xxpdf$(E): $(xpdf_objects) $(xpdfapp_objects) $(splash_objects)
        $(LL) $(CPPFLAGS) -DXPDFEXE -g -I xpdf -I . $(xpdfapp_objects) $(xpdf_objects) $(splash_objects) xpdf/parseargs.c -o xxpdf$(E) $(LIBS) -lXm -lX11
 
-pdftoppm$(E): $(xpdf_objects) $(splash_objects)
+pdftoppm$(E): $(XPDFOK) xpdf/pdftoppm.cc $(xpdf_objects) $(splash_objects)
        $(LL) $(CPPFLAGS) -DXPDFEXE -g -I xpdf -I . xpdf/pdftoppm.cc $(xpdf_objects) $(splash_objects) xpdf/parseargs.c -o pdftoppm$(E) $(LIBS)
-pdftotext$(E): $(xpdf_objects) $(splash_objects)
-       $(LL) $(CPPFLAGS) -DXPDFEXE -g -I xpdf -I . xpdf/pdftotext.cc $(xpdf_objects) xpdf/TextOutput*.cc xpdf/UnicodeType*.cc xpdf/parseargs.c -o pdftotext$(E) $(LIBS)
+pdftotext$(E): $(XPDFOK) xpdf/pdftotext.cc $(xpdf_objects)
+       $(LL) $(CPPFLAGS) -DXPDFEXE -g -I xpdf -I . xpdf/pdftotext.cc $(xpdf_objects) xpdf/parseargs.c -o pdftotext$(E) $(LIBS)
+pdfinfo$(E): $(XPDFOK) xpdf/pdfinfo.cc $(xpdf_objects)
+       $(LL) $(CPPFLAGS) -DXPDFEXE -g -I xpdf -I . xpdf/pdfinfo.cc $(xpdf_objects) xpdf/parseargs.c -o pdfinfo$(E) $(LIBS)
 
 gfx_objects = ../libgfxswf$(A) ../libgfx$(A) ../librfxswf$(A) ../libbase$(A)
 gfx_objects2 = $(gfx_objects) ../devices/lrf.$(O) ../libocr$(A)
 
-pdf2swf$(E): ../../src/pdf2swf.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects)
+pdf2swf$(E): $(XPDFOK) ../../src/pdf2swf.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects)
        $(LL) $(CPPFLAGS) -g ../../src/pdf2swf.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects) -o pdf2swf$(E) $(LIBS)
-gfx2gfx$(E): ../../src/gfx2gfx.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2)
+gfx2gfx$(E): $(XPDFOK) ../../src/gfx2gfx.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2)
        $(LL) $(CPPFLAGS) -g ../../src/gfx2gfx.c $(libpdf_objects) $(xpdf_in_source) $(splash_in_source) $(gfx_objects2) -o gfx2gfx$(E) $(LIBS)
 
 install:
+       $(mkinstalldirs) $(bindir)
+       @for file in pdfinfo pdftoppm pdftotext; do if test -f $$file;then $(INSTALL_BIN);fi;done
+
 uninstall:
 
 
 clean: 
        rm -f xpdf/*.o xpdf/*.obj *.o pdf2swf pdftoppm pdftotext pdf2swf.exe pdftoppm.exe pdftotext.exe *.obj *.lo *.a *.lib *.la gmon.out
 
-.PHONY: clean install uninstall check all
+.PHONY: clean install uninstall check all xpdf
 
 
diff --git a/lib/pdf/XMLOutputDev.cc b/lib/pdf/XMLOutputDev.cc
new file mode 100644 (file)
index 0000000..d6f1d2d
--- /dev/null
@@ -0,0 +1,126 @@
+/* XMLOutputDev.cc
+
+   This file is part of swftools.
+
+   Swftools is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Swftools is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with swftools; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#include "../../config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "gfile.h"
+#include "XMLOutputDev.h"
+#include "GfxState.h"
+
+XMLOutputDev::XMLOutputDev(char*filename)
+:TextOutputDev(mktmpname(0), false, false, false)
+{
+  out = fopen(filename, "wb");
+  if(!out) {
+      perror(filename);
+      exit(-1);
+  }
+  fprintf(out, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
+  fprintf(out, "<document>\n");
+}
+
+XMLOutputDev::~XMLOutputDev()
+{
+  fprintf(out, "</document>\n");
+  fclose(out);
+}
+
+void XMLOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2)
+{
+    TextOutputDev::startPage(pageNum, state, x1, y1, x2, y2);
+    fprintf(out, "<page nr=\"%d\" width=\"%.0f\" height=\"%.0f\">\n", pageNum,
+       state->getPageWidth(), state->getPageHeight());
+}
+
+void XMLOutputDev::endPage()
+{
+    TextOutputDev::endPage();
+    TextWordList* list = makeWordList();
+    int len = list->getLength();
+    int i;
+
+    char textTag = 0;
+    GString*fontname = new GString();
+    double fontsize = -99999;
+    double base = -9999;
+    for(i=0;i<len;i++) {
+       TextWord*word = list->get(i);
+       GString*newfont = word->getFontName();
+       double newsize = word->getFontSize();
+       double newbase = word->base;
+
+       if((newfont && newfont->cmp(fontname)) || 
+          newsize != fontsize ||
+          newbase != base) 
+       {
+           TextFontInfo*info = word->getFontInfo();
+           if(textTag)
+               fprintf(out, "</t>\n");
+           textTag = 1;
+           GBool italic = gFalse;
+           GBool bold = gFalse;
+           GBool serif = gFalse;
+
+           if(info->isItalic()) italic = gTrue;
+           if(info->isBold()) bold = gTrue;
+           if(info->isSerif()) serif = gTrue;
+           char*name = (char*)"";
+           if(newfont) {
+               name = newfont->lowerCase()->getCString();
+               if(strlen(name)>7 && name[6]=='+')
+                   name += 7;
+               if(strstr(name, "ital")) italic = gTrue;
+               if(strstr(name, "slan")) italic = gTrue;
+               if(strstr(name, "obli")) italic = gTrue;
+               if(strstr(name, "bold")) bold = gTrue;
+               if(strstr(name, "heav")) bold = gTrue;
+               if(strstr(name, "medi")) bold = gTrue;
+               if(strstr(name, "serif")) serif = gTrue;
+           }
+           
+           fprintf(out, "<t font=\"%s\" y=\"%f\" x=\"%f\" style=\"%s%s%s%s\" fontsize=\"%.0fpt\">", 
+                   name,
+                   newbase,
+                   (word->rot&1)?word->yMin:word->xMin,
+                   info->isFixedWidth()?"fixed;":"",
+                   serif?"serif;":"",
+                   italic?"italic;":"",
+                   bold?"bold;":"",
+                   newsize);
+           fontname = newfont->copy();
+           fontsize = newsize;
+           base = newbase;
+       }
+       char*s = word->getText()->getCString();
+       while(*s) {
+           switch(*s) {
+               case '<': fprintf(out, "&lt;");break;
+               case '>': fprintf(out, "&gt;");break;
+               case '&': fprintf(out, "&amp;");break;
+               default: fwrite(s, 1, 1, out);
+           }
+           s++;
+       }
+       if(word->spaceAfter)
+           fprintf(out, " ");
+    }
+    if(textTag) fprintf(out, "</t>\n");
+    fprintf(out, "</page>\n");
+}
+
diff --git a/lib/pdf/XMLOutputDev.h b/lib/pdf/XMLOutputDev.h
new file mode 100644 (file)
index 0000000..b06c231
--- /dev/null
@@ -0,0 +1,35 @@
+/* XMLOutputDev.h
+   
+   This file is part of swftools.
+
+   Swftools is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   Swftools is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with swftools; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+
+#ifndef __xmloutputdev_h__
+#define __xmloutputdev_h__
+
+#include "OutputDev.h"
+#include "TextOutputDev.h"
+
+class XMLOutputDev: public TextOutputDev
+{
+    public:
+       XMLOutputDev(char*filename);
+        virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
+       virtual void endPage();
+       virtual ~XMLOutputDev();
+    private:
+       FILE*out;
+};
+#endif //__xmloutputdev_h__
index 61878ec..53817a4 100644 (file)
@@ -13,6 +13,8 @@
 
 #define HAVE_STRINGS_H 1
 
+#define TEXTOUT_WORD_LIST 1
+
 // todo:
 //
 // HAVE_STRINGS_H
index e3d8481..dbc02ae 100644 (file)
@@ -541,17 +541,6 @@ diff -u -r1.5 -r1.6
    int w, h;
    double *ctm;
    SplashCoord mat[6];
---- TextOutputDev.h    2006-11-12 12:23:01.000000000 +0100
-+++ TextOutputDev.h    2006-11-12 12:25:31.000000000 +0100
-@@ -578,7 +578,7 @@
-   //----- initialization and control
-   // Start a page.
--  virtual void startPage(int pageNum, GfxState *state);
-+  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
-   // End a page.
-   virtual void endPage();
 --- TextOutputDev.cc   2006-11-12 12:22:53.000000000 +0100
 +++ TextOutputDev.cc   2006-11-12 12:25:03.000000000 +0100
 @@ -3805,7 +3805,7 @@
@@ -986,3 +975,22 @@ diff -u -r1.5 -r1.6
      out->endTransparencyGroup(state);
    }
  
+--- TextOutputDev.h.orig       2009-10-07 17:00:29.000000000 -0700
++++ TextOutputDev.h    2009-10-07 17:01:50.000000000 -0700
+@@ -170,6 +170,7 @@
+   friend class TextFlow;
+   friend class TextWordList;
+   friend class TextPage;
++  friend class XMLOutputDev;
+ };
+ //------------------------------------------------------------------------
+@@ -578,7 +579,7 @@
+   //----- initialization and control
+   // Start a page.
+-  virtual void startPage(int pageNum, GfxState *state);
++  virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
+   // End a page.
+   virtual void endPage();
index c4f42e8..f6353a3 100644 (file)
@@ -415,7 +415,6 @@ float swf_GetF16(TAG * t)
     U32 f2 = (f1&0x8000)<<16; //sign
     f2 |= ((f1&0x7c00)<<13)+(0x40000000-(0x4000<<13)); //exp
     f2 |= (f1&0x03ff)<<13; //mantissa
-    fprintf(stderr, "%f = %d-%d-%x\n", *(float*)&f2, f1>>15, (f1>>10)&31, f1&0x3ff);
     return *(float*)&f2;
 }
 void swf_SetF16(TAG * t, float f)