Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37650118
en ru br
Репозитории ALT

Группа :: Офис
Пакет: zathura-djvu

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

pax_global_header00006660000000000000000000000064121440041250014503gustar00rootroot0000000000000052 comment=fd8c04f3af0b546c1d2cbf84dd4b263d69ed0965
zathura-djvu-0.2.3/000075500000000000000000000000001214400412500141275ustar00rootroot00000000000000zathura-djvu-0.2.3/.gitignore000064400000000000000000000000621214400412500161150ustar00rootroot00000000000000*.o
*~
.depend
djvu.so
*swp
zathura-version-check
zathura-djvu-0.2.3/AUTHORS000064400000000000000000000002751214400412500152030ustar00rootroot00000000000000zathura-djvu is written by:

Moritz Lipp <mlq@pwmt.org>
Sebastian Ramacher <s.ramacher@gmx.at>

Other contributors are (in alphabetical order):

Pavel Borzenkov <pavel.borzenkov@gmail.com>
zathura-djvu-0.2.3/Doxyfile000064400000000000000000000011641214400412500156370ustar00rootroot00000000000000# 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
zathura-djvu-0.2.3/LICENSE000064400000000000000000000015421214400412500151360ustar00rootroot00000000000000Copyright (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.
zathura-djvu-0.2.3/Makefile000064400000000000000000000052471214400412500155770ustar00rootroot00000000000000# 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
zathura-djvu-0.2.3/common.mk000064400000000000000000000001761214400412500157540ustar00rootroot00000000000000# See LICENSE file for license and copyright information

ifeq "$(VERBOSE)" "0"
ECHO=@echo
QUIET=@
else
ECHO=@\#
QUIET=
endif
zathura-djvu-0.2.3/config.mk000064400000000000000000000027251214400412500157330ustar00rootroot00000000000000# 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
zathura-djvu-0.2.3/djvu.c000064400000000000000000000530531214400412500152510ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include <stdlib.h>
#include <ctype.h>
#include <girara/datastructures.h>
#include <string.h>
#include <libdjvu/miniexp.h>
#include <glib.h>

#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;
}
zathura-djvu-0.2.3/djvu.h000064400000000000000000000075041214400412500152560ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#ifndef DJVU_H
#define DJVU_H

#include <stdbool.h>
#include <zathura/plugin-api.h>
#include <libdjvu/ddjvuapi.h>
#ifdef HAVE_CAIRO
#include <cairo.h>
#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
zathura-djvu-0.2.3/internal.h000064400000000000000000000004201214400412500161100ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#ifndef DJVU_INTERNAL_H
#define DJVU_INTERNAL_H

#include <girara/macros.h>

#define ZATHURA_DJVU_SCALE 0.2

GIRARA_HIDDEN void handle_messages(djvu_document_t* document, bool wait);

#endif // DJVU_INTERNAL_H
zathura-djvu-0.2.3/page-text.c000064400000000000000000000313621214400412500161760ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#include <libdjvu/miniexp.h>
#include <string.h>
#include <sys/types.h>
#include <glib.h>

#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;
}
zathura-djvu-0.2.3/page-text.h000064400000000000000000000035421214400412500162020ustar00rootroot00000000000000/* See LICENSE file for license and copyright information */

#ifndef DJVU_PAGE_H
#define DJVU_PAGE_H

#include <girara/datastructures.h>
#include <girara/macros.h>
#include <zathura/document.h>
#include <libdjvu/miniexp.h>

#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
zathura-djvu-0.2.3/zathura-djvu.desktop000064400000000000000000000017331214400412500201520ustar00rootroot00000000000000[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;
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin