zathura-pdf-poppler-0.2.8/0000775000175000017500000000000013216732465016144 5ustar sebastiansebastianzathura-pdf-poppler-0.2.8/LICENSE0000664000175000017500000000154213216732465017153 0ustar sebastiansebastianCopyright (c) 2011-2017 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.8/Makefile0000664000175000017500000000661213216732465017611 0ustar sebastiansebastian# See LICENSE file for license and copyright information include config.mk include common.mk PROJECT = zathura-pdf-poppler PLUGIN = pdf SOURCE = $(sort $(wildcard *.c)) HEADER = $(wildcard *.h) OBJECTS = ${SOURCE:.c=.o} DOBJECTS = ${SOURCE:.c=.do} 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 ${SOFILE} # 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: $(ECHO) "CFLAGS = ${CFLAGS}" $(ECHO) "LDFLAGS = ${LDFLAGS}" $(ECHO) "DFLAGS = ${DFLAGS}" $(ECHO) "CC = ${CC}" $(ECHO) "PKG_CONFIG = ${PKG_CONFIG}" %.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 \ .version-checks/ZATHURA \ .version-checks/POPPLER ${DOBJECTS}: config.mk \ .version-checks/ZATHURA \ .version-checks/POPPLER ${SOFILE}: ${OBJECTS} $(ECHO) LD $@ $(QUIET)${CC} ${PLATFORMFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS} ${SODEBUGFILE}: ${DOBJECTS} $(ECHO) LD $@ $(QUIET)${CC} ${PLATFORMFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${LIBS} clean: $(QUIET)rm -rf ${OBJECTS} ${DOBJECTS} ${SOFILE} ${SODEBUGFILE} \ doc .depend ${PROJECT}-${VERSION}.tar.gz zathura-version-check debug: options ${SODEBUGFILE} dist: clean $(QUIET)mkdir -p ${PROJECT}-${VERSION} $(QUIET)cp -R LICENSE Makefile config.mk common.mk Doxyfile \ ${HEADER} ${SOURCE} AUTHORS ${PROJECT}.desktop \ ${PROJECT}.metainfo.xml \ ${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 ${SOFILE} ${DESTDIR}${PLUGINDIR} $(QUIET)mkdir -m 755 -p ${DESTDIR}${DESKTOPPREFIX} $(ECHO) installing desktop file $(QUIET)install -m 644 ${PROJECT}.desktop ${DESTDIR}${DESKTOPPREFIX} $(ECHO) installing AppData file $(QUIET)mkdir -m 755 -p $(DESTDIR)$(APPDATAPREFIX) $(QUIET)install -m 644 $(PROJECT).metainfo.xml $(DESTDIR)$(APPDATAPREFIX) uninstall: $(ECHO) uninstalling ${PLUGIN} plugin $(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)find ${DESTDIR}${DESKTOPPREFIX} -type d -empty -delete 2> /dev/null $(ECHO) removing AppData file $(QUIET)rm -f $(DESTDIR)$(APPDATAPREFIX)/$(PROJECT).metainfo.xml -include $(wildcard .depend/*.dep) .PHONY: all options clean debug doc dist install uninstall zathura-pdf-poppler-0.2.8/config.mk0000664000175000017500000000305213216732465017742 0ustar sebastiansebastian# See LICENSE file for license and copyright information VERSION_MAJOR = 0 VERSION_MINOR = 2 VERSION_REV = 8 VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV} PKG_CONFIG ?= pkg-config # 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.3.8 ZATHURA_PKG_CONFIG_NAME = zathura # poppler POPPLER_VERSION_CHECK ?= 1 POPPLER_MIN_VERSION = 0.18 POPPLER_PKG_CONFIG_NAME = poppler-glib # paths PREFIX ?= /usr LIBDIR ?= ${PREFIX}/lib DESKTOPPREFIX ?= ${PREFIX}/share/applications APPDATAPREFIX ?= ${PREFIX}/share/metainfo # 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-gtk3) GIRARA_LIB ?= $(shell $(PKG_CONFIG) --libs girara-gtk3) 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} # 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 # compiler CC ?= gcc LD ?= ld # set to something != 0 if you want verbose build output VERBOSE ?= 0 zathura-pdf-poppler-0.2.8/common.mk0000664000175000017500000000017613216732465017771 0ustar sebastiansebastian# See LICENSE file for license and copyright information ifeq "$(VERBOSE)" "0" ECHO=@echo QUIET=@ else ECHO=@\# QUIET= endif zathura-pdf-poppler-0.2.8/Doxyfile0000664000175000017500000000117313216732465017654 0ustar sebastiansebastian# 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.8/plugin.h0000664000175000017500000001354313216732465017621 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #ifndef PDF_H #define PDF_H #include #include #include #include #include #include #include /** * Open a pdf document * * @param document Zathura document * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN 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 occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t pdf_document_free(zathura_document_t* document, void* poppler_document); /** * Initializes the page with the needed values * * @param page The page object * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN 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 occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t pdf_page_clear(zathura_page_t* page, void* poppler_page); /** * Saves the document to the given path * * @param document Zathura document * @param path File path * @return ZATHURA_ERROR_OK when no error occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t pdf_document_save_as(zathura_document_t* document, void* 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 occurred * @return Tree node object or NULL if an error occurred (e.g.: the document has * no index) */ GIRARA_HIDDEN girara_tree_node_t* pdf_document_index_generate(zathura_document_t* document, void* 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 occurred * @return List of attachments or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* pdf_document_attachments_get(zathura_document_t* document, void* 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 occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t pdf_document_attachment_save(zathura_document_t* document, void* 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 occurred * @return List of images */ GIRARA_HIDDEN girara_list_t* pdf_page_images_get(zathura_page_t* page, void* poppler_page, zathura_error_t* error); /** * 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 occurred * @return The cairo image surface or NULL if an error occurred */ GIRARA_HIDDEN cairo_surface_t* pdf_page_image_get_cairo(zathura_page_t* page, void* poppler_page, zathura_image_t* image, zathura_error_t* error); /** * 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 occurred * @return List of information entries or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* pdf_document_get_information(zathura_document_t* document, void* 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 occurred * @return List of search results or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* pdf_page_search_text(zathura_page_t* page, void* 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 occurred * @return List of links or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* pdf_page_links_get(zathura_page_t* page, void* 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 occurred * @return List of form fields or NULL if an error occurred */ GIRARA_HIDDEN girara_list_t* pdf_page_form_fields_get(zathura_page_t* page, void* 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 * occurred * @return The selected text (needs to be deallocated with g_free) */ GIRARA_HIDDEN char* pdf_page_get_text(zathura_page_t* page, void* poppler_page, zathura_rectangle_t rectangle, zathura_error_t* error); /** * 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 occurred, otherwise see * zathura_error_t */ GIRARA_HIDDEN zathura_error_t pdf_page_render_cairo(zathura_page_t* page, void* poppler_page, cairo_t* cairo, bool printing); #endif // PDF_H zathura-pdf-poppler-0.2.8/utils.h0000664000175000017500000000102713216732465017455 0ustar sebastiansebastian/* 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 */ GIRARA_HIDDEN 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.8/attachments.c0000664000175000017500000000401313216732465020621 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include #include "plugin.h" girara_list_t* pdf_document_attachments_get(zathura_document_t* document, void* data, zathura_error_t* error) { if (document == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } PopplerDocument* poppler_document = data; 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, 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); 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)); } return res; } zathura_error_t pdf_document_attachment_save(zathura_document_t* document, void* data, const char* attachmentname, const char* file) { if (document == NULL || data == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } PopplerDocument* poppler_document = data; 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); 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; } return poppler_attachment_save(attachment, file, NULL); } return ZATHURA_ERROR_OK; } zathura-pdf-poppler-0.2.8/document.c0000664000175000017500000000413613216732465020132 0ustar sebastiansebastian/* 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, NULL); 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, void* data) { if (document == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } PopplerDocument* poppler_document = data; 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, void* data, const char* path) { if (document == NULL || data == NULL || path == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } /* format path */ char* file_uri = g_filename_to_uri(path, NULL, NULL); if (file_uri == NULL) { return ZATHURA_ERROR_UNKNOWN; } PopplerDocument* poppler_document = data; const gboolean ret = poppler_document_save(poppler_document, file_uri, NULL); g_free(file_uri); return (ret == TRUE ? ZATHURA_ERROR_OK : ZATHURA_ERROR_UNKNOWN); } zathura-pdf-poppler-0.2.8/forms.c0000664000175000017500000000043313216732465017436 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" girara_list_t* pdf_page_form_fields_get(zathura_page_t* page, void* poppler_page, zathura_error_t* error) { if (error != NULL) { *error = ZATHURA_ERROR_NOT_IMPLEMENTED; } return NULL; } zathura-pdf-poppler-0.2.8/image.c0000664000175000017500000000523113216732465017373 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" #include "utils.h" static void pdf_zathura_image_free(void* image); girara_list_t* pdf_page_images_get(zathura_page_t* page, void* data, zathura_error_t* error) { if (page == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } goto error_ret; } girara_list_t* list = NULL; GList* image_mapping = NULL; PopplerPage* poppler_page = data; 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, 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; } cairo_surface_t* pdf_page_image_get_cairo(zathura_page_t* page, void* data, zathura_image_t* image, zathura_error_t* error) { if (page == NULL || data == NULL || image == NULL || image->data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } goto error_ret; } gint* image_id = (gint*) image->data; PopplerPage* poppler_page = 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; } static void pdf_zathura_image_free(void* data) { if (data == NULL) { return; } zathura_image_t* image = data; if (image->data != NULL) { g_free(image->data); } g_free(image); } zathura-pdf-poppler-0.2.8/index.c0000664000175000017500000000412313216732465017417 0ustar sebastiansebastian/* 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, void* data, zathura_error_t* error) { if (document == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } PopplerDocument* poppler_document = data; 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.8/links.c0000664000175000017500000000375013216732465017435 0ustar sebastiansebastian/* 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, void* data, zathura_error_t* error) { if (page == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } goto error_ret; } girara_list_t* list = NULL; GList* link_mapping = NULL; PopplerPage* poppler_page = data; 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); 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 */ 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, 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.8/meta.c0000664000175000017500000000453413216732465017244 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include #include "plugin.h" #define LENGTH(x) (sizeof(x)/sizeof((x)[0])) girara_list_t* pdf_document_get_information(zathura_document_t* document, void* data, zathura_error_t* error) { if (document == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } PopplerDocument* poppler_document = data; 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.8/page.c0000664000175000017500000000226213216732465017226 0ustar sebastiansebastian/* 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, void* data) { if (page == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } PopplerPage* poppler_page = data; if (poppler_page != NULL) { g_object_unref(poppler_page); } return ZATHURA_ERROR_OK; } zathura-pdf-poppler-0.2.8/plugin.c0000664000175000017500000000220413216732465017604 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" ZATHURA_PLUGIN_REGISTER_WITH_FUNCTIONS( "pdf-poppler", VERSION_MAJOR, VERSION_MINOR, VERSION_REV, ZATHURA_PLUGIN_FUNCTIONS({ .document_open = pdf_document_open, .document_free = pdf_document_free, .document_index_generate = pdf_document_index_generate, .document_save_as = pdf_document_save_as, .document_attachments_get = pdf_document_attachments_get, .document_attachment_save = pdf_document_attachment_save, .document_get_information = pdf_document_get_information, .page_init = pdf_page_init, .page_clear = pdf_page_clear, .page_search_text = pdf_page_search_text, .page_links_get = pdf_page_links_get, .page_form_fields_get = pdf_page_form_fields_get, .page_images_get = pdf_page_images_get, .page_get_text = pdf_page_get_text, .page_render_cairo = pdf_page_render_cairo, .page_image_get_cairo = pdf_page_image_get_cairo }), ZATHURA_PLUGIN_MIMETYPES({ "application/pdf" }) ) zathura-pdf-poppler-0.2.8/render.c0000664000175000017500000000077513216732465017600 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" zathura_error_t pdf_page_render_cairo(zathura_page_t* page, void* data, cairo_t* cairo, bool printing) { if (page == NULL || data == NULL || cairo == NULL) { return ZATHURA_ERROR_INVALID_ARGUMENTS; } PopplerPage* poppler_page = data; if (printing == false) { poppler_page_render(poppler_page, cairo); } else { poppler_page_render_for_printing(poppler_page, cairo); } return ZATHURA_ERROR_OK; } zathura-pdf-poppler-0.2.8/search.c0000664000175000017500000000321313216732465017554 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include #include "plugin.h" girara_list_t* pdf_page_search_text(zathura_page_t* page, void* data, const char* text, zathura_error_t* error) { if (page == NULL || data == NULL || text == NULL || strlen(text) == 0) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } goto error_ret; } PopplerPage* poppler_page = data; 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.8/select.c0000664000175000017500000000115513216732465017571 0ustar sebastiansebastian/* See LICENSE file for license and copyright information */ #include "plugin.h" char* pdf_page_get_text(zathura_page_t* page, void* data, zathura_rectangle_t rectangle, zathura_error_t* error) { if (page == NULL || data == NULL) { if (error != NULL) { *error = ZATHURA_ERROR_INVALID_ARGUMENTS; } return NULL; } PopplerRectangle rect = { .x1 = rectangle.x1, .x2 = rectangle.x2, .y1 = rectangle.y1, .y2 = rectangle.y2 }; PopplerPage* poppler_page = data; /* get selected text */ return poppler_page_get_selected_text(poppler_page, POPPLER_SELECTION_GLYPH, &rect); } zathura-pdf-poppler-0.2.8/utils.c0000664000175000017500000001163613216732465017457 0ustar sebastiansebastian/* 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.8/AUTHORS0000664000175000017500000000035013216732465017212 0ustar sebastiansebastianzathura-pdf-poppler is written by: Moritz Lipp Sebastian Ramacher Other contributors are (in no particular order): oblique Benoît Knecht zathura-pdf-poppler-0.2.8/zathura-pdf-poppler.desktop0000664000175000017500000000173313216732465023447 0ustar sebastiansebastian[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 %U Terminal=false NoDisplay=true Categories=Office;Viewer; MimeType=application/pdf; zathura-pdf-poppler-0.2.8/zathura-pdf-poppler.metainfo.xml0000664000175000017500000000076113216732465024377 0ustar sebastiansebastian zathura-pdf-poppler.desktop CC0-1.0 Zlib zathura.desktop PDF plugin for Zathura PDF plugin based on Poppler https://pwmt.org/projects/zathura-pdf-poppler/ zathura@lists.pwmt.org