diff -Nru zathura-extras-0.2/cb-0-1-2/AUTHORS zathura-extras-0.2/cb-0-1-2/AUTHORS --- zathura-extras-0.2/cb-0-1-2/AUTHORS 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/AUTHORS 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -zathura-cb is written by: - -Moritz Lipp -Sebastian Ramacher - -Other contributors are (in no particular order): - -Frank Smit diff -Nru zathura-extras-0.2/cb-0-1-2/common.mk zathura-extras-0.2/cb-0-1-2/common.mk --- zathura-extras-0.2/cb-0-1-2/common.mk 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/common.mk 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -# See LICENSE file for license and copyright information - -ifeq "$(VERBOSE)" "0" -ECHO=@echo -QUIET=@ -else -ECHO=@\# -QUIET= -endif diff -Nru zathura-extras-0.2/cb-0-1-2/config.mk zathura-extras-0.2/cb-0-1-2/config.mk --- zathura-extras-0.2/cb-0-1-2/config.mk 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/config.mk 1970-01-01 00:00:00.000000000 +0000 @@ -1,56 +0,0 @@ -# See LICENSE file for license and copyright information - -VERSION_MAJOR = 0 -VERSION_MINOR = 1 -VERSION_REV = 2 -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) - -LIBARCHIVE_INC ?= $(shell pkg-config --cflags libarchive) -LIBARCHIVE_LIB ?= $(shell pkg-config --libs libarchive) - -GLIB_INC ?= $(shell pkg-config --cflags glib-2.0) -GLIB_LIB ?= $(shell pkg-config --libs glib-2.0) - -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) - -INCS = ${GIRARA_INC} ${GLIB_INC} ${ZATHURA_INC} ${LIBARCHIVE_INC} -LIBS = ${GIRARA_LIB} ${GLIB_LIB} ${LIBARCHIVE_LIB} - -# plugindir -PLUGINDIR ?= $(shell pkg-config --variable=plugindir zathura) -ifeq (,${PLUGINDIR}) -PLUGINDIR = ${LIBDIR}/zathura -endif - -# 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 diff -Nru zathura-extras-0.2/cb-0-1-2/document.c zathura-extras-0.2/cb-0-1-2/document.c --- zathura-extras-0.2/cb-0-1-2/document.c 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/document.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,218 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "plugin.h" -#include "internal.h" -#include "utils.h" - -static int compare_pages(const cb_document_page_meta_t* page1, const cb_document_page_meta_t* page2); -static bool read_archive(cb_document_t* cb_document, const char* archive, girara_list_t* supported_extensions); -static const char* get_extension(const char* path); -static void cb_document_page_meta_free(cb_document_page_meta_t* meta); - -zathura_error_t -cb_document_open(zathura_document_t* document) -{ - if (document == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - cb_document_t* cb_document = g_malloc0(sizeof(cb_document)); - - /* archive path */ - const char* path = zathura_document_get_path(document); - - /* create list of supported formats */ - girara_list_t* supported_extensions = girara_list_new2(g_free); - if (supported_extensions == NULL) { - goto error_free; - } - - GSList* formats = gdk_pixbuf_get_formats(); - for (GSList* list = formats; list != NULL; list = list->next) { - GdkPixbufFormat* format = (GdkPixbufFormat*) list->data; - char** extensions = gdk_pixbuf_format_get_extensions(format); - - for (unsigned int i = 0; extensions[i] != NULL; i++) { - girara_list_append(supported_extensions, g_strdup(extensions[i])); - } - - g_strfreev(extensions); - } - g_slist_free(formats); - - /* create list of supported files (pages) */ - cb_document->pages = girara_sorted_list_new2((girara_compare_function_t) - compare_pages, (girara_free_function_t) cb_document_page_meta_free); - if (cb_document->pages == NULL) { - goto error_free; - } - - /* read files recursively */ - if (read_archive(cb_document, path, supported_extensions) == false) { - goto error_free; - } - - girara_list_free(supported_extensions); - - /* set document information */ - zathura_document_set_number_of_pages(document, girara_list_size(cb_document->pages)); - zathura_document_set_data(document, cb_document); - - return ZATHURA_ERROR_OK; - -error_free: - - girara_list_free(supported_extensions); - cb_document_free(document, cb_document); - - return ZATHURA_ERROR_UNKNOWN; -} - -zathura_error_t -cb_document_free(zathura_document_t* document, cb_document_t* cb_document) -{ - if (cb_document == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - /* remove page list */ - if (cb_document->pages != NULL) { - girara_list_free(cb_document->pages); - } - - g_free(cb_document); - - return ZATHURA_ERROR_OK; -} - -static void -cb_document_page_meta_free(cb_document_page_meta_t* meta) -{ - if (meta == NULL) { - return; - } - - if (meta->file != NULL) { - g_free(meta->file); - } - g_free(meta); -} - -static void -get_pixbuf_size(GdkPixbufLoader* loader, int width, int height, gpointer data) -{ - cb_document_page_meta_t* meta = (cb_document_page_meta_t*)data; - - meta->width = width; - meta->height = height; - - gdk_pixbuf_loader_set_size(loader, 0, 0); -} - -static bool -read_archive(cb_document_t* cb_document, const char* archive, girara_list_t* supported_extensions) -{ - struct archive* a = archive_read_new(); - if (a == NULL) { - return false; - } - - archive_read_support_filter_all(a); - archive_read_support_format_all(a); - int r = archive_read_open_filename(a, archive, (size_t) LIBARCHIVE_BUFFER_SIZE); - if (r != ARCHIVE_OK) { - archive_read_free(a); - return false; - } - - struct archive_entry *entry = NULL; - while ((r = archive_read_next_header(a, &entry)) != ARCHIVE_EOF) { - if (r < ARCHIVE_WARN) { - // let's ignore warnings ... they are non-fatal errors - archive_read_close(a); - archive_read_free(a); - return false; - } - - if (archive_entry_filetype(entry) != AE_IFREG) { - // we only care about regular files - continue; - } - - const char* path = archive_entry_pathname(entry); - const char* extension = get_extension(path); - - GIRARA_LIST_FOREACH(supported_extensions, char*, iter, ext) - if (g_strcmp0(extension, ext) == 0) { - cb_document_page_meta_t* meta = g_malloc0(sizeof(cb_document_page_meta_t)); - meta->file = g_strdup(path); - - GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); - g_signal_connect(loader, "size-prepared", G_CALLBACK(get_pixbuf_size), meta); - - size_t size = 0; - const void* buf = NULL; - off_t offset = 0; - while ((r = archive_read_data_block(a, &buf, &size, &offset)) != ARCHIVE_EOF) { - if (size <= 0) { - continue; - } - - if (gdk_pixbuf_loader_write(loader, buf, size, NULL) == false) { - break; - } - - if (meta->width > 0 || meta->height > 0) { - break; - } - } - - gdk_pixbuf_loader_close(loader, NULL); - g_object_unref(loader); - - if (meta->width > 0 && meta->height > 0) { - girara_list_append(cb_document->pages, meta); - } else { - cb_document_page_meta_free(meta); - } - - break; - } - GIRARA_LIST_FOREACH_END(supported_extensions, char*, iter, ext); - } - - archive_read_close(a); - archive_read_free(a); - return true; -} - -static int -compare_pages(const cb_document_page_meta_t* page1, const cb_document_page_meta_t* page2) -{ - return compare_path(page1->file, page2->file); -} - -static const char* -get_extension(const char* path) -{ - if (path == NULL) { - return NULL; - } - - const char* res = strrchr(path, '.'); - if (res == NULL) { - return NULL; - } - - return res + 1; -} diff -Nru zathura-extras-0.2/cb-0-1-2/Doxyfile zathura-extras-0.2/cb-0-1-2/Doxyfile --- zathura-extras-0.2/cb-0-1-2/Doxyfile 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/Doxyfile 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -# See LICENSE file for license and copyright information - -# General information -PROJECT_NAME = zathura-cb -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 diff -Nru zathura-extras-0.2/cb-0-1-2/internal.h zathura-extras-0.2/cb-0-1-2/internal.h --- zathura-extras-0.2/cb-0-1-2/internal.h 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/internal.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef INTERNAL_H -#define INTERNAL_H - -#define LIBARCHIVE_BUFFER_SIZE 8192 - -struct cb_document_s { - girara_list_t* pages; /**< List of metadata structs */ -}; - -struct cb_page_s { - char* file; /**< Image associated to the page */ -}; - -/** Image meta-data read during the document initialization - */ -typedef struct cb_document_page_meta_s { - char* file; /**< Image file */ - int width; /**< Image width */ - int height; /**< Image height */ -} cb_document_page_meta_t; - -#endif // INTERNAL_H diff -Nru zathura-extras-0.2/cb-0-1-2/LICENSE zathura-extras-0.2/cb-0-1-2/LICENSE --- zathura-extras-0.2/cb-0-1-2/LICENSE 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/LICENSE 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Copyright (c) 2012-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. diff -Nru zathura-extras-0.2/cb-0-1-2/Makefile zathura-extras-0.2/cb-0-1-2/Makefile --- zathura-extras-0.2/cb-0-1-2/Makefile 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/Makefile 1970-01-01 00:00:00.000000000 +0000 @@ -1,96 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk -include common.mk - -PROJECT = zathura-cb -PLUGIN = cb -SOURCE = $(wildcard *.c) -HEADER = $(wildcard *.h) -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -ifneq "$(WITH_CAIRO)" "0" -CPPFLAGS += -DHAVE_CAIRO -INCS += $(CAIRO_INC) -LIBS += $(CAIRO_LIB) -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 diff -Nru zathura-extras-0.2/cb-0-1-2/page.c zathura-extras-0.2/cb-0-1-2/page.c --- zathura-extras-0.2/cb-0-1-2/page.c 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/page.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,52 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include - -#include "plugin.h" -#include "internal.h" - -zathura_error_t -cb_page_init(zathura_page_t* page) -{ - if (page == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - zathura_document_t* document = zathura_page_get_document(page); - cb_document_t* cb_document = zathura_document_get_data(document); - - if (document == NULL || cb_document == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - cb_document_page_meta_t* meta = girara_list_nth(cb_document->pages, zathura_page_get_index(page)); - if (meta == NULL || meta->file == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - cb_page_t* cb_page = g_malloc0(sizeof(cb_page_t)); - if (cb_page == NULL) { - return ZATHURA_ERROR_OUT_OF_MEMORY; - } - - cb_page->file = g_strdup(meta->file); - zathura_page_set_width(page, meta->width); - zathura_page_set_height(page, meta->height); - zathura_page_set_data(page, cb_page); - - return ZATHURA_ERROR_OK; -} - -zathura_error_t -cb_page_clear(zathura_page_t* page, cb_page_t* cb_page) -{ - if (cb_page == NULL) { - return ZATHURA_ERROR_OK; - } - - g_free(cb_page->file); - g_free(cb_page); - - return ZATHURA_ERROR_OK; -} diff -Nru zathura-extras-0.2/cb-0-1-2/plugin.c zathura-extras-0.2/cb-0-1-2/plugin.c --- zathura-extras-0.2/cb-0-1-2/plugin.c 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/plugin.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,31 +0,0 @@ -/* 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) cb_document_open; - functions->document_free = (zathura_plugin_document_free_t) cb_document_free; - functions->page_init = (zathura_plugin_page_init_t) cb_page_init; - functions->page_clear = (zathura_plugin_page_clear_t) cb_page_clear; -#ifdef HAVE_CAIRO - functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) cb_page_render_cairo; -#endif -} - -ZATHURA_PLUGIN_REGISTER( - "cb", - VERSION_MAJOR, VERSION_MINOR, VERSION_REV, - register_functions, - ZATHURA_PLUGIN_MIMETYPES({ - "application/x-cbr", - "application/x-rar", - "application/x-cbz", - "application/zip", - "application/x-cb7", - "application/x-7z-compressed", - "application/x-cbt", - "application/x-tar" - }) -) diff -Nru zathura-extras-0.2/cb-0-1-2/plugin.h zathura-extras-0.2/cb-0-1-2/plugin.h --- zathura-extras-0.2/cb-0-1-2/plugin.h 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/plugin.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,65 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef CB_H -#define CB_H - -#include - -#if HAVE_CAIRO -#include -#endif - -#include - -typedef struct cb_document_s cb_document_t; -typedef struct cb_page_s cb_page_t; - -/** - * Opens a new document - * - * @param document The document - * @return ZATHURA_ERROR_OK if no error occured - */ -zathura_error_t cb_document_open(zathura_document_t* document); - -/** - * Frees the document - * - * @param document The document - * @param data Custom data - * @return ZATHURA_ERROR_OK if no error occured - */ -zathura_error_t cb_document_free(zathura_document_t* document, cb_document_t* cb_document); - -/** - * Initializes a page - * - * @param page The page - * @return ZATHURA_ERROR_OK if no error occured - */ -zathura_error_t cb_page_init(zathura_page_t* page); - -/** - * Clear page - * - * @param page The page - * @param cb_page cb Page - * @return ZATHURA_ERROR_OK if no error occured - */ -zathura_error_t cb_page_clear(zathura_page_t* page, cb_page_t* cb_page); - -#if HAVE_CAIRO -/** - * Renders the page to a cairo object - * - * @param page The page - * @param cb_page cb Page - * @param cairo Cairo object - * @param printing Render for printing - * @return ZATHURA_ERROR_OK if no error occured - */ -zathura_error_t cb_page_render_cairo(zathura_page_t* page, cb_page_t* cb_page, - cairo_t* cairo, bool printing); -#endif - -#endif // CB_H diff -Nru zathura-extras-0.2/cb-0-1-2/render.c zathura-extras-0.2/cb-0-1-2/render.c --- zathura-extras-0.2/cb-0-1-2/render.c 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/render.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,131 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include -#include -#include -#include - -#include "plugin.h" -#include "internal.h" -#include "utils.h" - -#if !defined(HAVE_CAIRO) -#error "Cannot render without cairo" -#endif - -static GdkPixbuf* load_pixbuf_from_archive(const char* archive, const char* file); - -#if HAVE_CAIRO -zathura_error_t -cb_page_render_cairo(zathura_page_t* page, cb_page_t* cb_page, - cairo_t* cairo, bool printing) -{ - if (page == NULL || cb_page == NULL || cairo == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - zathura_document_t* document = zathura_page_get_document(page); - if (document == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - GdkPixbuf* pixbuf = load_pixbuf_from_archive(zathura_document_get_path(document), cb_page->file); - if (pixbuf == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - gdk_cairo_set_source_pixbuf(cairo, pixbuf, 0, 0); - cairo_paint(cairo); - g_object_unref(pixbuf); - - return ZATHURA_ERROR_OK; -} -#endif - -static GdkPixbuf* -load_pixbuf_from_archive(const char* archive, const char* file) -{ - if (archive == NULL || file == NULL) { - return NULL; - } - - struct archive* a = archive_read_new(); - if (a == NULL) { - return NULL; - } - - archive_read_support_filter_all(a); - archive_read_support_format_all(a); - int r = archive_read_open_filename(a, archive, LIBARCHIVE_BUFFER_SIZE); - if (r != ARCHIVE_OK) { - return NULL; - } - - struct archive_entry* entry = NULL; - while ((r = archive_read_next_header(a, &entry)) != ARCHIVE_EOF) { - if (r < ARCHIVE_WARN) { - archive_read_close(a); - archive_read_free(a); - return NULL; - } - - const char* path = archive_entry_pathname(entry); - if (compare_path(path, file) != 0) { - continue; - } - - GInputStream* is = g_memory_input_stream_new(); - if (is == NULL) { - archive_read_close(a); - archive_read_free(a); - return NULL; - } - GMemoryInputStream* mis = G_MEMORY_INPUT_STREAM(is); - - size_t size = 0; - const void* buf = NULL; - off_t offset = 0; - while ((r = archive_read_data_block(a, &buf, &size, &offset)) != ARCHIVE_EOF) { - if (r < ARCHIVE_WARN) { - archive_read_close(a); - archive_read_free(a); - g_object_unref(mis); - return NULL; - } - - if (size == 0) { - continue; - } - - void* tmp = g_malloc0(size); - if (tmp == NULL) { - archive_read_close(a); - archive_read_free(a); - g_object_unref(mis); - return NULL; - } - - memcpy(tmp, buf, size); - g_memory_input_stream_add_data(mis, tmp, size, g_free); - } - - GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(is, NULL, NULL); - if (pixbuf == NULL) { - archive_read_close(a); - archive_read_free(a); - g_object_unref(mis); - return NULL; - } - - archive_read_close(a); - archive_read_free(a); - g_object_unref(mis); - return pixbuf; - } - - archive_read_close(a); - archive_read_free(a); - return NULL; -} - diff -Nru zathura-extras-0.2/cb-0-1-2/utils.c zathura-extras-0.2/cb-0-1-2/utils.c --- zathura-extras-0.2/cb-0-1-2/utils.c 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/utils.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,17 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include - -#include "utils.h" - -int -compare_path(const char* str1, const char* str2) -{ - char* ustr1 = g_utf8_casefold(str1, -1); - char* ustr2 = g_utf8_casefold(str2, -1); - int result = g_utf8_collate(ustr1, ustr2); - g_free(ustr1); - g_free(ustr2); - - return result; -} diff -Nru zathura-extras-0.2/cb-0-1-2/utils.h zathura-extras-0.2/cb-0-1-2/utils.h --- zathura-extras-0.2/cb-0-1-2/utils.h 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/utils.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,16 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef UTILS_H -#define UTILS_H - -/** - * Compares two paths with each other - * - * @param str1 First path - * @param str2 Second path - * - * @return - */ -int compare_path(const char* str1, const char* str2); - -#endif // UTILS_H diff -Nru zathura-extras-0.2/cb-0-1-2/zathura-cb.desktop zathura-extras-0.2/cb-0-1-2/zathura-cb.desktop --- zathura-extras-0.2/cb-0-1-2/zathura-cb.desktop 2013-11-09 14:24:12.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-2/zathura-cb.desktop 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -[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/x-cbr;application/x-rar;application/x-cbz;application/zip;application/x-cb7;application/x-7z-compressed;application/x-cbt;application/x-tar; diff -Nru zathura-extras-0.2/cb-0-1-3/AUTHORS zathura-extras-0.2/cb-0-1-3/AUTHORS --- zathura-extras-0.2/cb-0-1-3/AUTHORS 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/AUTHORS 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,8 @@ +zathura-cb is written by: + +Moritz Lipp +Sebastian Ramacher + +Other contributors are (in no particular order): + +Frank Smit diff -Nru zathura-extras-0.2/cb-0-1-3/common.mk zathura-extras-0.2/cb-0-1-3/common.mk --- zathura-extras-0.2/cb-0-1-3/common.mk 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/common.mk 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,9 @@ +# See LICENSE file for license and copyright information + +ifeq "$(VERBOSE)" "0" +ECHO=@echo +QUIET=@ +else +ECHO=@\# +QUIET= +endif diff -Nru zathura-extras-0.2/cb-0-1-3/config.mk zathura-extras-0.2/cb-0-1-3/config.mk --- zathura-extras-0.2/cb-0-1-3/config.mk 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/config.mk 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,59 @@ +# See LICENSE file for license and copyright information + +VERSION_MAJOR = 0 +VERSION_MINOR = 1 +VERSION_REV = 3 +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) + +LIBARCHIVE_INC ?= $(shell pkg-config --cflags libarchive) +LIBARCHIVE_LIB ?= $(shell pkg-config --libs libarchive) + +GLIB_INC ?= $(shell pkg-config --cflags glib-2.0 gio-2.0) +GLIB_LIB ?= $(shell pkg-config --libs glib-2.0 gio-2.0) + +GDK_INC ?= $(shell pkg-config --cflags gdk-pixbuf-2.0 gdk-${ZATHURA_GTK_VERSION}.0) +GDK_LIB ?= $(shell pkg-config --libs gdk-pixbuf-2.0 gdk-${ZATHURA_GTK_VERSION}.0) + +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) + +INCS = ${GIRARA_INC} ${GDK_INC} ${GLIB_INC} ${ZATHURA_INC} ${LIBARCHIVE_INC} +LIBS = ${GIRARA_LIB} ${GDK_LIB} ${GLIB_LIB} ${LIBARCHIVE_LIB} + +# plugindir +PLUGINDIR ?= $(shell pkg-config --variable=plugindir zathura) +ifeq (,${PLUGINDIR}) +PLUGINDIR = ${LIBDIR}/zathura +endif + +# 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 diff -Nru zathura-extras-0.2/cb-0-1-3/document.c zathura-extras-0.2/cb-0-1-3/document.c --- zathura-extras-0.2/cb-0-1-3/document.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/document.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,224 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "plugin.h" +#include "internal.h" +#include "utils.h" + +static int compare_pages(const cb_document_page_meta_t* page1, const cb_document_page_meta_t* page2); +static bool read_archive(cb_document_t* cb_document, const char* archive, girara_list_t* supported_extensions); +static char* get_extension(const char* path); +static void cb_document_page_meta_free(cb_document_page_meta_t* meta); + +zathura_error_t +cb_document_open(zathura_document_t* document) +{ + if (document == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + cb_document_t* cb_document = g_malloc0(sizeof(cb_document)); + + /* archive path */ + const char* path = zathura_document_get_path(document); + + /* create list of supported formats */ + girara_list_t* supported_extensions = girara_list_new2(g_free); + if (supported_extensions == NULL) { + goto error_free; + } + + GSList* formats = gdk_pixbuf_get_formats(); + for (GSList* list = formats; list != NULL; list = list->next) { + GdkPixbufFormat* format = (GdkPixbufFormat*) list->data; + char** extensions = gdk_pixbuf_format_get_extensions(format); + + for (unsigned int i = 0; extensions[i] != NULL; i++) { + girara_list_append(supported_extensions, g_strdup(extensions[i])); + } + + g_strfreev(extensions); + } + g_slist_free(formats); + + /* create list of supported files (pages) */ + cb_document->pages = girara_sorted_list_new2((girara_compare_function_t) + compare_pages, (girara_free_function_t) cb_document_page_meta_free); + if (cb_document->pages == NULL) { + goto error_free; + } + + /* read files recursively */ + if (read_archive(cb_document, path, supported_extensions) == false) { + goto error_free; + } + + girara_list_free(supported_extensions); + + /* set document information */ + zathura_document_set_number_of_pages(document, girara_list_size(cb_document->pages)); + zathura_document_set_data(document, cb_document); + + return ZATHURA_ERROR_OK; + +error_free: + + girara_list_free(supported_extensions); + cb_document_free(document, cb_document); + + return ZATHURA_ERROR_UNKNOWN; +} + +zathura_error_t +cb_document_free(zathura_document_t* document, cb_document_t* cb_document) +{ + if (cb_document == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + /* remove page list */ + if (cb_document->pages != NULL) { + girara_list_free(cb_document->pages); + } + + g_free(cb_document); + + return ZATHURA_ERROR_OK; +} + +static void +cb_document_page_meta_free(cb_document_page_meta_t* meta) +{ + if (meta == NULL) { + return; + } + + if (meta->file != NULL) { + g_free(meta->file); + } + g_free(meta); +} + +static void +get_pixbuf_size(GdkPixbufLoader* loader, int width, int height, gpointer data) +{ + cb_document_page_meta_t* meta = (cb_document_page_meta_t*)data; + + meta->width = width; + meta->height = height; + + gdk_pixbuf_loader_set_size(loader, 0, 0); +} + +static bool +read_archive(cb_document_t* cb_document, const char* archive, girara_list_t* supported_extensions) +{ + struct archive* a = archive_read_new(); + if (a == NULL) { + return false; + } + + archive_read_support_filter_all(a); + archive_read_support_format_all(a); + int r = archive_read_open_filename(a, archive, (size_t) LIBARCHIVE_BUFFER_SIZE); + if (r != ARCHIVE_OK) { + archive_read_free(a); + return false; + } + + struct archive_entry *entry = NULL; + while ((r = archive_read_next_header(a, &entry)) != ARCHIVE_EOF) { + if (r < ARCHIVE_WARN) { + // let's ignore warnings ... they are non-fatal errors + archive_read_close(a); + archive_read_free(a); + return false; + } + + if (archive_entry_filetype(entry) != AE_IFREG) { + // we only care about regular files + continue; + } + + const char* path = archive_entry_pathname(entry); + char* extension = get_extension(path); + + if (extension == NULL) { + continue; + } + + GIRARA_LIST_FOREACH(supported_extensions, char*, iter, ext) + if (g_strcmp0(extension, ext) == 0) { + cb_document_page_meta_t* meta = g_malloc0(sizeof(cb_document_page_meta_t)); + meta->file = g_strdup(path); + + GdkPixbufLoader* loader = gdk_pixbuf_loader_new(); + g_signal_connect(loader, "size-prepared", G_CALLBACK(get_pixbuf_size), meta); + + size_t size = 0; + const void* buf = NULL; + off_t offset = 0; + while ((r = archive_read_data_block(a, &buf, &size, &offset)) != ARCHIVE_EOF) { + if (size <= 0) { + continue; + } + + if (gdk_pixbuf_loader_write(loader, buf, size, NULL) == false) { + break; + } + + if (meta->width > 0 || meta->height > 0) { + break; + } + } + + gdk_pixbuf_loader_close(loader, NULL); + g_object_unref(loader); + + if (meta->width > 0 && meta->height > 0) { + girara_list_append(cb_document->pages, meta); + } else { + cb_document_page_meta_free(meta); + } + + break; + } + GIRARA_LIST_FOREACH_END(supported_extensions, char*, iter, ext); + + g_free(extension); + } + + archive_read_close(a); + archive_read_free(a); + return true; +} + +static int +compare_pages(const cb_document_page_meta_t* page1, const cb_document_page_meta_t* page2) +{ + return compare_path(page1->file, page2->file); +} + +static char* +get_extension(const char* path) +{ + if (path == NULL) { + return NULL; + } + + const char* res = strrchr(path, '.'); + if (res == NULL) { + return NULL; + } + + return g_ascii_strdown(res + 1, -1); +} diff -Nru zathura-extras-0.2/cb-0-1-3/Doxyfile zathura-extras-0.2/cb-0-1-3/Doxyfile --- zathura-extras-0.2/cb-0-1-3/Doxyfile 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/Doxyfile 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,29 @@ +# See LICENSE file for license and copyright information + +# General information +PROJECT_NAME = zathura-cb +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 diff -Nru zathura-extras-0.2/cb-0-1-3/index.c zathura-extras-0.2/cb-0-1-3/index.c --- zathura-extras-0.2/cb-0-1-3/index.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/index.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,40 @@ +/* See LICENSE file for license and copyright information */ + +#include "plugin.h" +#include "internal.h" +#include + +girara_tree_node_t* +cb_document_index_generate(zathura_document_t* document, + cb_document_t* cb_document, zathura_error_t* error) +{ + if (document == NULL || cb_document == NULL) { + if (error != NULL) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + return NULL; + } + + girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); + unsigned int page_number = 0; + GIRARA_LIST_FOREACH(cb_document->pages, cb_document_page_meta_t*, iter, page) + { + gchar* markup = g_markup_escape_text(page->file, -1); + zathura_index_element_t* index_element = zathura_index_element_new(markup); + g_free(markup); + + if (index_element != NULL) { + zathura_rectangle_t rect = { 0, 0, 0, 0 }; + zathura_link_target_t target = { ZATHURA_LINK_DESTINATION_XYZ, NULL, + page_number, -1, -1, -1, -1, 0 }; + + index_element->link = zathura_link_new(ZATHURA_LINK_GOTO_DEST, rect, + target); + girara_node_append_data(root, index_element); + } + ++page_number; + } + GIRARA_LIST_FOREACH_END(cb_document->pages, cb_document_page_meta_t*, iter, page); + + return root; +} diff -Nru zathura-extras-0.2/cb-0-1-3/internal.h zathura-extras-0.2/cb-0-1-3/internal.h --- zathura-extras-0.2/cb-0-1-3/internal.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/internal.h 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,24 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef INTERNAL_H +#define INTERNAL_H + +#define LIBARCHIVE_BUFFER_SIZE 8192 + +struct cb_document_s { + girara_list_t* pages; /**< List of metadata structs */ +}; + +struct cb_page_s { + char* file; /**< Image associated to the page */ +}; + +/** Image meta-data read during the document initialization + */ +typedef struct cb_document_page_meta_s { + char* file; /**< Image file */ + int width; /**< Image width */ + int height; /**< Image height */ +} cb_document_page_meta_t; + +#endif // INTERNAL_H diff -Nru zathura-extras-0.2/cb-0-1-3/LICENSE zathura-extras-0.2/cb-0-1-3/LICENSE --- zathura-extras-0.2/cb-0-1-3/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/LICENSE 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,20 @@ +Copyright (c) 2012-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. diff -Nru zathura-extras-0.2/cb-0-1-3/Makefile zathura-extras-0.2/cb-0-1-3/Makefile --- zathura-extras-0.2/cb-0-1-3/Makefile 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/Makefile 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,96 @@ +# See LICENSE file for license and copyright information + +include config.mk +include common.mk + +PROJECT = zathura-cb +PLUGIN = cb +SOURCE = $(wildcard *.c) +HEADER = $(wildcard *.h) +OBJECTS = ${SOURCE:.c=.o} +DOBJECTS = ${SOURCE:.c=.do} + +ifneq "$(WITH_CAIRO)" "0" +CPPFLAGS += -DHAVE_CAIRO +INCS += $(CAIRO_INC) +LIBS += $(CAIRO_LIB) +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 diff -Nru zathura-extras-0.2/cb-0-1-3/page.c zathura-extras-0.2/cb-0-1-3/page.c --- zathura-extras-0.2/cb-0-1-3/page.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/page.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,52 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include + +#include "plugin.h" +#include "internal.h" + +zathura_error_t +cb_page_init(zathura_page_t* page) +{ + if (page == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + zathura_document_t* document = zathura_page_get_document(page); + cb_document_t* cb_document = zathura_document_get_data(document); + + if (document == NULL || cb_document == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + cb_document_page_meta_t* meta = girara_list_nth(cb_document->pages, zathura_page_get_index(page)); + if (meta == NULL || meta->file == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + cb_page_t* cb_page = g_malloc0(sizeof(cb_page_t)); + if (cb_page == NULL) { + return ZATHURA_ERROR_OUT_OF_MEMORY; + } + + cb_page->file = g_strdup(meta->file); + zathura_page_set_width(page, meta->width); + zathura_page_set_height(page, meta->height); + zathura_page_set_data(page, cb_page); + + return ZATHURA_ERROR_OK; +} + +zathura_error_t +cb_page_clear(zathura_page_t* page, cb_page_t* cb_page) +{ + if (cb_page == NULL) { + return ZATHURA_ERROR_OK; + } + + g_free(cb_page->file); + g_free(cb_page); + + return ZATHURA_ERROR_OK; +} diff -Nru zathura-extras-0.2/cb-0-1-3/plugin.c zathura-extras-0.2/cb-0-1-3/plugin.c --- zathura-extras-0.2/cb-0-1-3/plugin.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/plugin.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,32 @@ +/* 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) cb_document_open; + functions->document_free = (zathura_plugin_document_free_t) cb_document_free; + functions->document_index_generate = (zathura_plugin_document_index_generate_t) cb_document_index_generate; + functions->page_init = (zathura_plugin_page_init_t) cb_page_init; + functions->page_clear = (zathura_plugin_page_clear_t) cb_page_clear; +#ifdef HAVE_CAIRO + functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) cb_page_render_cairo; +#endif +} + +ZATHURA_PLUGIN_REGISTER( + "cb", + VERSION_MAJOR, VERSION_MINOR, VERSION_REV, + register_functions, + ZATHURA_PLUGIN_MIMETYPES({ + "application/x-cbr", + "application/x-rar", + "application/x-cbz", + "application/zip", + "application/x-cb7", + "application/x-7z-compressed", + "application/x-cbt", + "application/x-tar" + }) +) diff -Nru zathura-extras-0.2/cb-0-1-3/plugin.h zathura-extras-0.2/cb-0-1-3/plugin.h --- zathura-extras-0.2/cb-0-1-3/plugin.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/plugin.h 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,77 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef CB_H +#define CB_H + +#include + +#if HAVE_CAIRO +#include +#endif + +#include + +typedef struct cb_document_s cb_document_t; +typedef struct cb_page_s cb_page_t; + +/** + * Opens a new document + * + * @param document The document + * @return ZATHURA_ERROR_OK if no error occured + */ +zathura_error_t cb_document_open(zathura_document_t* document); + +/** + * Frees the document + * + * @param document The document + * @param data Custom data + * @return ZATHURA_ERROR_OK if no error occured + */ +zathura_error_t cb_document_free(zathura_document_t* document, cb_document_t* cb_document); + +/** + * 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* cb_document_index_generate(zathura_document_t* document, + cb_document_t* cb_document, zathura_error_t* error); + +/** + * Initializes a page + * + * @param page The page + * @return ZATHURA_ERROR_OK if no error occured + */ +zathura_error_t cb_page_init(zathura_page_t* page); + +/** + * Clear page + * + * @param page The page + * @param cb_page cb Page + * @return ZATHURA_ERROR_OK if no error occured + */ +zathura_error_t cb_page_clear(zathura_page_t* page, cb_page_t* cb_page); + +#if HAVE_CAIRO +/** + * Renders the page to a cairo object + * + * @param page The page + * @param cb_page cb Page + * @param cairo Cairo object + * @param printing Render for printing + * @return ZATHURA_ERROR_OK if no error occured + */ +zathura_error_t cb_page_render_cairo(zathura_page_t* page, cb_page_t* cb_page, + cairo_t* cairo, bool printing); +#endif + +#endif // CB_H diff -Nru zathura-extras-0.2/cb-0-1-3/render.c zathura-extras-0.2/cb-0-1-3/render.c --- zathura-extras-0.2/cb-0-1-3/render.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/render.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,131 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include +#include +#include +#include + +#include "plugin.h" +#include "internal.h" +#include "utils.h" + +#if !defined(HAVE_CAIRO) +#error "Cannot render without cairo" +#endif + +static GdkPixbuf* load_pixbuf_from_archive(const char* archive, const char* file); + +#if HAVE_CAIRO +zathura_error_t +cb_page_render_cairo(zathura_page_t* page, cb_page_t* cb_page, + cairo_t* cairo, bool printing) +{ + if (page == NULL || cb_page == NULL || cairo == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + zathura_document_t* document = zathura_page_get_document(page); + if (document == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + GdkPixbuf* pixbuf = load_pixbuf_from_archive(zathura_document_get_path(document), cb_page->file); + if (pixbuf == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + gdk_cairo_set_source_pixbuf(cairo, pixbuf, 0, 0); + cairo_paint(cairo); + g_object_unref(pixbuf); + + return ZATHURA_ERROR_OK; +} +#endif + +static GdkPixbuf* +load_pixbuf_from_archive(const char* archive, const char* file) +{ + if (archive == NULL || file == NULL) { + return NULL; + } + + struct archive* a = archive_read_new(); + if (a == NULL) { + return NULL; + } + + archive_read_support_filter_all(a); + archive_read_support_format_all(a); + int r = archive_read_open_filename(a, archive, LIBARCHIVE_BUFFER_SIZE); + if (r != ARCHIVE_OK) { + return NULL; + } + + struct archive_entry* entry = NULL; + while ((r = archive_read_next_header(a, &entry)) != ARCHIVE_EOF) { + if (r < ARCHIVE_WARN) { + archive_read_close(a); + archive_read_free(a); + return NULL; + } + + const char* path = archive_entry_pathname(entry); + if (compare_path(path, file) != 0) { + continue; + } + + GInputStream* is = g_memory_input_stream_new(); + if (is == NULL) { + archive_read_close(a); + archive_read_free(a); + return NULL; + } + GMemoryInputStream* mis = G_MEMORY_INPUT_STREAM(is); + + size_t size = 0; + const void* buf = NULL; + off_t offset = 0; + while ((r = archive_read_data_block(a, &buf, &size, &offset)) != ARCHIVE_EOF) { + if (r < ARCHIVE_WARN) { + archive_read_close(a); + archive_read_free(a); + g_object_unref(mis); + return NULL; + } + + if (size == 0) { + continue; + } + + void* tmp = g_malloc0(size); + if (tmp == NULL) { + archive_read_close(a); + archive_read_free(a); + g_object_unref(mis); + return NULL; + } + + memcpy(tmp, buf, size); + g_memory_input_stream_add_data(mis, tmp, size, g_free); + } + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(is, NULL, NULL); + if (pixbuf == NULL) { + archive_read_close(a); + archive_read_free(a); + g_object_unref(mis); + return NULL; + } + + archive_read_close(a); + archive_read_free(a); + g_object_unref(mis); + return pixbuf; + } + + archive_read_close(a); + archive_read_free(a); + return NULL; +} + diff -Nru zathura-extras-0.2/cb-0-1-3/utils.c zathura-extras-0.2/cb-0-1-3/utils.c --- zathura-extras-0.2/cb-0-1-3/utils.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/utils.c 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,17 @@ +/* See LICENSE file for license and copyright information */ + +#include + +#include "utils.h" + +int +compare_path(const char* str1, const char* str2) +{ + char* ustr1 = g_utf8_casefold(str1, -1); + char* ustr2 = g_utf8_casefold(str2, -1); + int result = g_utf8_collate(ustr1, ustr2); + g_free(ustr1); + g_free(ustr2); + + return result; +} diff -Nru zathura-extras-0.2/cb-0-1-3/utils.h zathura-extras-0.2/cb-0-1-3/utils.h --- zathura-extras-0.2/cb-0-1-3/utils.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/utils.h 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,16 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef UTILS_H +#define UTILS_H + +/** + * Compares two paths with each other + * + * @param str1 First path + * @param str2 Second path + * + * @return + */ +int compare_path(const char* str1, const char* str2); + +#endif // UTILS_H diff -Nru zathura-extras-0.2/cb-0-1-3/zathura-cb.desktop zathura-extras-0.2/cb-0-1-3/zathura-cb.desktop --- zathura-extras-0.2/cb-0-1-3/zathura-cb.desktop 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/cb-0-1-3/zathura-cb.desktop 2014-10-16 22:12:52.000000000 +0000 @@ -0,0 +1,24 @@ +[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/x-cbr;application/x-rar;application/x-cbz;application/zip;application/x-cb7;application/x-7z-compressed;application/x-cbt;application/x-tar; diff -Nru zathura-extras-0.2/debian/changelog zathura-extras-0.2/debian/changelog --- zathura-extras-0.2/debian/changelog 2013-11-09 20:11:06.000000000 +0000 +++ zathura-extras-0.2/debian/changelog 2014-10-17 10:31:00.000000000 +0000 @@ -1,3 +1,12 @@ +zathura-extras (0.2-6) unstable; urgency=medium + + * New upstream release. + - zathura-cb 0.1.3. + - zathura-djvu 0.2.4. + * debian/control: Bump Standards-Version to 3.9.6. + + -- Sebastian Ramacher Fri, 17 Oct 2014 12:30:49 +0200 + zathura-extras (0.2-5) unstable; urgency=low * New upstream release. diff -Nru zathura-extras-0.2/debian/control zathura-extras-0.2/debian/control --- zathura-extras-0.2/debian/control 2013-11-09 20:09:31.000000000 +0000 +++ zathura-extras-0.2/debian/control 2014-10-17 10:30:46.000000000 +0000 @@ -12,7 +12,7 @@ libspectre-dev, libdjvulibre-dev, libarchive-dev -Standards-Version: 3.9.5 +Standards-Version: 3.9.6 Homepage: http://pwmt.org/projects/zathura Package: zathura-djvu diff -Nru zathura-extras-0.2/debian/rules zathura-extras-0.2/debian/rules --- zathura-extras-0.2/debian/rules 2013-11-09 16:30:24.000000000 +0000 +++ zathura-extras-0.2/debian/rules 2014-10-17 10:26:56.000000000 +0000 @@ -10,9 +10,9 @@ psVER=0.2.2 psVERC=$(subst .,-,$(psVER)) -djvuVER=0.2.3 +djvuVER=0.2.4 djvuVERC=$(subst .,-,$(djvuVER)) -cbVER=0.1.2 +cbVER=0.1.3 cbVERC=$(subst .,-,$(cbVER)) %: diff -Nru zathura-extras-0.2/djvu-0-2-3/AUTHORS zathura-extras-0.2/djvu-0-2-3/AUTHORS --- zathura-extras-0.2/djvu-0-2-3/AUTHORS 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/AUTHORS 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -zathura-djvu is written by: - -Moritz Lipp -Sebastian Ramacher - -Other contributors are (in alphabetical order): - -Pavel Borzenkov diff -Nru zathura-extras-0.2/djvu-0-2-3/common.mk zathura-extras-0.2/djvu-0-2-3/common.mk --- zathura-extras-0.2/djvu-0-2-3/common.mk 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/common.mk 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -# See LICENSE file for license and copyright information - -ifeq "$(VERBOSE)" "0" -ECHO=@echo -QUIET=@ -else -ECHO=@\# -QUIET= -endif diff -Nru zathura-extras-0.2/djvu-0-2-3/config.mk zathura-extras-0.2/djvu-0-2-3/config.mk --- zathura-extras-0.2/djvu-0-2-3/config.mk 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/config.mk 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -# See LICENSE file for license and copyright information - -VERSION_MAJOR = 0 -VERSION_MINOR = 2 -VERSION_REV = 3 -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) - -GLIB_INC ?= $(shell pkg-config --cflags glib-2.0) -GLIB_LIB ?= $(shell pkg-config --libs glib-2.0) - -DJVU_INC ?= $(shell pkg-config --cflags ddjvuapi) -DJVU_LIB ?= $(shell pkg-config --libs ddjvuapi) - -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 = ${GIRARA_INC} ${GLIB_INC} ${DJVU_INC} ${ZATHURA_INC} -LIBS = ${GIRARA_LIB} ${GLIB_LIB} ${DJVU_LIB} - -# flags -CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length -Wextra $(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 diff -Nru zathura-extras-0.2/djvu-0-2-3/djvu.c zathura-extras-0.2/djvu-0-2-3/djvu.c --- zathura-extras-0.2/djvu-0-2-3/djvu.c 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/djvu.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,853 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include -#include -#include -#include -#include - -#include "djvu.h" -#include "page-text.h" -#include "internal.h" - -/* forward declarations */ -static const char* get_extension(const char* path); -static void build_index(djvu_document_t *djvu_document, miniexp_t expression, girara_tree_node_t* root); -static bool exp_to_str(miniexp_t expression, const char** string); -static bool exp_to_int(miniexp_t expression, int* integer); -static bool exp_to_rect(miniexp_t expression, zathura_rectangle_t* rect); - -void -register_functions(zathura_plugin_functions_t* functions) -{ - functions->document_open = (zathura_plugin_document_open_t) djvu_document_open; - functions->document_free = (zathura_plugin_document_free_t) djvu_document_free; - functions->document_index_generate = (zathura_plugin_document_index_generate_t) djvu_document_index_generate; - functions->document_save_as = (zathura_plugin_document_save_as_t) djvu_document_save_as; - functions->page_init = (zathura_plugin_page_init_t) djvu_page_init; - functions->page_clear = (zathura_plugin_page_clear_t) djvu_page_clear; - functions->page_search_text = (zathura_plugin_page_search_text_t) djvu_page_search_text; - functions->page_get_text = (zathura_plugin_page_get_text_t) djvu_page_get_text; - functions->page_links_get = (zathura_plugin_page_links_get_t) djvu_page_links_get; - functions->page_render = (zathura_plugin_page_render_t) djvu_page_render; -#ifdef HAVE_CAIRO - functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) djvu_page_render_cairo; -#endif -} - -ZATHURA_PLUGIN_REGISTER( - "djvu", - VERSION_MAJOR, VERSION_MINOR, VERSION_REV, - register_functions, - ZATHURA_PLUGIN_MIMETYPES({ - "image/vnd.djvu" - }) -) - -zathura_error_t -djvu_document_open(zathura_document_t* document) -{ - zathura_error_t error = ZATHURA_ERROR_OK; - - if (document == NULL) { - error = ZATHURA_ERROR_INVALID_ARGUMENTS; - goto error_out; - } - - djvu_document_t* djvu_document = calloc(1, sizeof(djvu_document_t)); - if (djvu_document == NULL) { - error = ZATHURA_ERROR_OUT_OF_MEMORY; - goto error_out; - } - - /* setup format */ - static unsigned int masks[4] = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}; - djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks); - - if (djvu_document->format == NULL) { - error = ZATHURA_ERROR_UNKNOWN; - goto error_free; - } - - ddjvu_format_set_row_order(djvu_document->format, TRUE); - - /* setup context */ - djvu_document->context = ddjvu_context_create("zathura"); - - if (djvu_document->context == NULL) { - error = ZATHURA_ERROR_UNKNOWN; - goto error_free; - } - - /* setup document */ - djvu_document->document = - ddjvu_document_create_by_filename( - djvu_document->context, - zathura_document_get_path(document), - FALSE - ); - - if (djvu_document->document == NULL) { - error = ZATHURA_ERROR_UNKNOWN; - goto error_free; - } - - /* load document info */ - ddjvu_message_t* msg; - ddjvu_message_wait(djvu_document->context); - - while ((msg = ddjvu_message_peek(djvu_document->context)) && - (msg->m_any.tag != DDJVU_DOCINFO)) { - if (msg->m_any.tag == DDJVU_ERROR) { - error = ZATHURA_ERROR_UNKNOWN; - goto error_free; - } - - ddjvu_message_pop(djvu_document->context); - } - - /* decoding error */ - if (ddjvu_document_decoding_error(djvu_document->document)) { - handle_messages(djvu_document, true); - error = ZATHURA_ERROR_UNKNOWN; - goto error_free; - } - - zathura_document_set_data(document, djvu_document); - zathura_document_set_number_of_pages(document, - ddjvu_document_get_pagenum(djvu_document->document)); - - return error; - -error_free: - - if (djvu_document->format != NULL) { - ddjvu_format_release(djvu_document->format); - } - - if (djvu_document->context != NULL) { - ddjvu_context_release(djvu_document->context); - } - - free(djvu_document); - -error_out: - - return error; -} - -zathura_error_t -djvu_document_free(zathura_document_t* document, djvu_document_t* djvu_document) -{ - if (document == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - if (djvu_document != NULL) { - ddjvu_context_release(djvu_document->context); - ddjvu_document_release(djvu_document->document); - ddjvu_format_release(djvu_document->format); - free(djvu_document); - } - - return ZATHURA_ERROR_OK; -} - -girara_tree_node_t* -djvu_document_index_generate(zathura_document_t* document, djvu_document_t* - djvu_document, zathura_error_t* error) -{ - if (document == NULL || djvu_document == NULL) { - if (error != NULL) { - *error = ZATHURA_ERROR_INVALID_ARGUMENTS; - } - return NULL; - } - - miniexp_t outline = miniexp_dummy; - while ((outline = ddjvu_document_get_outline(djvu_document->document)) == - miniexp_dummy) { - handle_messages(djvu_document, true); - } - - if (outline == miniexp_dummy) { - return NULL; - } - - if (miniexp_consp(outline) == 0 || miniexp_car(outline) != miniexp_symbol("bookmarks")) { - ddjvu_miniexp_release(djvu_document->document, outline); - return NULL; - } - - girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); - build_index(djvu_document, miniexp_cdr(outline), root); - - ddjvu_miniexp_release(djvu_document->document, outline); - - return root; -} - -zathura_error_t -djvu_document_save_as(zathura_document_t* document, djvu_document_t* djvu_document, const char* path) -{ - if (document == NULL || djvu_document == NULL || path == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - FILE* fp = fopen(path, "w"); - if (fp == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - const char* extension = get_extension(path); - - ddjvu_job_t* job = NULL; - if (extension != NULL && g_strcmp0(extension, "ps") == 0) { - job = ddjvu_document_print(djvu_document->document, fp, 0, NULL); - } else { - job = ddjvu_document_save(djvu_document->document, fp, 0, NULL); - } - while (ddjvu_job_done(job) != true) { - handle_messages(djvu_document, true); - } - - fclose(fp); - - return ZATHURA_ERROR_OK; -} - -zathura_error_t -djvu_page_init(zathura_page_t* page, void* UNUSED(data)) -{ - if (page == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - zathura_document_t* document = zathura_page_get_document(page); - djvu_document_t* djvu_document = zathura_document_get_data(document); - - ddjvu_status_t status; - ddjvu_pageinfo_t page_info; - - unsigned int index = zathura_page_get_index(page); - while ((status = ddjvu_document_get_pageinfo(djvu_document->document, index, - &page_info)) < DDJVU_JOB_OK) { - handle_messages(djvu_document, true); - } - - if (status >= DDJVU_JOB_FAILED) { - handle_messages(djvu_document, true); - return ZATHURA_ERROR_UNKNOWN; - } - - zathura_page_set_width(page, ZATHURA_DJVU_SCALE * page_info.width); - zathura_page_set_height(page, ZATHURA_DJVU_SCALE * page_info.height); - - return ZATHURA_ERROR_OK; -} - -zathura_error_t -djvu_page_clear(zathura_page_t* page, void* UNUSED(data)) -{ - if (page == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - return ZATHURA_ERROR_OK; -} - -girara_list_t* -djvu_page_search_text(zathura_page_t* page, void* UNUSED(data), const char* text, zathura_error_t* error) -{ - if (page == NULL || text == NULL || strlen(text) == 0) { - if (error != NULL) { - *error = ZATHURA_ERROR_INVALID_ARGUMENTS; - } - goto error_ret; - } - - zathura_document_t* document = zathura_page_get_document(page); - if (document == NULL) { - goto error_ret; - } - - djvu_document_t* djvu_document = zathura_document_get_data(document); - - djvu_page_text_t* page_text = djvu_page_text_new(djvu_document, page); - if (page_text == NULL) { - goto error_ret; - } - - girara_list_t* results = djvu_page_text_search(page_text, text); - if (results == NULL) { - goto error_free; - } - - djvu_page_text_free(page_text); - - return results; - -error_free: - - if (page_text != NULL) { - djvu_page_text_free(page_text); - } - -error_ret: - - if (error != NULL && *error == ZATHURA_ERROR_OK) { - *error = ZATHURA_ERROR_UNKNOWN; - } - - return NULL; -} - -char* -djvu_page_get_text(zathura_page_t* page, void* UNUSED(data), zathura_rectangle_t - rectangle, zathura_error_t* error) -{ - if (page == NULL) { - if (error != NULL) { - *error = ZATHURA_ERROR_INVALID_ARGUMENTS; - } - goto error_ret; - } - - zathura_document_t* document = zathura_page_get_document(page); - if (document == NULL) { - goto error_ret; - } - - djvu_document_t* djvu_document = zathura_document_get_data(document); - - djvu_page_text_t* page_text = djvu_page_text_new(djvu_document, page); - if (page_text == NULL) { - goto error_ret; - } - - double tmp = 0; - double page_height = zathura_page_get_height(page); - double page_width = zathura_page_get_width(page); - - switch (zathura_document_get_rotation(document)) { - case 90: - tmp = rectangle.x1; - rectangle.x1 = rectangle.y1; - rectangle.y1 = tmp; - tmp = rectangle.x2; - rectangle.x2 = rectangle.y2; - rectangle.y2 = tmp; - break; - case 180: - tmp = rectangle.x1; - rectangle.x1 = (page_width - rectangle.x2); - rectangle.x2 = (page_width - tmp); - break; - case 270: - tmp = rectangle.y2; - rectangle.y2 = (page_height - rectangle.x1); - rectangle.x1 = (page_width - tmp); - tmp = rectangle.y1; - rectangle.y1 = (page_height - rectangle.x2); - rectangle.x2 = (page_width - tmp); - break; - default: - tmp = rectangle.y1; - rectangle.y1 = (page_height - rectangle.y2); - rectangle.y2 = (page_height - tmp); - break; - } - - /* adjust to scale */ - rectangle.x1 /= ZATHURA_DJVU_SCALE; - rectangle.x2 /= ZATHURA_DJVU_SCALE; - rectangle.y1 /= ZATHURA_DJVU_SCALE; - rectangle.y2 /= ZATHURA_DJVU_SCALE; - - char* text = djvu_page_text_select(page_text, rectangle); - - djvu_page_text_free(page_text); - - return text; - -error_ret: - - if (error != NULL && *error == ZATHURA_ERROR_OK) { - *error = ZATHURA_ERROR_UNKNOWN; - } - - return NULL; -} - -girara_list_t* -djvu_page_links_get(zathura_page_t* page, void* UNUSED(data), zathura_error_t* error) -{ - if (page == NULL) { - if (error != NULL) { - *error = ZATHURA_ERROR_INVALID_ARGUMENTS; - } - goto error_ret; - } - - zathura_document_t* document = zathura_page_get_document(page); - if (document == NULL) { - goto error_ret; - } - - girara_list_t* 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_ret; - } - - djvu_document_t* djvu_document = zathura_document_get_data(document); - - miniexp_t annotations = miniexp_nil; - while ((annotations = ddjvu_document_get_pageanno(djvu_document->document, - zathura_page_get_index(page))) == miniexp_dummy) { - handle_messages(djvu_document, true); - } - - if (annotations == miniexp_nil) { - goto error_free; - } - - miniexp_t* hyperlinks = ddjvu_anno_get_hyperlinks(annotations); - for (miniexp_t* iter = hyperlinks; *iter != NULL; iter++) { - if (miniexp_car(*iter) != miniexp_symbol("maparea")) { - continue; - } - - miniexp_t inner = miniexp_cdr(*iter); - - /* extract url information */ - const char* target_string = NULL; - - if (miniexp_caar(inner) == miniexp_symbol("url")) { - if (exp_to_str(miniexp_caddr(miniexp_car(inner)), &target_string) == false) { - continue; - } - } else { - if (exp_to_str(miniexp_car(inner), &target_string) == false) { - continue; - } - } - - /* skip comment */ - inner = miniexp_cdr(inner); - - /* extract link area */ - inner = miniexp_cdr(inner); - - zathura_rectangle_t rect = { 0, 0, 0, 0 }; - if (exp_to_rect(miniexp_car(inner), &rect) == false) { - continue; - } - - /* update rect */ - unsigned int page_height = zathura_page_get_height(page) / ZATHURA_DJVU_SCALE; - rect.x1 = rect.x1 * ZATHURA_DJVU_SCALE; - rect.x2 = rect.x2 * ZATHURA_DJVU_SCALE; - double tmp = rect.y1; - rect.y1 = (page_height - rect.y2) * ZATHURA_DJVU_SCALE; - rect.y2 = (page_height - tmp) * ZATHURA_DJVU_SCALE; - - /* create zathura link */ - zathura_link_type_t type = ZATHURA_LINK_INVALID; - zathura_link_target_t target; - - /* goto page */ - if (target_string[0] == '#' && target_string[1] == 'p') { - type = ZATHURA_LINK_GOTO_DEST; - target.page_number = atoi(target_string + 2) - 1; - /* url or other? */ - } else if (strstr(target_string, "//") != NULL) { - type = ZATHURA_LINK_URI; - target.value = (char*) target_string; - /* TODO: Parse all different links */ - } else { - continue; - } - - zathura_link_t* link = zathura_link_new(type, rect, target); - if (link != NULL) { - girara_list_append(list, link); - } - } - - return list; - -error_free: - - if (list != NULL) { - girara_list_free(list); - } - -error_ret: - - return NULL; -} - -#ifdef HAVE_CAIRO -zathura_error_t -djvu_page_render_cairo(zathura_page_t* page, void* UNUSED(data), cairo_t* cairo, - bool GIRARA_UNUSED(printing)) -{ - if (page == NULL || cairo == NULL) { - return ZATHURA_ERROR_INVALID_ARGUMENTS; - } - - zathura_document_t* document = zathura_page_get_document(page); - if (document == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - /* init ddjvu render data */ - djvu_document_t* djvu_document = zathura_document_get_data(document); - ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, zathura_page_get_index(page)); - - if (djvu_page == NULL) { - return ZATHURA_ERROR_UNKNOWN; - } - - while (!ddjvu_page_decoding_done(djvu_page)) { - handle_messages(djvu_document, true); - } - - cairo_surface_t* surface = cairo_get_target(cairo); - - if (surface == NULL || - cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS || - cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_IMAGE) { - ddjvu_page_release(djvu_page); - return ZATHURA_ERROR_UNKNOWN; - } - - unsigned int page_width = cairo_image_surface_get_width(surface); - unsigned int page_height = cairo_image_surface_get_height(surface);; - - ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; - ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - - char* surface_data = (char*) cairo_image_surface_get_data(surface); - - if (surface_data == NULL) { - ddjvu_page_release(djvu_page); - return ZATHURA_ERROR_UNKNOWN; - } - - /* render page */ - ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, - djvu_document->format, cairo_image_surface_get_stride(surface), surface_data); - - ddjvu_page_release(djvu_page); - - return ZATHURA_ERROR_OK; -} -#endif - -zathura_image_buffer_t* -djvu_page_render(zathura_page_t* page, void* UNUSED(data), zathura_error_t* error) -{ - if (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 */ - unsigned int page_width = zathura_document_get_scale(document) * zathura_page_get_width(page); - unsigned int page_height = zathura_document_get_scale(document) * zathura_page_get_height(page); - - if (page_width == 0 || page_height == 0) { - if (error != NULL) { - *error = ZATHURA_ERROR_UNKNOWN; - } - goto error_out; - } - - /* init ddjvu render data */ - djvu_document_t* djvu_document = zathura_document_get_data(document); - ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno( - djvu_document->document, zathura_page_get_index(page)); - - if (djvu_page == NULL) { - if (error != NULL) { - *error = ZATHURA_ERROR_UNKNOWN; - } - goto error_out; - } - - while (!ddjvu_page_decoding_done(djvu_page)) { - handle_messages(djvu_document, true); - } - - ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; - ddjvu_rect_t prect = { 0, 0, page_width, page_height }; - - 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; - } - goto error_free; - } - - /* set rotation */ - ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0); - - /* render page */ - ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, - djvu_document->format, 3 * page_width, (char*) image_buffer->data); - - return image_buffer; - -error_free: - - ddjvu_page_release(djvu_page); - zathura_image_buffer_free(image_buffer); - -error_out: - - return NULL; -} - -static const char* -get_extension(const char* path) -{ - if (path == NULL) { - return NULL; - } - - unsigned int i = strlen(path); - for (; i > 0; i--) { - if (*(path + i) != '.') { - continue; - } else { - break; - } - } - - if (i == 0) { - return NULL; - } - - return path + i + 1; -} - -void -handle_messages(djvu_document_t* document, bool wait) -{ - if (document == NULL || document->context == NULL) { - return; - } - - ddjvu_context_t* context = document->context; - const ddjvu_message_t* message; - - if (wait == true) { - ddjvu_message_wait(context); - } - - while ((message = ddjvu_message_peek(context)) != NULL) { - ddjvu_message_pop(context); - } -} - -static void -build_index(djvu_document_t *djvu_document, miniexp_t expression, girara_tree_node_t* root) -{ - if (expression == miniexp_nil || root == NULL) { - return; - } - - int fileno = ddjvu_document_get_filenum(djvu_document->document); - int curfile = 0; - - while (miniexp_consp(expression) != 0) { - miniexp_t inner = miniexp_car(expression); - - if (miniexp_consp(inner) - && miniexp_consp(miniexp_cdr(inner)) - && miniexp_stringp(miniexp_car(inner)) - && miniexp_stringp(miniexp_car(inner)) - ) { - const char* name = miniexp_to_str(miniexp_car(inner)); - const char* link = miniexp_to_str(miniexp_cadr(inner)); - - /* TODO: handle other links? */ - if (link == NULL || link[0] != '#') { - expression = miniexp_cdr(expression); - continue; - } - - zathura_link_type_t type = ZATHURA_LINK_GOTO_DEST; - zathura_rectangle_t rect; - zathura_link_target_t target = { 0 }; - target.destination_type = ZATHURA_LINK_DESTINATION_XYZ; - - /* Check if link+1 contains a number */ - bool number = true; - const size_t linklen = strlen(link); - for (unsigned int k = 1; k < linklen; k++) { - if (!isdigit(link[k])) { - number = false; - break; - } - } - - /* if link starts with a number assume it is a number */ - if (number == true) { - target.page_number = atoi(link + 1) - 1; - } else { - /* otherwise assume it is an id for a page */ - ddjvu_fileinfo_t info; - int f, i; - for (i=0; i < fileno; i++) { - f = (curfile + i) % fileno; - ddjvu_document_get_fileinfo(djvu_document->document, f, &info); - if (info.id != NULL && !strcmp(link+1, info.id)) { - break; - } - } - - /* got a page */ - if (i < fileno && info.pageno >= 0) { - curfile = (f+1) % fileno; - target.page_number = info.pageno; - } else { - /* give up */ - expression = miniexp_cdr(expression); - continue; - } - } - - zathura_index_element_t* index_element = zathura_index_element_new(name); - if (index_element == NULL) { - continue; - } - - index_element->link = zathura_link_new(type, rect, target); - if (index_element->link == NULL) { - zathura_index_element_free(index_element); - continue; - } - - girara_tree_node_t* node = girara_node_append_data(root, index_element); - - /* search recursive */ - build_index(djvu_document, miniexp_cddr(inner), node); - } - - expression = miniexp_cdr(expression); - } -} - -static bool -exp_to_str(miniexp_t expression, const char** string) -{ - if (string == NULL) { - return false; - } - - if (miniexp_stringp(expression)) { - *string = miniexp_to_str(expression); - return true; - } - - return false; -} - -static bool -exp_to_int(miniexp_t expression, int* integer) -{ - if (integer == NULL) { - return false; - } - - if (miniexp_numberp(expression)) { - *integer = miniexp_to_int(expression); - return true; - } - - return false; -} - -static bool -exp_to_rect(miniexp_t expression, zathura_rectangle_t* rect) -{ - if ((miniexp_car(expression) == miniexp_symbol("rect") - || miniexp_car(expression) == miniexp_symbol("oval")) - && miniexp_length(expression) == 5) { - int min_x = 0; - int min_y = 0; - int width = 0; - int height = 0; - - miniexp_t iter = miniexp_cdr(expression); - if (exp_to_int(miniexp_car(iter), &min_x) == false) { - return false; - } - iter = miniexp_cdr(iter); - if (exp_to_int(miniexp_car(iter), &min_y) == false) { - return false; - } - iter = miniexp_cdr(iter); - if (exp_to_int(miniexp_car(iter), &width) == false) { - return false; - } - iter = miniexp_cdr(iter); - if (exp_to_int(miniexp_car(iter), &height) == false) { - return false; - } - - rect->x1 = min_x; - rect->x2 = min_x + width; - rect->y1 = min_y; - rect->y2 = min_y + height; - } else if (miniexp_car(expression) == miniexp_symbol("poly") - && miniexp_length(expression) >= 5) { - int min_x = 0; - int min_y = 0; - int max_x = 0; - int max_y = 0; - - miniexp_t iter = miniexp_cdr(expression); - while (iter != miniexp_nil) { - int x = 0; - int y = 0; - - if (exp_to_int(miniexp_car(iter), &x) == false) { - return false; - } - iter = miniexp_cdr(iter); - if (exp_to_int(miniexp_car(iter), &y) == false) { - return false; - } - iter = miniexp_cdr(iter); - - min_x = MIN(min_x, x); - min_y = MIN(min_y, y); - max_x = MAX(max_x, x); - max_y = MAX(max_y, y); - } - - rect->x1 = min_x; - rect->x2 = max_x; - rect->y1 = min_y; - rect->y2 = max_y; - } - - return true; -} diff -Nru zathura-extras-0.2/djvu-0-2-3/djvu.h zathura-extras-0.2/djvu-0-2-3/djvu.h --- zathura-extras-0.2/djvu-0-2-3/djvu.h 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/djvu.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,138 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef DJVU_H -#define DJVU_H - -#include -#include -#include -#ifdef HAVE_CAIRO -#include -#endif - -/** - * DjVu document - */ -typedef struct djvu_document_s -{ - ddjvu_context_t* context; /**< Document context */ - ddjvu_document_t* document; /**< Document */ - ddjvu_format_t* format; /**< Format */ -} djvu_document_t; - -/** - * Open a DjVU document - * - * @param document Zathura document - * @return ZATHURA_ERROR_OK when no error occured, otherwise see - * zathura_error_t - */ -zathura_error_t djvu_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 djvu_document_free(zathura_document_t* document, djvu_document_t* djvu_document); - -/** - * 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* djvu_document_index_generate(zathura_document_t* document, - djvu_document_t* djvu_document, zathura_error_t* error); - -/** - * 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 djvu_document_save_as(zathura_document_t* document, djvu_document_t* djvu_document, const char* path); - -/** - * Initializes the page - * - * @param page The page object - * @return ZATHURA_ERROR_OK when no error occured, otherwise see - * zathura_error_t - */ -zathura_error_t djvu_page_init(zathura_page_t* page, void* data); - -/** - * Frees a DjVu page - * - * @param page Page - * @return ZATHURA_ERROR_OK when no error occured, otherwise see - * zathura_error_t - */ -zathura_error_t djvu_page_clear(zathura_page_t* page, void* data); - -/** - * 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* djvu_page_search_text(zathura_page_t* page, void* data, const char* text, 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* djvu_page_get_text(zathura_page_t* page, void* data, zathura_rectangle_t rectangle, zathura_error_t* error); - -/** - * Returns list of links - * - * @param page The page - * @param data Unused page data - * @param error Error code - * @return List of links or NULL if an error occured - */ -girara_list_t* djvu_page_links_get(zathura_page_t* page, void* data, - zathura_error_t* error); - -/** - * 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* djvu_page_render(zathura_page_t* page, void* data, zathura_error_t* error); - -#ifdef 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 djvu_page_render_cairo(zathura_page_t* page, void* data, cairo_t* cairo, bool printing); -#endif - -#endif // DJVU_H diff -Nru zathura-extras-0.2/djvu-0-2-3/Doxyfile zathura-extras-0.2/djvu-0-2-3/Doxyfile --- zathura-extras-0.2/djvu-0-2-3/Doxyfile 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/Doxyfile 1970-01-01 00:00:00.000000000 +0000 @@ -1,29 +0,0 @@ -# See LICENSE file for license and copyright information - -# General information -PROJECT_NAME = zathura-djvu -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 diff -Nru zathura-extras-0.2/djvu-0-2-3/internal.h zathura-extras-0.2/djvu-0-2-3/internal.h --- zathura-extras-0.2/djvu-0-2-3/internal.h 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/internal.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef DJVU_INTERNAL_H -#define DJVU_INTERNAL_H - -#include - -#define ZATHURA_DJVU_SCALE 0.2 - -GIRARA_HIDDEN void handle_messages(djvu_document_t* document, bool wait); - -#endif // DJVU_INTERNAL_H diff -Nru zathura-extras-0.2/djvu-0-2-3/LICENSE zathura-extras-0.2/djvu-0-2-3/LICENSE --- zathura-extras-0.2/djvu-0-2-3/LICENSE 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/LICENSE 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -Copyright (c) 2010-2012 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. diff -Nru zathura-extras-0.2/djvu-0-2-3/Makefile zathura-extras-0.2/djvu-0-2-3/Makefile --- zathura-extras-0.2/djvu-0-2-3/Makefile 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/Makefile 1970-01-01 00:00:00.000000000 +0000 @@ -1,96 +0,0 @@ -# See LICENSE file for license and copyright information - -include config.mk -include common.mk - -PROJECT = zathura-djvu -PLUGIN = djvu -SOURCE = $(shell find . -iname "*.c") -HEADER = $(shell find . -iname "*.h") -OBJECTS = ${SOURCE:.c=.o} -DOBJECTS = ${SOURCE:.c=.do} - -ifneq "$(WITH_CAIRO)" "0" -CPPFLAGS += -DHAVE_CAIRO -INCS += $(CAIRO_INC) -LIBS += $(CAIRO_LIB) -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 diff -Nru zathura-extras-0.2/djvu-0-2-3/page-text.c zathura-extras-0.2/djvu-0-2-3/page-text.c --- zathura-extras-0.2/djvu-0-2-3/page-text.c 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/page-text.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,515 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#include -#include -#include -#include - -#include "page-text.h" -#include "internal.h" - -/** - * To determine the position of a character - */ -typedef struct text_position_s { - unsigned int position; /**< Index */ - miniexp_t exp; /**< Correspondending expression */ -} text_position_t; - -/* forward declaration */ -static void djvu_page_text_content_append(djvu_page_text_t* page_text, - miniexp_t exp); -static miniexp_t text_position_get_exp(djvu_page_text_t* page_text, - unsigned int index); -static bool djvu_page_text_build_rectangle(djvu_page_text_t* page_text, - miniexp_t exp, miniexp_t start, miniexp_t end); -static bool djvu_page_text_build_rectangle_process(djvu_page_text_t* page_text, - miniexp_t exp, miniexp_t start, miniexp_t end); -static void djvu_page_text_limit(djvu_page_text_t* page_text, miniexp_t exp, - zathura_rectangle_t* rectangle); -static void djvu_page_text_limit_process(djvu_page_text_t* page_text, - miniexp_t exp, zathura_rectangle_t* rectangle); -static bool djvu_page_text_select_content(djvu_page_text_t* page_text, - miniexp_t exp, int delimiter); - -djvu_page_text_t* -djvu_page_text_new(djvu_document_t* document, zathura_page_t* page) -{ - if (document == NULL || document->document == NULL || page == NULL) { - goto error_ret; - } - - djvu_page_text_t* page_text = calloc(1, sizeof(djvu_page_text_t)); - if (page_text == NULL) { - goto error_ret; - } - - page_text->text_information = miniexp_nil; - page_text->begin = miniexp_nil; - page_text->end = miniexp_nil; - page_text->document = document; - page_text->page = page; - - /* read page text */ - while ((page_text->text_information = - ddjvu_document_get_pagetext(document->document, zathura_page_get_index(page), "char")) - == miniexp_dummy) { - handle_messages(document, true); - } - - if (page_text->text_information == miniexp_nil) { - goto error_free; - } - - return page_text; - -error_free: - - if (page_text != NULL) { - djvu_page_text_free(page_text); - } - -error_ret: - - return NULL; -} - -void -djvu_page_text_free(djvu_page_text_t* page_text) -{ - if (page_text == NULL) { - return; - } - - if (page_text->text_information != miniexp_nil && page_text->document != NULL) { - ddjvu_miniexp_release(page_text->document->document, - page_text->text_information); - } - - if (page_text->content != NULL) { - g_free(page_text->content); - } - - if (page_text->text_positions != NULL) { - girara_list_free(page_text->text_positions); - } - - if (page_text->rectangle != NULL) { - free(page_text->rectangle); - } - - free(page_text); -} - -girara_list_t* -djvu_page_text_search(djvu_page_text_t* page_text, const char* text) -{ - if (page_text == NULL || text == NULL) { - goto error_ret; - } - - /* clean and reset */ - if (page_text->content != NULL) { - g_free(page_text->content); - page_text->content = NULL; - } - - if (page_text->text_positions != NULL) { - girara_list_free(page_text->text_positions); - page_text->text_positions = NULL; - } - - /* create result list */ - girara_list_t* results = girara_list_new2( - (girara_free_function_t) free); - - if (results == NULL) { - goto error_ret; - } - - /* create list */ - page_text->text_positions = girara_list_new2( - (girara_free_function_t) free); - - if (page_text->text_positions == NULL) { - goto error_free; - } - - /* get page content */ - djvu_page_text_content_append(page_text, page_text->text_information); - - if (page_text->content == NULL || strlen(page_text->content) == 0) { - goto error_free; - } - - /* search through content */ - int search_length = strlen(text); - char* tmp = page_text->content; - - while ((tmp = strstr(tmp, text)) != NULL) { - int start_pointer = tmp - page_text->content; - int end_pointer = start_pointer + search_length - 1; - - miniexp_t start = text_position_get_exp(page_text, start_pointer); - miniexp_t end = text_position_get_exp(page_text, end_pointer); - - /* reset rectangle */ - if (page_text->rectangle != NULL) { - free(page_text->rectangle); - page_text->rectangle = NULL; - } - - djvu_page_text_build_rectangle(page_text, page_text->text_information, - start, end); - - if (page_text->rectangle == NULL) { - tmp += search_length; - continue; - } - - /* scale rectangle coordinates */ - page_text->rectangle->x1 = ZATHURA_DJVU_SCALE * page_text->rectangle->x1; - page_text->rectangle->x2 = ZATHURA_DJVU_SCALE * page_text->rectangle->x2; - page_text->rectangle->y1 = ZATHURA_DJVU_SCALE * page_text->rectangle->y1; - page_text->rectangle->y2 = ZATHURA_DJVU_SCALE * page_text->rectangle->y2; - - /* invert */ - int y1 = zathura_page_get_height(page_text->page) - page_text->rectangle->y1; - page_text->rectangle->y1 = zathura_page_get_height(page_text->page) - page_text->rectangle->y2; - page_text->rectangle->y2 = y1; - - /* add rectangle to result list */ - girara_list_append(results, page_text->rectangle); - page_text->rectangle = NULL; - - tmp += search_length; - } - - /* clean up */ - girara_list_free(page_text->text_positions); - page_text->text_positions = NULL; - - if (girara_list_size(results) == 0) { - girara_list_free(results); - return NULL; - } - - return results; - -error_free: - - if (results != NULL) { - girara_list_free(results); - } - - if (page_text->text_positions != NULL) { - girara_list_free(page_text->text_positions); - } - - if (page_text->content != NULL) { - g_free(page_text->content); - page_text->content = NULL; - } - -error_ret: - - return NULL; -} - -static void -djvu_page_text_content_append(djvu_page_text_t* page_text, miniexp_t exp) -{ - if (page_text == NULL || exp == miniexp_nil) { - return; - } - - if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { - return; - } - - miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); - while (inner != miniexp_nil) { - miniexp_t data = miniexp_car(inner); - - if (miniexp_stringp(data) != 0) { - /* create position */ - if (page_text->text_positions != NULL) { - text_position_t* position = malloc(sizeof(text_position_t)); - if (position == NULL) { - inner = miniexp_cdr(inner); - continue; - } - - position->position = (page_text->content != NULL) ? - strlen(page_text->content) : 0; - position->exp = exp; - - girara_list_append(page_text->text_positions, position); - } - - /* append text */ - char* text = (char*) miniexp_to_str(data); - - if (page_text->content == NULL) { - page_text->content = g_strdup(text); - } else { - char* tmp = g_strjoin(" ", page_text->content, text, NULL); - g_free(page_text->content); - page_text->content = tmp; - } - /* not a string, recursive call */ - } else { - djvu_page_text_content_append(page_text, data); - } - - /* move to next object */ - inner = miniexp_cdr(inner); - } -} - -static miniexp_t -text_position_get_exp(djvu_page_text_t* page_text, unsigned int index) -{ - if (page_text == NULL || page_text->text_positions == NULL) { - goto error_ret; - } - - int l = 0; - int m = 0; - int h = girara_list_size(page_text->text_positions) - 1; - - if (h < 0) { - goto error_ret; - } - - while (l <= h) { - m = (l + h) >> 1; - - text_position_t* text_position = girara_list_nth(page_text->text_positions, m); - if (text_position == NULL) { - goto error_ret; - } - - if (text_position->position == index) { - break; - } else if (text_position->position > index) { - h = --m; - } else { - l = m + 1; - } - } - - text_position_t* text_position = girara_list_nth(page_text->text_positions, m); - if (text_position == NULL) { - goto error_ret; - } else { - return text_position->exp; - } - -error_ret: - - return miniexp_nil; -} - -static bool -djvu_page_text_build_rectangle_process(djvu_page_text_t* page_text, miniexp_t exp, - miniexp_t start, miniexp_t end) -{ - if (page_text == NULL) { - goto error_ret; - } - - if (page_text->rectangle != NULL || exp == start) { - zathura_rectangle_t* rectangle = calloc(1, sizeof(zathura_rectangle_t)); - if (rectangle == NULL) { - goto error_ret; - } - - rectangle->x1 = miniexp_to_int(miniexp_nth(1, exp)); - rectangle->y1 = miniexp_to_int(miniexp_nth(2, exp)); - rectangle->x2 = miniexp_to_int(miniexp_nth(3, exp)); - rectangle->y2 = miniexp_to_int(miniexp_nth(4, exp)); - - if (page_text->rectangle != NULL) { - if (rectangle->x1 < page_text->rectangle->x1) { - page_text->rectangle->x1 = rectangle->x1; - } - - if (rectangle->x2 > page_text->rectangle->x2) { - page_text->rectangle->x2 = rectangle->x2; - } - - if (rectangle->y1 < page_text->rectangle->y1) { - page_text->rectangle->y1 = rectangle->y1; - } - - if (rectangle->y2 > page_text->rectangle->y2) { - page_text->rectangle->y2 = rectangle->y2; - } - - free(rectangle); - } else { - page_text->rectangle = rectangle; - } - - if (exp == end) { - return false; - } - } - - return true; - -error_ret: - - return false; -} - -static bool -djvu_page_text_build_rectangle(djvu_page_text_t* page_text, miniexp_t exp, - miniexp_t start, miniexp_t end) -{ - if (page_text == NULL) { - goto error_ret; - } - - if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { - return false; - } - - miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); - while (inner != miniexp_nil) { - miniexp_t data = miniexp_car(inner); - - if (miniexp_stringp(data) != 0) { - if (djvu_page_text_build_rectangle_process(page_text, - exp, start, end) == false) { - goto error_ret; - } - } else { - if (djvu_page_text_build_rectangle(page_text, data, start, end) == false) { - goto error_ret; - } - } - - inner = miniexp_cdr(inner); - } - - return true; - -error_ret: - - return false; -} - -char* -djvu_page_text_select(djvu_page_text_t* page_text, zathura_rectangle_t rectangle) -{ - if (page_text == NULL) { - return NULL; - } - - djvu_page_text_limit(page_text, page_text->text_information, &rectangle); - djvu_page_text_select_content(page_text, page_text->text_information, 0); - - return (page_text->content != NULL) ? g_strdup(page_text->content) : NULL; -} - -static void -djvu_page_text_limit_process(djvu_page_text_t* page_text, miniexp_t exp, - zathura_rectangle_t* rectangle) -{ - zathura_rectangle_t current_rectangle; - current_rectangle.x1 = miniexp_to_int(miniexp_nth(1, exp)); - current_rectangle.y1 = miniexp_to_int(miniexp_nth(2, exp)); - current_rectangle.x2 = miniexp_to_int(miniexp_nth(3, exp)); - current_rectangle.y2 = miniexp_to_int(miniexp_nth(4, exp)); - - if (current_rectangle.x2 >= rectangle->x1 && current_rectangle.y1 <= rectangle->y2 - && current_rectangle.x1 <= rectangle->x2 && current_rectangle.y2 >= rectangle->y1) { - if (page_text->begin == miniexp_nil) { - page_text->begin = exp; - } - - page_text->end = exp; - } -} - -static void -djvu_page_text_limit(djvu_page_text_t* page_text, miniexp_t exp, - zathura_rectangle_t* rectangle) -{ - if (page_text == NULL || rectangle == NULL) { - return; - } - - if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { - return; - } - - miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); - while (inner != miniexp_nil) { - miniexp_t data = miniexp_car(inner); - - if (miniexp_stringp(data) != 0) { - djvu_page_text_limit_process(page_text, exp, rectangle); - } else { - djvu_page_text_limit(page_text, data, rectangle); - } - - inner = miniexp_cdr(inner); - } - -} - -static bool -djvu_page_text_select_content(djvu_page_text_t* page_text, miniexp_t exp, int delimiter) -{ - if (page_text == NULL) { - return false; - } - - if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { - return false; - } - - if (miniexp_car(exp) != miniexp_symbol("char")) { - delimiter |= (miniexp_car(exp) == miniexp_symbol("word")) ? 1 : 2; - } - - miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); - while (inner != miniexp_nil) { - miniexp_t data = miniexp_car(inner); - - if (miniexp_stringp(data) != 0) { - if (page_text->content != NULL || exp == page_text->begin) { - char* token_content = (char*) miniexp_to_str(miniexp_nth(5, exp)); - - if (page_text->content != NULL) { - char* content = g_strjoin( - (delimiter & 2) ? "\n" : (delimiter & 1) ? " " : NULL, - page_text->content, - token_content, - NULL - ); - g_free(page_text->content); - page_text->content = content; - } else { - page_text->content = g_strdup(token_content); - } - - if (exp == page_text->end) { - return false; - } - } - } else { - if (djvu_page_text_select_content(page_text, data, delimiter) == false) { - return false; - } - } - - delimiter = 0; - inner = miniexp_cdr(inner); - } - - return true; -} diff -Nru zathura-extras-0.2/djvu-0-2-3/page-text.h zathura-extras-0.2/djvu-0-2-3/page-text.h --- zathura-extras-0.2/djvu-0-2-3/page-text.h 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/page-text.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,66 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef DJVU_PAGE_H -#define DJVU_PAGE_H - -#include -#include -#include -#include - -#include "djvu.h" - -/** - * DjVu page text - */ -typedef struct djvu_page_text_s { - miniexp_t text_information; /**< Text by ddjvu_document_get_pagetext */ - char* content; /**< Actual content */ - - miniexp_t begin; /**< Begin index */ - miniexp_t end; /**< End index */ - girara_list_t* text_positions; /**< Position/Expression duple */ - zathura_rectangle_t* rectangle; /**< Rectangle */ - - djvu_document_t* document; /**< Correspondening document */ - zathura_page_t* page; /**< Correspondening page */ -} djvu_page_text_t; - -/** - * Creates a new djvu page object - * - * @param document The document - * @param page_number The number of the page - * @return The page object or NULL if an error occured - */ -GIRARA_HIDDEN djvu_page_text_t* djvu_page_text_new(djvu_document_t* document, - zathura_page_t* page); - -/** - * Frees a djvu page object - * - * @param page The page to be freed - */ -GIRARA_HIDDEN void djvu_page_text_free(djvu_page_text_t* page_text); - -/** - * Searchs the page for a specific key word and returns a list of results - * - * @param page_text The djvu page text object - * @param text The text to search - * @return List of results or NULL if an error occured - */ -GIRARA_HIDDEN girara_list_t* djvu_page_text_search(djvu_page_text_t* page_text, - const char* text); - -/** - * Returns the text on the page under the given rectangle - * - * @param page_text The djvu page text object - * @param rectangle The area of where the text should be copied - * @return Copy of the text or NULL if an error occured or if the area is empty - */ -GIRARA_HIDDEN char* djvu_page_text_select(djvu_page_text_t* page_text, - zathura_rectangle_t rectangle); - -#endif // DJVU_PAGE_H diff -Nru zathura-extras-0.2/djvu-0-2-3/zathura-djvu.desktop zathura-extras-0.2/djvu-0-2-3/zathura-djvu.desktop --- zathura-extras-0.2/djvu-0-2-3/zathura-djvu.desktop 2013-05-12 21:23:50.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-3/zathura-djvu.desktop 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ -[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=image/vnd.djvu; diff -Nru zathura-extras-0.2/djvu-0-2-4/AUTHORS zathura-extras-0.2/djvu-0-2-4/AUTHORS --- zathura-extras-0.2/djvu-0-2-4/AUTHORS 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/AUTHORS 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,8 @@ +zathura-djvu is written by: + +Moritz Lipp +Sebastian Ramacher + +Other contributors are (in alphabetical order): + +Pavel Borzenkov diff -Nru zathura-extras-0.2/djvu-0-2-4/common.mk zathura-extras-0.2/djvu-0-2-4/common.mk --- zathura-extras-0.2/djvu-0-2-4/common.mk 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/common.mk 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,9 @@ +# See LICENSE file for license and copyright information + +ifeq "$(VERBOSE)" "0" +ECHO=@echo +QUIET=@ +else +ECHO=@\# +QUIET= +endif diff -Nru zathura-extras-0.2/djvu-0-2-4/config.mk zathura-extras-0.2/djvu-0-2-4/config.mk --- zathura-extras-0.2/djvu-0-2-4/config.mk 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/config.mk 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,54 @@ +# See LICENSE file for license and copyright information + +VERSION_MAJOR = 0 +VERSION_MINOR = 2 +VERSION_REV = 4 +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) + +GLIB_INC ?= $(shell pkg-config --cflags glib-2.0) +GLIB_LIB ?= $(shell pkg-config --libs glib-2.0) + +DJVU_INC ?= $(shell pkg-config --cflags ddjvuapi) +DJVU_LIB ?= $(shell pkg-config --libs ddjvuapi) + +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 = ${GIRARA_INC} ${GLIB_INC} ${DJVU_INC} ${ZATHURA_INC} +LIBS = ${GIRARA_LIB} ${GLIB_LIB} ${DJVU_LIB} + +# flags +CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length -Wextra $(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 diff -Nru zathura-extras-0.2/djvu-0-2-4/djvu.c zathura-extras-0.2/djvu-0-2-4/djvu.c --- zathura-extras-0.2/djvu-0-2-4/djvu.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/djvu.c 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,853 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include +#include +#include +#include +#include + +#include "djvu.h" +#include "page-text.h" +#include "internal.h" + +/* forward declarations */ +static const char* get_extension(const char* path); +static void build_index(djvu_document_t *djvu_document, miniexp_t expression, girara_tree_node_t* root); +static bool exp_to_str(miniexp_t expression, const char** string); +static bool exp_to_int(miniexp_t expression, int* integer); +static bool exp_to_rect(miniexp_t expression, zathura_rectangle_t* rect); + +void +register_functions(zathura_plugin_functions_t* functions) +{ + functions->document_open = (zathura_plugin_document_open_t) djvu_document_open; + functions->document_free = (zathura_plugin_document_free_t) djvu_document_free; + functions->document_index_generate = (zathura_plugin_document_index_generate_t) djvu_document_index_generate; + functions->document_save_as = (zathura_plugin_document_save_as_t) djvu_document_save_as; + functions->page_init = (zathura_plugin_page_init_t) djvu_page_init; + functions->page_clear = (zathura_plugin_page_clear_t) djvu_page_clear; + functions->page_search_text = (zathura_plugin_page_search_text_t) djvu_page_search_text; + functions->page_get_text = (zathura_plugin_page_get_text_t) djvu_page_get_text; + functions->page_links_get = (zathura_plugin_page_links_get_t) djvu_page_links_get; + functions->page_render = (zathura_plugin_page_render_t) djvu_page_render; +#ifdef HAVE_CAIRO + functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) djvu_page_render_cairo; +#endif +} + +ZATHURA_PLUGIN_REGISTER( + "djvu", + VERSION_MAJOR, VERSION_MINOR, VERSION_REV, + register_functions, + ZATHURA_PLUGIN_MIMETYPES({ + "image/vnd.djvu" + }) +) + +zathura_error_t +djvu_document_open(zathura_document_t* document) +{ + zathura_error_t error = ZATHURA_ERROR_OK; + + if (document == NULL) { + error = ZATHURA_ERROR_INVALID_ARGUMENTS; + goto error_out; + } + + djvu_document_t* djvu_document = calloc(1, sizeof(djvu_document_t)); + if (djvu_document == NULL) { + error = ZATHURA_ERROR_OUT_OF_MEMORY; + goto error_out; + } + + /* setup format */ + static unsigned int masks[4] = {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}; + djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGBMASK32, 4, masks); + + if (djvu_document->format == NULL) { + error = ZATHURA_ERROR_UNKNOWN; + goto error_free; + } + + ddjvu_format_set_row_order(djvu_document->format, TRUE); + + /* setup context */ + djvu_document->context = ddjvu_context_create("zathura"); + + if (djvu_document->context == NULL) { + error = ZATHURA_ERROR_UNKNOWN; + goto error_free; + } + + /* setup document */ + djvu_document->document = + ddjvu_document_create_by_filename( + djvu_document->context, + zathura_document_get_path(document), + FALSE + ); + + if (djvu_document->document == NULL) { + error = ZATHURA_ERROR_UNKNOWN; + goto error_free; + } + + /* load document info */ + ddjvu_message_t* msg; + ddjvu_message_wait(djvu_document->context); + + while ((msg = ddjvu_message_peek(djvu_document->context)) && + (msg->m_any.tag != DDJVU_DOCINFO)) { + if (msg->m_any.tag == DDJVU_ERROR) { + error = ZATHURA_ERROR_UNKNOWN; + goto error_free; + } + + ddjvu_message_pop(djvu_document->context); + } + + /* decoding error */ + if (ddjvu_document_decoding_error(djvu_document->document)) { + handle_messages(djvu_document, true); + error = ZATHURA_ERROR_UNKNOWN; + goto error_free; + } + + zathura_document_set_data(document, djvu_document); + zathura_document_set_number_of_pages(document, + ddjvu_document_get_pagenum(djvu_document->document)); + + return error; + +error_free: + + if (djvu_document->format != NULL) { + ddjvu_format_release(djvu_document->format); + } + + if (djvu_document->context != NULL) { + ddjvu_context_release(djvu_document->context); + } + + free(djvu_document); + +error_out: + + return error; +} + +zathura_error_t +djvu_document_free(zathura_document_t* document, djvu_document_t* djvu_document) +{ + if (document == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + if (djvu_document != NULL) { + ddjvu_context_release(djvu_document->context); + ddjvu_document_release(djvu_document->document); + ddjvu_format_release(djvu_document->format); + free(djvu_document); + } + + return ZATHURA_ERROR_OK; +} + +girara_tree_node_t* +djvu_document_index_generate(zathura_document_t* document, djvu_document_t* + djvu_document, zathura_error_t* error) +{ + if (document == NULL || djvu_document == NULL) { + if (error != NULL) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + return NULL; + } + + miniexp_t outline = miniexp_dummy; + while ((outline = ddjvu_document_get_outline(djvu_document->document)) == + miniexp_dummy) { + handle_messages(djvu_document, true); + } + + if (outline == miniexp_dummy) { + return NULL; + } + + if (miniexp_consp(outline) == 0 || miniexp_car(outline) != miniexp_symbol("bookmarks")) { + ddjvu_miniexp_release(djvu_document->document, outline); + return NULL; + } + + girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); + build_index(djvu_document, miniexp_cdr(outline), root); + + ddjvu_miniexp_release(djvu_document->document, outline); + + return root; +} + +zathura_error_t +djvu_document_save_as(zathura_document_t* document, djvu_document_t* djvu_document, const char* path) +{ + if (document == NULL || djvu_document == NULL || path == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + FILE* fp = fopen(path, "w"); + if (fp == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + const char* extension = get_extension(path); + + ddjvu_job_t* job = NULL; + if (extension != NULL && g_strcmp0(extension, "ps") == 0) { + job = ddjvu_document_print(djvu_document->document, fp, 0, NULL); + } else { + job = ddjvu_document_save(djvu_document->document, fp, 0, NULL); + } + while (ddjvu_job_done(job) != true) { + handle_messages(djvu_document, true); + } + + fclose(fp); + + return ZATHURA_ERROR_OK; +} + +zathura_error_t +djvu_page_init(zathura_page_t* page, void* UNUSED(data)) +{ + if (page == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + zathura_document_t* document = zathura_page_get_document(page); + djvu_document_t* djvu_document = zathura_document_get_data(document); + + ddjvu_status_t status; + ddjvu_pageinfo_t page_info; + + unsigned int index = zathura_page_get_index(page); + while ((status = ddjvu_document_get_pageinfo(djvu_document->document, index, + &page_info)) < DDJVU_JOB_OK) { + handle_messages(djvu_document, true); + } + + if (status >= DDJVU_JOB_FAILED) { + handle_messages(djvu_document, true); + return ZATHURA_ERROR_UNKNOWN; + } + + zathura_page_set_width(page, ZATHURA_DJVU_SCALE * page_info.width); + zathura_page_set_height(page, ZATHURA_DJVU_SCALE * page_info.height); + + return ZATHURA_ERROR_OK; +} + +zathura_error_t +djvu_page_clear(zathura_page_t* page, void* UNUSED(data)) +{ + if (page == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + return ZATHURA_ERROR_OK; +} + +girara_list_t* +djvu_page_search_text(zathura_page_t* page, void* UNUSED(data), const char* text, zathura_error_t* error) +{ + if (page == NULL || text == NULL || strlen(text) == 0) { + if (error != NULL) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + goto error_ret; + } + + zathura_document_t* document = zathura_page_get_document(page); + if (document == NULL) { + goto error_ret; + } + + djvu_document_t* djvu_document = zathura_document_get_data(document); + + djvu_page_text_t* page_text = djvu_page_text_new(djvu_document, page); + if (page_text == NULL) { + goto error_ret; + } + + girara_list_t* results = djvu_page_text_search(page_text, text); + if (results == NULL) { + goto error_free; + } + + djvu_page_text_free(page_text); + + return results; + +error_free: + + if (page_text != NULL) { + djvu_page_text_free(page_text); + } + +error_ret: + + if (error != NULL && *error == ZATHURA_ERROR_OK) { + *error = ZATHURA_ERROR_UNKNOWN; + } + + return NULL; +} + +char* +djvu_page_get_text(zathura_page_t* page, void* UNUSED(data), zathura_rectangle_t + rectangle, zathura_error_t* error) +{ + if (page == NULL) { + if (error != NULL) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + goto error_ret; + } + + zathura_document_t* document = zathura_page_get_document(page); + if (document == NULL) { + goto error_ret; + } + + djvu_document_t* djvu_document = zathura_document_get_data(document); + + djvu_page_text_t* page_text = djvu_page_text_new(djvu_document, page); + if (page_text == NULL) { + goto error_ret; + } + + double tmp = 0; + double page_height = zathura_page_get_height(page); + double page_width = zathura_page_get_width(page); + + switch (zathura_document_get_rotation(document)) { + case 90: + tmp = rectangle.x1; + rectangle.x1 = rectangle.y1; + rectangle.y1 = tmp; + tmp = rectangle.x2; + rectangle.x2 = rectangle.y2; + rectangle.y2 = tmp; + break; + case 180: + tmp = rectangle.x1; + rectangle.x1 = (page_width - rectangle.x2); + rectangle.x2 = (page_width - tmp); + break; + case 270: + tmp = rectangle.y2; + rectangle.y2 = (page_height - rectangle.x1); + rectangle.x1 = (page_width - tmp); + tmp = rectangle.y1; + rectangle.y1 = (page_height - rectangle.x2); + rectangle.x2 = (page_width - tmp); + break; + default: + tmp = rectangle.y1; + rectangle.y1 = (page_height - rectangle.y2); + rectangle.y2 = (page_height - tmp); + break; + } + + /* adjust to scale */ + rectangle.x1 /= ZATHURA_DJVU_SCALE; + rectangle.x2 /= ZATHURA_DJVU_SCALE; + rectangle.y1 /= ZATHURA_DJVU_SCALE; + rectangle.y2 /= ZATHURA_DJVU_SCALE; + + char* text = djvu_page_text_select(page_text, rectangle); + + djvu_page_text_free(page_text); + + return text; + +error_ret: + + if (error != NULL && *error == ZATHURA_ERROR_OK) { + *error = ZATHURA_ERROR_UNKNOWN; + } + + return NULL; +} + +girara_list_t* +djvu_page_links_get(zathura_page_t* page, void* UNUSED(data), zathura_error_t* error) +{ + if (page == NULL) { + if (error != NULL) { + *error = ZATHURA_ERROR_INVALID_ARGUMENTS; + } + goto error_ret; + } + + zathura_document_t* document = zathura_page_get_document(page); + if (document == NULL) { + goto error_ret; + } + + girara_list_t* 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_ret; + } + + djvu_document_t* djvu_document = zathura_document_get_data(document); + + miniexp_t annotations = miniexp_nil; + while ((annotations = ddjvu_document_get_pageanno(djvu_document->document, + zathura_page_get_index(page))) == miniexp_dummy) { + handle_messages(djvu_document, true); + } + + if (annotations == miniexp_nil) { + goto error_free; + } + + miniexp_t* hyperlinks = ddjvu_anno_get_hyperlinks(annotations); + for (miniexp_t* iter = hyperlinks; *iter != NULL; iter++) { + if (miniexp_car(*iter) != miniexp_symbol("maparea")) { + continue; + } + + miniexp_t inner = miniexp_cdr(*iter); + + /* extract url information */ + const char* target_string = NULL; + + if (miniexp_caar(inner) == miniexp_symbol("url")) { + if (exp_to_str(miniexp_caddr(miniexp_car(inner)), &target_string) == false) { + continue; + } + } else { + if (exp_to_str(miniexp_car(inner), &target_string) == false) { + continue; + } + } + + /* skip comment */ + inner = miniexp_cdr(inner); + + /* extract link area */ + inner = miniexp_cdr(inner); + + zathura_rectangle_t rect = { 0, 0, 0, 0 }; + if (exp_to_rect(miniexp_car(inner), &rect) == false) { + continue; + } + + /* update rect */ + unsigned int page_height = zathura_page_get_height(page) / ZATHURA_DJVU_SCALE; + rect.x1 = rect.x1 * ZATHURA_DJVU_SCALE; + rect.x2 = rect.x2 * ZATHURA_DJVU_SCALE; + double tmp = rect.y1; + rect.y1 = (page_height - rect.y2) * ZATHURA_DJVU_SCALE; + rect.y2 = (page_height - tmp) * ZATHURA_DJVU_SCALE; + + /* create zathura link */ + zathura_link_type_t type = ZATHURA_LINK_INVALID; + zathura_link_target_t target = { ZATHURA_LINK_DESTINATION_UNKNOWN, NULL, 0, -1, -1, -1, -1, 0 };; + + /* goto page */ + if (target_string[0] == '#' && target_string[1] == 'p') { + type = ZATHURA_LINK_GOTO_DEST; + target.page_number = atoi(target_string + 2) - 1; + /* url or other? */ + } else if (strstr(target_string, "//") != NULL) { + type = ZATHURA_LINK_URI; + target.value = (char*) target_string; + /* TODO: Parse all different links */ + } else { + continue; + } + + zathura_link_t* link = zathura_link_new(type, rect, target); + if (link != NULL) { + girara_list_append(list, link); + } + } + + return list; + +error_free: + + if (list != NULL) { + girara_list_free(list); + } + +error_ret: + + return NULL; +} + +#ifdef HAVE_CAIRO +zathura_error_t +djvu_page_render_cairo(zathura_page_t* page, void* UNUSED(data), cairo_t* cairo, + bool GIRARA_UNUSED(printing)) +{ + if (page == NULL || cairo == NULL) { + return ZATHURA_ERROR_INVALID_ARGUMENTS; + } + + zathura_document_t* document = zathura_page_get_document(page); + if (document == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + /* init ddjvu render data */ + djvu_document_t* djvu_document = zathura_document_get_data(document); + ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, zathura_page_get_index(page)); + + if (djvu_page == NULL) { + return ZATHURA_ERROR_UNKNOWN; + } + + while (!ddjvu_page_decoding_done(djvu_page)) { + handle_messages(djvu_document, true); + } + + cairo_surface_t* surface = cairo_get_target(cairo); + + if (surface == NULL || + cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS || + cairo_surface_get_type(surface) != CAIRO_SURFACE_TYPE_IMAGE) { + ddjvu_page_release(djvu_page); + return ZATHURA_ERROR_UNKNOWN; + } + + unsigned int page_width = cairo_image_surface_get_width(surface); + unsigned int page_height = cairo_image_surface_get_height(surface);; + + ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; + ddjvu_rect_t prect = { 0, 0, page_width, page_height }; + + char* surface_data = (char*) cairo_image_surface_get_data(surface); + + if (surface_data == NULL) { + ddjvu_page_release(djvu_page); + return ZATHURA_ERROR_UNKNOWN; + } + + /* render page */ + ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, + djvu_document->format, cairo_image_surface_get_stride(surface), surface_data); + + ddjvu_page_release(djvu_page); + + return ZATHURA_ERROR_OK; +} +#endif + +zathura_image_buffer_t* +djvu_page_render(zathura_page_t* page, void* UNUSED(data), zathura_error_t* error) +{ + if (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 */ + unsigned int page_width = zathura_document_get_scale(document) * zathura_page_get_width(page); + unsigned int page_height = zathura_document_get_scale(document) * zathura_page_get_height(page); + + if (page_width == 0 || page_height == 0) { + if (error != NULL) { + *error = ZATHURA_ERROR_UNKNOWN; + } + goto error_out; + } + + /* init ddjvu render data */ + djvu_document_t* djvu_document = zathura_document_get_data(document); + ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno( + djvu_document->document, zathura_page_get_index(page)); + + if (djvu_page == NULL) { + if (error != NULL) { + *error = ZATHURA_ERROR_UNKNOWN; + } + goto error_out; + } + + while (!ddjvu_page_decoding_done(djvu_page)) { + handle_messages(djvu_document, true); + } + + ddjvu_rect_t rrect = { 0, 0, page_width, page_height }; + ddjvu_rect_t prect = { 0, 0, page_width, page_height }; + + 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; + } + goto error_free; + } + + /* set rotation */ + ddjvu_page_set_rotation(djvu_page, DDJVU_ROTATE_0); + + /* render page */ + ddjvu_page_render(djvu_page, DDJVU_RENDER_COLOR, &prect, &rrect, + djvu_document->format, 3 * page_width, (char*) image_buffer->data); + + return image_buffer; + +error_free: + + ddjvu_page_release(djvu_page); + zathura_image_buffer_free(image_buffer); + +error_out: + + return NULL; +} + +static const char* +get_extension(const char* path) +{ + if (path == NULL) { + return NULL; + } + + unsigned int i = strlen(path); + for (; i > 0; i--) { + if (*(path + i) != '.') { + continue; + } else { + break; + } + } + + if (i == 0) { + return NULL; + } + + return path + i + 1; +} + +void +handle_messages(djvu_document_t* document, bool wait) +{ + if (document == NULL || document->context == NULL) { + return; + } + + ddjvu_context_t* context = document->context; + const ddjvu_message_t* message; + + if (wait == true) { + ddjvu_message_wait(context); + } + + while ((message = ddjvu_message_peek(context)) != NULL) { + ddjvu_message_pop(context); + } +} + +static void +build_index(djvu_document_t *djvu_document, miniexp_t expression, girara_tree_node_t* root) +{ + if (expression == miniexp_nil || root == NULL) { + return; + } + + int fileno = ddjvu_document_get_filenum(djvu_document->document); + int curfile = 0; + + while (miniexp_consp(expression) != 0) { + miniexp_t inner = miniexp_car(expression); + + if (miniexp_consp(inner) + && miniexp_consp(miniexp_cdr(inner)) + && miniexp_stringp(miniexp_car(inner)) + && miniexp_stringp(miniexp_car(inner)) + ) { + const char* name = miniexp_to_str(miniexp_car(inner)); + const char* link = miniexp_to_str(miniexp_cadr(inner)); + + /* TODO: handle other links? */ + if (link == NULL || link[0] != '#') { + expression = miniexp_cdr(expression); + continue; + } + + zathura_link_type_t type = ZATHURA_LINK_GOTO_DEST; + zathura_rectangle_t rect; + zathura_link_target_t target = { 0 }; + target.destination_type = ZATHURA_LINK_DESTINATION_XYZ; + + /* Check if link+1 contains a number */ + bool number = true; + const size_t linklen = strlen(link); + for (unsigned int k = 1; k < linklen; k++) { + if (!isdigit(link[k])) { + number = false; + break; + } + } + + /* if link starts with a number assume it is a number */ + if (number == true) { + target.page_number = atoi(link + 1) - 1; + } else { + /* otherwise assume it is an id for a page */ + ddjvu_fileinfo_t info; + int f, i; + for (i=0; i < fileno; i++) { + f = (curfile + i) % fileno; + ddjvu_document_get_fileinfo(djvu_document->document, f, &info); + if (info.id != NULL && !strcmp(link+1, info.id)) { + break; + } + } + + /* got a page */ + if (i < fileno && info.pageno >= 0) { + curfile = (f+1) % fileno; + target.page_number = info.pageno; + } else { + /* give up */ + expression = miniexp_cdr(expression); + continue; + } + } + + zathura_index_element_t* index_element = zathura_index_element_new(name); + if (index_element == NULL) { + continue; + } + + index_element->link = zathura_link_new(type, rect, target); + if (index_element->link == NULL) { + zathura_index_element_free(index_element); + continue; + } + + girara_tree_node_t* node = girara_node_append_data(root, index_element); + + /* search recursive */ + build_index(djvu_document, miniexp_cddr(inner), node); + } + + expression = miniexp_cdr(expression); + } +} + +static bool +exp_to_str(miniexp_t expression, const char** string) +{ + if (string == NULL) { + return false; + } + + if (miniexp_stringp(expression)) { + *string = miniexp_to_str(expression); + return true; + } + + return false; +} + +static bool +exp_to_int(miniexp_t expression, int* integer) +{ + if (integer == NULL) { + return false; + } + + if (miniexp_numberp(expression)) { + *integer = miniexp_to_int(expression); + return true; + } + + return false; +} + +static bool +exp_to_rect(miniexp_t expression, zathura_rectangle_t* rect) +{ + if ((miniexp_car(expression) == miniexp_symbol("rect") + || miniexp_car(expression) == miniexp_symbol("oval")) + && miniexp_length(expression) == 5) { + int min_x = 0; + int min_y = 0; + int width = 0; + int height = 0; + + miniexp_t iter = miniexp_cdr(expression); + if (exp_to_int(miniexp_car(iter), &min_x) == false) { + return false; + } + iter = miniexp_cdr(iter); + if (exp_to_int(miniexp_car(iter), &min_y) == false) { + return false; + } + iter = miniexp_cdr(iter); + if (exp_to_int(miniexp_car(iter), &width) == false) { + return false; + } + iter = miniexp_cdr(iter); + if (exp_to_int(miniexp_car(iter), &height) == false) { + return false; + } + + rect->x1 = min_x; + rect->x2 = min_x + width; + rect->y1 = min_y; + rect->y2 = min_y + height; + } else if (miniexp_car(expression) == miniexp_symbol("poly") + && miniexp_length(expression) >= 5) { + int min_x = 0; + int min_y = 0; + int max_x = 0; + int max_y = 0; + + miniexp_t iter = miniexp_cdr(expression); + while (iter != miniexp_nil) { + int x = 0; + int y = 0; + + if (exp_to_int(miniexp_car(iter), &x) == false) { + return false; + } + iter = miniexp_cdr(iter); + if (exp_to_int(miniexp_car(iter), &y) == false) { + return false; + } + iter = miniexp_cdr(iter); + + min_x = MIN(min_x, x); + min_y = MIN(min_y, y); + max_x = MAX(max_x, x); + max_y = MAX(max_y, y); + } + + rect->x1 = min_x; + rect->x2 = max_x; + rect->y1 = min_y; + rect->y2 = max_y; + } + + return true; +} diff -Nru zathura-extras-0.2/djvu-0-2-4/djvu.h zathura-extras-0.2/djvu-0-2-4/djvu.h --- zathura-extras-0.2/djvu-0-2-4/djvu.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/djvu.h 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,138 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DJVU_H +#define DJVU_H + +#include +#include +#include +#ifdef HAVE_CAIRO +#include +#endif + +/** + * DjVu document + */ +typedef struct djvu_document_s +{ + ddjvu_context_t* context; /**< Document context */ + ddjvu_document_t* document; /**< Document */ + ddjvu_format_t* format; /**< Format */ +} djvu_document_t; + +/** + * Open a DjVU document + * + * @param document Zathura document + * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * zathura_error_t + */ +zathura_error_t djvu_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 djvu_document_free(zathura_document_t* document, djvu_document_t* djvu_document); + +/** + * 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* djvu_document_index_generate(zathura_document_t* document, + djvu_document_t* djvu_document, zathura_error_t* error); + +/** + * 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 djvu_document_save_as(zathura_document_t* document, djvu_document_t* djvu_document, const char* path); + +/** + * Initializes the page + * + * @param page The page object + * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * zathura_error_t + */ +zathura_error_t djvu_page_init(zathura_page_t* page, void* data); + +/** + * Frees a DjVu page + * + * @param page Page + * @return ZATHURA_ERROR_OK when no error occured, otherwise see + * zathura_error_t + */ +zathura_error_t djvu_page_clear(zathura_page_t* page, void* data); + +/** + * 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* djvu_page_search_text(zathura_page_t* page, void* data, const char* text, 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* djvu_page_get_text(zathura_page_t* page, void* data, zathura_rectangle_t rectangle, zathura_error_t* error); + +/** + * Returns list of links + * + * @param page The page + * @param data Unused page data + * @param error Error code + * @return List of links or NULL if an error occured + */ +girara_list_t* djvu_page_links_get(zathura_page_t* page, void* data, + zathura_error_t* error); + +/** + * 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* djvu_page_render(zathura_page_t* page, void* data, zathura_error_t* error); + +#ifdef 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 djvu_page_render_cairo(zathura_page_t* page, void* data, cairo_t* cairo, bool printing); +#endif + +#endif // DJVU_H diff -Nru zathura-extras-0.2/djvu-0-2-4/Doxyfile zathura-extras-0.2/djvu-0-2-4/Doxyfile --- zathura-extras-0.2/djvu-0-2-4/Doxyfile 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/Doxyfile 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,29 @@ +# See LICENSE file for license and copyright information + +# General information +PROJECT_NAME = zathura-djvu +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 diff -Nru zathura-extras-0.2/djvu-0-2-4/internal.h zathura-extras-0.2/djvu-0-2-4/internal.h --- zathura-extras-0.2/djvu-0-2-4/internal.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/internal.h 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,12 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DJVU_INTERNAL_H +#define DJVU_INTERNAL_H + +#include + +#define ZATHURA_DJVU_SCALE 0.2 + +GIRARA_HIDDEN void handle_messages(djvu_document_t* document, bool wait); + +#endif // DJVU_INTERNAL_H diff -Nru zathura-extras-0.2/djvu-0-2-4/LICENSE zathura-extras-0.2/djvu-0-2-4/LICENSE --- zathura-extras-0.2/djvu-0-2-4/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/LICENSE 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,20 @@ +Copyright (c) 2010-2012 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. diff -Nru zathura-extras-0.2/djvu-0-2-4/Makefile zathura-extras-0.2/djvu-0-2-4/Makefile --- zathura-extras-0.2/djvu-0-2-4/Makefile 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/Makefile 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,96 @@ +# See LICENSE file for license and copyright information + +include config.mk +include common.mk + +PROJECT = zathura-djvu +PLUGIN = djvu +SOURCE = $(shell find . -iname "*.c") +HEADER = $(shell find . -iname "*.h") +OBJECTS = ${SOURCE:.c=.o} +DOBJECTS = ${SOURCE:.c=.do} + +ifneq "$(WITH_CAIRO)" "0" +CPPFLAGS += -DHAVE_CAIRO +INCS += $(CAIRO_INC) +LIBS += $(CAIRO_LIB) +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 diff -Nru zathura-extras-0.2/djvu-0-2-4/page-text.c zathura-extras-0.2/djvu-0-2-4/page-text.c --- zathura-extras-0.2/djvu-0-2-4/page-text.c 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/page-text.c 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,515 @@ +/* See LICENSE file for license and copyright information */ + +#include +#include +#include +#include + +#include "page-text.h" +#include "internal.h" + +/** + * To determine the position of a character + */ +typedef struct text_position_s { + unsigned int position; /**< Index */ + miniexp_t exp; /**< Correspondending expression */ +} text_position_t; + +/* forward declaration */ +static void djvu_page_text_content_append(djvu_page_text_t* page_text, + miniexp_t exp); +static miniexp_t text_position_get_exp(djvu_page_text_t* page_text, + unsigned int index); +static bool djvu_page_text_build_rectangle(djvu_page_text_t* page_text, + miniexp_t exp, miniexp_t start, miniexp_t end); +static bool djvu_page_text_build_rectangle_process(djvu_page_text_t* page_text, + miniexp_t exp, miniexp_t start, miniexp_t end); +static void djvu_page_text_limit(djvu_page_text_t* page_text, miniexp_t exp, + zathura_rectangle_t* rectangle); +static void djvu_page_text_limit_process(djvu_page_text_t* page_text, + miniexp_t exp, zathura_rectangle_t* rectangle); +static bool djvu_page_text_select_content(djvu_page_text_t* page_text, + miniexp_t exp, int delimiter); + +djvu_page_text_t* +djvu_page_text_new(djvu_document_t* document, zathura_page_t* page) +{ + if (document == NULL || document->document == NULL || page == NULL) { + goto error_ret; + } + + djvu_page_text_t* page_text = calloc(1, sizeof(djvu_page_text_t)); + if (page_text == NULL) { + goto error_ret; + } + + page_text->text_information = miniexp_nil; + page_text->begin = miniexp_nil; + page_text->end = miniexp_nil; + page_text->document = document; + page_text->page = page; + + /* read page text */ + while ((page_text->text_information = + ddjvu_document_get_pagetext(document->document, zathura_page_get_index(page), "char")) + == miniexp_dummy) { + handle_messages(document, true); + } + + if (page_text->text_information == miniexp_nil) { + goto error_free; + } + + return page_text; + +error_free: + + if (page_text != NULL) { + djvu_page_text_free(page_text); + } + +error_ret: + + return NULL; +} + +void +djvu_page_text_free(djvu_page_text_t* page_text) +{ + if (page_text == NULL) { + return; + } + + if (page_text->text_information != miniexp_nil && page_text->document != NULL) { + ddjvu_miniexp_release(page_text->document->document, + page_text->text_information); + } + + if (page_text->content != NULL) { + g_free(page_text->content); + } + + if (page_text->text_positions != NULL) { + girara_list_free(page_text->text_positions); + } + + if (page_text->rectangle != NULL) { + free(page_text->rectangle); + } + + free(page_text); +} + +girara_list_t* +djvu_page_text_search(djvu_page_text_t* page_text, const char* text) +{ + if (page_text == NULL || text == NULL) { + goto error_ret; + } + + /* clean and reset */ + if (page_text->content != NULL) { + g_free(page_text->content); + page_text->content = NULL; + } + + if (page_text->text_positions != NULL) { + girara_list_free(page_text->text_positions); + page_text->text_positions = NULL; + } + + /* create result list */ + girara_list_t* results = girara_list_new2( + (girara_free_function_t) free); + + if (results == NULL) { + goto error_ret; + } + + /* create list */ + page_text->text_positions = girara_list_new2( + (girara_free_function_t) free); + + if (page_text->text_positions == NULL) { + goto error_free; + } + + /* get page content */ + djvu_page_text_content_append(page_text, page_text->text_information); + + if (page_text->content == NULL || strlen(page_text->content) == 0) { + goto error_free; + } + + /* search through content */ + int search_length = strlen(text); + char* tmp = page_text->content; + + while ((tmp = strstr(tmp, text)) != NULL) { + int start_pointer = tmp - page_text->content; + int end_pointer = start_pointer + search_length - 1; + + miniexp_t start = text_position_get_exp(page_text, start_pointer); + miniexp_t end = text_position_get_exp(page_text, end_pointer); + + /* reset rectangle */ + if (page_text->rectangle != NULL) { + free(page_text->rectangle); + page_text->rectangle = NULL; + } + + djvu_page_text_build_rectangle(page_text, page_text->text_information, + start, end); + + if (page_text->rectangle == NULL) { + tmp += search_length; + continue; + } + + /* scale rectangle coordinates */ + page_text->rectangle->x1 = ZATHURA_DJVU_SCALE * page_text->rectangle->x1; + page_text->rectangle->x2 = ZATHURA_DJVU_SCALE * page_text->rectangle->x2; + page_text->rectangle->y1 = ZATHURA_DJVU_SCALE * page_text->rectangle->y1; + page_text->rectangle->y2 = ZATHURA_DJVU_SCALE * page_text->rectangle->y2; + + /* invert */ + int y1 = zathura_page_get_height(page_text->page) - page_text->rectangle->y1; + page_text->rectangle->y1 = zathura_page_get_height(page_text->page) - page_text->rectangle->y2; + page_text->rectangle->y2 = y1; + + /* add rectangle to result list */ + girara_list_append(results, page_text->rectangle); + page_text->rectangle = NULL; + + tmp += search_length; + } + + /* clean up */ + girara_list_free(page_text->text_positions); + page_text->text_positions = NULL; + + if (girara_list_size(results) == 0) { + girara_list_free(results); + return NULL; + } + + return results; + +error_free: + + if (results != NULL) { + girara_list_free(results); + } + + if (page_text->text_positions != NULL) { + girara_list_free(page_text->text_positions); + } + + if (page_text->content != NULL) { + g_free(page_text->content); + page_text->content = NULL; + } + +error_ret: + + return NULL; +} + +static void +djvu_page_text_content_append(djvu_page_text_t* page_text, miniexp_t exp) +{ + if (page_text == NULL || exp == miniexp_nil) { + return; + } + + if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { + return; + } + + miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); + while (inner != miniexp_nil) { + miniexp_t data = miniexp_car(inner); + + if (miniexp_stringp(data) != 0) { + /* create position */ + if (page_text->text_positions != NULL) { + text_position_t* position = malloc(sizeof(text_position_t)); + if (position == NULL) { + inner = miniexp_cdr(inner); + continue; + } + + position->position = (page_text->content != NULL) ? + strlen(page_text->content) : 0; + position->exp = exp; + + girara_list_append(page_text->text_positions, position); + } + + /* append text */ + char* text = (char*) miniexp_to_str(data); + + if (page_text->content == NULL) { + page_text->content = g_strdup(text); + } else { + char* tmp = g_strjoin(" ", page_text->content, text, NULL); + g_free(page_text->content); + page_text->content = tmp; + } + /* not a string, recursive call */ + } else { + djvu_page_text_content_append(page_text, data); + } + + /* move to next object */ + inner = miniexp_cdr(inner); + } +} + +static miniexp_t +text_position_get_exp(djvu_page_text_t* page_text, unsigned int index) +{ + if (page_text == NULL || page_text->text_positions == NULL) { + goto error_ret; + } + + int l = 0; + int m = 0; + int h = girara_list_size(page_text->text_positions) - 1; + + if (h < 0) { + goto error_ret; + } + + while (l <= h) { + m = (l + h) >> 1; + + text_position_t* text_position = girara_list_nth(page_text->text_positions, m); + if (text_position == NULL) { + goto error_ret; + } + + if (text_position->position == index) { + break; + } else if (text_position->position > index) { + h = --m; + } else { + l = m + 1; + } + } + + text_position_t* text_position = girara_list_nth(page_text->text_positions, m); + if (text_position == NULL) { + goto error_ret; + } else { + return text_position->exp; + } + +error_ret: + + return miniexp_nil; +} + +static bool +djvu_page_text_build_rectangle_process(djvu_page_text_t* page_text, miniexp_t exp, + miniexp_t start, miniexp_t end) +{ + if (page_text == NULL) { + goto error_ret; + } + + if (page_text->rectangle != NULL || exp == start) { + zathura_rectangle_t* rectangle = calloc(1, sizeof(zathura_rectangle_t)); + if (rectangle == NULL) { + goto error_ret; + } + + rectangle->x1 = miniexp_to_int(miniexp_nth(1, exp)); + rectangle->y1 = miniexp_to_int(miniexp_nth(2, exp)); + rectangle->x2 = miniexp_to_int(miniexp_nth(3, exp)); + rectangle->y2 = miniexp_to_int(miniexp_nth(4, exp)); + + if (page_text->rectangle != NULL) { + if (rectangle->x1 < page_text->rectangle->x1) { + page_text->rectangle->x1 = rectangle->x1; + } + + if (rectangle->x2 > page_text->rectangle->x2) { + page_text->rectangle->x2 = rectangle->x2; + } + + if (rectangle->y1 < page_text->rectangle->y1) { + page_text->rectangle->y1 = rectangle->y1; + } + + if (rectangle->y2 > page_text->rectangle->y2) { + page_text->rectangle->y2 = rectangle->y2; + } + + free(rectangle); + } else { + page_text->rectangle = rectangle; + } + + if (exp == end) { + return false; + } + } + + return true; + +error_ret: + + return false; +} + +static bool +djvu_page_text_build_rectangle(djvu_page_text_t* page_text, miniexp_t exp, + miniexp_t start, miniexp_t end) +{ + if (page_text == NULL) { + goto error_ret; + } + + if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { + return false; + } + + miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); + while (inner != miniexp_nil) { + miniexp_t data = miniexp_car(inner); + + if (miniexp_stringp(data) != 0) { + if (djvu_page_text_build_rectangle_process(page_text, + exp, start, end) == false) { + goto error_ret; + } + } else { + if (djvu_page_text_build_rectangle(page_text, data, start, end) == false) { + goto error_ret; + } + } + + inner = miniexp_cdr(inner); + } + + return true; + +error_ret: + + return false; +} + +char* +djvu_page_text_select(djvu_page_text_t* page_text, zathura_rectangle_t rectangle) +{ + if (page_text == NULL) { + return NULL; + } + + djvu_page_text_limit(page_text, page_text->text_information, &rectangle); + djvu_page_text_select_content(page_text, page_text->text_information, 0); + + return (page_text->content != NULL) ? g_strdup(page_text->content) : NULL; +} + +static void +djvu_page_text_limit_process(djvu_page_text_t* page_text, miniexp_t exp, + zathura_rectangle_t* rectangle) +{ + zathura_rectangle_t current_rectangle; + current_rectangle.x1 = miniexp_to_int(miniexp_nth(1, exp)); + current_rectangle.y1 = miniexp_to_int(miniexp_nth(2, exp)); + current_rectangle.x2 = miniexp_to_int(miniexp_nth(3, exp)); + current_rectangle.y2 = miniexp_to_int(miniexp_nth(4, exp)); + + if (current_rectangle.x2 >= rectangle->x1 && current_rectangle.y1 <= rectangle->y2 + && current_rectangle.x1 <= rectangle->x2 && current_rectangle.y2 >= rectangle->y1) { + if (page_text->begin == miniexp_nil) { + page_text->begin = exp; + } + + page_text->end = exp; + } +} + +static void +djvu_page_text_limit(djvu_page_text_t* page_text, miniexp_t exp, + zathura_rectangle_t* rectangle) +{ + if (page_text == NULL || rectangle == NULL) { + return; + } + + if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { + return; + } + + miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); + while (inner != miniexp_nil) { + miniexp_t data = miniexp_car(inner); + + if (miniexp_stringp(data) != 0) { + djvu_page_text_limit_process(page_text, exp, rectangle); + } else { + djvu_page_text_limit(page_text, data, rectangle); + } + + inner = miniexp_cdr(inner); + } + +} + +static bool +djvu_page_text_select_content(djvu_page_text_t* page_text, miniexp_t exp, int delimiter) +{ + if (page_text == NULL) { + return false; + } + + if (miniexp_consp(exp) == 0 || miniexp_symbolp(miniexp_car(exp)) == 0) { + return false; + } + + if (miniexp_car(exp) != miniexp_symbol("char")) { + delimiter |= (miniexp_car(exp) == miniexp_symbol("word")) ? 1 : 2; + } + + miniexp_t inner = miniexp_cddr(miniexp_cdddr(exp)); + while (inner != miniexp_nil) { + miniexp_t data = miniexp_car(inner); + + if (miniexp_stringp(data) != 0) { + if (page_text->content != NULL || exp == page_text->begin) { + char* token_content = (char*) miniexp_to_str(miniexp_nth(5, exp)); + + if (page_text->content != NULL) { + char* content = g_strjoin( + (delimiter & 2) ? "\n" : (delimiter & 1) ? " " : NULL, + page_text->content, + token_content, + NULL + ); + g_free(page_text->content); + page_text->content = content; + } else { + page_text->content = g_strdup(token_content); + } + + if (exp == page_text->end) { + return false; + } + } + } else { + if (djvu_page_text_select_content(page_text, data, delimiter) == false) { + return false; + } + } + + delimiter = 0; + inner = miniexp_cdr(inner); + } + + return true; +} diff -Nru zathura-extras-0.2/djvu-0-2-4/page-text.h zathura-extras-0.2/djvu-0-2-4/page-text.h --- zathura-extras-0.2/djvu-0-2-4/page-text.h 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/page-text.h 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,66 @@ +/* See LICENSE file for license and copyright information */ + +#ifndef DJVU_PAGE_H +#define DJVU_PAGE_H + +#include +#include +#include +#include + +#include "djvu.h" + +/** + * DjVu page text + */ +typedef struct djvu_page_text_s { + miniexp_t text_information; /**< Text by ddjvu_document_get_pagetext */ + char* content; /**< Actual content */ + + miniexp_t begin; /**< Begin index */ + miniexp_t end; /**< End index */ + girara_list_t* text_positions; /**< Position/Expression duple */ + zathura_rectangle_t* rectangle; /**< Rectangle */ + + djvu_document_t* document; /**< Correspondening document */ + zathura_page_t* page; /**< Correspondening page */ +} djvu_page_text_t; + +/** + * Creates a new djvu page object + * + * @param document The document + * @param page_number The number of the page + * @return The page object or NULL if an error occured + */ +GIRARA_HIDDEN djvu_page_text_t* djvu_page_text_new(djvu_document_t* document, + zathura_page_t* page); + +/** + * Frees a djvu page object + * + * @param page The page to be freed + */ +GIRARA_HIDDEN void djvu_page_text_free(djvu_page_text_t* page_text); + +/** + * Searchs the page for a specific key word and returns a list of results + * + * @param page_text The djvu page text object + * @param text The text to search + * @return List of results or NULL if an error occured + */ +GIRARA_HIDDEN girara_list_t* djvu_page_text_search(djvu_page_text_t* page_text, + const char* text); + +/** + * Returns the text on the page under the given rectangle + * + * @param page_text The djvu page text object + * @param rectangle The area of where the text should be copied + * @return Copy of the text or NULL if an error occured or if the area is empty + */ +GIRARA_HIDDEN char* djvu_page_text_select(djvu_page_text_t* page_text, + zathura_rectangle_t rectangle); + +#endif // DJVU_PAGE_H diff -Nru zathura-extras-0.2/djvu-0-2-4/zathura-djvu.desktop zathura-extras-0.2/djvu-0-2-4/zathura-djvu.desktop --- zathura-extras-0.2/djvu-0-2-4/zathura-djvu.desktop 1970-01-01 00:00:00.000000000 +0000 +++ zathura-extras-0.2/djvu-0-2-4/zathura-djvu.desktop 2014-10-16 22:19:06.000000000 +0000 @@ -0,0 +1,24 @@ +[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=image/vnd.djvu;