Sisyphus repository
Last update: 1 october 2023 | SRPMs: 18631 | Visits: 37908882
en ru br
ALT Linux repos
S:0.3.1-alt1

Group :: Office
RPM: zathura-pdf-poppler

 Main   Changelog   Spec   Patches   Sources   Download   Gear   Bugs and FR  Repocop 

pax_global_header00006660000000000000000000000064123004155340014507gustar00rootroot0000000000000052 comment=b1a784893126ad8ed28bedfc1fe532ef6790f372
zathura-pdf-poppler-0.2.5/000075500000000000000000000000001230041553400154155ustar00rootroot00000000000000zathura-pdf-poppler-0.2.5/.gitignore000064400000000000000000000001421230041553400174020ustar00rootroot00000000000000*.o
*.do
*~
.depend
*.so
*.swp
zathura-version-check
tags
compile_commands.json
.ycm_extra_conf.*
zathura-pdf-poppler-0.2.5/AUTHORS000064400000000000000000000003501230041553400164630ustar00rootroot00000000000000zathura-pdf-poppler is written by:

Moritz Lipp <mlq@pwmt.org>
Sebastian Ramacher <sebastian+dev@ramacher.at>

Other contributors are (in no particular order):

oblique <psyberbits@gmail.com>
Benoît Knecht <benoit.knecht@fsfe.org>
zathura-pdf-poppler-0.2.5/Doxyfile000064400000000000000000000011731230041553400171250ustar00rootroot00000000000000# See LICENSE file for license and copyright information

# General information
PROJECT_NAME = zathura-pdf-poppler
OUTPUT_DIRECTORY = ./doc/
OUTPUT_LANGUAGE = English
TAB_SIZE = 2
EXTRACT_ALL = YES
OPTIMIZE_OUTPUT_FOR_C = YES
DOXYFILE_ENCODING = UTF-8
TYPEDEF_HIDES_STRUCT = YES

# Warning and progress messages
QUIET = YES
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES

# Input files
INPUT =
FILE_PATTERNS = *.h *.c
RECURSIVE = YES

# Output files
GENERATE_HTML = YES
GENERATE_LATEX = NO
GENERATE_RTF = NO
GENERATE_XML = NO

SOURCE_BROWSER = YES
zathura-pdf-poppler-0.2.5/LICENSE000064400000000000000000000015421230041553400164240ustar00rootroot00000000000000Copyright (c) 2011-2013 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
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.

2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.

3. This notice may not be removed or altered from any source
distribution.
zathura-pdf-poppler-0.2.5/Makefile000064400000000000000000000051501230041553400170560ustar00rootroot00000000000000# See LICENSE file for license and copyright information

include config.mk
include common.mk

PROJECT = zathura-pdf-poppler
PLUGIN = pdf
SOURCE = $(wildcard *.c)
HEADER = $(wildcard *.h)
OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do}

ifneq "$(WITH_CAIRO)" "0"
CPPFLAGS += -DHAVE_CAIRO
endif

CPPFLAGS += "-DVERSION_MAJOR=${VERSION_MAJOR}"
CPPFLAGS += "-DVERSION_MINOR=${VERSION_MINOR}"
CPPFLAGS += "-DVERSION_REV=${VERSION_REV}"

all: options ${PLUGIN}.so

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

options:
$(ECHO) ${PLUGIN} build options:
$(ECHO) "CFLAGS = ${CFLAGS}"
$(ECHO) "LDFLAGS = ${LDFLAGS}"
$(ECHO) "DFLAGS = ${DFLAGS}"
$(ECHO) "CC = ${CC}"

%.o: %.c
$(ECHO) CC $<
@mkdir -p .depend
$(QUIET)${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep

%.do: %.c
$(ECHO) CC $<
@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

${PLUGIN}.so: ${OBJECTS}
$(ECHO) LD $@
$(QUIET)${CC} -shared ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS}

${PLUGIN}-debug.so: ${DOBJECTS}
$(ECHO) LD $@
$(QUIET)${CC} -shared ${LDFLAGS} -o $@ ${DOBJECTS} ${LIBS}

clean:
$(QUIET)rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so $(PLUGIN)-debug.so \
doc .depend ${PROJECT}-${VERSION}.tar.gz zathura-version-check

debug: options ${PLUGIN}-debug.so

dist: clean
$(QUIET)mkdir -p ${PROJECT}-${VERSION}
$(QUIET)cp -R LICENSE Makefile config.mk common.mk Doxyfile \
${HEADER} ${SOURCE} AUTHORS ${PROJECT}.desktop \
${PROJECT}-${VERSION}
$(QUIET)tar -cf ${PROJECT}-${VERSION}.tar ${PROJECT}-${VERSION}
$(QUIET)gzip ${PROJECT}-${VERSION}.tar
$(QUIET)rm -rf ${PROJECT}-${VERSION}

doc: clean
$(QUIET)doxygen Doxyfile

install: all
$(ECHO) installing ${PLUGIN} plugin
$(QUIET)mkdir -p ${DESTDIR}${PLUGINDIR}
$(QUIET)cp -f ${PLUGIN}.so ${DESTDIR}${PLUGINDIR}
$(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX}
$(ECHO) installing desktop file
$(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX}

uninstall:
$(ECHO) uninstalling ${PLUGIN} plugin
$(QUIET)rm -f ${DESTDIR}${PLUGINDIR}/${PLUGIN}.so
$(QUIET)rmdir --ignore-fail-on-non-empty ${DESTDIR}${PLUGINDIR} 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

-include $(wildcard .depend/*.dep)

.PHONY: all options clean debug doc dist install uninstall
zathura-pdf-poppler-0.2.5/README000064400000000000000000000005641230041553400163020ustar00rootroot00000000000000zathura-pdf-poppler
===================
The zathura-pdf-poppler plugin adds PDF support to zathura by using the poppler
rendering library.

Requirements
------------
zathura (>= 0.2.0)
girara
poppler-glib

Installation
------------
To build and install the plugin:

make install

Uninstall:
----------
To delete the plugin from your system, just type:

make uninstall
zathura-pdf-poppler-0.2.5/attachments.c000064400000000000000000000040501230041553400200730ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include <girara/utils.h>

#include "plugin.h"

girara_list_t*
pdf_document_attachments_get(zathura_document_t* document, PopplerDocument* poppler_document, zathura_error_t* error)
{
if (document == NULL || poppler_document == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}

if (poppler_document_has_attachments(poppler_document) == FALSE) {
girara_warning("PDF file has no attachments");
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
return NULL;
}

girara_list_t* res = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0,
(girara_free_function_t) g_free);
if (res == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
return NULL;
}

GList* attachment_list = poppler_document_get_attachments(poppler_document);
GList* attachments;

for (attachments = attachment_list; attachments; attachments = g_list_next(attachments)) {
PopplerAttachment* attachment = (PopplerAttachment*) attachments->data;
girara_list_append(res, g_strdup(attachment->name));
}

return res;
}

zathura_error_t
pdf_document_attachment_save(zathura_document_t* document,
PopplerDocument* poppler_document, const char* attachmentname, const char* file)
{
if (document == NULL || poppler_document == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

if (poppler_document_has_attachments(poppler_document) == FALSE) {
girara_warning("PDF file has no attachments");
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}


GList* attachment_list = poppler_document_get_attachments(poppler_document);
GList* attachments;

for (attachments = attachment_list; attachments; attachments = g_list_next(attachments)) {
PopplerAttachment* attachment = (PopplerAttachment*) attachments->data;
if (g_strcmp0(attachment->name, attachmentname) != 0) {
continue;
}

return poppler_attachment_save(attachment, file, NULL);
}

return ZATHURA_ERROR_OK;
}
zathura-pdf-poppler-0.2.5/common.mk000064400000000000000000000001761230041553400172420ustar00rootroot00000000000000# See LICENSE file for license and copyright information

ifeq "$(VERBOSE)" "0"
ECHO=@echo
QUIET=@
else
ECHO=@\#
QUIET=
endif
zathura-pdf-poppler-0.2.5/config.mk000064400000000000000000000025601230041553400172160ustar00rootroot00000000000000# See LICENSE file for license and copyright information

VERSION_MAJOR = 0
VERSION_MINOR = 2
VERSION_REV = 5
VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}

# minimum required zathura version
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)

# paths
PREFIX ?= /usr
LIBDIR ?= ${PREFIX}/lib
DESKTOPPREFIX ?= ${PREFIX}/share/applications

# libs
CAIRO_INC ?= $(shell pkg-config --cflags cairo)
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})

ZATHURA_INC ?= $(shell pkg-config --cflags zathura)
PLUGINDIR ?= $(shell pkg-config --variable=plugindir zathura)
ifeq (,${PLUGINDIR})
PLUGINDIR = ${LIBDIR}/zathura
endif

INCS = ${CAIRO_INC} ${PDF_INC} ${ZATHURA_INC} ${GIRARA_INC}
LIBS = ${GIRARA_LIB} ${CAIRO_LIB} ${PDF_LIB}

# flags
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)

# debug
DFLAGS ?= -g

# build with cairo support?
WITH_CAIRO ?= 1

# compiler
CC ?= gcc
LD ?= ld

# set to something != 0 if you want verbose build output
VERBOSE ?= 0
zathura-pdf-poppler-0.2.5/document.c000064400000000000000000000037641230041553400174110ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"
#include "utils.h"

zathura_error_t
pdf_document_open(zathura_document_t* document)
{
if (document == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

zathura_error_t error = ZATHURA_ERROR_OK;

/* format path */
GError* gerror = NULL;
char* file_uri = g_filename_to_uri(zathura_document_get_path(document), NULL, &gerror);

if (file_uri == NULL) {
error = ZATHURA_ERROR_UNKNOWN;
goto error_free;
}

PopplerDocument* poppler_document = poppler_document_new_from_file(file_uri,
zathura_document_get_password(document), &gerror);

if (poppler_document == NULL) {
if(gerror != NULL && gerror->code == POPPLER_ERROR_ENCRYPTED) {
error = ZATHURA_ERROR_INVALID_PASSWORD;
} else {
error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}

zathura_document_set_data(document, poppler_document);

zathura_document_set_number_of_pages(document,
poppler_document_get_n_pages(poppler_document));

g_free(file_uri);

return ZATHURA_ERROR_OK;

error_free:

if (gerror != NULL) {
g_error_free(gerror);
}

if (file_uri != NULL) {
g_free(file_uri);
}

return error;
}

zathura_error_t
pdf_document_free(zathura_document_t* document, PopplerDocument* poppler_document)
{
if (document == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

if (poppler_document != NULL) {
g_object_unref(poppler_document);
zathura_document_set_data(document, NULL);
}

return ZATHURA_ERROR_OK;
}

zathura_error_t
pdf_document_save_as(zathura_document_t* document, PopplerDocument* poppler_document, const char* path)
{
if (document == NULL || poppler_document == NULL || path == NULL) {
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);

return (ret == true ? ZATHURA_ERROR_OK : ZATHURA_ERROR_UNKNOWN);
}
zathura-pdf-poppler-0.2.5/forms.c000064400000000000000000000004421230041553400167070ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"

girara_list_t*
pdf_page_form_fields_get(zathura_page_t* page, PopplerPage* poppler_page,
zathura_error_t* error)
{
if (error != NULL) {
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
}
return NULL;
}
zathura-pdf-poppler-0.2.5/image.c000064400000000000000000000052461230041553400166520ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"
#include "utils.h"

static void pdf_zathura_image_free(zathura_image_t* image);

girara_list_t*
pdf_page_images_get(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;
}
goto error_ret;
}

girara_list_t* list = NULL;
GList* image_mapping = NULL;

image_mapping = poppler_page_get_image_mapping(poppler_page);
if (image_mapping == NULL || g_list_length(image_mapping) == 0) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}

list = girara_list_new();
if (list == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
goto error_free;
}

girara_list_set_free_function(list, (girara_free_function_t) pdf_zathura_image_free);

for (GList* image = image_mapping; image != NULL; image = g_list_next(image)) {
zathura_image_t* zathura_image = g_malloc0(sizeof(zathura_image_t));

PopplerImageMapping* poppler_image = (PopplerImageMapping*) image->data;

/* extract id */
zathura_image->data = g_malloc(sizeof(gint));

gint* image_id = zathura_image->data;
*image_id = poppler_image->image_id;

/* extract position */
zathura_image->position.x1 = poppler_image->area.x1;
zathura_image->position.x2 = poppler_image->area.x2;
zathura_image->position.y1 = poppler_image->area.y1;
zathura_image->position.y2 = poppler_image->area.y2;

girara_list_append(list, zathura_image);
}

poppler_page_free_image_mapping(image_mapping);

return list;

error_free:

if (list != NULL) {
girara_list_free(list);
}

if (image_mapping != NULL) {
poppler_page_free_image_mapping(image_mapping);
}

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)
{
if (page == NULL || poppler_page == NULL || image == NULL || image->data == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
goto error_ret;
}

gint* image_id = (gint*) image->data;

cairo_surface_t* surface = poppler_page_get_image(poppler_page, *image_id);
if (surface == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_ret;
}

return surface;

error_ret:

return NULL;
}
#endif


static void
pdf_zathura_image_free(zathura_image_t* image)
{
if (image == NULL) {
return;
}

if (image->data != NULL) {
g_free(image->data);
}

g_free(image);
}
zathura-pdf-poppler-0.2.5/index.c000064400000000000000000000041121230041553400166660ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"
#include "utils.h"

static void build_index(PopplerDocument* poppler_document, girara_tree_node_t*
root, PopplerIndexIter* iter);

girara_tree_node_t*
pdf_document_index_generate(zathura_document_t* document, PopplerDocument* poppler_document, zathura_error_t* error)
{
if (document == NULL || poppler_document == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}

PopplerIndexIter* iter = poppler_index_iter_new(poppler_document);

if (iter == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
return NULL;
}

girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT"));
// girara_node_set_free_function(root, (girara_free_function_t) zathura_index_element_free);
build_index(poppler_document, root, iter);

poppler_index_iter_free(iter);
return root;
}

static void
build_index(PopplerDocument* poppler_document, girara_tree_node_t* root, PopplerIndexIter* iter)
{
if (poppler_document == NULL || root == NULL || iter == NULL) {
return;
}

do {
PopplerAction* action = poppler_index_iter_get_action(iter);

if (action == NULL) {
continue;
}

gchar* markup = g_markup_escape_text(action->any.title, -1);
zathura_index_element_t* index_element = zathura_index_element_new(markup);

g_free(markup);

if (index_element == NULL) {
poppler_action_free(action);
continue;
}

zathura_rectangle_t rect = { 0, 0, 0, 0 };
index_element->link = poppler_link_to_zathura_link(poppler_document, action, rect);
if (index_element->link == NULL) {
poppler_action_free(action);
continue;
}

poppler_action_free(action);

girara_tree_node_t* node = girara_node_append_data(root, index_element);
PopplerIndexIter* child = poppler_index_iter_get_child(iter);

if (child != NULL) {
build_index(poppler_document, node, child);
}

poppler_index_iter_free(child);

} while (poppler_index_iter_next(iter));
}
zathura-pdf-poppler-0.2.5/links.c000064400000000000000000000037201230041553400167030ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"
#include "utils.h"

girara_list_t*
pdf_page_links_get(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;
}
goto error_ret;
}

girara_list_t* list = NULL;
GList* link_mapping = NULL;

link_mapping = poppler_page_get_link_mapping(poppler_page);
if (link_mapping == NULL || g_list_length(link_mapping) == 0) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}
link_mapping = g_list_reverse(link_mapping);

list = girara_list_new2((girara_free_function_t) zathura_link_free);
if (list == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
goto error_free;
}

zathura_document_t* zathura_document = (zathura_document_t*) zathura_page_get_document(page);
PopplerDocument* poppler_document = zathura_document_get_data(zathura_document);

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;

zathura_link_t* zathura_link =
poppler_link_to_zathura_link(poppler_document, poppler_link->action,
position);
if (zathura_link != NULL) {
girara_list_append(list, zathura_link);
}
}

poppler_page_free_link_mapping(link_mapping);

return list;

error_free:

if (list != NULL) {
girara_list_free(list);
}

if (link_mapping != NULL) {
poppler_page_free_link_mapping(link_mapping);
}

error_ret:

return NULL;
}
zathura-pdf-poppler-0.2.5/meta.c000064400000000000000000000045111230041553400165100ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include <string.h>

#include "plugin.h"

#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))

girara_list_t*
pdf_document_get_information(zathura_document_t* document, PopplerDocument*
poppler_document, zathura_error_t* error)
{
if (document == NULL || poppler_document == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
return NULL;
}

girara_list_t* list = zathura_document_information_entry_list_new();
if (list == NULL) {
return NULL;
}

/* get string values */
typedef struct info_value_s {
const char* property;
zathura_document_information_type_t type;
} info_value_t;

static const info_value_t string_values[] = {
{ "title", ZATHURA_DOCUMENT_INFORMATION_TITLE },
{ "author", ZATHURA_DOCUMENT_INFORMATION_AUTHOR },
{ "subject", ZATHURA_DOCUMENT_INFORMATION_SUBJECT },
{ "keywords", ZATHURA_DOCUMENT_INFORMATION_KEYWORDS },
{ "creator", ZATHURA_DOCUMENT_INFORMATION_CREATOR },
{ "producer", ZATHURA_DOCUMENT_INFORMATION_PRODUCER }
};

char* string_value;
for (unsigned int i = 0; i < LENGTH(string_values); i++) {
g_object_get(poppler_document, string_values[i].property, &string_value, NULL);
zathura_document_information_entry_t* entry = zathura_document_information_entry_new(
string_values[i].type, string_value);
if (entry != NULL) {
girara_list_append(list, entry);
}
}

/* get time values */
static const info_value_t time_values[] = {
{ "creation-date", ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE },
{ "mod-date", ZATHURA_DOCUMENT_INFORMATION_MODIFICATION_DATE }
};

for (unsigned int i = 0; i < LENGTH(time_values); i++) {
/* the properties stored in PopplerDocument are gints */
gint time_value;
g_object_get(poppler_document, time_values[i].property, &time_value, NULL);
/* but we need time_ts */
time_t r_time_value = time_value;
char* tmp = ctime(&r_time_value);
if (tmp != NULL) {
string_value = g_strndup(tmp, strlen(tmp) - 1);
zathura_document_information_entry_t* entry = zathura_document_information_entry_new(
time_values[i].type, string_value);
if (entry != NULL) {
girara_list_append(list, entry);
}
g_free(string_value);
}
}

return list;
}
zathura-pdf-poppler-0.2.5/page.c000064400000000000000000000022421230041553400164750ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"

zathura_error_t
pdf_page_init(zathura_page_t* page)
{
if (page == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

zathura_document_t* document = zathura_page_get_document(page);
PopplerDocument* poppler_document = zathura_document_get_data(document);

if (poppler_document == NULL) {
return ZATHURA_ERROR_UNKNOWN;
}

/* init poppler data */
PopplerPage* poppler_page = poppler_document_get_page(poppler_document, zathura_page_get_index(page));

if (poppler_page == NULL) {
g_free(poppler_page);
return ZATHURA_ERROR_UNKNOWN;
}

zathura_page_set_data(page, poppler_page);

/* calculate dimensions */
double width;
double height;
poppler_page_get_size(poppler_page, &width, &height);
zathura_page_set_width(page, width);
zathura_page_set_height(page, height);

return ZATHURA_ERROR_OK;
}

zathura_error_t
pdf_page_clear(zathura_page_t* page, PopplerPage* poppler_page)
{
if (page == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

if (poppler_page != NULL) {
g_object_unref(poppler_page);
}

return ZATHURA_ERROR_OK;
}
zathura-pdf-poppler-0.2.5/plugin.c000064400000000000000000000040241230041553400170570ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "plugin.h"

void
register_functions(zathura_plugin_functions_t* functions)
{
functions->document_open = (zathura_plugin_document_open_t) pdf_document_open;
functions->document_free = (zathura_plugin_document_free_t) pdf_document_free;
functions->document_index_generate = (zathura_plugin_document_index_generate_t) pdf_document_index_generate;
functions->document_save_as = (zathura_plugin_document_save_as_t) pdf_document_save_as;
functions->document_attachments_get = (zathura_plugin_document_attachments_get_t) pdf_document_attachments_get;
functions->document_attachment_save = (zathura_plugin_document_attachment_save_t) pdf_document_attachment_save;
functions->document_get_information = (zathura_plugin_document_get_information_t) pdf_document_get_information;
functions->page_init = (zathura_plugin_page_init_t) pdf_page_init;
functions->page_clear = (zathura_plugin_page_clear_t) pdf_page_clear;
functions->page_search_text = (zathura_plugin_page_search_text_t) pdf_page_search_text;
functions->page_links_get = (zathura_plugin_page_links_get_t) pdf_page_links_get;
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(
"pdf-poppler",
VERSION_MAJOR, VERSION_MINOR, VERSION_REV,
register_functions,
ZATHURA_PLUGIN_MIMETYPES({
"application/pdf"
})
)
zathura-pdf-poppler-0.2.5/plugin.h000064400000000000000000000143131230041553400170660ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#ifndef PDF_H
#define PDF_H

#include <stdbool.h>
#include <poppler.h>

#if HAVE_CAIRO
#include <cairo.h>
#endif

#include <zathura/page.h>
#include <zathura/document.h>
#include <zathura/plugin-api.h>

/**
* Open a pdf document
*
* @param document Zathura document
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t
*/
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
* zathura_error_t
*/
zathura_error_t pdf_document_free(zathura_document_t* document, PopplerDocument* poppler_document);

/**
* Initializes the page with the needed values
*
* @param page The page object
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t
*/
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
* zathura_error_t
*/
zathura_error_t pdf_page_clear(zathura_page_t* page, PopplerPage* poppler_page);

/**
* Saves the document to the given path
*
* @param document Zathura document
* @param path File path
* @return ZATHURA_ERROR_OK when no error occured, otherwise see
* zathura_error_t
*/
zathura_error_t pdf_document_save_as(zathura_document_t* document,
PopplerDocument* poppler_document, const char* path);

/**
* Generates the index of the document
*
* @param document Zathura document
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return Tree node object or NULL if an error occurred (e.g.: the document has
* no index)
*/
girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document,
PopplerDocument* poppler_document, zathura_error_t* error);

/**
* Returns a list of attachments included in the zathura document
*
* @param document Zathura document
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return List of attachments or NULL if an error occurred
*/
girara_list_t* pdf_document_attachments_get(zathura_document_t* document,
PopplerDocument* poppler_document, zathura_error_t* error);

/**
* Saves an attachment to a file
*
* @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
* zathura_error_t
*/
zathura_error_t pdf_document_attachment_save(zathura_document_t*
document, PopplerDocument* poppler_document, const char* attachment, const char* filename);

/**
* Returns a list of images included on the zathura page
*
* @param page The page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @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
*/
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
* @return List of information entries or NULL if an error occurred
*/
girara_list_t* pdf_document_get_information(zathura_document_t* document,
PopplerDocument* poppler_document, zathura_error_t* error);

/**
* Searches for a specific text on a page and returns a list of results
*
* @param page Page
* @param text Search item
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return List of search results or NULL if an error occurred
*/
girara_list_t* pdf_page_search_text(zathura_page_t* page, PopplerPage*
data, const char* text, zathura_error_t* error);

/**
* Returns a list of internal/external links that are shown on the given page
*
* @param page Page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return List of links or NULL if an error occurred
*/
girara_list_t* pdf_page_links_get(zathura_page_t* page,
PopplerPage* poppler_page, zathura_error_t* error);

/**
* Returns a list of form fields available on the given page
*
* @param page Page
* @param error Set to an error value (see zathura_error_t) if an
* error occured
* @return List of form fields or NULL if an error occurred
*/
girara_list_t* pdf_page_form_fields_get(zathura_page_t* page,
PopplerPage* poppler_page, zathura_error_t* error);

/**
* Get text for selection
* @param page Page
* @param rectangle Selection
* @error Set to an error value (see \ref zathura_error_t) if an error
* occured
* @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
* 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
zathura-pdf-poppler-0.2.5/render.c000064400000000000000000000046521230041553400170470ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#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)
{
if (page == NULL || poppler_page == NULL || cairo == NULL) {
return ZATHURA_ERROR_INVALID_ARGUMENTS;
}

if (printing == false) {
poppler_page_render(poppler_page, cairo);
} else {
poppler_page_render_for_printing(poppler_page, cairo);
}

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
zathura-pdf-poppler-0.2.5/search.c000064400000000000000000000031621230041553400170300ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include <string.h>

#include "plugin.h"

girara_list_t*
pdf_page_search_text(zathura_page_t* page, PopplerPage* poppler_page, const
char* text, zathura_error_t* error)
{
if (page == NULL || poppler_page == NULL || text == NULL || strlen(text) == 0) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
goto error_ret;
}

GList* results = NULL;
girara_list_t* list = NULL;

/* search text */
results = poppler_page_find_text(poppler_page, text);
if (results == NULL || g_list_length(results) == 0) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}

list = girara_list_new2(g_free);
if (list == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_OUT_OF_MEMORY;
}
goto error_free;
}

GList* entry = NULL;
for (entry = results; entry && entry->data; entry = g_list_next(entry)) {
PopplerRectangle* poppler_rectangle = (PopplerRectangle*) entry->data;
zathura_rectangle_t* rectangle = g_malloc0(sizeof(zathura_rectangle_t));

rectangle->x1 = poppler_rectangle->x1;
rectangle->x2 = poppler_rectangle->x2;
rectangle->y1 = zathura_page_get_height(page) - poppler_rectangle->y2;
rectangle->y2 = zathura_page_get_height(page) - poppler_rectangle->y1;

girara_list_append(list, rectangle);
poppler_rectangle_free(poppler_rectangle);
}

g_list_free(results);
return list;

error_free:

if (results != NULL) {
g_list_free(results);
}

if (list != NULL) {
girara_list_free(list);
}

error_ret:

return NULL;
}
zathura-pdf-poppler-0.2.5/select.c000064400000000000000000000016111230041553400170370ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#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)
{
if (page == NULL || poppler_page == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_INVALID_ARGUMENTS;
}
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

/* get selected text */
return poppler_page_get_selected_text(poppler_page, POPPLER_SELECTION_GLYPH, &rect);
}
zathura-pdf-poppler-0.2.5/utils.c000064400000000000000000000116361230041553400167300ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include "utils.h"

zathura_link_t*
poppler_link_to_zathura_link(PopplerDocument* poppler_document, PopplerAction*
poppler_action, zathura_rectangle_t position)
{
zathura_link_type_t type = ZATHURA_LINK_INVALID;
zathura_link_target_t target = { ZATHURA_LINK_DESTINATION_UNKNOWN, NULL, 0, -1, -1, -1, -1, 0 };

/* extract link */
switch (poppler_action->type) {
case POPPLER_ACTION_NONE:
type = ZATHURA_LINK_NONE;
break;
case POPPLER_ACTION_GOTO_DEST: {
PopplerDest* poppler_destination = poppler_action->goto_dest.dest;
if (poppler_destination == NULL) {
return NULL;
}

type = ZATHURA_LINK_GOTO_DEST;

if (poppler_action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
poppler_destination = poppler_document_find_dest(poppler_document, poppler_destination->named_dest);
if (poppler_destination == NULL) {
return NULL;
}
}

PopplerPage* poppler_page = poppler_document_get_page(poppler_document, poppler_destination->page_num - 1);
double height = 0;
poppler_page_get_size(poppler_page, NULL, &height);

switch (poppler_destination->type) {
case POPPLER_DEST_XYZ:
target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
target.page_number = poppler_destination->page_num - 1;
if (poppler_destination->change_zoom != 0) {
target.scale = poppler_destination->zoom;
}
if (poppler_destination->change_left != 0) {
target.left = poppler_destination->left;
}
if (poppler_destination->change_top != 0) {
target.top = height - MIN(height, poppler_destination->top);
}
break;
case POPPLER_DEST_FIT:
target.destination_type = ZATHURA_LINK_DESTINATION_FIT;
target.page_number = poppler_destination->page_num - 1;
break;
case POPPLER_DEST_FITH:
target.destination_type = ZATHURA_LINK_DESTINATION_FITH;
target.page_number = poppler_destination->page_num - 1;
if (poppler_destination->change_top != 0) {
target.top = height - MIN(height, poppler_destination->top);
}
break;
case POPPLER_DEST_FITV:
target.destination_type = ZATHURA_LINK_DESTINATION_FITV;
target.page_number = poppler_destination->page_num - 1;
if (poppler_destination->change_left != 0) {
target.left = poppler_destination->left;
}
break;
case POPPLER_DEST_FITR:
target.destination_type = ZATHURA_LINK_DESTINATION_FITR;
target.page_number = poppler_destination->page_num - 1;
if (poppler_destination->change_left != 0) {
target.left = poppler_destination->left;
}
if (poppler_destination->change_top != 0) {
target.top = height - MIN(height, poppler_destination->top);
}
target.right = poppler_destination->right;
target.bottom = height - MIN(height, poppler_destination->bottom);
break;
case POPPLER_DEST_FITB:
target.destination_type = ZATHURA_LINK_DESTINATION_FITB;
target.page_number = poppler_destination->page_num - 1;
break;
case POPPLER_DEST_FITBH:
target.destination_type = ZATHURA_LINK_DESTINATION_FITBH;
target.page_number = poppler_destination->page_num - 1;
if (poppler_destination->change_top != 0) {
target.top = height - MIN(height, poppler_destination->top);
}
break;
case POPPLER_DEST_FITBV:
target.destination_type = ZATHURA_LINK_DESTINATION_FITBV;
target.page_number = poppler_destination->page_num - 1;
target.left = poppler_destination->top;
break;
case POPPLER_DEST_UNKNOWN:
target.destination_type = ZATHURA_LINK_DESTINATION_UNKNOWN;
target.page_number = poppler_destination->page_num - 1;
break;
default:
return NULL;
}
break;
}
case POPPLER_ACTION_GOTO_REMOTE:
type = ZATHURA_LINK_GOTO_REMOTE;
if ((target.value = poppler_action->goto_remote.file_name) == NULL) {
return NULL;
}
break;
case POPPLER_ACTION_URI:
type = ZATHURA_LINK_URI;
target.value = poppler_action->uri.uri;
break;
case POPPLER_ACTION_LAUNCH:
type = ZATHURA_LINK_LAUNCH;
target.value = poppler_action->launch.file_name;
break;
case POPPLER_ACTION_NAMED:
type = ZATHURA_LINK_NAMED;
target.value = poppler_action->named.named_dest;
break;
default:
return NULL;
}

return zathura_link_new(type, position, target);
}
zathura-pdf-poppler-0.2.5/utils.h000064400000000000000000000010111230041553400167170ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#ifndef UTILS_H
#define UTILS_H

#include "plugin.h"

/**
* Convert a poppler link object to a zathura link object
*
* @param poppler_document The poppler document
* @param poppler_action The poppler action
* @param position The position of the link
*
* @return Zathura link object
*/
zathura_link_t* poppler_link_to_zathura_link(PopplerDocument* poppler_document,
PopplerAction* poppler_action, zathura_rectangle_t position);

#endif // UTILS_H
zathura-pdf-poppler-0.2.5/zathura-pdf-poppler.desktop000064400000000000000000000017331230041553400227200ustar00rootroot00000000000000[Desktop Entry]
Version=1.0
Type=Application
Name=Zathura
Comment=A minimalistic document viewer
Comment[ca]=Un visualitzador de documents minimalista
Comment[de]=Ein minimalistischer Dokumenten-Betrachter
Comment[el]=Ένας ελαφρύς προβολέας κειμένων
Comment[eo]=Malpeza dokumento spektanto
Comment[es_CL]=Un visor de documentos minimalista
Comment[fr]=Un visionneur de document minimaliste
Comment[he]=מציג מסמכים מינימליסטי
Comment[id_ID]=Pembaca dokumen minimalis
Comment[it]=Un visualizzatore di documenti minimalista
Comment[pl]=Minimalistyczna przeglądarka dokumentów
Comment[pt_BR]=Um visualizador de documentos minimalista
Comment[ru]=Минималистичный просмотрщик документов
Comment[tr]=Minimalist bir belge görüntüleyicisi
Comment[uk_UA]=Легкий переглядач документів
Exec=zathura %f
Terminal=false
NoDisplay=true
Categories=Office;Viewer;
MimeType=application/pdf;
 
design & coding: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
current maintainer: Michael Shigorin