updated on Mon Jan 23 12:00:23 UTC 2012
[aur-mirror.git] / poppler-qt-lcd / 0001-Cairo-backend-added-to-Qt4-wrapper.patch
blob62fef8df0bfe70feb140f907c35d9d3519f07737
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
6 ---
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}
23 +if (HAVE_CAIRO)
24 + include_directories(${CAIRO_INCLUDE_DIRS})
25 + add_definitions(${CAIRO_CFLAGS})
26 +endif (HAVE_CAIRO)
28 set(poppler_qt4_SRCS
29 poppler-annotation.cc
30 poppler-document.cc
31 @@ -27,10 +32,20 @@ set(poppler_qt4_SRCS
32 poppler-page-transition.cc
33 ${CMAKE_SOURCE_DIR}/poppler/ArthurOutputDev.cc
35 +if (HAVE_CAIRO)
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
40 + )
41 +endif(HAVE_CAIRO)
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})
46 +if (HAVE_CAIRO)
47 + target_link_libraries(poppler-qt4 ${CAIRO_LIBRARIES})
48 +endif (HAVE_CAIRO)
49 if(MSVC)
50 target_link_libraries(poppler-qt4 poppler ${poppler_LIBS})
51 endif(MSVC)
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;
58 #endif
59 ret << Document::ArthurBackend;
60 +#if defined(HAVE_CAIRO)
61 + ret << Document::CairoBackend;
62 +#endif
63 return ret;
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
70 @@ -35,6 +35,7 @@
71 #include <QtGui/QPainter>
73 #include <config.h>
74 +#include <math.h>
75 #include <PDFDoc.h>
76 #include <Catalog.h>
77 #include <Form.h>
78 @@ -258,6 +259,53 @@ QImage Page::renderToImage(double xres, double yres, int x, int y, int w, int h,
79 img = tmpimg;
80 break;
82 + case Poppler::Document::CairoBackend:
83 + {
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;
90 + cairo_t *cairo;
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();
96 + } else {
97 + height = m_page->page->getCropHeight();
98 + width = m_page->page->getCropWidth();
99 + }
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(
110 + img.bits(),
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);
122 + // Clean up
123 + output_dev->setCairo(NULL);
124 + cairo_destroy(cairo);
125 + cairo_surface_destroy(surface);
126 +#endif
127 + break;
131 return img;
132 @@ -300,6 +348,8 @@ bool Page::renderToPainter(QPainter* painter, double xres, double yres, int x, i
133 painter->restore();
134 return true;
136 + case Poppler::Document::CairoBackend:
137 + return false;
139 return false;
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
145 @@ -41,6 +41,9 @@
146 #if defined(HAVE_SPLASH)
147 #include <SplashOutputDev.h>
148 #endif
149 +#if defined(HAVE_CAIRO)
150 +#include <CairoOutputDev.h>
151 +#endif
153 #include "poppler-qt4.h"
154 #include "poppler-embeddedfile-private.h"
155 @@ -136,6 +139,15 @@ namespace Poppler {
156 #endif
157 break;
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;
165 +#endif
166 + break;
170 return m_outputDev;
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;
177 enum RenderBackend {
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(
190 ${QT4_INCLUDE_DIR}
193 +if (HAVE_CAIRO)
194 + include_directories(${CAIRO_INCLUDE_DIRS})
195 + add_definitions(${CAIRO_CFLAGS})
196 +endif (HAVE_CAIRO)
198 macro(QT4_ADD_SIMPLETEST exe source)
199 string(REPLACE "-" "" test_name ${exe})
200 set(${test_name}_SOURCES
202 1.7.8.4