[poppler] poppler/qt: poppler-page.cc,1.7,1.8 poppler-qt.h,1.8,1.9

Albert Astals Cid aacid at freedesktop.org
Mon Nov 21 14:12:18 PST 2005


Update of /cvs/poppler/poppler/qt
In directory gabe:/tmp/cvs-serv10647/qt

Modified Files:
	poppler-page.cc poppler-qt.h 
Log Message:
PAtch to add some more functions to the qt binding by Stefan Kebekus


Index: poppler-page.cc
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-page.cc,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- poppler-page.cc	30 Oct 2005 20:29:05 -0000	1.7
+++ poppler-page.cc	21 Nov 2005 22:12:16 -0000	1.8
@@ -157,6 +157,11 @@
 
 void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h) const
 {
+  renderToPixmap(q, x, y, w, h, 72.0, 72.0);
+}
+
+void Page::renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const
+{
   SplashOutputDev *output_dev;
   SplashBitmap *bitmap;
   SplashColor white;
@@ -167,7 +172,7 @@
   output_dev = new SplashOutputDev(splashModeRGB8, 4, gFalse, white);
   output_dev->startDoc(data->doc->data->doc.getXRef ());
   
-  data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72,
+  data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, xres, yres,
       0, false, false, false, -1, -1, -1, -1);
   bitmap = output_dev->getBitmap ();
   color_ptr = bitmap->getDataPtr ();
@@ -223,6 +228,41 @@
   return result;
 }
 
+QValueList<TextBox*> Page::textList() const
+{
+  TextOutputDev *output_dev;
+  
+  QValueList<TextBox*> output_list;
+  
+  output_dev = new TextOutputDev(0, gFalse, gFalse, gFalse);
+
+  data->doc->data->doc.displayPageSlice(output_dev, data->index + 1, 72, 72,
+      0, false, false, false, -1, -1, -1, -1);
+
+  TextWordList *word_list = output_dev->makeWordList();
+  
+  if (!word_list) {
+    delete output_dev;
+    return output_list;
+  }
+  
+  for (int i = 0; i < word_list->getLength(); i++) {
+    TextWord *word = word_list->get(i);
+    QString string = QString::fromUtf8(word->getText()->getCString());
+    double xMin, yMin, xMax, yMax;
+    word->getBBox(&xMin, &yMin, &xMax, &yMax);
+    
+    TextBox* text_box = new TextBox(string, Rectangle(xMin, yMin, xMax, yMax));
+    
+    output_list.append(text_box);
+  }
+  
+  delete word_list;
+  delete output_dev;
+  
+  return output_list;
+}
+
 PageTransition *Page::getTransition() const
 {
   if (!data->transition) 
@@ -236,4 +276,31 @@
   return data->transition;
 }
 
+QSize Page::pageSize() const
+{
+  ::Page *p = data->doc->data->doc.getCatalog()->getPage(data->index + 1);
+  return QSize( (int)p->getMediaWidth(), (int)p->getMediaHeight() );
+}
+
+Page::Orientation Page::orientation() const
+{
+  ::Page *p = data->doc->data->doc.getCatalog()->getPage(data->index + 1);
+
+  int rotation = p->getRotate();
+  switch (rotation) {
+  case 90:
+    return Page::Landscape;
+    break;
+  case 180:
+    return Page::UpsideDown;
+    break;
+  case 270:
+    return Page::Seascape;
+    break;
+  default:
+    return Page::Portrait;
+  }
+}
+
+
 }

Index: poppler-qt.h
===================================================================
RCS file: /cvs/poppler/poppler/qt/poppler-qt.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- poppler-qt.h	26 Jun 2005 23:35:27 -0000	1.8
+++ poppler-qt.h	21 Nov 2005 22:12:16 -0000	1.9
@@ -43,6 +43,21 @@
     double m_y2;
 };
 
+class TextBox
+{
+ public:
+    TextBox(const QString& text, const Rectangle &bBox) :
+    m_text(text), m_bBox(bBox) {};
+
+    QString getText() const { return m_text; };
+    Rectangle getBoundingBox() const { return m_bBox; };
+
+  private:
+    QString m_text;
+    Rectangle m_bBox;
+};
+
+
 class PageTransitionData;
 class PageTransition
 {
@@ -118,18 +133,44 @@
   friend class Document;
   public:
     ~Page();
+    void renderToPixmap(QPixmap **q, int x, int y, int w, int h, double xres, double yres) const;
+
+    /**
+     * This is a convenience function that is equivalent to
+     * renderToPixmap() with xres and yres set to 72.0. We keep it
+     * only for binary compatibility
+     **/
     void renderToPixmap(QPixmap **q, int x, int y, int w, int h) const;
     
     /**
+     * Returns the size of the page in points
+     **/
+    QSize pageSize() const;
+
+    /**
     * Returns the text that is inside the Rectangle r
     * If r is a null Rectangle all text of the page is given
     **/
     QString getText(const Rectangle &r) const;
 
+    QValueList<TextBox*> textList() const;
+
     /**
     * Returns the transition of this page
     **/
     PageTransition *getTransition() const;
+
+    enum Orientation {
+      Landscape,
+      Portrait,
+      Seascape,
+      UpsideDown
+    };
+
+    /**
+    *  The orientation of the page
+    **/
+    Orientation orientation() const;
     
   private:
     Page(const Document *doc, int index);



More information about the poppler mailing list