1 From 42b05fa1b5a3f4a1bbab77f6acb80e0346c8ff72 Mon Sep 17 00:00:00 2001
2 From: Paul Gideon Dann <pdgiddie@gmail.com>
3 Date: Wed, 20 May 2009 11:42:28 +0100
4 Subject: [PATCH 1/4] Cairo backend added to Qt4 wrapper
7 qt4/src/CMakeLists.txt | 15 +++++++++++++
8 qt4/src/poppler-document.cc | 3 ++
9 qt4/src/poppler-page.cc | 50 +++++++++++++++++++++++++++++++++++++++++++
10 qt4/src/poppler-private.h | 12 ++++++++++
11 qt4/src/poppler-qt4.h | 3 +-
12 qt4/tests/CMakeLists.txt | 5 ++++
13 6 files changed, 87 insertions(+), 1 deletions(-)
15 diff --git a/qt4/src/CMakeLists.txt b/qt4/src/CMakeLists.txt
16 index 8ce8ff4..9d8e75d 100644
17 --- a/qt4/src/CMakeLists.txt
18 +++ b/qt4/src/CMakeLists.txt
19 @@ -6,6 +6,11 @@ include_directories(
20 ${CMAKE_CURRENT_BINARY_DIR}
24 + include_directories(${CAIRO_INCLUDE_DIRS})
25 + add_definitions(${CAIRO_CFLAGS})
31 @@ -27,10 +32,20 @@ set(poppler_qt4_SRCS
32 poppler-page-transition.cc
33 ${CMAKE_SOURCE_DIR}/poppler/ArthurOutputDev.cc
36 + set(poppler_qt4_SRCS ${poppler_qt4_SRCS}
37 + ${CMAKE_SOURCE_DIR}/poppler/CairoOutputDev.cc
38 + ${CMAKE_SOURCE_DIR}/poppler/CairoRescaleBox.cc
39 + ${CMAKE_SOURCE_DIR}/poppler/CairoFontEngine.cc
42 qt4_automoc(${poppler_qt4_SRCS})
43 add_library(poppler-qt4 SHARED ${poppler_qt4_SRCS})
44 set_target_properties(poppler-qt4 PROPERTIES VERSION 3.7.0 SOVERSION 3)
45 target_link_libraries(poppler-qt4 poppler ${QT4_QTCORE_LIBRARY} ${QT4_QTGUI_LIBRARY} ${QT4_QTXML_LIBRARY})
47 + target_link_libraries(poppler-qt4 ${CAIRO_LIBRARIES})
50 target_link_libraries(poppler-qt4 poppler ${poppler_LIBS})
52 diff --git a/qt4/src/poppler-document.cc b/qt4/src/poppler-document.cc
53 index 7b3e1af..681dc80 100644
54 --- a/qt4/src/poppler-document.cc
55 +++ b/qt4/src/poppler-document.cc
56 @@ -509,6 +509,9 @@ namespace Poppler {
57 ret << Document::SplashBackend;
59 ret << Document::ArthurBackend;
60 +#if defined(HAVE_CAIRO)
61 + ret << Document::CairoBackend;
66 diff --git a/qt4/src/poppler-page.cc b/qt4/src/poppler-page.cc
67 index f76700a..ce93442 100644
68 --- a/qt4/src/poppler-page.cc
69 +++ b/qt4/src/poppler-page.cc
71 #include <QtGui/QPainter>
78 @@ -258,6 +259,53 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
82 + case Poppler::Document::CairoBackend:
84 +#if defined(HAVE_CAIRO)
85 + CairoOutputDev *output_dev =
86 + static_cast<CairoOutputDev *>(m_page->parentDoc->getOutputDev());
87 + double width, height;
88 + int buffer_width, buffer_height, rotate;
89 + cairo_surface_t *surface;
92 + rotate = rotation + m_page->page->getRotate();
93 + if (rotate == 90 || rotate == 270) {
94 + height = m_page->page->getCropWidth();
95 + width = m_page->page->getCropHeight();
97 + height = m_page->page->getCropHeight();
98 + width = m_page->page->getCropWidth();
101 + const double xscale = xres / 72.0;
102 + const double yscale = yres / 72.0;
103 + buffer_width = (int) ceil(width * xscale);
104 + buffer_height = (int) ceil(height * yscale);
106 + img = QImage(buffer_width, buffer_height, QImage::Format_ARGB32);
107 + img.fill(Qt::white); // Never transparent
109 + surface = cairo_image_surface_create_for_data(
111 + CAIRO_FORMAT_ARGB32,
112 + buffer_width, buffer_height,
113 + img.bytesPerLine());
115 + cairo = cairo_create(surface);
116 + output_dev->setCairo(cairo);
118 + m_page->parentDoc->doc->displayPageSlice(
119 + output_dev, m_page->index + 1, xres, yres, rotation, false, true,
120 + false, x, y, w, h);
123 + output_dev->setCairo(NULL);
124 + cairo_destroy(cairo);
125 + cairo_surface_destroy(surface);
132 @@ -300,6 +348,8 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i
136 + case Poppler::Document::CairoBackend:
141 diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h
142 index b4383d8..a15ea4f 100644
143 --- a/qt4/src/poppler-private.h
144 +++ b/qt4/src/poppler-private.h
146 #if defined(HAVE_SPLASH)
147 #include <SplashOutputDev.h>
149 +#if defined(HAVE_CAIRO)
150 +#include <CairoOutputDev.h>
153 #include "poppler-qt4.h"
154 #include "poppler-embeddedfile-private.h"
155 @@ -136,6 +139,15 @@ namespace Poppler {
159 + case Document::CairoBackend:
161 +#if defined(HAVE_CAIRO)
162 + CairoOutputDev *cairoOutputDev = new CairoOutputDev();
163 + cairoOutputDev->startDoc(doc->getXRef(), doc->getCatalog());
164 + m_outputDev = cairoOutputDev;
171 diff --git a/qt4/src/poppler-qt4.h b/qt4/src/poppler-qt4.h
172 index 9a4373f..eedf55a 100644
173 --- a/qt4/src/poppler-qt4.h
174 +++ b/qt4/src/poppler-qt4.h
175 @@ -794,7 +794,8 @@ delete it;
178 SplashBackend, ///< Splash backend
179 - ArthurBackend ///< Arthur (Qt4) backend
180 + ArthurBackend, ///< Arthur (Qt4) backend
181 + CairoBackend ///< Cairo backend
185 diff --git a/qt4/tests/CMakeLists.txt b/qt4/tests/CMakeLists.txt
186 index d0ba762..f7121b6 100644
187 --- a/qt4/tests/CMakeLists.txt
188 +++ b/qt4/tests/CMakeLists.txt
189 @@ -7,6 +7,11 @@ include_directories(
194 + include_directories(${CAIRO_INCLUDE_DIRS})
195 + add_definitions(${CAIRO_CFLAGS})
198 macro(QT4_ADD_SIMPLETEST exe source)
199 string(REPLACE "-" "" test_name ${exe})
200 set(${test_name}_SOURCES