summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2005-12-30 22:31:32 +0000
committerAlbert Astals Cid <aacid@kde.org>2005-12-30 22:31:32 +0000
commitcf6f8123af19aca4200b58a454652f68ce8132e2 (patch)
tree127328f713c2796b6a991241e769f8e511953e5a
parent56035ab199ac6deb5c1e07e745d120d1121a5960 (diff)
Puting PageTransition implementation into poppler "core", both Qt and Qt4 frontends use it.
-rw-r--r--poppler/Makefile.am1
-rw-r--r--poppler/PageTransition.cc188
-rw-r--r--poppler/PageTransition.h118
-rw-r--r--poppler/Private.h30
-rw-r--r--qt/Makefile.am2
-rw-r--r--qt/poppler-page.cc111
-rw-r--r--qt/poppler-qt.h72
-rw-r--r--qt4/src/Makefile.am2
-rw-r--r--qt4/src/poppler-page.cc17
-rw-r--r--qt4/src/poppler-qt4.h14
10 files changed, 374 insertions, 181 deletions
diff --git a/poppler/Makefile.am b/poppler/Makefile.am
index 42bc5bd5..d2586bee 100644
--- a/poppler/Makefile.am
+++ b/poppler/Makefile.am
@@ -185,6 +185,7 @@ libpoppler_la_SOURCES = \
Outline.cc \
OutputDev.cc \
Page.cc \
+ PageTransition.cc \
Parser.cc \
PDFDoc.cc \
PDFDocEncoding.cc \
diff --git a/poppler/PageTransition.cc b/poppler/PageTransition.cc
new file mode 100644
index 00000000..1145a04d
--- /dev/null
+++ b/poppler/PageTransition.cc
@@ -0,0 +1,188 @@
+/* PageTransition.cc
+ * Copyright (C) 2005, Net Integration Technologies, Inc.
+ *
+ * This program 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, or (at your option)
+ * any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <iostream>
+
+#include "Object.h"
+#include "PageTransition.h"
+#include "Private.h"
+
+namespace Poppler {
+
+class PageTransitionData
+{
+ public:
+ PageTransition::Type type;
+ int duration;
+ PageTransition::Alignment alignment;
+ PageTransition::Direction direction;
+ int angle;
+ double scale;
+ bool rectangular;
+};
+
+PageTransition::PageTransition(const PageTransitionParams &params)
+{
+ data = new PageTransitionData();
+ data->type = Replace;
+ data->duration = 1;
+ data->alignment = Horizontal;
+ data->direction = Inward;
+ data->angle = 0;
+ data->scale = 1.0;
+ data->rectangular = false;
+
+ // Paranoid safety checks
+ if (params.dictObj == 0) {
+ std::cerr << "ERROR in the poppler library: the method PageTransition_x::PageTransition_x(Object *params.dictObj) was called with params.dictObj==0\n";
+ return;
+ }
+ if (params.dictObj->isDict() == false) {
+ std::cerr << "ERROR in the poppler library: the method PageTransition_x::PageTransition_x(Object *params.dictObj) was called where params.dictObj->isDict()==false\n";
+ return;
+ }
+
+ // Obtain a pointer to the dictionary and start parsing.
+ Dict *transDict = params.dictObj->getDict();
+ Object obj;
+
+ if (transDict->lookup("S", &obj)->isName()) {
+ const char *s = obj.getName();
+ if (strcmp("R", s) == 0)
+ data->type = Replace;
+ else if (strcmp("Split", s) == 0)
+ data->type = Split;
+ else if (strcmp("Blinds", s) == 0)
+ data->type = Blinds;
+ else if (strcmp("Box", s) == 0)
+ data->type = Box;
+ else if (strcmp("Wipe", s) == 0)
+ data->type = Wipe;
+ else if (strcmp("Dissolve", s) == 0)
+ data->type = Dissolve;
+ else if (strcmp("Glitter", s) == 0)
+ data->type = Glitter;
+ else if (strcmp("Fly", s) == 0)
+ data->type = Fly;
+ else if (strcmp("Push", s) == 0)
+ data->type = Push;
+ else if (strcmp("Cover", s) == 0)
+ data->type = Cover;
+ else if (strcmp("Uncover", s) == 0)
+ data->type = Push;
+ else if (strcmp("Fade", s) == 0)
+ data->type = Cover;
+ }
+ obj.free();
+
+ if (transDict->lookup("D", &obj)->isInt()) {
+ data->duration = obj.getInt();
+ }
+ obj.free();
+
+ if (transDict->lookup("Dm", &obj)->isName()) {
+ const char *dm = obj.getName();
+ if ( strcmp( "H", dm ) == 0 )
+ data->alignment = Horizontal;
+ else if ( strcmp( "V", dm ) == 0 )
+ data->alignment = Vertical;
+ }
+ obj.free();
+
+ if (transDict->lookup("M", &obj)->isName()) {
+ const char *m = obj.getName();
+ if ( strcmp( "I", m ) == 0 )
+ data->direction = Inward;
+ else if ( strcmp( "O", m ) == 0 )
+ data->direction = Outward;
+ }
+ obj.free();
+
+ if (transDict->lookup("Di", &obj)->isInt()) {
+ data->angle = obj.getInt();
+ }
+ obj.free();
+
+ if (transDict->lookup("Di", &obj)->isName()) {
+ if ( strcmp( "None", obj.getName() ) == 0 )
+ data->angle = 0;
+ }
+ obj.free();
+
+ if (transDict->lookup("SS", &obj)->isReal()) {
+ data->scale = obj.getReal();
+ }
+ obj.free();
+
+ if (transDict->lookup("B", &obj)->isBool()) {
+ data->rectangular = obj.getBool();
+ }
+ obj.free();
+}
+
+PageTransition::PageTransition(const PageTransition &pt)
+{
+ data = new PageTransitionData();
+ data->type = pt.data->type;
+ data->duration = pt.data->duration;
+ data->alignment = pt.data->alignment;
+ data->direction = pt.data->direction;
+ data->angle = pt.data->angle;
+ data->scale = pt.data->scale;
+ data->rectangular = pt.data->rectangular;
+}
+
+PageTransition::~PageTransition()
+{
+}
+
+PageTransition::Type PageTransition::type() const
+{
+ return data->type;
+}
+
+int PageTransition::duration() const
+{
+ return data->duration;
+}
+
+PageTransition::Alignment PageTransition::alignment() const
+{
+ return data->alignment;
+}
+
+PageTransition::Direction PageTransition::direction() const
+{
+ return data->direction;
+}
+
+int PageTransition::angle() const
+{
+ return data->angle;
+}
+
+double PageTransition::scale() const
+{
+ return data->scale;
+}
+bool PageTransition::isRectangular() const
+{
+ return data->rectangular;
+}
+
+}
diff --git a/poppler/PageTransition.h b/poppler/PageTransition.h
new file mode 100644
index 00000000..db86ced4
--- /dev/null
+++ b/poppler/PageTransition.h
@@ -0,0 +1,118 @@
+/* PageTransition.h
+ * Copyright (C) 2005, Net Integration Technologies, Inc.
+ * Copyright (C) 2005, Brad Hards <bradh@frogmouth.net>
+ *
+ * This program 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, or (at your option)
+ * any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PAGETRANSITION_X_H__
+#define __PAGETRANSITION_X_H__
+
+class PageTransitionParams;
+
+namespace Poppler {
+
+class PageTransitionData;
+
+class PageTransition {
+ public:
+ enum Type {
+ Replace,
+ Split,
+ Blinds,
+ Box,
+ Wipe,
+ Dissolve,
+ Glitter,
+ Fly,
+ Push,
+ Cover,
+ Uncover,
+ Fade
+ };
+
+ enum Alignment {
+ Horizontal,
+ Vertical
+ };
+
+ enum Direction {
+ Inward,
+ Outward
+ };
+
+ /** \brief Construct a new PageTransition object from a page dictionary.
+
+ In case or error, this method will print an error message to stderr,
+ and construct a default object.
+
+ @param dictObj pointer to an object whose dictionary will be read
+ and parsed. The pointer dictObj must point to a valid object, whose
+ dictionaries are accessed by the constructor. The dictObj is only
+ accessed by this constructor, and may be deleted after the
+ constructor returns.
+ */
+ PageTransition(const PageTransitionParams &params);
+
+ PageTransition(const PageTransition &pt);
+
+ /**
+ Destructor
+ */
+ ~PageTransition();
+
+ /**
+ \brief Get type of the transition.
+ */
+ Type type() const;
+
+ /**
+ \brief Get duration of the transition in seconds.
+ */
+ int duration() const;
+
+ /**
+ \brief Get dimension in which the transition effect occurs.
+ */
+ Alignment alignment() const;
+
+ /**
+ \brief Get direction of motion of the transition effect.
+ */
+ Direction direction() const;
+
+ /**
+ \brief Get direction in which the transition effect moves.
+ */
+ int angle() const;
+
+ /**
+ \brief Get starting or ending scale.
+ */
+ double scale() const;
+
+ /**
+ \brief Returns true if the area to be flown is rectangular and
+ opaque.
+ */
+ bool isRectangular() const;
+
+ private:
+ PageTransitionData *data;
+};
+
+}
+
+#endif
diff --git a/poppler/Private.h b/poppler/Private.h
new file mode 100644
index 00000000..dc6a0241
--- /dev/null
+++ b/poppler/Private.h
@@ -0,0 +1,30 @@
+/* Private.h
+ * Copyright (C) 2005, Albert Astals Cid <aacid@kde.org>
+ *
+ * This program 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, or (at your option)
+ * any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PRIVATE_H__
+#define __PRIVATE_H__
+
+class Object;
+
+class PageTransitionParams
+{
+ public:
+ Object *dictObj;
+};
+
+#endif
diff --git a/qt/Makefile.am b/qt/Makefile.am
index 78c5b236..91757085 100644
--- a/qt/Makefile.am
+++ b/qt/Makefile.am
@@ -9,7 +9,7 @@ INCLUDES = \
poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
- poppler-qt.h
+ poppler-qt.h ../poppler/PageTransition.h
lib_LTLIBRARIES=libpoppler-qt.la
libpoppler_qt_la_SOURCES = \
diff --git a/qt/poppler-page.cc b/qt/poppler-page.cc
index 6e292a3f..691e02d3 100644
--- a/qt/poppler-page.cc
+++ b/qt/poppler-page.cc
@@ -22,6 +22,7 @@
#include <qimage.h>
#include <GlobalParams.h>
#include <PDFDoc.h>
+#include <Private.h>
#include <Catalog.h>
#include <ErrorCodes.h>
#include <SplashOutputDev.h>
@@ -31,110 +32,6 @@
namespace Poppler {
-class PageTransitionData {
- public:
- Object *trans;
-};
-
-//------------------------------------------------------------------------
-// PageTransition
-//------------------------------------------------------------------------
-
-PageTransition::PageTransition(const PageTransitionData &data)
- : type(Replace),
- duration(1),
- alignment(Horizontal),
- direction(Inward),
- angle(0),
- scale(1.0),
- rectangular(false)
-{
- Object obj;
- Object *dictObj = data.trans;
-
- if (dictObj->isDict()) {
- Dict *transDict = dictObj->getDict();
-
- if (transDict->lookup("S", &obj)->isName()) {
- const char *s = obj.getName();
- if (strcmp("R", s) == 0)
- type = Replace;
- else if (strcmp("Split", s) == 0)
- type = Split;
- else if (strcmp("Blinds", s) == 0)
- type = Blinds;
- else if (strcmp("Box", s) == 0)
- type = Box;
- else if (strcmp("Wipe", s) == 0)
- type = Wipe;
- else if (strcmp("Dissolve", s) == 0)
- type = Dissolve;
- else if (strcmp("Glitter", s) == 0)
- type = Glitter;
- else if (strcmp("Fly", s) == 0)
- type = Fly;
- else if (strcmp("Push", s) == 0)
- type = Push;
- else if (strcmp("Cover", s) == 0)
- type = Cover;
- else if (strcmp("Uncover", s) == 0)
- type = Push;
- else if (strcmp("Fade", s) == 0)
- type = Cover;
- }
- obj.free();
-
- if (transDict->lookup("D", &obj)->isInt()) {
- duration = obj.getInt();
- }
- obj.free();
-
- if (transDict->lookup("Dm", &obj)->isName()) {
- const char *dm = obj.getName();
- if ( strcmp( "H", dm ) == 0 )
- alignment = Horizontal;
- else if ( strcmp( "V", dm ) == 0 )
- alignment = Vertical;
- }
- obj.free();
-
- if (transDict->lookup("M", &obj)->isName()) {
- const char *m = obj.getName();
- if ( strcmp( "I", m ) == 0 )
- direction = Inward;
- else if ( strcmp( "O", m ) == 0 )
- direction = Outward;
- }
- obj.free();
-
- if (transDict->lookup("Di", &obj)->isInt()) {
- angle = obj.getInt();
- }
- obj.free();
-
- if (transDict->lookup("Di", &obj)->isName()) {
- if ( strcmp( "None", obj.getName() ) == 0 )
- angle = 0;
- }
- obj.free();
-
- if (transDict->lookup("SS", &obj)->isReal()) {
- scale = obj.getReal();
- }
- obj.free();
-
- if (transDict->lookup("B", &obj)->isBool()) {
- rectangular = obj.getBool();
- }
- obj.free();
- }
-}
-
-PageTransition::~PageTransition()
-{
-}
-
-
class PageData {
public:
const Document *doc;
@@ -268,9 +165,9 @@ PageTransition *Page::getTransition() const
if (!data->transition)
{
Object o;
- PageTransitionData ptd;
- ptd.trans = data->doc->data->doc.getCatalog()->getPage(data->index + 1)->getTrans(&o);
- data->transition = new PageTransition(ptd);
+ PageTransitionParams params;
+ params.dictObj = data->doc->data->doc.getCatalog()->getPage(data->index + 1)->getTrans(&o);
+ data->transition = new PageTransition(params);
o.free();
}
return data->transition;
diff --git a/qt/poppler-qt.h b/qt/poppler-qt.h
index 22bd6cdf..c0172a15 100644
--- a/qt/poppler-qt.h
+++ b/qt/poppler-qt.h
@@ -24,6 +24,8 @@
#include <qdatetime.h>
#include <qpixmap.h>
+#include <PageTransition.h>
+
namespace Poppler {
class Document;
@@ -118,76 +120,6 @@ private:
FontInfoData *data;
};
-class PageTransitionData;
-class PageTransition
-{
-friend class Page;
-public:
- enum Type {
- Replace,
- Split,
- Blinds,
- Box,
- Wipe,
- Dissolve,
- Glitter,
- Fly,
- Push,
- Cover,
- Uncover,
- Fade
- };
-
- enum Alignment {
- Horizontal,
- Vertical
- };
-
- enum Direction {
- Inward,
- Outward
- };
-
-
- // Destructor
- ~PageTransition();
-
- // Get type of the transition.
- Type getType() const { return type; }
-
- // Get duration of the transition in seconds.
- int getDuration() const { return duration; }
-
- // Get dimension in which the transition effect
- // occurs.
- Alignment getAlignment() const { return alignment; }
-
- // Get direction of motion of the transition effect.
- Direction getDirection() const { return direction; }
-
- // Get direction in which the transition effect moves.
- int getAngle() const { return angle; }
-
- // Get starting or ending scale.
- double getScale() const { return scale; }
-
- // Returns true if the area to be flown is rectangular and
- // opaque.
- bool isRectangular() const { return rectangular; }
-
-private:
- // Construct a new PageTransition object from a page dictionary.
- PageTransition( const PageTransitionData &data );
-
- Type type;
- int duration;
- Alignment alignment;
- Direction direction;
- int angle;
- double scale;
- bool rectangular;
-};
-
class PageData;
class Page {
friend class Document;
diff --git a/qt4/src/Makefile.am b/qt4/src/Makefile.am
index 120cb63d..ee9f3e1c 100644
--- a/qt4/src/Makefile.am
+++ b/qt4/src/Makefile.am
@@ -7,7 +7,7 @@ INCLUDES = \
poppler_includedir = $(includedir)/poppler
poppler_include_HEADERS = \
- poppler-qt4.h
+ poppler-qt4.h ../../poppler/PageTransition.h
lib_LTLIBRARIES=libpoppler-qt4.la
diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
index 652e10e2..588f4f26 100644
--- a/qt4/src/poppler-page.cc
+++ b/qt4/src/poppler-page.cc
@@ -26,6 +26,7 @@
#include <Catalog.h>
#include <ErrorCodes.h>
#include <ArthurOutputDev.h>
+#include <Private.h>
#include <TextOutputDev.h>
#include "poppler-private.h"
@@ -38,12 +39,14 @@ class PageData {
public:
const Document *parentDoc;
int index;
+ PageTransition *transition;
};
Page::Page(const Document *doc, int index) {
m_page = new PageData();
m_page->index = index;
m_page->parentDoc = doc;
+ m_page->transition = 0;
}
Page::~Page()
@@ -174,7 +177,7 @@ QList<TextBox*> Page::textList() const
double xMin, yMin, xMax, yMax;
word->getBBox(&xMin, &yMin, &xMax, &yMax);
- TextBox* text_box = new TextBox(string, QRectF(xMin, yMin, xMax, yMax));
+ TextBox* text_box = new TextBox(string, QRectF(xMin, yMin, xMax-xMin, yMax-yMin));
output_list.append(text_box);
}
@@ -185,6 +188,18 @@ QList<TextBox*> Page::textList() const
return output_list;
}
+PageTransition *Page::transition() const
+{
+ if (!m_page->transition) {
+ Object o;
+ PageTransitionParams params;
+ params.dictObj = m_page->parentDoc->m_doc->doc.getCatalog()->getPage(m_page->index + 1)->getTrans(&o);
+ m_page->transition = new PageTransition(params);
+ o.free();
+ }
+ return m_page->transition;
+}
+
QSizeF Page::pageSizeF() const
{
::Page *p;
diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
index 801e1bb9..29b80f63 100644
--- a/qt4/src/poppler-qt4.h
+++ b/qt4/src/poppler-qt4.h
@@ -26,6 +26,8 @@
#include <QtCore/QDateTime>
#include <QtGui/QPixmap>
+#include <PageTransition.h>
+
/**
The Poppler Qt bindings
*/
@@ -254,7 +256,6 @@ delete pixmap;
\warning This method is not tested with Asian scripts
*/
-
QList<TextBox*> textList() const;
/**
@@ -268,6 +269,17 @@ delete pixmap;
QSize pageSize() const;
/**
+ \brief Returns the transition of this page
+
+ @returns a pointer to a PageTransition structure that
+ defines how transition to this page shall be performed. The
+ PageTransition structure is owned by this page, and will
+ automatically be destroyed when this page class is
+ destroyed.
+ **/
+ PageTransition *transition() const;
+
+ /**
Types of orientations that are possible
*/
enum Orientation {