mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 06:46:00 +01:00
Postscript support through libspectre
This commit is contained in:
parent
1806b04786
commit
691b5c7697
6 changed files with 290 additions and 20 deletions
23
README
23
README
|
@ -1,21 +1,16 @@
|
||||||
zathura - pdf viewer
|
zathura - a document viewer
|
||||||
--------------------
|
--------------------
|
||||||
zathura is a pdf viewer based on the poppler pdf rendering library
|
zathura is a highly customizable and functional document viewer based on the
|
||||||
|
girara user interface library and several document libraries.
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
poppler-glib (0.12.3)
|
gtk2 (>= 2.18.6)
|
||||||
gtk2 (2.18.6)
|
girara
|
||||||
glib2 (2.22.4)
|
|
||||||
|
|
||||||
Configuration
|
|
||||||
-------------
|
|
||||||
You can modify some parts of zathura by editing the config.h file
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
Customise config.h according to your wishes and run the following
|
To build and install zathura:
|
||||||
command to build and install zathura:
|
|
||||||
|
|
||||||
make install
|
make install
|
||||||
|
|
||||||
|
@ -24,9 +19,3 @@ Uninstall:
|
||||||
To delete zathura from your system, just type:
|
To delete zathura from your system, just type:
|
||||||
|
|
||||||
make uninstall
|
make uninstall
|
||||||
|
|
||||||
Use zathura
|
|
||||||
-----------
|
|
||||||
Just run:
|
|
||||||
|
|
||||||
zathura <file>
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ zathura_document_plugins_free(zathura_t* zathura)
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||||
free(plugin->file_extension);
|
free(plugin->file_extension);
|
||||||
|
@ -158,7 +158,7 @@ zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t*
|
||||||
girara_error("plugin: already registered for filetype %s\n", plugin->file_extension);
|
girara_error("plugin: already registered for filetype %s\n", plugin->file_extension);
|
||||||
girara_list_iterator_free(iter);
|
girara_list_iterator_free(iter);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} while (girara_list_iterator_next(iter));
|
} while (girara_list_iterator_next(iter));
|
||||||
girara_list_iterator_free(iter);
|
girara_list_iterator_free(iter);
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
||||||
if (iter == NULL) {
|
if (iter == NULL) {
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||||
if (!strcmp(file_extension, plugin->file_extension)) {
|
if (!strcmp(file_extension, plugin->file_extension)) {
|
||||||
|
@ -403,6 +403,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
|
||||||
page->event_box = gtk_event_box_new();
|
page->event_box = gtk_event_box_new();
|
||||||
page->drawing_area = gtk_drawing_area_new();
|
page->drawing_area = gtk_drawing_area_new();
|
||||||
page->surface = NULL;
|
page->surface = NULL;
|
||||||
|
page->document = document;
|
||||||
g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page);
|
g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page);
|
||||||
|
|
||||||
gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale);
|
gtk_widget_set_size_request(page->drawing_area, page->width * document->scale, page->height * document->scale);
|
||||||
|
|
57
ft/ps/Makefile
Normal file
57
ft/ps/Makefile
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# See LICENSE file for license and copyright information
|
||||||
|
|
||||||
|
include config.mk
|
||||||
|
|
||||||
|
PLUGIN = ps
|
||||||
|
SOURCE = ps.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
|
21
ft/ps/config.mk
Normal file
21
ft/ps/config.mk
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# 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} -lspectre
|
||||||
|
|
||||||
|
# flags
|
||||||
|
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)
|
||||||
|
|
||||||
|
# debug
|
||||||
|
DFLAGS = -g
|
||||||
|
|
||||||
|
# compiler
|
||||||
|
CC ?= gcc
|
||||||
|
LD ?= ld
|
180
ft/ps/ps.c
Normal file
180
ft/ps/ps.c
Normal file
|
@ -0,0 +1,180 @@
|
||||||
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "ps.h"
|
||||||
|
#include "../../zathura.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
plugin_register(zathura_document_plugin_t* plugin)
|
||||||
|
{
|
||||||
|
plugin->file_extension = "ps";
|
||||||
|
plugin->open_function = ps_document_open;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ps_document_open(zathura_document_t* document)
|
||||||
|
{
|
||||||
|
if (!document) {
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
document->functions.document_free = ps_document_free;
|
||||||
|
document->functions.page_get = ps_page_get;
|
||||||
|
document->functions.page_render = ps_page_render;
|
||||||
|
document->functions.page_free = ps_page_free;
|
||||||
|
|
||||||
|
document->data = malloc(sizeof(ps_document_t));
|
||||||
|
if (!document->data) {
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ps_document_t* ps_document = (ps_document_t*) document->data;
|
||||||
|
ps_document->document = spectre_document_new();
|
||||||
|
|
||||||
|
if (ps_document->document == NULL) {
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
spectre_document_load(ps_document->document, document->file_path);
|
||||||
|
|
||||||
|
if (spectre_document_status(ps_document->document) != SPECTRE_STATUS_SUCCESS) {
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
document->number_of_pages = spectre_document_get_n_pages(ps_document->document);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
error_free:
|
||||||
|
|
||||||
|
if (ps_document->document != NULL) {
|
||||||
|
spectre_document_free(ps_document->document);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(document->data);
|
||||||
|
document->data = NULL;
|
||||||
|
|
||||||
|
error_ret:
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ps_document_free(zathura_document_t* document)
|
||||||
|
{
|
||||||
|
if (!document) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document->data != NULL) {
|
||||||
|
ps_document_t* ps_document = (ps_document_t*) document->data;
|
||||||
|
spectre_document_free(ps_document->document);
|
||||||
|
free(document->data);
|
||||||
|
document->data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_page_t*
|
||||||
|
ps_page_get(zathura_document_t* document, unsigned int page)
|
||||||
|
{
|
||||||
|
if (!document || !document->data) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ps_document_t* ps_document = (ps_document_t*) document->data;
|
||||||
|
zathura_page_t* document_page = malloc(sizeof(zathura_page_t));
|
||||||
|
|
||||||
|
if (document_page == NULL) {
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpectrePage* ps_page = spectre_document_get_page(ps_document->document, page);
|
||||||
|
|
||||||
|
if (ps_page == NULL) {
|
||||||
|
goto error_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
int page_width;
|
||||||
|
int page_height;
|
||||||
|
spectre_page_get_size(ps_page, &(page_width), &(page_height));
|
||||||
|
|
||||||
|
document_page->width = page_width;
|
||||||
|
document_page->height = page_height;
|
||||||
|
document_page->document = document;
|
||||||
|
document_page->data = ps_page;
|
||||||
|
|
||||||
|
return document_page;
|
||||||
|
|
||||||
|
error_free:
|
||||||
|
|
||||||
|
free(document_page);
|
||||||
|
|
||||||
|
error_ret:
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ps_page_free(zathura_page_t* page)
|
||||||
|
{
|
||||||
|
if (page == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page->data != NULL) {
|
||||||
|
SpectrePage* ps_page = (SpectrePage*) page->data;
|
||||||
|
spectre_page_free(ps_page);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(page);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_image_buffer_t*
|
||||||
|
ps_page_render(zathura_page_t* page)
|
||||||
|
{
|
||||||
|
if (!page || !page->data || !page->document) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* calculate sizes */
|
||||||
|
unsigned int page_width = page->document->scale * page->width;
|
||||||
|
unsigned int page_height = page->document->scale * page->height;
|
||||||
|
|
||||||
|
/* create image buffer */
|
||||||
|
zathura_image_buffer_t* image_buffer = zathura_image_buffer_create(page_width, page_height);
|
||||||
|
|
||||||
|
if (image_buffer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpectrePage* ps_page = (SpectrePage*) page->data;
|
||||||
|
SpectreRenderContext* context = spectre_render_context_new();
|
||||||
|
|
||||||
|
spectre_render_context_set_scale(context, page->document->scale, page->document->scale);
|
||||||
|
spectre_render_context_set_rotation(context, 0);
|
||||||
|
|
||||||
|
unsigned char* page_data;
|
||||||
|
int row_length;
|
||||||
|
spectre_page_render(ps_page, context, &page_data, &row_length);
|
||||||
|
|
||||||
|
for (unsigned int y = 0; y < page_height; y++) {
|
||||||
|
for (unsigned int x = 0; x < page_width; x++) {
|
||||||
|
unsigned char *s = page_data + y * row_length + x * 4;
|
||||||
|
guchar* p = image_buffer->data + y * image_buffer->rowstride + x * 3;
|
||||||
|
p[0] = s[0];
|
||||||
|
p[1] = s[1];
|
||||||
|
p[2] = s[2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spectre_render_context_free(context);
|
||||||
|
|
||||||
|
ps_document_t* ps_document = (ps_document_t*) page->document->data;
|
||||||
|
|
||||||
|
return image_buffer;
|
||||||
|
}
|
22
ft/ps/ps.h
Normal file
22
ft/ps/ps.h
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
|
#ifndef PS_H
|
||||||
|
#define PS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <libspectre/spectre.h>
|
||||||
|
|
||||||
|
#include "../../document.h"
|
||||||
|
|
||||||
|
typedef struct ps_document_s
|
||||||
|
{
|
||||||
|
SpectreDocument* document;
|
||||||
|
} ps_document_t;
|
||||||
|
|
||||||
|
bool ps_document_open(zathura_document_t* document);
|
||||||
|
bool ps_document_free(zathura_document_t* document);
|
||||||
|
zathura_page_t* ps_page_get(zathura_document_t* document, unsigned int page);
|
||||||
|
zathura_image_buffer_t* ps_page_render(zathura_page_t* page);
|
||||||
|
bool ps_page_free(zathura_page_t* page);
|
||||||
|
|
||||||
|
#endif // PS_H
|
Loading…
Reference in a new issue