[poppler] poppler/qt: Makefile.am, 1.11, 1.12 poppler-document.cc, 1.9, 1.10 poppler-page.cc, 1.15, 1.16 poppler-private.h, 1.6, 1.7 poppler-qt.h, 1.16, 1.17

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jun 25 03:29:25 PDT 2006


Update of /cvs/poppler/poppler/qt
In directory kemper:/tmp/cvs-serv15717/qt

Modified Files:
	Makefile.am poppler-document.cc poppler-page.cc 
	poppler-private.h poppler-qt.h 
Log Message:
add link support to qt3 frontend.
Patch by Wilfried Huss based on Qt4 code


Index: Makefile.am
===================================================================
RCS file: /cvs/poppler/poppler/qt/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Makefile.am	28 Feb 2006 23:24:59 -0000	1.11
+++ Makefile.am	25 Jun 2006 10:29:22 -0000	1.12
@@ -10,12 +10,14 @@
 poppler_includedir = $(includedir)/poppler
 poppler_include_HEADERS =			\
 	poppler-qt.h				\
-	poppler-page-transition.h
+	poppler-page-transition.h               \
+	poppler-link.h
 
 lib_LTLIBRARIES = libpoppler-qt.la
 libpoppler_qt_la_SOURCES =			\
 	poppler-document.cc			\
 	poppler-fontinfo.cc			\
+	poppler-link.cc                         \
 	poppler-page.cc				\
 	poppler-page-transition.cc		\
 	poppler-page-transition-private.h	\

Index: poppler-document.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-document.cc,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- poppler-document.cc	1 Jun 2006 17:23:45 -0000	1.9
+++ poppler-document.cc	25 Jun 2006 10:29:22 -0000	1.10
@@ -137,16 +137,6 @@
 }
 
 /* borrowed from kpdf */
-static QString unicodeToQString(Unicode* u, int len) {
-  QString ret;
-  ret.setLength(len);
-  QChar* qch = (QChar*) ret.unicode();
-  for (;len;--len)
-    *qch++ = (QChar) *u++;
-  return ret;
-}
-
-/* borrowed from kpdf */
 QString Document::getInfo( const QString & type ) const
 {
   // [Albert] Code adapted from pdfinfo.cc on xpdf
@@ -294,6 +284,15 @@
   return data->doc.getPDFVersion();
 }
 
+LinkDestination *Document::linkDestination( const QString &name )
+{
+  UGooString * namedDest = QStringToUGooString( name );
+  LinkDestinationData ldd(NULL, namedDest, data);
+  LinkDestination *ld = new LinkDestination(ldd);
+  delete namedDest;
+  return ld;
+}
+
 bool Document::print(const QString &file, QValueList<int> pageList, double hDPI, double vDPI, int rotate)
 {
   PSOutputDev *psOut = new PSOutputDev(file.latin1(), data->doc.getXRef(), data->doc.getCatalog(), 1, data->doc.getNumPages(), psModePS);

Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-page.cc,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- poppler-page.cc	21 May 2006 18:14:15 -0000	1.15
+++ poppler-page.cc	25 Jun 2006 10:29:22 -0000	1.16
@@ -52,18 +52,18 @@
   delete data;
 }
 
-void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const
+void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, bool doLinks) const
 {
-  renderToPixmap(q, x, y, w, h, 72.0, 72.0);
+  renderToPixmap(q, x, y, w, h, 72.0, 72.0, doLinks);
 }
 
-void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const
+void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres, bool doLinks) const
 {
-  QImage img = renderToImage(xres, yres);
+  QImage img = renderToImage(xres, yres, doLinks);
   *q = new QPixmap( img );
 }
 
-QImage Page::renderToImage(double xres, double yres) const
+QImage Page::renderToImage(double xres, double yres, bool doLinks) const
 {
   SplashOutputDev *output_dev;
   SplashBitmap *bitmap;
@@ -71,7 +71,7 @@
   output_dev = data->doc->data->getOutputDev();
 
   data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres,
-      0, false, false, false, -1, -1, -1, -1);
+      0, false, false, doLinks, -1, -1, -1, -1);
   bitmap = output_dev->getBitmap ();
   color_ptr = bitmap->getDataPtr ();
   int bw = output_dev->getBitmap()->getWidth();
@@ -210,5 +210,129 @@
   }
 }
 
+QValueList<Link*> Page::links() const
+{
+  QValueList<Link*> popplerLinks;
+
+  Links *xpdfLinks = data->doc->data->doc.takeLinks();
+  for (int i = 0; i < xpdfLinks->getNumLinks(); ++i)
+  {
+    ::Link *xpdfLink = xpdfLinks->getLink(i);
+    
+    double left, top, right, bottom;
+    int leftAux, topAux, rightAux, bottomAux;
+    xpdfLink->getRect( &left, &top, &right, &bottom );
+    QRect linkArea;
+    
+    data->doc->data->m_outputDev->cvtUserToDev( left, top, &leftAux, &topAux );
+    data->doc->data->m_outputDev->cvtUserToDev( right, bottom, &rightAux, &bottomAux );
+    linkArea.setLeft(leftAux);
+    linkArea.setTop(topAux);
+    linkArea.setRight(rightAux);
+    linkArea.setBottom(bottomAux);
+
+    if (!xpdfLink->isOk()) continue;
+
+    Link *popplerLink = NULL;
+    ::LinkAction *a = xpdfLink->getAction();
+    if ( a )
+    {
+      switch ( a->getKind() )
+      {
+        case actionGoTo:
+        {
+          LinkGoTo * g = (LinkGoTo *) a;
+          // create link: no ext file, namedDest, object pointer
+          popplerLink = new LinkGoto( linkArea, QString::null, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), data->doc->data ) ) );
+        }
+        break;
+
+        case actionGoToR:
+        {
+          LinkGoToR * g = (LinkGoToR *) a;
+          // copy link file
+          const char * fileName = g->getFileName()->getCString();
+          // ceate link: fileName, namedDest, object pointer
+          popplerLink = new LinkGoto( linkArea, (QString)fileName, LinkDestination( LinkDestinationData(g->getDest(), g->getNamedDest(), data->doc->data ) ) );
+        }
+        break;
+
+        case actionLaunch:
+	{
+          LinkLaunch * e = (LinkLaunch *)a;
+          GooString * p = e->getParams();
+          popplerLink = new LinkExecute( linkArea, e->getFileName()->getCString(), p ? p->getCString() : 0 );
+	}
+        break;
+
+        case actionNamed:
+	{
+          const char * name = ((LinkNamed *)a)->getName()->getCString();
+          if ( !strcmp( name, "NextPage" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::PageNext );
+          else if ( !strcmp( name, "PrevPage" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::PagePrev );
+          else if ( !strcmp( name, "FirstPage" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::PageFirst );
+          else if ( !strcmp( name, "LastPage" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::PageLast );
+          else if ( !strcmp( name, "GoBack" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::HistoryBack );
+          else if ( !strcmp( name, "GoForward" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::HistoryForward );
+          else if ( !strcmp( name, "Quit" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::Quit );
+          else if ( !strcmp( name, "GoToPage" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::GoToPage );
+          else if ( !strcmp( name, "Find" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::Find );
+          else if ( !strcmp( name, "FullScreen" ) )
+              popplerLink = new LinkAction( linkArea, LinkAction::Presentation );
+          else if ( !strcmp( name, "Close" ) )
+          {
+              // acroread closes the document always, doesnt care whether 
+              // its presentation mode or not
+              // popplerLink = new LinkAction( linkArea, LinkAction::EndPresentation );
+              popplerLink = new LinkAction( linkArea, LinkAction::Close );
+          }
+          else
+          {
+                // TODO
+          }
+	}
+        break;
+
+        case actionURI:
+	{
+          popplerLink = new LinkBrowse( linkArea, ((LinkURI *)a)->getURI()->getCString() );
+	}
+        break;
+
+        case actionMovie:
+/*      TODO this (Movie link)
+          m_type = Movie;
+          LinkMovie * m = (LinkMovie *) a;
+          // copy Movie parameters (2 IDs and a const char *)
+          Ref * r = m->getAnnotRef();
+          m_refNum = r->num;
+          m_refGen = r->gen;
+          copyString( m_uri, m->getTitle()->getCString() );
+*/      break;
+
+        case actionUnknown:
+        break;
+      }
+    }
+    
+    if (popplerLink)
+    {
+      popplerLinks.append(popplerLink);
+    }
+  }
+
+  delete xpdfLinks;
+  
+  return popplerLinks;
+}
 
 }

Index: poppler-private.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-private.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- poppler-private.h	23 May 2006 20:49:16 -0000	1.6
+++ poppler-private.h	25 Jun 2006 10:29:22 -0000	1.7
@@ -16,12 +16,43 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <Object.h>
 #include <SplashOutputDev.h>
+#include <Link.h>
 #include <PDFDoc.h>
 #include <FontInfo.h>
-#include <Object.h>
+#include <UGooString.h>
 
 namespace Poppler {
+    
+/* borrowed from kpdf */
+static QString unicodeToQString(Unicode* u, int len) {
+  QString ret;
+  ret.setLength(len);
+  QChar* qch = (QChar*) ret.unicode();
+  for (;len;--len)
+    *qch++ = (QChar) *u++;
+  return ret;
+}
+
+static UGooString *QStringToUGooString(const QString &s) {
+  int len = s.length();
+  Unicode *u = (Unicode *)gmallocn(s.length(), sizeof(Unicode));
+  for (int i = 0; i < len; ++i)
+    u[i] = s.at(i).unicode();
+  return new UGooString(u, len);
+}
+    
+class LinkDestinationData {
+  public:
+     LinkDestinationData( LinkDest *l, UGooString *nd, Poppler::DocumentData *pdfdoc ) : ld(l), namedDest(nd), doc(pdfdoc)
+     {
+     }
+	
+     LinkDest *ld;
+     UGooString *namedDest;
+     Poppler::DocumentData *doc;
+};
 
 class DocumentData {
   public:

Index: poppler-qt.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-qt.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- poppler-qt.h	1 Jun 2006 17:23:45 -0000	1.16
+++ poppler-qt.h	25 Jun 2006 10:29:22 -0000	1.17
@@ -24,6 +24,7 @@
 #include <qdatetime.h>
 #include <qpixmap.h>
 
+#include <poppler-link.h>
 #include <poppler-page-transition.h>
 
 namespace Poppler {
@@ -125,7 +126,7 @@
   friend class Document;
   public:
     ~Page();
-    void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const;
+    void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres, bool doLinks = false) const;
 
     /**
       This is a convenience function that is equivalent to
@@ -134,7 +135,7 @@
 
       \sa renderToImage()
      */
-    void renderToPixmap(QPixmap **q, int x, int y, int w, int h) const;
+    void renderToPixmap(QPixmap **q, int x, int y, int w, int h, bool doLinks = false) const;
 
     /**
       \brief Render the page to a QImage using the Splash renderer
@@ -152,7 +153,7 @@
 
      \sa renderToPixmap()
     */
-    QImage renderToImage(double xres = 72.0, double yres = 72.0) const;
+    QImage renderToImage(double xres = 72.0, double yres = 72.0, bool doLinks = false) const;
 
     /**
      * Returns the size of the page in points
@@ -184,6 +185,11 @@
     **/
     Orientation orientation() const;
     
+    /**
+      Gets the links of the page once it has been rendered if doLinks was true
+    */
+    QValueList<Link*> links() const;
+
   private:
     Page(const Document *doc, int index);
     PageData *data;
@@ -247,6 +253,8 @@
   */
   bool scanForFonts( int numPages, QValueList<FontInfo> *fontList ) const;
 
+  LinkDestination *linkDestination( const QString &name );
+
   ~Document();
   
 private:



More information about the poppler mailing list