Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ankur Sinha
zathura-pdf-poppler
Commits
ced9b3cf
Commit
ced9b3cf
authored
Jan 11, 2017
by
Moritz Lipp
Browse files
Merge branch 'release/0.2.7'
parents
308c9c39
986f12a6
Changes
12
Hide whitespace changes
Inline
Side-by-side
LICENSE
View file @
ced9b3cf
Copyright (c) 2011-201
5
pwmt.org
Copyright (c) 2011-201
7
pwmt.org
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
...
...
Makefile
View file @
ced9b3cf
...
...
@@ -5,26 +5,37 @@ include common.mk
PROJECT
=
zathura-pdf-poppler
PLUGIN
=
pdf
SOURCE
=
$(
wildcard
*
.c
)
SOURCE
=
$(
sort
$(
wildcard
*
.c
)
)
HEADER
=
$(
wildcard
*
.h
)
OBJECTS
=
${SOURCE:.c=.o}
DOBJECTS
=
${SOURCE:.c=.do}
ifneq
"$(WITH_CAIRO)" "0"
CPPFLAGS
+=
-DHAVE_CAIRO
ifeq
($(UNAME), Darwin)
SOFILE
=
${PLUGIN}
.dylib
SODEBUGFILE
=
${PLUGIN}
-debug
.dylib
ZATHURAFILE
=
${PREFIX}
/bin/zathura
PLATFORMFLAGS
=
-Wl
,-dylib_install_name,
${DESTDIR}${PLUGINDIR}
/pdf.dylib
-Wl
,-bundle_loader,
${ZATHURAFILE}
-bundle
else
SOFILE
=
${PLUGIN}
.so
SODEBUGFILE
=
${PLUGIN}
-debug
.so
PLATFORMFLAGS
=
-shared
endif
CPPFLAGS
+=
"-DVERSION_MAJOR=
${VERSION_MAJOR}
"
CPPFLAGS
+=
"-DVERSION_MINOR=
${VERSION_MINOR}
"
CPPFLAGS
+=
"-DVERSION_REV=
${VERSION_REV}
"
all
:
options ${
PLUGIN}.so
all
:
options ${
SOFILE}
zathura-version-check
:
ifneq
($(ZATHURA_VERSION_CHECK), 0)
$(
error
"The minimum required version of zathura is
${ZATHURA_MIN_VERSION}
"
)
endif
$(QUIET)
touch
zathura-version-check
# pkg-config based version checks
.version-checks/%
:
config.mk
$(QUIET)
test
$
(
$
(
*
)
_VERSION_CHECK
)
-eq
0
||
\
${PKG_CONFIG}
--atleast-version
$
(
$
(
*
)
_MIN_VERSION
)
$
(
$
(
*
)
_PKG_CONFIG_NAME
)
||
(
\
echo
"The minimum required version of
$
(*) is
$
(
$
(*)_MIN_VERSION)"
&&
\
false
\
)
@
mkdir
-p
.version-checks
$(QUIET)
touch
$@
options
:
$(ECHO)
${PLUGIN}
build options:
...
...
@@ -44,22 +55,26 @@ options:
@
mkdir
-p
.depend
$(QUIET)${CC}
-c
${CPPFLAGS}
${CFLAGS}
${DFLAGS}
-o
$@
$<
-MMD
-MF
.depend/
$@
.dep
${OBJECTS}
:
config.mk zathura-version-check
${DOBJECTS}
:
config.mk zathura-version-check
${OBJECTS}
:
config.mk
\
.version-checks/ZATHURA
\
.version-checks/POPPLER
${DOBJECTS}
:
config.mk
\
.version-checks/ZATHURA
\
.version-checks/POPPLER
${
PLUGIN}.so
:
${OBJECTS}
${
SOFILE}
:
${OBJECTS}
$(ECHO)
LD
$@
$(QUIET)${CC}
-shared
${LDFLAGS}
-o
$@
${OBJECTS}
${LIBS}
$(QUIET)${CC}
${PLATFORMFLAGS}
${LDFLAGS}
-o
$@
${OBJECTS}
${LIBS}
${
PLUGIN}-debug.so
:
${DOBJECTS}
${
SODEBUGFILE}
:
${DOBJECTS}
$(ECHO)
LD
$@
$(QUIET)${CC}
-shared
${LDFLAGS}
-o
$@
${
D
OBJECTS}
${LIBS}
$(QUIET)${CC}
${PLATFORMFLAGS}
${LDFLAGS}
-o
$@
${OBJECTS}
${LIBS}
clean
:
$(QUIET)
rm
-rf
${OBJECTS}
${DOBJECTS}
$
(PLUGIN)
.so
$(PLUGIN)
-debug
.so
\
$(QUIET)
rm
-rf
${OBJECTS}
${DOBJECTS}
$
{SOFILE}
${SODEBUGFILE}
\
doc .depend
${PROJECT}
-
${VERSION}
.tar.gz zathura-version-check
debug
:
options ${
PLUGIN}-debug.so
debug
:
options ${
SODEBUGFILE}
dist
:
clean
$(QUIET)
mkdir
-p
${PROJECT}
-
${VERSION}
...
...
@@ -77,7 +92,7 @@ doc: clean
install
:
all
$(ECHO)
installing
${PLUGIN}
plugin
$(QUIET)
mkdir
-p
${DESTDIR}${PLUGINDIR}
$(QUIET)
cp
-f
${
PLUGIN}
.so
${DESTDIR}${PLUGINDIR}
$(QUIET)
cp
-f
${
SOFILE}
${DESTDIR}${PLUGINDIR}
$(QUIET)
mkdir
-m
755
-p
${DESTDIR}${DESKTOPPREFIX}
$(ECHO)
installing desktop file
$(QUIET)
install
-m
644
${PROJECT}
.desktop
${DESTDIR}${DESKTOPPREFIX}
...
...
@@ -87,11 +102,11 @@ install: all
uninstall
:
$(ECHO)
uninstalling
${PLUGIN}
plugin
$(QUIET)
rm
-f
${DESTDIR}${PLUGINDIR}
/
${
PLUGIN}
.so
$(QUIET)
rmdir
--ignore-fail-on-non-empty
${DESTDIR}${PLUGINDIR}
2> /dev/null
$(QUIET)
rm
-f
${DESTDIR}${PLUGINDIR}
/
${
SOFILE}
$(QUIET)
find
${DESTDIR}${PLUGINDIR}
-type
d
-empty
-delete
2> /dev/null
$(ECHO)
removing desktop file
$(QUIET)
rm
-f
${DESTDIR}${DESKTOPPREFIX}
/
${PROJECT}
.desktop
$(QUIET)
rmdir
--ignore-fail-on-non-empty
${DESTDIR}${DESKTOPPREFIX}
2> /dev/null
$(QUIET)
find
${DESTDIR}${DESKTOPPREFIX}
-type
d
-empty
-delete
2> /dev/null
$(ECHO)
removing AppData file
$(QUIET)
rm
-f
$(DESTDIR)$(APPDATAPREFIX)
/
$(PROJECT)
.metainfo.xml
...
...
README
View file @
ced9b3cf
...
...
@@ -7,7 +7,7 @@ Requirements
------------
zathura (>= 0.2.0)
girara
poppler-glib
poppler-glib
(>= 0.18)
Installation
------------
...
...
attachments.c
View file @
ced9b3cf
...
...
@@ -32,9 +32,7 @@ pdf_document_attachments_get(zathura_document_t* document, PopplerDocument* popp
}
GList
*
attachment_list
=
poppler_document_get_attachments
(
poppler_document
);
GList
*
attachments
;
for
(
attachments
=
attachment_list
;
attachments
;
attachments
=
g_list_next
(
attachments
))
{
for
(
GList
*
attachments
=
attachment_list
;
attachments
!=
NULL
;
attachments
=
g_list_next
(
attachments
))
{
PopplerAttachment
*
attachment
=
(
PopplerAttachment
*
)
attachments
->
data
;
girara_list_append
(
res
,
g_strdup
(
attachment
->
name
));
}
...
...
@@ -57,9 +55,7 @@ pdf_document_attachment_save(zathura_document_t* document,
GList
*
attachment_list
=
poppler_document_get_attachments
(
poppler_document
);
GList
*
attachments
;
for
(
attachments
=
attachment_list
;
attachments
;
attachments
=
g_list_next
(
attachments
))
{
for
(
GList
*
attachments
=
attachment_list
;
attachments
!=
NULL
;
attachments
=
g_list_next
(
attachments
))
{
PopplerAttachment
*
attachment
=
(
PopplerAttachment
*
)
attachments
->
data
;
if
(
g_strcmp0
(
attachment
->
name
,
attachmentname
)
!=
0
)
{
continue
;
...
...
config.mk
View file @
ced9b3cf
...
...
@@ -2,15 +2,23 @@
VERSION_MAJOR
=
0
VERSION_MINOR
=
2
VERSION_REV
=
6
VERSION_REV
=
7
VERSION
=
${VERSION_MAJOR}
.
${VERSION_MINOR}
.
${VERSION_REV}
PKG_CONFIG
?=
pkg-config
# minimum required zathura version
# version checks
# If you want to disable any of the checks, set *_VERSION_CHECK to 0.
# zathura
ZATHURA_VERSION_CHECK
?=
1
ZATHURA_MIN_VERSION
=
0.2.0
ZATHURA_VERSION_CHECK
?=
$(
shell
$(PKG_CONFIG)
--atleast-version
=
$(ZATHURA_MIN_VERSION)
zathura
;
echo
$$
?
)
ZATHURA_GTK_VERSION
?=
$(
shell
$(PKG_CONFIG)
--variable
=
GTK_VERSION zathura
)
ZATHURA_PKG_CONFIG_NAME
=
zathura
# poppler
POPPLER_VERSION_CHECK
?=
1
POPPLER_MIN_VERSION
=
0.18
POPPLER_PKG_CONFIG_NAME
=
poppler-glib
# paths
PREFIX
?=
/usr
...
...
@@ -25,8 +33,8 @@ CAIRO_LIB ?= $(shell $(PKG_CONFIG) --libs cairo)
PDF_INC
?=
$(
shell
$(PKG_CONFIG)
--cflags
poppler-glib
)
PDF_LIB
?=
$(
shell
$(PKG_CONFIG)
--libs
poppler-glib
)
GIRARA_INC
?=
$(
shell
$(PKG_CONFIG)
--cflags
girara-gtk
${ZATHURA_GTK_VERSION}
)
GIRARA_LIB
?=
$(
shell
$(PKG_CONFIG)
--libs
girara-gtk
${ZATHURA_GTK_VERSION}
)
GIRARA_INC
?=
$(
shell
$(PKG_CONFIG)
--cflags
girara-gtk
3
)
GIRARA_LIB
?=
$(
shell
$(PKG_CONFIG)
--libs
girara-gtk
3
)
ZATHURA_INC
?=
$(
shell
$(PKG_CONFIG)
--cflags
zathura
)
PLUGINDIR
?=
$(
shell
$(PKG_CONFIG)
--variable
=
plugindir zathura
)
...
...
@@ -37,15 +45,21 @@ endif
INCS
=
${CAIRO_INC}
${PDF_INC}
${ZATHURA_INC}
${GIRARA_INC}
LIBS
=
${GIRARA_LIB}
${CAIRO_LIB}
${PDF_LIB}
# flags
# uname
UNAME
:=
$(
shell
uname
-s
)
# compiler flags
CFLAGS
+=
-std
=
c11
-fPIC
-pedantic
-Wall
-Wno-format-zero-length
$(INCS)
# linker flags
LDFLAGS
+=
-fPIC
ifeq
($(UNAME), Darwin)
LDFLAGS
+=
-fno-common
endif
# debug
DFLAGS
?=
-g
# build with cairo support?
WITH_CAIRO
?=
1
# compiler
CC
?=
gcc
LD
?=
ld
...
...
document.c
View file @
ced9b3cf
...
...
@@ -14,7 +14,7 @@ pdf_document_open(zathura_document_t* document)
/* format path */
GError
*
gerror
=
NULL
;
char
*
file_uri
=
g_filename_to_uri
(
zathura_document_get_path
(
document
),
NULL
,
&
gerror
);
char
*
file_uri
=
g_filename_to_uri
(
zathura_document_get_path
(
document
),
NULL
,
NULL
);
if
(
file_uri
==
NULL
)
{
error
=
ZATHURA_ERROR_UNKNOWN
;
...
...
@@ -44,13 +44,13 @@ pdf_document_open(zathura_document_t* document)
error_free:
if
(
gerror
!=
NULL
)
{
g_error_free
(
gerror
);
}
if
(
gerror
!=
NULL
)
{
g_error_free
(
gerror
);
}
if
(
file_uri
!=
NULL
)
{
g_free
(
file_uri
);
}
if
(
file_uri
!=
NULL
)
{
g_free
(
file_uri
);
}
return
error
;
}
...
...
@@ -77,9 +77,14 @@ pdf_document_save_as(zathura_document_t* document, PopplerDocument* poppler_docu
return
ZATHURA_ERROR_INVALID_ARGUMENTS
;
}
char
*
file_path
=
g_strdup_printf
(
"file://%s"
,
path
);
gboolean
ret
=
poppler_document_save
(
poppler_document
,
file_path
,
NULL
);
g_free
(
file_path
);
/* format path */
char
*
file_uri
=
g_filename_to_uri
(
path
,
NULL
,
NULL
);
if
(
file_uri
==
NULL
)
{
return
ZATHURA_ERROR_UNKNOWN
;
}
gboolean
ret
=
poppler_document_save
(
poppler_document
,
file_uri
,
NULL
);
g_free
(
file_uri
);
return
(
ret
==
true
?
ZATHURA_ERROR_OK
:
ZATHURA_ERROR_UNKNOWN
);
return
(
ret
==
TRUE
?
ZATHURA_ERROR_OK
:
ZATHURA_ERROR_UNKNOWN
);
}
image.c
View file @
ced9b3cf
...
...
@@ -75,7 +75,6 @@ error_ret:
return
NULL
;
}
#if HAVE_CAIRO
cairo_surface_t
*
pdf_page_image_get_cairo
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_image_t
*
image
,
zathura_error_t
*
error
)
...
...
@@ -103,8 +102,6 @@ error_ret:
return
NULL
;
}
#endif
static
void
pdf_zathura_image_free
(
zathura_image_t
*
image
)
...
...
links.c
View file @
ced9b3cf
...
...
@@ -36,15 +36,18 @@ pdf_page_links_get(zathura_page_t* page, PopplerPage* poppler_page, zathura_erro
zathura_document_t
*
zathura_document
=
(
zathura_document_t
*
)
zathura_page_get_document
(
page
);
PopplerDocument
*
poppler_document
=
zathura_document_get_data
(
zathura_document
);
const
double
page_height
=
zathura_page_get_height
(
page
);
for
(
GList
*
link
=
link_mapping
;
link
!=
NULL
;
link
=
g_list_next
(
link
))
{
PopplerLinkMapping
*
poppler_link
=
(
PopplerLinkMapping
*
)
link
->
data
;
/* extract position */
zathura_rectangle_t
position
=
{
0
,
0
,
0
,
0
};
position
.
x1
=
poppler_link
->
area
.
x1
;
position
.
x2
=
poppler_link
->
area
.
x2
;
position
.
y1
=
zathura_page_get_height
(
page
)
-
poppler_link
->
area
.
y2
;
position
.
y2
=
zathura_page_get_height
(
page
)
-
poppler_link
->
area
.
y1
;
const
zathura_rectangle_t
position
=
{
.
x1
=
poppler_link
->
area
.
x1
,
.
x2
=
poppler_link
->
area
.
x2
,
.
y1
=
page_height
-
poppler_link
->
area
.
y2
,
.
y2
=
page_height
-
poppler_link
->
area
.
y1
};
zathura_link_t
*
zathura_link
=
poppler_link_to_zathura_link
(
poppler_document
,
poppler_link
->
action
,
...
...
plugin.c
View file @
ced9b3cf
...
...
@@ -19,13 +19,8 @@ register_functions(zathura_plugin_functions_t* functions)
functions
->
page_form_fields_get
=
(
zathura_plugin_page_form_fields_get_t
)
pdf_page_form_fields_get
;
functions
->
page_images_get
=
(
zathura_plugin_page_images_get_t
)
pdf_page_images_get
;
functions
->
page_get_text
=
(
zathura_plugin_page_get_text_t
)
pdf_page_get_text
;
#if !POPPLER_CHECK_VERSION(0,18,0)
functions
->
page_render
=
(
zathura_plugin_page_render_t
)
pdf_page_render
;
#endif
#if HAVE_CAIRO
functions
->
page_render_cairo
=
(
zathura_plugin_page_render_cairo_t
)
pdf_page_render_cairo
;
functions
->
page_image_get_cairo
=
(
zathura_plugin_page_image_get_cairo_t
)
pdf_page_image_get_cairo
;
#endif
}
ZATHURA_PLUGIN_REGISTER
(
...
...
plugin.h
View file @
ced9b3cf
...
...
@@ -6,9 +6,7 @@
#include
<stdbool.h>
#include
<poppler.h>
#if HAVE_CAIRO
#include
<cairo.h>
#endif
#include
<zathura/page.h>
#include
<zathura/document.h>
...
...
@@ -18,7 +16,7 @@
* Open a pdf document
*
* @param document Zathura document
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_document_open
(
zathura_document_t
*
document
);
...
...
@@ -27,7 +25,7 @@ zathura_error_t pdf_document_open(zathura_document_t* document);
* Closes and frees the internal document structure
*
* @param document Zathura document
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_document_free
(
zathura_document_t
*
document
,
PopplerDocument
*
poppler_document
);
...
...
@@ -36,7 +34,7 @@ zathura_error_t pdf_document_free(zathura_document_t* document, PopplerDocument*
* Initializes the page with the needed values
*
* @param page The page object
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_page_init
(
zathura_page_t
*
page
);
...
...
@@ -45,7 +43,7 @@ zathura_error_t pdf_page_init(zathura_page_t* page);
* Frees the data that is used by the plugin in the page
*
* @param page Page
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_page_clear
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
);
...
...
@@ -55,7 +53,7 @@ zathura_error_t pdf_page_clear(zathura_page_t* page, PopplerPage* poppler_page);
*
* @param document Zathura document
* @param path File path
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_document_save_as
(
zathura_document_t
*
document
,
...
...
@@ -66,7 +64,7 @@ zathura_error_t pdf_document_save_as(zathura_document_t* document,
*
* @param document Zathura document
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return Tree node object or NULL if an error occurred (e.g.: the document has
* no index)
*/
...
...
@@ -78,7 +76,7 @@ girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document,
*
* @param document Zathura document
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of attachments or NULL if an error occurred
*/
girara_list_t
*
pdf_document_attachments_get
(
zathura_document_t
*
document
,
...
...
@@ -90,7 +88,7 @@ girara_list_t* pdf_document_attachments_get(zathura_document_t* document,
* @param document Zathura document
* @param attachment Name of the attachment
* @param filename Target file path where the attachment should be saved to
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_document_attachment_save
(
zathura_document_t
*
...
...
@@ -101,32 +99,30 @@ zathura_error_t pdf_document_attachment_save(zathura_document_t*
*
* @param page The page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of images
*/
girara_list_t
*
pdf_page_images_get
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_error_t
*
error
);
#if HAVE_CAIRO
/**
* Gets the content of the image in a cairo surface
*
* @param page Page
* @param image Image identifier
* @param error Set to an error value (see \ref zathura_error_t) if an
* error occured
* @return The cairo image surface or NULL if an error occured
* error occur
r
ed
* @return The cairo image surface or NULL if an error occur
r
ed
*/
cairo_surface_t
*
pdf_page_image_get_cairo
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_image_t
*
image
,
zathura_error_t
*
error
);
#endif
/**
* Returns a list of document information entries of the document
*
* @param document Zathura document
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of information entries or NULL if an error occurred
*/
girara_list_t
*
pdf_document_get_information
(
zathura_document_t
*
document
,
...
...
@@ -138,7 +134,7 @@ girara_list_t* pdf_document_get_information(zathura_document_t* document,
* @param page Page
* @param text Search item
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of search results or NULL if an error occurred
*/
girara_list_t
*
pdf_page_search_text
(
zathura_page_t
*
page
,
PopplerPage
*
...
...
@@ -149,7 +145,7 @@ girara_list_t* pdf_page_search_text(zathura_page_t* page, PopplerPage*
*
* @param page Page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of links or NULL if an error occurred
*/
girara_list_t
*
pdf_page_links_get
(
zathura_page_t
*
page
,
...
...
@@ -160,7 +156,7 @@ girara_list_t* pdf_page_links_get(zathura_page_t* page,
*
* @param page Page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* error occur
r
ed
* @return List of form fields or NULL if an error occurred
*/
girara_list_t
*
pdf_page_form_fields_get
(
zathura_page_t
*
page
,
...
...
@@ -171,38 +167,22 @@ girara_list_t* pdf_page_form_fields_get(zathura_page_t* page,
* @param page Page
* @param rectangle Selection
* @error Set to an error value (see \ref zathura_error_t) if an error
* occured
* occur
r
ed
* @return The selected text (needs to be deallocated with g_free)
*/
char
*
pdf_page_get_text
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_rectangle_t
rectangle
,
zathura_error_t
*
error
);
#if !POPPLER_CHECK_VERSION(0,18,0)
/**
* Renders a page and returns a allocated image buffer which has to be freed
* with zathura_image_buffer_free
*
* @param page Page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return Image buffer or NULL if an error occurred
*/
zathura_image_buffer_t
*
pdf_page_render
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_error_t
*
error
);
#endif
#if HAVE_CAIRO
/**
* Renders a page onto a cairo object
*
* @param page Page
* @param cairo Cairo object
* @param printing Set to true if page should be rendered for printing
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* @return ZATHURA_ERROR_OK when no error occur
r
ed, otherwise see
* zathura_error_t
*/
zathura_error_t
pdf_page_render_cairo
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
cairo_t
*
cairo
,
bool
printing
);
#endif
#endif // PDF_H
render.c
View file @
ced9b3cf
...
...
@@ -2,11 +2,6 @@
#include
"plugin.h"
#if !defined(HAVE_CAIRO) && POPPLER_CHECK_VERSION(0,18,0)
#error "Cannot render without cairo and poppler >= 0.18"
#endif
#ifdef HAVE_CAIRO
zathura_error_t
pdf_page_render_cairo
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
cairo_t
*
cairo
,
bool
printing
)
...
...
@@ -23,72 +18,3 @@ pdf_page_render_cairo(zathura_page_t* page, PopplerPage* poppler_page, cairo_t*
return
ZATHURA_ERROR_OK
;
}
#endif
#if !POPPLER_CHECK_VERSION(0,18,0)
zathura_image_buffer_t
*
pdf_page_render
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_error_t
*
error
)
{
if
(
page
==
NULL
||
poppler_page
==
NULL
)
{
if
(
error
!=
NULL
)
{
*
error
=
ZATHURA_ERROR_INVALID_ARGUMENTS
;
}
return
NULL
;
}
zathura_document_t
*
document
=
zathura_page_get_document
(
page
);
if
(
document
==
NULL
)
{
return
NULL
;
}
/* calculate sizes */
double
scale
=
zathura_document_get_scale
(
document
);
unsigned
int
page_width
=
ceil
(
scale
*
zathura_page_get_width
(
page
));
unsigned
int
page_height
=
ceil
(
scale
*
zathura_page_get_height
(
page
));
/* create pixbuf */
GdkPixbuf
*
pixbuf
=
gdk_pixbuf_new
(
GDK_COLORSPACE_RGB
,
FALSE
,
8
,
page_width
,
page_height
);
if
(
pixbuf
==
NULL
)
{
if
(
error
!=
NULL
)
{
*
error
=
ZATHURA_ERROR_OUT_OF_MEMORY
;
}
return
NULL
;
}
poppler_page_render_to_pixbuf
(
poppler_page
,
0
,
0
,
page_width
,
page_height
,
scale
,
0
,
pixbuf
);
/* create image buffer */
zathura_image_buffer_t
*
image_buffer
=
zathura_image_buffer_create
(
page_width
,
page_height
);
if
(
image_buffer
==
NULL
)
{
if
(
error
!=
NULL
)
{
*
error
=
ZATHURA_ERROR_OUT_OF_MEMORY
;
}
g_object_unref
(
pixbuf
);
return
NULL
;
}
/* copy buffer */
guchar
*
pixels
=
gdk_pixbuf_get_pixels
(
pixbuf
);
int
rowstride
=
gdk_pixbuf_get_rowstride
(
pixbuf
);
int
n_channels
=
gdk_pixbuf_get_n_channels
(
pixbuf
);
for
(
unsigned
int
y
=
0
;
y
<
page_height
;
y
++
)
{
for
(
unsigned
int
x
=
0
;
x
<
page_width
;
x
++
)
{
unsigned
char
*
s
=
pixels
+
y
*
rowstride
+
x
*
n_channels
;
guchar
*
p
=
image_buffer
->
data
+
y
*
image_buffer
->
rowstride
+
x
*
3
;
p
[
0
]
=
s
[
0
];
p
[
1
]
=
s
[
1
];
p
[
2
]
=
s
[
2
];
}
}
g_object_unref
(
pixbuf
);
return
image_buffer
;
}
#endif
select.c
View file @
ced9b3cf
...
...
@@ -2,10 +2,6 @@
#include
"plugin.h"
#if !POPPLER_CHECK_VERSION(0,15,0)
#define poppler_page_get_selected_text poppler_page_get_text
#endif
char
*
pdf_page_get_text
(
zathura_page_t
*
page
,
PopplerPage
*
poppler_page
,
zathura_rectangle_t
rectangle
,
zathura_error_t
*
error
)
...
...
@@ -17,17 +13,12 @@ pdf_page_get_text(zathura_page_t* page, PopplerPage* poppler_page,
return
NULL
;
}
PopplerRectangle
rect
;
rect
.
x1
=
rectangle
.
x1
;
rect
.
x2
=
rectangle
.
x2
;
#if !POPPLER_CHECK_VERSION(0,15,0)
/* adapt y coordinates */
rect
.
y1
=
zathura_page_get_height
(
page
)
-
rectangle
.
y1
;
rect
.
y2
=
zathura_page_get_height
(
page
)
-
rectangle
.
y2
;
#else
rect
.
y1
=
rectangle
.
y1
;
rect
.
y2
=
rectangle
.
y2
;
#endif
PopplerRectangle
rect
=
{
.
x1
=
rectangle
.
x1
,
.
x2
=
rectangle
.
x2
,
.
y1
=
rectangle
.
y1
,
.
y2
=
rectangle
.
y2
};
/* get selected text */
return
poppler_page_get_selected_text
(
poppler_page
,
POPPLER_SELECTION_GLYPH
,
&
rect
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment