Commit 2bedb3b3 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Merge branch 'release/0.3.2'

parents 18854c2f 38380d0f
......@@ -10,10 +10,6 @@ HEADER = $(sort $(wildcard *.h))
OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do}
ifneq "$(WITH_CAIRO)" "0"
CPPFLAGS += -DHAVE_CAIRO
endif
CPPFLAGS += "-DVERSION_MAJOR=${VERSION_MAJOR}"
CPPFLAGS += "-DVERSION_MINOR=${VERSION_MINOR}"
CPPFLAGS += "-DVERSION_REV=${VERSION_REV}"
......
......@@ -2,14 +2,16 @@
VERSION_MAJOR = 0
VERSION_MINOR = 3
VERSION_REV = 1
VERSION_REV = 2
VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}
PKG_CONFIG ?= pkg-config
# minimum required zathura version
ZATHURA_MIN_VERSION = 0.2.0
ZATHURA_MIN_VERSION = 0.3.8
ZATHURA_VERSION_CHECK ?= $(shell pkg-config --atleast-version=$(ZATHURA_MIN_VERSION) zathura; echo $$?)
ZATHURA_GTK_VERSION ?= $(shell pkg-config --variable=GTK_VERSION zathura)
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
......@@ -17,31 +19,34 @@ LIBDIR ?= ${PREFIX}/lib
DESKTOPPREFIX ?= ${PREFIX}/share/applications
# libs
GTK_INC ?= $(shell pkg-config --cflags gtk+-${ZATHURA_GTK_VERSION}.0)
GTK_LIB ?= $(shell pkg-config --libs gtk+-${ZATHURA_GTK_VERSION}.0)
CAIRO_INC ?= $(shell $(PKG_CONFIG) --cflags cairo)
CAIRO_LIB ?= $(shell $(PKG_CONFIG) --libs cairo)
GTK_INC ?= $(shell $(PKG_CONFIG) --cflags gtk+-${ZATHURA_GTK_VERSION}.0)
GTK_LIB ?= $(shell $(PKG_CONFIG) --libs gtk+-${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})
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)
ZATHURA_INC ?= $(shell $(PKG_CONFIG) --cflags zathura)
PLUGINDIR ?= $(shell $(PKG_CONFIG) --variable=plugindir zathura)
ifeq (,${PLUGINDIR})
PLUGINDIR = ${LIBDIR}/zathura
endif
OPENSSL_INC ?= $(shell pkg-config --cflags libcrypto)
OPENSSL_LIB ?= $(shell pkg-config --libs libcrypto)
OPENSSL_INC ?= $(shell $(PKG_CONFIG) --cflags libcrypto)
OPENSSL_LIB ?= $(shell $(PKG_CONFIG) --libs libcrypto)
FREETYPE_INC ?= $(shell pkg-config --cflags freetype2)
FREETYPE_LIB ?= $(shell pkg-config --libs freetype2)
FREETYPE_INC ?= $(shell $(PKG_CONFIG) --cflags freetype2)
FREETYPE_LIB ?= $(shell $(PKG_CONFIG) --libs freetype2)
HARFBUZZ_INC ?= $(shell pkg-config --cflags harfbuzz)
HARFBUZZ_LIB ?= $(shell pkg-config --libs harfbuzz)
HARFBUZZ_INC ?= $(shell $(PKG_CONFIG) --cflags harfbuzz)
HARFBUZZ_LIB ?= $(shell $(PKG_CONFIG) --libs harfbuzz)
MUPDF_LIB ?= -lmupdf -lmupdfthird
INCS = ${GTK_INC} ${GIRARA_INC} ${OPENSSL_INC} ${ZATHURA_INC} ${FREETYPE_INC} ${HARFBUZZ_INC}
LIBS = ${GTK_LIB} ${GIRARA_LIB} ${MUPDF_LIB} ${OPENSSL_LIB} ${FREETYPE_LIB} ${HARFBUZZ_LIB} -ljbig2dec -lopenjp2 -ljpeg -lz
INCS = ${GTK_INC} ${GIRARA_INC} ${OPENSSL_INC} ${CAIRO_INC} ${ZATHURA_INC} ${FREETYPE_INC} ${HARFBUZZ_INC}
LIBS = ${GTK_LIB} ${GIRARA_LIB} ${MUPDF_LIB} ${OPENSSL_LIB} ${CAIRO_LIB} ${FREETYPE_LIB} ${HARFBUZZ_LIB} -ljbig2dec -lopenjp2 -ljpeg -lz
# compiler flags
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)
......@@ -52,9 +57,6 @@ LDFLAGS += -fPIC
# debug
DFLAGS ?= -g
# build with cairo support?
WITH_CAIRO ?= 1
# compiler
CC ?= gcc
LD ?= ld
......
......@@ -43,18 +43,16 @@ pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_erro
/* Extract images */
mupdf_page_extract_text(mupdf_document, mupdf_page);
fz_page_block* block;
for (block = mupdf_page->text->blocks; block < mupdf_page->text->blocks + mupdf_page->text->len; block++) {
if (block->type == FZ_PAGE_BLOCK_IMAGE) {
fz_image_block *image_block = block->u.image;
fz_stext_block* block;
for (block = mupdf_page->text->first_block; block; block = block->next) {
if (block->type == FZ_STEXT_BLOCK_IMAGE) {
zathura_image_t* zathura_image = g_malloc(sizeof(zathura_image_t));
zathura_image->position.x1 = image_block->bbox.x0;
zathura_image->position.y1 = image_block->bbox.y0;
zathura_image->position.x2 = image_block->bbox.x1;
zathura_image->position.y2 = image_block->bbox.y1;
zathura_image->data = image_block->image;
zathura_image->position.x1 = block->bbox.x0;
zathura_image->position.y1 = block->bbox.y0;
zathura_image->position.x2 = block->bbox.x1;
zathura_image->position.y2 = block->bbox.y1;
zathura_image->data = block->u.i.image;
girara_list_append(list, zathura_image);
}
......
......@@ -51,7 +51,9 @@ build_index(fz_context* ctx, fz_document* document, fz_outline* outline, girara_
zathura_link_type_t type = ZATHURA_LINK_INVALID;
zathura_rectangle_t rect = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 };
if (fz_is_external_link(ctx, outline->uri) == 1) {
if (outline->uri == NULL) {
type = ZATHURA_LINK_NONE;
} else if (fz_is_external_link(ctx, outline->uri) == 1) {
if (strstr(outline->uri, "file://") == outline->uri) {
type = ZATHURA_LINK_GOTO_REMOTE;
target.value = outline->uri;
......
......@@ -20,8 +20,6 @@ pdf_page_init(zathura_page_t* page)
return ZATHURA_ERROR_OUT_OF_MEMORY;
}
zathura_page_set_data(page, mupdf_page);
mupdf_page->ctx = mupdf_document->ctx;
if (mupdf_page->ctx == NULL) {
goto error_free;
......@@ -36,10 +34,6 @@ pdf_page_init(zathura_page_t* page)
fz_bound_page(mupdf_document->ctx, (fz_page*) mupdf_page->page, &mupdf_page->bbox);
/* get page dimensions */
zathura_page_set_width(page, mupdf_page->bbox.x1 - mupdf_page->bbox.x0);
zathura_page_set_height(page, mupdf_page->bbox.y1 - mupdf_page->bbox.y0);
/* setup text */
mupdf_page->extracted_text = false;
......@@ -50,10 +44,11 @@ pdf_page_init(zathura_page_t* page)
goto error_free;
}
mupdf_page->sheet = fz_new_stext_sheet(mupdf_page->ctx);
if (mupdf_page->sheet == NULL) {
goto error_free;
}
zathura_page_set_data(page, mupdf_page);
/* get page dimensions */
zathura_page_set_width(page, mupdf_page->bbox.x1 - mupdf_page->bbox.x0);
zathura_page_set_height(page, mupdf_page->bbox.y1 - mupdf_page->bbox.y0);
return ZATHURA_ERROR_OK;
......@@ -79,10 +74,6 @@ pdf_page_clear(zathura_page_t* page, mupdf_page_t* mupdf_page)
fz_drop_stext_page(mupdf_page->ctx, mupdf_page->text);
}
if (mupdf_page->sheet != NULL) {
fz_drop_stext_sheet(mupdf_page->ctx, mupdf_page->sheet);
}
if (mupdf_page->page != NULL) {
fz_drop_page(mupdf_document->ctx, mupdf_page->page);
}
......
......@@ -4,31 +4,25 @@
#include "plugin.h"
void
register_functions(zathura_plugin_functions_t* functions)
{
functions->document_open = (zathura_plugin_document_open_t) pdf_document_open;
functions->document_free = (zathura_plugin_document_free_t) pdf_document_free;
functions->document_save_as = (zathura_plugin_document_save_as_t) pdf_document_save_as;
functions->document_index_generate = (zathura_plugin_document_index_generate_t) pdf_document_index_generate;
functions->document_get_information = (zathura_plugin_document_get_information_t) pdf_document_get_information;
functions->page_init = (zathura_plugin_page_init_t) pdf_page_init;
functions->page_clear = (zathura_plugin_page_clear_t) pdf_page_clear;
functions->page_search_text = (zathura_plugin_page_search_text_t) pdf_page_search_text;
functions->page_links_get = (zathura_plugin_page_links_get_t) pdf_page_links_get;
functions->page_images_get = (zathura_plugin_page_images_get_t) pdf_page_images_get;
functions->page_get_text = (zathura_plugin_page_get_text_t) pdf_page_get_text;
functions->page_render = (zathura_plugin_page_render_t) pdf_page_render;
#if HAVE_CAIRO
functions->page_render_cairo = (zathura_plugin_page_render_cairo_t) pdf_page_render_cairo;
functions->page_image_get_cairo = (zathura_plugin_page_image_get_cairo_t) pdf_page_image_get_cairo;
#endif
}
ZATHURA_PLUGIN_REGISTER(
ZATHURA_PLUGIN_REGISTER_WITH_FUNCTIONS(
"pdf-mupdf",
VERSION_MAJOR, VERSION_MINOR, VERSION_REV,
register_functions,
ZATHURA_PLUGIN_FUNCTIONS({
.document_open = (zathura_plugin_document_open_t) pdf_document_open,
.document_free = (zathura_plugin_document_free_t) pdf_document_free,
.document_save_as = (zathura_plugin_document_save_as_t) pdf_document_save_as,
.document_index_generate = (zathura_plugin_document_index_generate_t) pdf_document_index_generate,
.document_get_information = (zathura_plugin_document_get_information_t) pdf_document_get_information,
.page_init = (zathura_plugin_page_init_t) pdf_page_init,
.page_clear = (zathura_plugin_page_clear_t) pdf_page_clear,
.page_search_text = (zathura_plugin_page_search_text_t) pdf_page_search_text,
.page_links_get = (zathura_plugin_page_links_get_t) pdf_page_links_get,
.page_images_get = (zathura_plugin_page_images_get_t) pdf_page_images_get,
.page_get_text = (zathura_plugin_page_get_text_t) pdf_page_get_text,
.page_render = (zathura_plugin_page_render_t) pdf_page_render,
.page_render_cairo = (zathura_plugin_page_render_cairo_t) pdf_page_render_cairo,
.page_image_get_cairo = (zathura_plugin_page_image_get_cairo_t) pdf_page_image_get_cairo
}),
ZATHURA_PLUGIN_MIMETYPES({
"application/pdf",
"application/oxps",
......
......@@ -3,13 +3,12 @@
#ifndef PDF_H
#define PDF_H
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <zathura/plugin-api.h>
#include <mupdf/fitz.h>
#if HAVE_CAIRO
#include <cairo.h>
#endif
typedef struct mupdf_document_s
{
......@@ -21,7 +20,6 @@ typedef struct mupdf_page_s
{
fz_page* page; /**< Reference to the mupdf page */
fz_context* ctx; /**< Context */
fz_stext_sheet* sheet; /**< Text sheet */
fz_stext_page* text; /**< Page text */
fz_rect bbox; /**< Bbox */
bool extracted_text; /**< If text has already been extracted */
......@@ -113,7 +111,6 @@ girara_list_t* pdf_page_links_get(zathura_page_t* page, mupdf_page_t* mupdf_page
*/
girara_list_t* pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error);
#if HAVE_CAIRO
/**
* Gets the content of the image in a cairo surface
*
......@@ -125,7 +122,6 @@ girara_list_t* pdf_page_images_get(zathura_page_t* page, mupdf_page_t* mupdf_pag
*/
cairo_surface_t* pdf_page_image_get_cairo(zathura_page_t* page, mupdf_page_t*
mupdf_page, zathura_image_t* image, zathura_error_t* error);
#endif
/**
* Get text for selection
......@@ -159,7 +155,6 @@ girara_list_t* pdf_document_get_information(zathura_document_t* document,
*/
zathura_image_buffer_t* pdf_page_render(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t* error);
#if HAVE_CAIRO
/**
* Renders a page onto a cairo object
*
......@@ -168,6 +163,5 @@ zathura_image_buffer_t* pdf_page_render(zathura_page_t* page, mupdf_page_t* mupd
* @return true if no error occurred, otherwise false
*/
zathura_error_t pdf_page_render_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page, cairo_t* cairo, bool printing);
#endif
#endif // PDF_H
......@@ -31,21 +31,25 @@ pdf_page_render_to_buffer(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_
return ZATHURA_ERROR_UNKNOWN;
}
fz_close_device(mupdf_page->ctx, device);
fz_drop_device(mupdf_page->ctx, device);
fz_irect irect = { .x1 = page_width, .y1 = page_height };
fz_rect rect = { .x1 = page_width, .y1 = page_height };
fz_colorspace* colorspace = fz_device_bgr(mupdf_document->ctx);
fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, 1, image);
fz_separations* seps= fz_page_separations(mupdf_page->ctx, mupdf_page->page);
fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, seps, 1, image);
fz_clear_pixmap_with_value(mupdf_page->ctx, pixmap, 0xFF);
device = fz_new_draw_device(mupdf_page->ctx, NULL, pixmap);
fz_run_display_list(mupdf_page->ctx, display_list, device, &fz_identity, &rect, NULL);
fz_close_device(mupdf_page->ctx, device);
fz_drop_device(mupdf_page->ctx, device);
fz_drop_pixmap(mupdf_page->ctx, pixmap);
fz_drop_display_list(mupdf_page->ctx, display_list);
fz_drop_separations(mupdf_page->ctx, seps);
return ZATHURA_ERROR_OK;
}
......@@ -100,7 +104,6 @@ pdf_page_render(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error_t*
return image_buffer;
}
#if HAVE_CAIRO
zathura_error_t
pdf_page_render_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page, cairo_t* cairo, bool GIRARA_UNUSED(printing))
{
......@@ -134,5 +137,4 @@ pdf_page_render_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page, cairo_t* c
return pdf_page_render_to_buffer(mupdf_document, mupdf_page, image, rowstride, 4,
page_width, page_height, scalex, scaley);
}
#endif
......@@ -24,9 +24,14 @@ pdf_page_get_text(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_rectan
mupdf_page_extract_text(mupdf_document, mupdf_page);
}
fz_rect rect = { rectangle.x1, rectangle.y1, rectangle.x2, rectangle.y2 };
return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, rect);
fz_point a = { rectangle.x1, rectangle.y1 };
fz_point b = { rectangle.x2, rectangle.y2 };
#ifdef _WIN32
return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, a, b, 1);
#else
return fz_copy_selection(mupdf_page->ctx, mupdf_page->text, a, b, 0);
#endif
error_ret:
......
......@@ -7,17 +7,17 @@
void
mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_page) {
if (mupdf_document == NULL || mupdf_document->ctx == NULL || mupdf_page == NULL ||
mupdf_page->sheet == NULL || mupdf_page->text == NULL) {
mupdf_page->text == NULL) {
return;
}
fz_device* text_device = NULL;
fz_try (mupdf_page->ctx) {
text_device = fz_new_stext_device(mupdf_page->ctx, mupdf_page->sheet, mupdf_page->text, NULL);
text_device = fz_new_stext_device(mupdf_page->ctx, mupdf_page->text, NULL);
/* Disable FZ_IGNORE_IMAGE to collect image blocks */
fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_IGNORE_IMAGE);
/* Disable FZ_DONT_INTERPOLATE_IMAGES to collect image blocks */
fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_DONT_INTERPOLATE_IMAGES);
fz_matrix ctm;
fz_scale(&ctm, 1.0, 1.0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment