Commit 18854c2f authored by Moritz Lipp's avatar Moritz Lipp

Merge branch 'release/0.3.1'

parents 37851fd7 12f2ea78
...@@ -5,5 +5,6 @@ Sebastian Ramacher <s.ramacher@gmx.at> ...@@ -5,5 +5,6 @@ Sebastian Ramacher <s.ramacher@gmx.at>
Other contributors are (in alphabetical order): Other contributors are (in alphabetical order):
Christian Hesse <mail@eworm.de>
Pavel Borzenkov <pavel.borzenkov@gmail.com> Pavel Borzenkov <pavel.borzenkov@gmail.com>
William Skeith <wes@cs.ccny.cuny.edu> William Skeith <wes@cs.ccny.cuny.edu>
Copyright (c) 2011-2016 pwmt.org Copyright (c) 2011-2017 pwmt.org
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
......
...@@ -5,8 +5,8 @@ include common.mk ...@@ -5,8 +5,8 @@ include common.mk
PROJECT = zathura-pdf-mupdf PROJECT = zathura-pdf-mupdf
PLUGIN = pdf PLUGIN = pdf
SOURCE = $(shell find . -iname "*.c") SOURCE = $(sort $(wildcard *.c))
HEADER = $(shell find . -iname "*.h") HEADER = $(sort $(wildcard *.h))
OBJECTS = ${SOURCE:.c=.o} OBJECTS = ${SOURCE:.c=.o}
DOBJECTS = ${SOURCE:.c=.do} DOBJECTS = ${SOURCE:.c=.do}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
VERSION_MAJOR = 0 VERSION_MAJOR = 0
VERSION_MINOR = 3 VERSION_MINOR = 3
VERSION_REV = 0 VERSION_REV = 1
VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV} VERSION = ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REV}
# minimum required zathura version # minimum required zathura version
...@@ -32,10 +32,16 @@ endif ...@@ -32,10 +32,16 @@ endif
OPENSSL_INC ?= $(shell pkg-config --cflags libcrypto) OPENSSL_INC ?= $(shell pkg-config --cflags libcrypto)
OPENSSL_LIB ?= $(shell pkg-config --libs libcrypto) OPENSSL_LIB ?= $(shell pkg-config --libs libcrypto)
MUPDF_LIB ?= -lmupdf -lmujs FREETYPE_INC ?= $(shell pkg-config --cflags freetype2)
FREETYPE_LIB ?= $(shell pkg-config --libs freetype2)
INCS = ${GTK_INC} ${GIRARA_INC} ${OPENSSL_INC} ${ZATHURA_INC} HARFBUZZ_INC ?= $(shell pkg-config --cflags harfbuzz)
LIBS = ${GTK_LIB} ${GIRARA_LIB} ${MUPDF_LIB} ${OPENSSL_LIB} -ljbig2dec -lopenjp2 -ljpeg 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
# compiler flags # compiler flags
CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS) CFLAGS += -std=c99 -fPIC -pedantic -Wall -Wno-format-zero-length $(INCS)
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#define _POSIX_C_SOURCE 1 #define _POSIX_C_SOURCE 1
#include <mupdf/fitz.h> #include <mupdf/fitz.h>
#include <mupdf/xps.h>
#include <mupdf/pdf.h> #include <mupdf/pdf.h>
#include <glib-2.0/glib.h> #include <glib-2.0/glib.h>
...@@ -109,12 +108,7 @@ pdf_document_save_as(zathura_document_t* document, mupdf_document_t* ...@@ -109,12 +108,7 @@ pdf_document_save_as(zathura_document_t* document, mupdf_document_t*
} }
fz_try (mupdf_document->ctx) { fz_try (mupdf_document->ctx) {
/* fz_write_document claims to accepts NULL as third argument but doesn't. pdf_save_document(mupdf_document->ctx, (pdf_document*) mupdf_document->document, (char*) path, NULL);
* pdf_write_document does not check if the third arguments is NULL for some
* options. */
fz_write_options opts = { 0 }; /* just use the default options */
fz_write_document(mupdf_document->ctx, mupdf_document->document, (char*) path, &opts);
} fz_catch (mupdf_document->ctx) { } fz_catch (mupdf_document->ctx) {
return ZATHURA_ERROR_UNKNOWN; return ZATHURA_ERROR_UNKNOWN;
} }
......
...@@ -93,7 +93,7 @@ pdf_page_image_get_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page, ...@@ -93,7 +93,7 @@ pdf_page_image_get_cairo(zathura_page_t* page, mupdf_page_t* mupdf_page,
fz_pixmap* pixmap = NULL; fz_pixmap* pixmap = NULL;
cairo_surface_t* surface = NULL; cairo_surface_t* surface = NULL;
pixmap = fz_new_pixmap_from_image(mupdf_page->ctx, mupdf_image, 0, 0); pixmap = fz_get_pixmap_from_image(mupdf_page->ctx, mupdf_image, NULL, NULL, 0, 0);
if (pixmap == NULL) { if (pixmap == NULL) {
goto error_free; goto error_free;
} }
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
#include "plugin.h" #include "plugin.h"
static void build_index(fz_outline* outline, girara_tree_node_t* root); static void build_index(fz_context* ctx, fz_document* document, fz_outline*
outline, girara_tree_node_t* root);
girara_tree_node_t* girara_tree_node_t*
pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupdf_document, zathura_error_t* error) pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupdf_document, zathura_error_t* error)
...@@ -29,7 +30,7 @@ pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupd ...@@ -29,7 +30,7 @@ pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupd
/* generate index */ /* generate index */
girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT")); girara_tree_node_t* root = girara_node_new(zathura_index_element_new("ROOT"));
build_index(outline, root); build_index(mupdf_document->ctx, mupdf_document->document, outline, root);
/* free outline */ /* free outline */
fz_drop_outline(mupdf_document->ctx, outline); fz_drop_outline(mupdf_document->ctx, outline);
...@@ -38,7 +39,7 @@ pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupd ...@@ -38,7 +39,7 @@ pdf_document_index_generate(zathura_document_t* document, mupdf_document_t* mupd
} }
static void static void
build_index(fz_outline* outline, girara_tree_node_t* root) build_index(fz_context* ctx, fz_document* document, fz_outline* outline, girara_tree_node_t* root)
{ {
if (outline == NULL || root == NULL) { if (outline == NULL || root == NULL) {
return; return;
...@@ -50,49 +51,24 @@ build_index(fz_outline* outline, girara_tree_node_t* root) ...@@ -50,49 +51,24 @@ build_index(fz_outline* outline, girara_tree_node_t* root)
zathura_link_type_t type = ZATHURA_LINK_INVALID; zathura_link_type_t type = ZATHURA_LINK_INVALID;
zathura_rectangle_t rect = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 }; zathura_rectangle_t rect = { .x1 = 0, .y1 = 0, .x2 = 0, .y2 = 0 };
switch (outline->dest.kind) { if (fz_is_external_link(ctx, outline->uri) == 1) {
case FZ_LINK_NONE: if (strstr(outline->uri, "file://") == outline->uri) {
type = ZATHURA_LINK_NONE; type = ZATHURA_LINK_GOTO_REMOTE;
break; target.value = outline->uri;
case FZ_LINK_URI: } else {
type = ZATHURA_LINK_URI; type = ZATHURA_LINK_URI;
target.value = outline->dest.ld.uri.uri; target.value = outline->uri;
break; }
case FZ_LINK_GOTO: } else {
type = ZATHURA_LINK_GOTO_DEST; float x = 0;
target.page_number = outline->dest.ld.gotor.page; float y = 0;
target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
target.left = 0; type = ZATHURA_LINK_GOTO_DEST;
target.top = 0; target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
target.scale = 0.0; target.page_number = fz_resolve_link(ctx, document, outline->uri, &x, &y);
{ target.left = x;
int gflags = outline->dest.ld.gotor.flags; target.top = y;
if (gflags & fz_link_flag_l_valid) { target.scale = 0.0;
target.left = outline->dest.ld.gotor.lt.x;
}
if (gflags & fz_link_flag_t_valid) {
target.top = outline->dest.ld.gotor.lt.y;
}
/* if (gflags & fz_link_flag_r_is_zoom) { */
/* target.scale = outline->dest.ld.gotor.rb.x; */
/* } */
}
break;
case FZ_LINK_LAUNCH:
type = ZATHURA_LINK_LAUNCH;
target.value = outline->dest.ld.launch.file_spec;
break;
case FZ_LINK_NAMED:
type = ZATHURA_LINK_NAMED;
target.value = outline->dest.ld.named.named;
break;
case FZ_LINK_GOTOR:
type = ZATHURA_LINK_GOTO_REMOTE;
target.value = outline->dest.ld.gotor.file_spec;
break;
default:
outline = outline->next; // TODO: Don't skip unknown type
continue;
} }
index_element->link = zathura_link_new(type, rect, target); index_element->link = zathura_link_new(type, rect, target);
...@@ -104,7 +80,7 @@ build_index(fz_outline* outline, girara_tree_node_t* root) ...@@ -104,7 +80,7 @@ build_index(fz_outline* outline, girara_tree_node_t* root)
girara_tree_node_t* node = girara_node_append_data(root, index_element); girara_tree_node_t* node = girara_node_append_data(root, index_element);
if (outline->down != NULL) { if (outline->down != NULL) {
build_index(outline->down, node); build_index(ctx, document, outline->down, node);
} }
outline = outline->next; outline = outline->next;
......
...@@ -43,59 +43,31 @@ pdf_page_links_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error ...@@ -43,59 +43,31 @@ pdf_page_links_get(zathura_page_t* page, mupdf_page_t* mupdf_page, zathura_error
zathura_link_type_t type = ZATHURA_LINK_INVALID; zathura_link_type_t type = ZATHURA_LINK_INVALID;
zathura_link_target_t target = { 0 }; zathura_link_target_t target = { 0 };
char* buffer = NULL; if (fz_is_external_link(mupdf_document->ctx, link->uri) == 1) {
switch (link->dest.kind) { if (strstr(link->uri, "file://") == link->uri) {
case FZ_LINK_NONE: type = ZATHURA_LINK_GOTO_REMOTE;
type = ZATHURA_LINK_NONE; target.value = link->uri;
break; } else {
case FZ_LINK_URI:
type = ZATHURA_LINK_URI; type = ZATHURA_LINK_URI;
target.value = link->dest.ld.uri.uri; target.value = link->uri;
break; }
case FZ_LINK_GOTO: } else {
type = ZATHURA_LINK_GOTO_DEST; float x = 0;
target.page_number = link->dest.ld.gotor.page; float y = 0;
target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
target.left = 0; type = ZATHURA_LINK_GOTO_DEST;
target.top = 0; target.destination_type = ZATHURA_LINK_DESTINATION_XYZ;
target.scale = 0.0; target.page_number = fz_resolve_link(mupdf_document->ctx,
{ mupdf_document->document, link->uri, &x, &y);
int gflags = link->dest.ld.gotor.flags; target.left = x;
if (gflags & fz_link_flag_l_valid) { target.top = y;
target.left = link->dest.ld.gotor.lt.x; target.scale = 0.0;
}
if (gflags & fz_link_flag_t_valid) {
target.top = link->dest.ld.gotor.lt.y;
}
/* if (gflags & fz_link_flag_r_is_zoom) { */
/* target.scale = link->dest.ld.gotor.rb.x; */
/* } */
}
break;
case FZ_LINK_LAUNCH:
type = ZATHURA_LINK_LAUNCH;
target.value = link->dest.ld.launch.file_spec;
break;
case FZ_LINK_NAMED:
type = ZATHURA_LINK_NAMED;
target.value = link->dest.ld.named.named;
break;
case FZ_LINK_GOTOR:
type = ZATHURA_LINK_GOTO_REMOTE;
target.value = link->dest.ld.gotor.file_spec;
break;
default:
continue;
} }
zathura_link_t* zathura_link = zathura_link_new(type, position, target); zathura_link_t* zathura_link = zathura_link_new(type, position, target);
if (zathura_link != NULL) { if (zathura_link != NULL) {
girara_list_append(list, zathura_link); girara_list_append(list, zathura_link);
} }
if (buffer != NULL) {
g_free(buffer);
}
} }
return list; return list;
......
...@@ -43,12 +43,14 @@ pdf_page_init(zathura_page_t* page) ...@@ -43,12 +43,14 @@ pdf_page_init(zathura_page_t* page)
/* setup text */ /* setup text */
mupdf_page->extracted_text = false; mupdf_page->extracted_text = false;
mupdf_page->text = fz_new_text_page(mupdf_page->ctx); fz_rect mediabox;
mupdf_page->text = fz_new_stext_page(mupdf_page->ctx,
fz_bound_page(mupdf_page->ctx, mupdf_page->page, &mediabox));
if (mupdf_page->text == NULL) { if (mupdf_page->text == NULL) {
goto error_free; goto error_free;
} }
mupdf_page->sheet = fz_new_text_sheet(mupdf_page->ctx); mupdf_page->sheet = fz_new_stext_sheet(mupdf_page->ctx);
if (mupdf_page->sheet == NULL) { if (mupdf_page->sheet == NULL) {
goto error_free; goto error_free;
} }
...@@ -74,11 +76,11 @@ pdf_page_clear(zathura_page_t* page, mupdf_page_t* mupdf_page) ...@@ -74,11 +76,11 @@ pdf_page_clear(zathura_page_t* page, mupdf_page_t* mupdf_page)
if (mupdf_page != NULL) { if (mupdf_page != NULL) {
if (mupdf_page->text != NULL) { if (mupdf_page->text != NULL) {
fz_drop_text_page(mupdf_page->ctx, mupdf_page->text); fz_drop_stext_page(mupdf_page->ctx, mupdf_page->text);
} }
if (mupdf_page->sheet != NULL) { if (mupdf_page->sheet != NULL) {
fz_drop_text_sheet(mupdf_page->ctx, mupdf_page->sheet); fz_drop_stext_sheet(mupdf_page->ctx, mupdf_page->sheet);
} }
if (mupdf_page->page != NULL) { if (mupdf_page->page != NULL) {
......
...@@ -21,8 +21,8 @@ typedef struct mupdf_page_s ...@@ -21,8 +21,8 @@ typedef struct mupdf_page_s
{ {
fz_page* page; /**< Reference to the mupdf page */ fz_page* page; /**< Reference to the mupdf page */
fz_context* ctx; /**< Context */ fz_context* ctx; /**< Context */
fz_text_sheet* sheet; /**< Text sheet */ fz_stext_sheet* sheet; /**< Text sheet */
fz_text_page* text; /**< Page text */ fz_stext_page* text; /**< Page text */
fz_rect bbox; /**< Bbox */ fz_rect bbox; /**< Bbox */
bool extracted_text; /**< If text has already been extracted */ bool extracted_text; /**< If text has already been extracted */
} mupdf_page_t; } mupdf_page_t;
......
...@@ -20,7 +20,7 @@ pdf_page_render_to_buffer(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_ ...@@ -20,7 +20,7 @@ pdf_page_render_to_buffer(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_
return ZATHURA_ERROR_UNKNOWN; return ZATHURA_ERROR_UNKNOWN;
} }
fz_display_list* display_list = fz_new_display_list(mupdf_page->ctx); fz_display_list* display_list = fz_new_display_list(mupdf_page->ctx, NULL);
fz_device* device = fz_new_list_device(mupdf_page->ctx, display_list); fz_device* device = fz_new_list_device(mupdf_page->ctx, display_list);
fz_try (mupdf_document->ctx) { fz_try (mupdf_document->ctx) {
...@@ -37,10 +37,10 @@ pdf_page_render_to_buffer(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_ ...@@ -37,10 +37,10 @@ pdf_page_render_to_buffer(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_
fz_rect rect = { .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_colorspace* colorspace = fz_device_bgr(mupdf_document->ctx);
fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, image); fz_pixmap* pixmap = fz_new_pixmap_with_bbox_and_data(mupdf_page->ctx, colorspace, &irect, 1, image);
fz_clear_pixmap_with_value(mupdf_page->ctx, pixmap, 0xFF); fz_clear_pixmap_with_value(mupdf_page->ctx, pixmap, 0xFF);
device = fz_new_draw_device(mupdf_page->ctx, pixmap); 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_run_display_list(mupdf_page->ctx, display_list, device, &fz_identity, &rect, NULL);
fz_drop_device(mupdf_page->ctx, device); fz_drop_device(mupdf_page->ctx, device);
......
...@@ -40,7 +40,7 @@ pdf_page_search_text(zathura_page_t* page, mupdf_page_t* mupdf_page, const char* ...@@ -40,7 +40,7 @@ pdf_page_search_text(zathura_page_t* page, mupdf_page_t* mupdf_page, const char*
} }
fz_rect* hit_bbox = fz_malloc_array(mupdf_page->ctx, N_SEARCH_RESULTS, sizeof(fz_rect)); fz_rect* hit_bbox = fz_malloc_array(mupdf_page->ctx, N_SEARCH_RESULTS, sizeof(fz_rect));
int num_results = fz_search_text_page(mupdf_page->ctx, mupdf_page->text, int num_results = fz_search_stext_page(mupdf_page->ctx, mupdf_page->text,
(char*) text, hit_bbox, N_SEARCH_RESULTS); (char*) text, hit_bbox, N_SEARCH_RESULTS);
for (int i = 0; i < num_results; i++) { for (int i = 0; i < num_results; i++) {
......
...@@ -14,7 +14,7 @@ mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_pa ...@@ -14,7 +14,7 @@ mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_pa
fz_device* text_device = NULL; fz_device* text_device = NULL;
fz_try (mupdf_page->ctx) { fz_try (mupdf_page->ctx) {
text_device = fz_new_text_device(mupdf_page->ctx, mupdf_page->sheet, mupdf_page->text); text_device = fz_new_stext_device(mupdf_page->ctx, mupdf_page->sheet, mupdf_page->text, NULL);
/* Disable FZ_IGNORE_IMAGE to collect image blocks */ /* Disable FZ_IGNORE_IMAGE to collect image blocks */
fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_IGNORE_IMAGE); fz_disable_device_hints(mupdf_page->ctx, text_device, FZ_IGNORE_IMAGE);
...@@ -23,6 +23,7 @@ mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_pa ...@@ -23,6 +23,7 @@ mupdf_page_extract_text(mupdf_document_t* mupdf_document, mupdf_page_t* mupdf_pa
fz_scale(&ctm, 1.0, 1.0); fz_scale(&ctm, 1.0, 1.0);
fz_run_page(mupdf_page->ctx, mupdf_page->page, text_device, &ctm, NULL); fz_run_page(mupdf_page->ctx, mupdf_page->page, text_device, &ctm, NULL);
} fz_always (mupdf_document->ctx) { } fz_always (mupdf_document->ctx) {
fz_close_device(mupdf_page->ctx, text_device);
fz_drop_device(mupdf_page->ctx, text_device); fz_drop_device(mupdf_page->ctx, text_device);
} fz_catch(mupdf_document->ctx) { } fz_catch(mupdf_document->ctx) {
} }
......
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