summaryrefslogtreecommitdiff
path: root/src/generic
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-06-13 13:15:49 +0200
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2016-06-14 10:53:34 +0200
commit6b74aad0238d177d6e435958420b9c606e7338db (patch)
tree40584bdfead7e6ec559871964dcf1af5acee0aa1 /src/generic
parentc6dfdeb0c8d0122c848e959cfb73d529c44d5176 (diff)
evas_generic_loaders: port poppler to the cpp api
Summary: This ports the loader to the stable cpp api. Test Plan: Please test this patch and tell me if there are differences Reviewers: DaveMDS Subscribers: jayji Differential Revision: https://phab.enlightenment.org/D4039
Diffstat (limited to 'src/generic')
-rw-r--r--src/generic/evas/pdf/main.cpp173
1 files changed, 77 insertions, 96 deletions
diff --git a/src/generic/evas/pdf/main.cpp b/src/generic/evas/pdf/main.cpp
index d9af1d342b..426e97c730 100644
--- a/src/generic/evas/pdf/main.cpp
+++ b/src/generic/evas/pdf/main.cpp
@@ -8,19 +8,19 @@
8#include <unistd.h> 8#include <unistd.h>
9#include <libgen.h> 9#include <libgen.h>
10 10
11#include <GlobalParams.h>
12#include <PDFDoc.h>
13#include <ErrorCodes.h>
14#include <Page.h>
15#include <SplashOutputDev.h>
16#include <splash/SplashBitmap.h>
17
18#include <Eina.h> 11#include <Eina.h>
19 12
13#include <poppler-global.h>
14#include <poppler-rectangle.h>
15#include <poppler-document.h>
16#include <poppler-page.h>
17#include <poppler-page-renderer.h>
18
20#include "shmfile.h" 19#include "shmfile.h"
21#include "timeout.h" 20#include "timeout.h"
22 21
23#define DATA32 unsigned int 22#define DATA32 unsigned int
23typedef char RGB24[3];
24 24
25//#define PDF_DBG 25//#define PDF_DBG
26 26
@@ -30,11 +30,12 @@
30#define D(fmt, args...) 30#define D(fmt, args...)
31#endif 31#endif
32 32
33using namespace poppler;
33 34
34PDFDoc *pdfdoc;
35bool locked = false; 35bool locked = false;
36 36
37::Page *page; 37document *doc;
38page *doc_page;
38int width = 0, height = 0; 39int width = 0, height = 0;
39int crop_width = 0, crop_height = 0; 40int crop_width = 0, crop_height = 0;
40void *data = NULL; 41void *data = NULL;
@@ -44,9 +45,7 @@ double dpi = -1.0;
44 45
45Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h) 46Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
46{ 47{
47 Object obj;
48 double w, h, cw, ch; 48 double w, h, cw, ch;
49 int rot;
50 49
51 if (!file || !*file) 50 if (!file || !*file)
52 return EINA_FALSE; 51 return EINA_FALSE;
@@ -54,55 +53,36 @@ Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
54 if (page_nbr < 0) 53 if (page_nbr < 0)
55 return EINA_FALSE; 54 return EINA_FALSE;
56 55
57 if (!(globalParams = new GlobalParams()))
58 return EINA_FALSE;
59
60 if (!eina_init()) 56 if (!eina_init())
61 goto del_global_param; 57 return EINA_FALSE;
62 58
63#ifndef HAVE_POPPLER_031
64 if (globalParams->getAntialias())
65 globalParams->setAntialias((char *)"yes");
66 if (globalParams->getVectorAntialias())
67 globalParams->setVectorAntialias((char *)"yes");
68#endif
69 59
70 pdfdoc = new PDFDoc(new GooString(file), NULL); 60 doc = document::load_from_file(file);
71 if (!pdfdoc)
72 goto del_global_param;
73 61
74 if (!pdfdoc->isOk() || (pdfdoc->getErrorCode() == errEncrypted)) 62 if (!doc)
75 goto del_pdfdoc; 63 return EINA_FALSE;
76 64
77 if (page_nbr >= pdfdoc->getNumPages()) 65 if (page_nbr >= doc->pages())
78 goto del_pdfdoc; 66 goto del_pdfdoc;
79 67
80 /* load the page */ 68 /* load the page */
81 69
82 page = pdfdoc->getCatalog()->getPage(page_nbr + 1); 70 doc_page = doc->create_page(page_nbr + 1);
83 if (!page || !page->isOk()) 71 if (!doc_page)
84 goto del_pdfdoc; 72 goto del_pdfdoc;
85 73
86 w = page->getMediaWidth(); 74 w = doc_page->page_rect(page_box_enum::media_box).width();
87 h = page->getMediaHeight(); 75 h = doc_page->page_rect(page_box_enum::media_box).height();
88 cw = page->getCropWidth(); 76 cw = doc_page->page_rect().width();
89 ch = page->getCropHeight(); 77 ch = doc_page->page_rect().height();
90 rot = page->getRotate(); 78
91 if (cw > w) cw = w; 79 if (cw > w) cw = w;
92 if (ch > h) ch = h; 80 if (ch > h) ch = h;
93 if ((rot == 90) || (rot == 270)) 81
94 {
95 double t;
96 // swap width & height
97 t = w; w = h; h = t;
98 // swap crop width & height
99 t = cw; cw = ch; ch = t;
100 }
101
102 if ((size_w > 0) || (size_h > 0)) 82 if ((size_w > 0) || (size_h > 0))
103 { 83 {
104 double w2 = cw, h2 = ch; 84 double w2 = cw, h2 = ch;
105 85
106 w2 = size_w; 86 w2 = size_w;
107 h2 = (size_w * ch) / cw; 87 h2 = (size_w * ch) / cw;
108 if (h2 > size_h) 88 if (h2 > size_h)
@@ -114,7 +94,7 @@ Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
114 if (w2 > h2) dpi = (w2 * DEF_DPI) / cw; 94 if (w2 > h2) dpi = (w2 * DEF_DPI) / cw;
115 else dpi = (h2 * DEF_DPI) / ch; 95 else dpi = (h2 * DEF_DPI) / ch;
116 } 96 }
117 97
118 if (dpi > 0.0) 98 if (dpi > 0.0)
119 { 99 {
120 cw = (cw * dpi) / DEF_DPI; 100 cw = (cw * dpi) / DEF_DPI;
@@ -130,77 +110,78 @@ Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
130 return EINA_TRUE; 110 return EINA_TRUE;
131 111
132 del_pdfdoc: 112 del_pdfdoc:
133 delete pdfdoc; 113 delete doc;
134 del_global_param:
135 delete globalParams;
136 114
137 return EINA_FALSE; 115 return EINA_FALSE;
138} 116}
139 117
140void poppler_shutdown() 118void poppler_shutdown()
141{ 119{
142 delete pdfdoc; 120 delete doc;
143 eina_shutdown(); 121 eina_shutdown();
144 delete globalParams;
145} 122}
146 123
124
147void poppler_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED) 125void poppler_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED)
148{ 126{
149 SplashOutputDev *output_dev; 127 page_renderer *renderer;
150 SplashColor white; 128 image out;
151 SplashColorPtr color_ptr; 129 DATA32 *dst;
152 DATA32 *src, *dst; 130 int y, x;
153 int y;
154
155 white[0] = 255;
156 white[1] = 255;
157 white[2] = 255;
158 white[3] = 255;
159
160 output_dev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, white);
161 if (!output_dev)
162 return;
163
164#ifdef HAVE_POPPLER_020
165 output_dev->startDoc(pdfdoc);
166#else
167 output_dev->startDoc(pdfdoc->getXRef());
168#endif
169 131
170 if (dpi <= 0.0) dpi = DEF_DPI; 132 if (dpi <= 0.0) dpi = DEF_DPI;
171 133
172#ifdef HAVE_POPPLER_031 134 renderer = new page_renderer();
173 output_dev->setFontAntialias(EINA_TRUE);
174 output_dev->setVectorAntialias(EINA_TRUE);
175#endif
176 135
177#ifdef HAVE_POPPLER_020 136 renderer->set_render_hint(page_renderer::render_hint::text_antialiasing, 1);
178 page->displaySlice(output_dev, dpi, dpi, 137 renderer->set_render_hint(page_renderer::render_hint::antialiasing, 1);
179 0, false, false, 138
180 0, 0, width, height, 139 out = renderer->render_page(doc_page, dpi, dpi,
181 false, NULL, NULL); 140 0, 0, width, height,
182#else 141 rotate_0);
183 page->displaySlice(output_dev, dpi, dpi,
184 0, false, false,
185 0, 0, width, height,
186 false, pdfdoc->getCatalog());
187#endif
188 color_ptr = output_dev->getBitmap()->getDataPtr();
189 142
190 shm_alloc(crop_width * crop_height * sizeof(DATA32)); 143 shm_alloc(crop_width * crop_height * sizeof(DATA32));
191 if (!shm_addr) goto del_outpput_dev; 144 if (!shm_addr) goto end;
192 data = shm_addr; 145 data = shm_addr;
193 src = (DATA32 *)color_ptr;
194 dst = (DATA32 *)data; 146 dst = (DATA32 *)data;
195 for (y = 0; y < crop_height; y++) 147
148#define IMAGE_PIXEL_ITERATOR \
149 for (y = 0; y < crop_height; y++) \
150 for (x = 0; x < crop_width; x++)
151
152 if (out.format() == image::format_mono)
196 { 153 {
197 memcpy(dst, src, crop_width * sizeof(DATA32)); 154 //FIXME no idea what this format is like
198 src += width;
199 dst += crop_width;
200 } 155 }
201 156 if (out.format() == image::format_rgb24)
202 del_outpput_dev: 157 {
203 delete output_dev; 158 RGB24 *src;
159 src = (RGB24*) out.data();
160 IMAGE_PIXEL_ITERATOR
161 {
162 DATA32 d = 0xFF000000;
163 int pos = x+y*crop_width;
164 d |= src[pos][0] >> 8;
165 d |= src[pos][1] >> 16;
166 d |= src[pos][2] >> 24;
167 dst[pos] = d;
168 }
169 }
170 else if (out.format() == image::format_argb32)
171 {
172 DATA32 *src;
173
174 src = (DATA32*) out.data();
175 IMAGE_PIXEL_ITERATOR
176 {
177 int pos = x+y*crop_width;
178
179 dst[pos] = src[pos];
180 }
181 }
182
183 end:
184 delete renderer;
204} 185}
205 186
206int 187int