forked from enlightenment/efl
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
This commit is contained in:
parent
c6dfdeb0c8
commit
6b74aad023
|
@ -2864,13 +2864,7 @@ have_rsvg="no"
|
||||||
|
|
||||||
### Check needed dependency for each generic loader
|
### Check needed dependency for each generic loader
|
||||||
if test "x${want_poppler}" = "xyes"; then
|
if test "x${want_poppler}" = "xyes"; then
|
||||||
PKG_CHECK_MODULES([POPPLER], [poppler >= 0.12], [have_poppler="yes"])
|
PKG_CHECK_MODULES([POPPLER], [poppler-cpp >= 0.12], [have_poppler="yes"])
|
||||||
|
|
||||||
PKG_CHECK_EXISTS([poppler >= 0.20],
|
|
||||||
[AC_DEFINE(HAVE_POPPLER_020, 1, [Have poppler at least 0.20])])
|
|
||||||
|
|
||||||
PKG_CHECK_EXISTS([poppler >= 0.31],
|
|
||||||
[AC_DEFINE(HAVE_POPPLER_031, 1, [Have poppler at least 0.31])])
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "x${want_spectre}" = "xyes"; then
|
if test "x${want_spectre}" = "xyes"; then
|
||||||
|
|
|
@ -8,19 +8,19 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
#include <GlobalParams.h>
|
|
||||||
#include <PDFDoc.h>
|
|
||||||
#include <ErrorCodes.h>
|
|
||||||
#include <Page.h>
|
|
||||||
#include <SplashOutputDev.h>
|
|
||||||
#include <splash/SplashBitmap.h>
|
|
||||||
|
|
||||||
#include <Eina.h>
|
#include <Eina.h>
|
||||||
|
|
||||||
|
#include <poppler-global.h>
|
||||||
|
#include <poppler-rectangle.h>
|
||||||
|
#include <poppler-document.h>
|
||||||
|
#include <poppler-page.h>
|
||||||
|
#include <poppler-page-renderer.h>
|
||||||
|
|
||||||
#include "shmfile.h"
|
#include "shmfile.h"
|
||||||
#include "timeout.h"
|
#include "timeout.h"
|
||||||
|
|
||||||
#define DATA32 unsigned int
|
#define DATA32 unsigned int
|
||||||
|
typedef char RGB24[3];
|
||||||
|
|
||||||
//#define PDF_DBG
|
//#define PDF_DBG
|
||||||
|
|
||||||
|
@ -30,11 +30,12 @@
|
||||||
#define D(fmt, args...)
|
#define D(fmt, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace poppler;
|
||||||
|
|
||||||
PDFDoc *pdfdoc;
|
|
||||||
bool locked = false;
|
bool locked = false;
|
||||||
|
|
||||||
::Page *page;
|
document *doc;
|
||||||
|
page *doc_page;
|
||||||
int width = 0, height = 0;
|
int width = 0, height = 0;
|
||||||
int crop_width = 0, crop_height = 0;
|
int crop_width = 0, crop_height = 0;
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
|
@ -44,9 +45,7 @@ double dpi = -1.0;
|
||||||
|
|
||||||
Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
|
Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
|
||||||
{
|
{
|
||||||
Object obj;
|
|
||||||
double w, h, cw, ch;
|
double w, h, cw, ch;
|
||||||
int rot;
|
|
||||||
|
|
||||||
if (!file || !*file)
|
if (!file || !*file)
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
@ -54,55 +53,36 @@ Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
|
||||||
if (page_nbr < 0)
|
if (page_nbr < 0)
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
|
||||||
if (!(globalParams = new GlobalParams()))
|
if (!eina_init())
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
|
|
||||||
if (!eina_init())
|
|
||||||
goto del_global_param;
|
|
||||||
|
|
||||||
#ifndef HAVE_POPPLER_031
|
doc = document::load_from_file(file);
|
||||||
if (globalParams->getAntialias())
|
|
||||||
globalParams->setAntialias((char *)"yes");
|
|
||||||
if (globalParams->getVectorAntialias())
|
|
||||||
globalParams->setVectorAntialias((char *)"yes");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pdfdoc = new PDFDoc(new GooString(file), NULL);
|
if (!doc)
|
||||||
if (!pdfdoc)
|
return EINA_FALSE;
|
||||||
goto del_global_param;
|
|
||||||
|
|
||||||
if (!pdfdoc->isOk() || (pdfdoc->getErrorCode() == errEncrypted))
|
if (page_nbr >= doc->pages())
|
||||||
goto del_pdfdoc;
|
|
||||||
|
|
||||||
if (page_nbr >= pdfdoc->getNumPages())
|
|
||||||
goto del_pdfdoc;
|
goto del_pdfdoc;
|
||||||
|
|
||||||
/* load the page */
|
/* load the page */
|
||||||
|
|
||||||
page = pdfdoc->getCatalog()->getPage(page_nbr + 1);
|
doc_page = doc->create_page(page_nbr + 1);
|
||||||
if (!page || !page->isOk())
|
if (!doc_page)
|
||||||
goto del_pdfdoc;
|
goto del_pdfdoc;
|
||||||
|
|
||||||
w = page->getMediaWidth();
|
w = doc_page->page_rect(page_box_enum::media_box).width();
|
||||||
h = page->getMediaHeight();
|
h = doc_page->page_rect(page_box_enum::media_box).height();
|
||||||
cw = page->getCropWidth();
|
cw = doc_page->page_rect().width();
|
||||||
ch = page->getCropHeight();
|
ch = doc_page->page_rect().height();
|
||||||
rot = page->getRotate();
|
|
||||||
if (cw > w) cw = w;
|
if (cw > w) cw = w;
|
||||||
if (ch > h) ch = h;
|
if (ch > h) ch = h;
|
||||||
if ((rot == 90) || (rot == 270))
|
|
||||||
{
|
|
||||||
double t;
|
|
||||||
// swap width & height
|
|
||||||
t = w; w = h; h = t;
|
|
||||||
// swap crop width & height
|
|
||||||
t = cw; cw = ch; ch = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size_w > 0) || (size_h > 0))
|
if ((size_w > 0) || (size_h > 0))
|
||||||
{
|
{
|
||||||
double w2 = cw, h2 = ch;
|
double w2 = cw, h2 = ch;
|
||||||
|
|
||||||
w2 = size_w;
|
w2 = size_w;
|
||||||
h2 = (size_w * ch) / cw;
|
h2 = (size_w * ch) / cw;
|
||||||
if (h2 > size_h)
|
if (h2 > size_h)
|
||||||
|
@ -114,7 +94,7 @@ Eina_Bool poppler_init(const char *file, int page_nbr, int size_w, int size_h)
|
||||||
if (w2 > h2) dpi = (w2 * DEF_DPI) / cw;
|
if (w2 > h2) dpi = (w2 * DEF_DPI) / cw;
|
||||||
else dpi = (h2 * DEF_DPI) / ch;
|
else dpi = (h2 * DEF_DPI) / ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dpi > 0.0)
|
if (dpi > 0.0)
|
||||||
{
|
{
|
||||||
cw = (cw * dpi) / DEF_DPI;
|
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)
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
del_pdfdoc:
|
del_pdfdoc:
|
||||||
delete pdfdoc;
|
delete doc;
|
||||||
del_global_param:
|
|
||||||
delete globalParams;
|
|
||||||
|
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void poppler_shutdown()
|
void poppler_shutdown()
|
||||||
{
|
{
|
||||||
delete pdfdoc;
|
delete doc;
|
||||||
eina_shutdown();
|
eina_shutdown();
|
||||||
delete globalParams;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void poppler_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED)
|
void poppler_load_image(int size_w EINA_UNUSED, int size_h EINA_UNUSED)
|
||||||
{
|
{
|
||||||
SplashOutputDev *output_dev;
|
page_renderer *renderer;
|
||||||
SplashColor white;
|
image out;
|
||||||
SplashColorPtr color_ptr;
|
DATA32 *dst;
|
||||||
DATA32 *src, *dst;
|
int y, x;
|
||||||
int y;
|
|
||||||
|
|
||||||
white[0] = 255;
|
|
||||||
white[1] = 255;
|
|
||||||
white[2] = 255;
|
|
||||||
white[3] = 255;
|
|
||||||
|
|
||||||
output_dev = new SplashOutputDev(splashModeXBGR8, 4, gFalse, white);
|
|
||||||
if (!output_dev)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef HAVE_POPPLER_020
|
|
||||||
output_dev->startDoc(pdfdoc);
|
|
||||||
#else
|
|
||||||
output_dev->startDoc(pdfdoc->getXRef());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (dpi <= 0.0) dpi = DEF_DPI;
|
if (dpi <= 0.0) dpi = DEF_DPI;
|
||||||
|
|
||||||
#ifdef HAVE_POPPLER_031
|
renderer = new page_renderer();
|
||||||
output_dev->setFontAntialias(EINA_TRUE);
|
|
||||||
output_dev->setVectorAntialias(EINA_TRUE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_POPPLER_020
|
renderer->set_render_hint(page_renderer::render_hint::text_antialiasing, 1);
|
||||||
page->displaySlice(output_dev, dpi, dpi,
|
renderer->set_render_hint(page_renderer::render_hint::antialiasing, 1);
|
||||||
0, false, false,
|
|
||||||
0, 0, width, height,
|
out = renderer->render_page(doc_page, dpi, dpi,
|
||||||
false, NULL, NULL);
|
0, 0, width, height,
|
||||||
#else
|
rotate_0);
|
||||||
page->displaySlice(output_dev, dpi, dpi,
|
|
||||||
0, false, false,
|
|
||||||
0, 0, width, height,
|
|
||||||
false, pdfdoc->getCatalog());
|
|
||||||
#endif
|
|
||||||
color_ptr = output_dev->getBitmap()->getDataPtr();
|
|
||||||
|
|
||||||
shm_alloc(crop_width * crop_height * sizeof(DATA32));
|
shm_alloc(crop_width * crop_height * sizeof(DATA32));
|
||||||
if (!shm_addr) goto del_outpput_dev;
|
if (!shm_addr) goto end;
|
||||||
data = shm_addr;
|
data = shm_addr;
|
||||||
src = (DATA32 *)color_ptr;
|
|
||||||
dst = (DATA32 *)data;
|
dst = (DATA32 *)data;
|
||||||
for (y = 0; y < crop_height; y++)
|
|
||||||
{
|
|
||||||
memcpy(dst, src, crop_width * sizeof(DATA32));
|
|
||||||
src += width;
|
|
||||||
dst += crop_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
del_outpput_dev:
|
#define IMAGE_PIXEL_ITERATOR \
|
||||||
delete output_dev;
|
for (y = 0; y < crop_height; y++) \
|
||||||
|
for (x = 0; x < crop_width; x++)
|
||||||
|
|
||||||
|
if (out.format() == image::format_mono)
|
||||||
|
{
|
||||||
|
//FIXME no idea what this format is like
|
||||||
|
}
|
||||||
|
if (out.format() == image::format_rgb24)
|
||||||
|
{
|
||||||
|
RGB24 *src;
|
||||||
|
src = (RGB24*) out.data();
|
||||||
|
IMAGE_PIXEL_ITERATOR
|
||||||
|
{
|
||||||
|
DATA32 d = 0xFF000000;
|
||||||
|
int pos = x+y*crop_width;
|
||||||
|
d |= src[pos][0] >> 8;
|
||||||
|
d |= src[pos][1] >> 16;
|
||||||
|
d |= src[pos][2] >> 24;
|
||||||
|
dst[pos] = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (out.format() == image::format_argb32)
|
||||||
|
{
|
||||||
|
DATA32 *src;
|
||||||
|
|
||||||
|
src = (DATA32*) out.data();
|
||||||
|
IMAGE_PIXEL_ITERATOR
|
||||||
|
{
|
||||||
|
int pos = x+y*crop_width;
|
||||||
|
|
||||||
|
dst[pos] = src[pos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end:
|
||||||
|
delete renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Reference in New Issue