Commit 1ba89165 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Moved plugins to own repositories

Every plugin is now accesible in a separate repository
parent 691b5c76
......@@ -3,12 +3,11 @@
include config.mk
PROJECT = zathura
SOURCE = $(shell find . -iname "*.c" -a ! -iwholename "*./ft*")
SOURCE = $(shell find . -iname "*.c")
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
all: options ${PROJECT}
${MAKE} -C ft
options:
@echo ${PROJECT} build options:
......@@ -37,14 +36,12 @@ ${PROJECT}: ${OBJECTS}
clean:
@rm -rf ${PROJECT} ${OBJECTS} ${PROJECT}-${VERSION}.tar.gz \
${DOBJECTS} ${PROJECT}-debug .depend
@${MAKE} -C ft clean
${PROJECT}-debug: ${DOBJECTS}
@echo CC -o ${PROJECT}-debug
@${CC} ${LDFLAGS} -o ${PROJECT}-debug ${DOBJECTS} ${LIBS}
debug: ${PROJECT}-debug
@${MAKE} -C ft debug
valgrind: debug
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes \
......@@ -66,18 +63,23 @@ install: all
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f ${PROJECT} ${DESTDIR}${PREFIX}/bin
@chmod 755 ${PROJECT} ${DESTDIR}${PREFIX}/bin/${PROJECT}
@echo installing header file
@mkdir -p ${DESTDIR}${PREFIX}/include/${PROJECT}
@cp -f document.h ${DESTDIR}${PREFIX}/include/${PROJECT}
@cp -f zathura.h ${DESTDIR}${PREFIX}/include/${PROJECT}
@echo installing manual page
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
@sed "s/VERSION/${VERSION}/g" < ${PROJECT}.1 > ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@${MAKE} -C ft install
uninstall:
@echo removing executable file
@rm -f ${DESTDIR}${PREFIX}/bin/${PROJECT}
@echo removing header file
@rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/document.h
@rm -f ${DESTDIR}${PREFIX}/include/${PROJECT}/zathura.h
@echo removing manual page
@rm -f ${DESTDIR}${MANPREFIX}/man1/${PROJECT}.1
@${MAKE} -C ft uninstall
-include $(wildcard .depend/*.dep)
......
# See LICENSE file for license and copyright information
SUBDIRS = $(shell find -mindepth 2 -maxdepth 2 -iname "Makefile" -exec dirname '{}' \;)
all:
@for dir in ${SUBDIRS}; do ${MAKE} -C $${dir}; done
debug:
@for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} debug; done
clean:
@for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} clean; done
install:
@for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} install; done
uninstall:
@for dir in ${SUBDIRS}; do ${MAKE} -C $${dir} uninstall; done
.PHONY: all debug clean install uninstall
# See LICENSE file for license and copyright information
include config.mk
PLUGIN = djvu
SOURCE = djvu.c
OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do}
all: options ${PLUGIN}
options:
@echo ${PLUGIN} build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "DFLAGS = ${DFLAGS}"
@echo "CC = ${CC}"
%.o: %.c
@echo CC $<
@mkdir -p .depend
@${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
%.do: %.c
@echo CC $<
@mkdir -p .depend
@${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
${OBJECTS}: config.mk
${DOBJECTS}: config.mk
${PLUGIN}: ${OBJECTS}
@echo LD $@
@${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS}
${PLUGIN}-debug: ${DOBJECTS}
@echo LD $@
@${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS}
clean:
@rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend
debug: options ${PLUGIN}-debug
install: all
@echo installing ${PLUGIN} plugin
@mkdir -p ${DESTDIR}${PREFIX}/lib/zathura
@cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura
uninstall:
@echo uninstalling ${PLUGIN} plugin
@rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so
@rm -rf ${DESTDIR}${PREFIX}/lib/zathura
-include $(wildcard .depend/*.dep)
.PHONY: all options clean debug install uninstall
# See LICENSE file for license and copyright information
# paths
PREFIX ?= /usr
# libs
DJVU_INC = $(shell pkg-config --cflags gtk+-2.0 ddjvuapi)
DJVU_LIB = $(shell pkg-config --libs gtk+-2.0 ddjvuapi)
INCS = -I. -I/usr/include ${DJVU_INC}
LIBS = -lc ${DJVU_LIB}
# flags
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)
# debug
DFLAGS = -g
# compiler
CC ?= gcc
LD ?= ld
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include "djvu.h"
#include "../../zathura.h"
void
plugin_register(zathura_document_plugin_t* plugin)
{
plugin->file_extension = "djvu";
plugin->open_function = djvu_document_open;
}
bool
djvu_document_open(zathura_document_t* document)
{
if (!document) {
goto error_out;
}
document->functions.document_free = djvu_document_free;
document->functions.document_index_generate = djvu_document_index_generate;;
document->functions.document_save_as = djvu_document_save_as;
document->functions.document_attachments_get = djvu_document_attachments_get;
document->functions.page_get = djvu_page_get;
document->functions.page_search_text = djvu_page_search_text;
document->functions.page_links_get = djvu_page_links_get;
document->functions.page_form_fields_get = djvu_page_form_fields_get;
document->functions.page_render = djvu_page_render;
document->functions.page_free = djvu_page_free;
document->data = malloc(sizeof(djvu_document_t));
if (!document->data) {
goto error_out;
}
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
djvu_document->context = NULL;
djvu_document->document = NULL;
djvu_document->format = NULL;
/* setup format */
djvu_document->format = ddjvu_format_create(DDJVU_FORMAT_RGB24, 0, NULL);
if (!djvu_document->format) {
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) {
goto error_free;
}
/* setup document */
djvu_document->document = ddjvu_document_create_by_filename(djvu_document->context, document->file_path, FALSE);
if (!djvu_document->document) {
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) {
goto error_free;
}
ddjvu_message_pop(djvu_document->context);
}
/* decoding error */
if (ddjvu_document_decoding_error(djvu_document->document)) {
goto error_free;
}
document->number_of_pages = ddjvu_document_get_pagenum(djvu_document->document);
return true;
error_free:
if (djvu_document->format) {
ddjvu_format_release(djvu_document->format);
}
if (djvu_document->context) {
ddjvu_context_release(djvu_document->context);
}
free(document->data);
document->data = NULL;
error_out:
return false;
}
bool
djvu_document_free(zathura_document_t* document)
{
if (!document) {
return false;
}
if (document->data) {
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
ddjvu_context_release(djvu_document->context);
ddjvu_document_release(djvu_document->document);
ddjvu_format_release(djvu_document->format);
free(document->data);
}
return true;
}
girara_tree_node_t*
djvu_document_index_generate(zathura_document_t* document)
{
return NULL;
}
bool
djvu_document_save_as(zathura_document_t* document, const char* path)
{
if (!document || !document->data || !path) {
return false;
}
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
FILE* fp = fopen(path, "w");
if (!fp) {
return false;
}
ddjvu_document_save(djvu_document->document, fp, 0, NULL);
fclose(fp);
return true;
}
zathura_list_t*
djvu_document_attachments_get(zathura_document_t* document)
{
return NULL;
}
zathura_page_t*
djvu_page_get(zathura_document_t* document, unsigned int page)
{
if (!document || !document->data) {
return NULL;
}
djvu_document_t* djvu_document = (djvu_document_t*) document->data;
zathura_page_t* document_page = malloc(sizeof(zathura_page_t));
if (!document_page) {
return NULL;
}
document_page->document = document;
document_page->data = NULL;
ddjvu_status_t status;
ddjvu_pageinfo_t page_info;
while ((status = ddjvu_document_get_pageinfo(djvu_document->document, page, &page_info)) < DDJVU_JOB_OK);
if (status >= DDJVU_JOB_FAILED) {
free(document_page);
return NULL;
}
document_page->width = 0.2 * page_info.width;
document_page->height = 0.2 * page_info.height;
return document_page;
}
bool
djvu_page_free(zathura_page_t* page)
{
if (!page) {
return false;
}
free(page);
return true;
}
zathura_list_t*
djvu_page_search_text(zathura_page_t* page, const char* text)
{
return NULL;
}
zathura_list_t*
djvu_page_links_get(zathura_page_t* page)
{
return NULL;
}
zathura_list_t*
djvu_page_form_fields_get(zathura_page_t* page)
{
return NULL;
}
zathura_image_buffer_t*
djvu_page_render(zathura_page_t* page)
{
if (!page || !page->document) {
return NULL;
}
/* calculate sizes */
unsigned int page_width = page->document->scale * page->width;
unsigned int page_height = page->document->scale * page->height;
if (!page_width || !page_height) {
goto error_out;
}
/* init ddjvu render data */
djvu_document_t* djvu_document = (djvu_document_t*) page->document->data;
ddjvu_page_t* djvu_page = ddjvu_page_create_by_pageno(djvu_document->document, page->number);
if (!djvu_page) {
goto error_out;
}
while (!ddjvu_page_decoding_done(djvu_page));
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) {
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;
}
/* See LICENSE file for license and copyright information */
#ifndef DJVU_H
#define DJVU_H
#include <stdbool.h>
#include <libdjvu/ddjvuapi.h>
#include "../../document.h"
typedef struct djvu_document_s
{
ddjvu_context_t* context;
ddjvu_document_t* document;
ddjvu_format_t* format;
} djvu_document_t;
bool djvu_document_open(zathura_document_t* document);
bool djvu_document_free(zathura_document_t* document);
girara_tree_node_t* djvu_document_index_generate(zathura_document_t* document);
bool djvu_document_save_as(zathura_document_t* document, const char* path);
zathura_list_t* djvu_document_attachments_get(zathura_document_t* document);
zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page);
zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text);
zathura_list_t* djvu_page_links_get(zathura_page_t* page);
zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page);
zathura_image_buffer_t* djvu_page_render(zathura_page_t* page);
bool djvu_page_free(zathura_page_t* page);
#endif // DJVU_H
# See LICENSE file for license and copyright information
include config.mk
PLUGIN = pdf
SOURCE = pdf.c
OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do}
all: options ${PLUGIN}
options:
@echo ${PLUGIN} build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "DFLAGS = ${DFLAGS}"
@echo "CC = ${CC}"
%.o: %.c
@echo CC $<
@mkdir -p .depend
@${CC} -c ${CFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
%.do: %.c
@echo CC $<
@mkdir -p .depend
@${CC} -c ${CFLAGS} ${DFLAGS} -o $@ $< -MMD -MF .depend/$@.dep
${OBJECTS}: config.mk
${DOBJECTS}: config.mk
${PLUGIN}: ${OBJECTS}
@echo LD $@
@${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(OBJECTS) ${LIBS}
${PLUGIN}-debug: ${DOBJECTS}
@echo LD $@
@${CC} -shared ${LDFLAGS} -o ${PLUGIN}.so $(DOBJECTS) ${LIBS}
clean:
@rm -rf ${OBJECTS} ${DOBJECTS} $(PLUGIN).so .depend
debug: options ${PLUGIN}-debug
install: all
@echo installing ${PLUGIN} plugin
@mkdir -p ${DESTDIR}${PREFIX}/lib/zathura
@cp -f ${PLUGIN}.so ${DESTDIR}${PREFIX}/lib/zathura
uninstall:
@echo uninstalling ${PLUGIN} plugin
@rm -f ${DESTDIR}${PREFIX}/lib/zathura/${PLUGIN}.so
@rm -rf ${DESTDIR}${PREFIX}/lib/zathura
-include $(wildcard .depend/*.dep)
.PHONY: all options clean debug install uninstall
# See LICENSE file for license and copyright information
# paths
PREFIX ?= /usr
# libs
GTK_INC = $(shell pkg-config --cflags gtk+-2.0)
GTK_LIB = $(shell pkg-config --libs gtk+-2.0)
INCS = -I. -I/usr/include ${GTK_INC}
LIBS = -lc ${GTK_LIB} -lmupdf -ljbig2dec -ljpeg -lopenjpeg
# flags
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)
# debug
DFLAGS = -g
# compiler
CC ?= gcc
LD ?= ld
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#include "pdf.h"
#include "../../zathura.h"
void
plugin_register(zathura_document_plugin_t* plugin)
{
plugin->file_extension = "pdf";
plugin->open_function = pdf_document_open;
}
bool
pdf_document_open(zathura_document_t* document)
{
if (!document) {
goto error_ret;
}
document->functions.document_free = pdf_document_free;
document->functions.page_get = pdf_page_get;
document->functions.page_search_text = pdf_page_search_text;
document->functions.page_links_get = pdf_page_links_get;
document->functions.page_form_fields_get = pdf_page_form_fields_get;
document->functions.page_render = pdf_page_render;
document->functions.page_free = pdf_page_free;
document->data = malloc(sizeof(pdf_document_t));
if (!document->data) {
goto error_ret;
}
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
fz_accelerate();
pdf_document->glyphcache = fz_newglyphcache();
if (pdf_openxref(&(pdf_document->document), document->file_path, NULL)) {
fprintf(stderr, "error: could not open file\n");
goto error_free;
}
if (pdf_loadpagetree(pdf_document->document)) {
fprintf(stderr, "error: could not open file\n");
goto error_free;
}
document->number_of_pages = pdf_getpagecount(pdf_document->document);
return true;
error_free:
if (pdf_document->document) {
pdf_freexref(pdf_document->document);
}
if (pdf_document->glyphcache) {
fz_freeglyphcache(pdf_document->glyphcache);
}
free(document->data);
document->data = NULL;
error_ret:
return false;
}
bool
pdf_document_free(zathura_document_t* document)
{
if (!document) {
return false;
}
if (document->data) {
pdf_document_t* pdf_document = (pdf_document_t*) document->data;
pdf_freexref(pdf_document->document);
fz_freeglyphcache(pdf_document->glyphcache);
free(document->data);
document->data = NULL;
}
return true;
}
zathura_page_t*
pdf_page_get(zathura_document_t* document, unsigned int page)
{