mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-04 02:46:01 +01:00
Merge branch 'develop'
This commit is contained in:
commit
5292390be0
14 changed files with 244 additions and 217 deletions
4
Makefile
4
Makefile
|
@ -8,10 +8,6 @@ SOURCE = $(shell find . -iname "*.c")
|
|||
OBJECTS = $(patsubst %.c, %.o, $(SOURCE))
|
||||
DOBJECTS = $(patsubst %.c, %.do, $(SOURCE))
|
||||
|
||||
ifneq "$(NEEDS_DL)" "0"
|
||||
LIBS += -ldl
|
||||
endif
|
||||
|
||||
all: options ${PROJECT}
|
||||
|
||||
options:
|
||||
|
|
|
@ -27,7 +27,7 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
|
|||
girara_warning("Failed to add bookmark to database.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return bookmark;
|
||||
}
|
||||
|
||||
|
@ -94,4 +94,3 @@ zathura_bookmarks_load(zathura_t* zathura, const gchar* file) {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
|
|||
cairo_surface_destroy(page->surface);
|
||||
page->surface = NULL;
|
||||
}
|
||||
|
||||
|
||||
free(offset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ MANPREFIX ?= ${PREFIX}/share/man
|
|||
# libs
|
||||
|
||||
# set this to 0 if you don't need to link against dl
|
||||
NEEDS_DL ?= 1
|
||||
|
||||
GTK_INC ?= $(shell pkg-config --cflags gtk+-2.0)
|
||||
GTK_LIB ?= $(shell pkg-config --libs gtk+-2.0 gthread-2.0)
|
||||
|
||||
|
@ -21,14 +19,16 @@ GIRARA_LIB ?= $(shell pkg-config --libs girara-gtk2)
|
|||
SQLITE_INC ?= $(shell pkg-config --cflags sqlite3)
|
||||
SQLITE_LIB ?= $(shell pkg-config --libs sqlite3)
|
||||
|
||||
DL_LIB ?= -ldl
|
||||
|
||||
INCS = ${GIRARA_INC} ${GTK_INC} $(SQLITE_INC)
|
||||
LIBS = ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) -lpthread -lm
|
||||
LIBS = ${GIRARA_LIB} ${GTK_LIB} $(SQLITE_LIB) $(DL_LIB) -lpthread -lm
|
||||
|
||||
# flags
|
||||
CFLAGS += -std=c99 -pedantic -Wall -Wno-format-zero-length -Wextra $(INCS)
|
||||
|
||||
# debug
|
||||
DFLAGS = -g
|
||||
DFLAGS ?= -g
|
||||
|
||||
# ld
|
||||
LDFLAGS += -rdynamic
|
||||
|
|
|
@ -15,7 +15,7 @@ zathura_database_t*
|
|||
zathura_db_init(const char* path)
|
||||
{
|
||||
zathura_database_t* db = g_malloc0(sizeof(zathura_database_t));
|
||||
|
||||
|
||||
/* create bookmarks database */
|
||||
static const char SQL_BOOKMARK_INIT[] =
|
||||
"CREATE TABLE IF NOT EXISTS bookmarks ("
|
||||
|
@ -167,7 +167,7 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file)
|
|||
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
|
||||
bookmark->id = g_strdup((const char*) sqlite3_column_text(stmt, 0));
|
||||
bookmark->page = sqlite3_column_int(stmt, 1);
|
||||
|
||||
|
||||
girara_list_append(result, bookmark);
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
|
|
200
document.c
200
document.c
|
@ -94,8 +94,9 @@ zathura_document_plugins_load(zathura_t* zathura)
|
|||
break;
|
||||
}
|
||||
|
||||
plugin->file_extension = NULL;
|
||||
plugin->open_function = NULL;
|
||||
plugin->content_types = girara_list_new();
|
||||
girara_list_set_free_function(plugin->content_types, g_free);
|
||||
|
||||
register_plugin(plugin);
|
||||
|
||||
|
@ -121,67 +122,55 @@ zathura_document_plugins_load(zathura_t* zathura)
|
|||
}
|
||||
|
||||
void
|
||||
zathura_document_plugins_free(zathura_t* zathura)
|
||||
zathura_document_plugin_free(zathura_document_plugin_t* plugin)
|
||||
{
|
||||
if (zathura == NULL) {
|
||||
if (plugin == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins);
|
||||
if (iter == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||
free(plugin);
|
||||
} while (girara_list_iterator_next(iter));
|
||||
girara_list_iterator_free(iter);
|
||||
girara_list_free(plugin->content_types);
|
||||
free(plugin);
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_document_plugin_register(zathura_t* zathura, zathura_document_plugin_t* new_plugin, void* handle)
|
||||
{
|
||||
if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL)
|
||||
if( (new_plugin == NULL) || (new_plugin->content_types == NULL) || (new_plugin->open_function == NULL)
|
||||
|| (handle == NULL) ) {
|
||||
girara_error("plugin: could not register\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* search existing plugins */
|
||||
girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins);
|
||||
if (iter) {
|
||||
do {
|
||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||
if (strcmp(plugin->file_extension, new_plugin->file_extension) == 0) {
|
||||
girara_error("plugin: already registered for filetype %s\n", plugin->file_extension);
|
||||
girara_list_iterator_free(iter);
|
||||
return false;
|
||||
}
|
||||
} while (girara_list_iterator_next(iter));
|
||||
girara_list_iterator_free(iter);
|
||||
}
|
||||
bool atleastone = false;
|
||||
GIRARA_LIST_FOREACH(new_plugin->content_types, gchar*, iter, type)
|
||||
if (!zathura_type_plugin_mapping_new(zathura, type, new_plugin)) {
|
||||
girara_error("plugin: already registered for filetype %s\n", type);
|
||||
}
|
||||
atleastone = true;
|
||||
GIRARA_LIST_FOREACH_END(new_plugin->content_types, gchar*, iter, type)
|
||||
|
||||
girara_list_append(zathura->plugins.plugins, new_plugin);
|
||||
return true;
|
||||
if (atleastone) {
|
||||
girara_list_append(zathura->plugins.plugins, new_plugin);
|
||||
}
|
||||
return atleastone;
|
||||
}
|
||||
|
||||
zathura_document_t*
|
||||
zathura_document_open(zathura_t* zathura, const char* path, const char* password)
|
||||
{
|
||||
if (path == NULL) {
|
||||
goto error_out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (file_exists(path) == false) {
|
||||
girara_error("File does not exist");
|
||||
goto error_out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* file_extension = file_get_extension(path);
|
||||
if (file_extension == NULL) {
|
||||
const gchar* content_type = g_content_type_guess(path, NULL, 0, NULL);
|
||||
if (content_type == NULL) {
|
||||
girara_error("Could not determine file type");
|
||||
goto error_out;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* determine real path */
|
||||
|
@ -199,79 +188,65 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
|||
|
||||
real_path = malloc(sizeof(char) * path_max);
|
||||
if (real_path == NULL) {
|
||||
goto error_out;
|
||||
g_free((void*)content_type);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (realpath(path, real_path) == NULL) {
|
||||
goto error_free;
|
||||
g_free((void*)content_type);
|
||||
free(real_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
document = malloc(sizeof(zathura_document_t));
|
||||
zathura_document_plugin_t* plugin = NULL;
|
||||
GIRARA_LIST_FOREACH(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
if (g_content_type_equals(content_type, mapping->type)) {
|
||||
plugin = mapping->plugin;
|
||||
break;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
g_free((void*)content_type);
|
||||
|
||||
if (plugin == NULL) {
|
||||
girara_error("unknown file type\n");
|
||||
free(real_path);
|
||||
}
|
||||
|
||||
document = g_malloc0(sizeof(zathura_document_t));
|
||||
if (document == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
document->file_path = real_path;
|
||||
document->password = password;
|
||||
document->current_page_number = 0;
|
||||
document->number_of_pages = 0;
|
||||
document->scale = 1.0;
|
||||
document->rotate = 0;
|
||||
document->data = NULL;
|
||||
document->pages = NULL;
|
||||
document->zathura = zathura;
|
||||
|
||||
document->functions.document_free = NULL;
|
||||
document->functions.document_index_generate = NULL;
|
||||
document->functions.document_save_as = NULL;
|
||||
document->functions.document_attachments_get = NULL;
|
||||
document->functions.page_get = NULL;
|
||||
document->functions.page_free = NULL;
|
||||
document->functions.page_search_text = NULL;
|
||||
document->functions.page_links_get = NULL;
|
||||
document->functions.page_form_fields_get = NULL;
|
||||
document->functions.page_render = NULL;
|
||||
if (plugin->open_function != NULL) {
|
||||
if (plugin->open_function(document) == true) {
|
||||
/* update statusbar */
|
||||
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path);
|
||||
|
||||
girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins);
|
||||
if (iter == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
/* read all pages */
|
||||
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*));
|
||||
if (document->pages == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
do {
|
||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||
if (strcmp(file_extension, plugin->file_extension) == 0) {
|
||||
girara_list_iterator_free(iter);
|
||||
if (plugin->open_function != NULL) {
|
||||
if (plugin->open_function(document) == true) {
|
||||
/* update statusbar */
|
||||
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path);
|
||||
|
||||
/* read all pages */
|
||||
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*));
|
||||
if (document->pages == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||
zathura_page_t* page = zathura_page_get(document, page_id);
|
||||
if (page == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
document->pages[page_id] = page;
|
||||
}
|
||||
|
||||
return document;
|
||||
} else {
|
||||
girara_error("could not open file\n");
|
||||
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||
zathura_page_t* page = zathura_page_get(document, page_id);
|
||||
if (page == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (girara_list_iterator_next(iter));
|
||||
girara_list_iterator_free(iter);
|
||||
|
||||
girara_error("unknown file type\n");
|
||||
document->pages[page_id] = page;
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
girara_error("could not open file\n");
|
||||
|
||||
error_free:
|
||||
|
||||
|
@ -285,10 +260,7 @@ error_free:
|
|||
free(document->pages);
|
||||
}
|
||||
|
||||
free(document);
|
||||
|
||||
error_out:
|
||||
|
||||
g_free(document);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -315,7 +287,7 @@ zathura_document_free(zathura_document_t* document)
|
|||
free(document->file_path);
|
||||
}
|
||||
|
||||
free(document);
|
||||
g_free(document);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -325,7 +297,7 @@ zathura_document_free(zathura_document_t* document)
|
|||
free(document->file_path);
|
||||
}
|
||||
|
||||
free(document);
|
||||
g_free(document);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -487,19 +459,19 @@ zathura_page_form_fields_free(zathura_list_t* UNUSED(list))
|
|||
return false;
|
||||
}
|
||||
|
||||
zathura_image_buffer_t*
|
||||
zathura_page_render(zathura_page_t* page)
|
||||
bool
|
||||
zathura_page_render(zathura_page_t* page, cairo_t* cairo)
|
||||
{
|
||||
if (page == NULL || page->document == NULL) {
|
||||
if (page == NULL || page->document == NULL || cairo == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (page->document->functions.page_render == NULL) {
|
||||
if (page->document->functions.page_render_cairo == NULL) {
|
||||
girara_error("%s not implemented", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return page->document->functions.page_render(page);
|
||||
return page->document->functions.page_render_cairo(page, cairo);
|
||||
}
|
||||
|
||||
zathura_index_element_t*
|
||||
|
@ -569,3 +541,33 @@ zathura_image_buffer_free(zathura_image_buffer_t* image_buffer)
|
|||
free(image_buffer->data);
|
||||
free(image_buffer);
|
||||
}
|
||||
|
||||
bool
|
||||
zathura_type_plugin_mapping_new(zathura_t* zathura, const gchar* type, zathura_document_plugin_t* plugin)
|
||||
{
|
||||
g_return_val_if_fail(zathura && type && plugin, false);
|
||||
|
||||
GIRARA_LIST_FOREACH(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
if (g_content_type_equals(type, mapping->type)) {
|
||||
girara_list_iterator_free(iter);
|
||||
return false;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
|
||||
zathura_type_plugin_mapping_t* mapping = g_malloc(sizeof(zathura_type_plugin_mapping_t));
|
||||
mapping->type = g_strdup(type);
|
||||
mapping->plugin = plugin;
|
||||
girara_list_append(zathura->plugins.type_plugin_mapping, mapping);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_type_plugin_mapping_free(zathura_type_plugin_mapping_t* mapping)
|
||||
{
|
||||
if (mapping == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_free((void*)mapping->type);
|
||||
g_free(mapping);
|
||||
}
|
||||
|
|
43
document.h
43
document.h
|
@ -3,6 +3,7 @@
|
|||
#ifndef DOCUMENT_H
|
||||
#define DOCUMENT_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -21,11 +22,17 @@ typedef bool (*zathura_document_open_t)(zathura_document_t* document);
|
|||
*/
|
||||
typedef struct zathura_document_plugin_s
|
||||
{
|
||||
char* file_extension; /**> File extension */
|
||||
girara_list_t* content_types; /**> List of supported content types */
|
||||
zathura_document_open_t open_function; /**> Document open function */
|
||||
void* handle; /**> DLL handle */
|
||||
} zathura_document_plugin_t;
|
||||
|
||||
typedef struct zathura_type_plugin_mapping_s
|
||||
{
|
||||
const gchar* type;
|
||||
zathura_document_plugin_t* plugin;
|
||||
} zathura_type_plugin_mapping_t;
|
||||
|
||||
/**
|
||||
* Function prototype that is called to register a document plugin
|
||||
*
|
||||
|
@ -149,7 +156,7 @@ struct zathura_page_s
|
|||
GtkWidget* event_box; /**> Widget wrapper for mouse events */
|
||||
GtkWidget* drawing_area; /**> Drawing area */
|
||||
GStaticMutex lock; /**> Lock */
|
||||
cairo_surface_t* surface; /** Cairo surface */
|
||||
cairo_surface_t* surface; /** Cairo surface */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -213,6 +220,11 @@ struct zathura_document_s
|
|||
*/
|
||||
zathura_image_buffer_t* (*page_render)(zathura_page_t* page);
|
||||
|
||||
/**
|
||||
* Renders the page
|
||||
*/
|
||||
bool (*page_render_cairo)(zathura_page_t* page, cairo_t* cairo);
|
||||
|
||||
/**
|
||||
* Free page
|
||||
*/
|
||||
|
@ -233,11 +245,11 @@ struct zathura_document_s
|
|||
void zathura_document_plugins_load(zathura_t* zathura);
|
||||
|
||||
/**
|
||||
* Free all document plugins
|
||||
* Free a document plugin
|
||||
*
|
||||
* @param zathura the zathura session
|
||||
* @param plugin The plugin
|
||||
*/
|
||||
void zathura_document_plugins_free(zathura_t* zathura);
|
||||
void zathura_document_plugin_free(zathura_document_plugin_t* plugin);
|
||||
|
||||
/**
|
||||
* Register document plugin
|
||||
|
@ -357,9 +369,10 @@ bool zathura_page_form_fields_free(zathura_list_t* list);
|
|||
* Render page
|
||||
*
|
||||
* @param page The page object
|
||||
* @return Image buffer or NULL if an error occured
|
||||
* @param cairo Cairo object
|
||||
* @return True if no error occured, otherwise false
|
||||
*/
|
||||
zathura_image_buffer_t* zathura_page_render(zathura_page_t* page);
|
||||
bool zathura_page_render(zathura_page_t* page, cairo_t* cairo);
|
||||
|
||||
/**
|
||||
* Create new index element
|
||||
|
@ -376,4 +389,20 @@ zathura_index_element_t* zathura_index_element_new(const char* title);
|
|||
*/
|
||||
void zathura_index_element_free(zathura_index_element_t* index);
|
||||
|
||||
/**
|
||||
* Add type -> plugin mapping
|
||||
* @param zathura zathura instance
|
||||
* @param type content type
|
||||
* @param plugin plugin instance
|
||||
* @return true on success, false if another plugin is already registered for
|
||||
* that type
|
||||
*/
|
||||
bool zathura_type_plugin_mapping_new(zathura_t* zathura, const gchar* type, zathura_document_plugin_t* plugin);
|
||||
|
||||
/**
|
||||
* Free type -> plugin mapping
|
||||
* @param mapping To be freed
|
||||
*/
|
||||
void zathura_type_plugin_mapping_free(zathura_type_plugin_mapping_t* mapping);
|
||||
|
||||
#endif // DOCUMENT_H
|
||||
|
|
45
print.c
45
print.c
|
@ -17,7 +17,7 @@ print(zathura_t* zathura)
|
|||
if (zathura->print.page_setup != NULL) {
|
||||
gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup);
|
||||
}
|
||||
|
||||
|
||||
gtk_print_operation_set_allow_async(print_operation, TRUE);
|
||||
gtk_print_operation_set_n_pages(print_operation, zathura->document->number_of_pages);
|
||||
gtk_print_operation_set_current_page(print_operation, zathura->document->current_page_number);
|
||||
|
@ -51,32 +51,33 @@ void
|
|||
cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
|
||||
context, gint page_number, zathura_t* zathura)
|
||||
{
|
||||
cairo_t* cairo = gtk_print_context_get_cairo_context(context);
|
||||
/* TODO: Implement with cairo */
|
||||
/*cairo_t* cairo = gtk_print_context_get_cairo_context(context);*/
|
||||
|
||||
girara_info("Printing page %d", page_number);
|
||||
/*girara_info("Printing page %d", page_number);*/
|
||||
|
||||
zathura_page_t* page = zathura->document->pages[page_number];
|
||||
/*zathura_page_t* page = zathura->document->pages[page_number];*/
|
||||
|
||||
double requested_with = gtk_print_context_get_width(context);
|
||||
double tmp_scale = zathura->document->scale;
|
||||
zathura->document->scale = requested_with / page->width;
|
||||
/*double requested_with = gtk_print_context_get_width(context);*/
|
||||
/*double tmp_scale = zathura->document->scale;*/
|
||||
/*zathura->document->scale = requested_with / page->width;*/
|
||||
|
||||
g_static_mutex_lock(&(page->lock));
|
||||
zathura_image_buffer_t* image_buffer = zathura_page_render(page);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
/*g_static_mutex_lock(&(page->lock));*/
|
||||
/*zathura_image_buffer_t* image_buffer = zathura_page_render(page);*/
|
||||
/*g_static_mutex_unlock(&(page->lock));*/
|
||||
|
||||
for (unsigned int y = 0; y < image_buffer->height; y++) {
|
||||
unsigned char* src = image_buffer->data + y * image_buffer->rowstride;
|
||||
for (unsigned int x = 0; x < image_buffer->width; x++) {
|
||||
if (src[0] != 255 && src[1] != 255 && src[2] != 255) {
|
||||
cairo_set_source_rgb(cairo, src[0], src[1], src[2]);
|
||||
cairo_rectangle(cairo, x, y, 1, 1);
|
||||
cairo_fill(cairo);
|
||||
}
|
||||
/*for (unsigned int y = 0; y < image_buffer->height; y++) {*/
|
||||
/*unsigned char* src = image_buffer->data + y * image_buffer->rowstride;*/
|
||||
/*for (unsigned int x = 0; x < image_buffer->width; x++) {*/
|
||||
/*if (src[0] != 255 && src[1] != 255 && src[2] != 255) {*/
|
||||
/*cairo_set_source_rgb(cairo, src[0], src[1], src[2]);*/
|
||||
/*cairo_rectangle(cairo, x, y, 1, 1);*/
|
||||
/*cairo_fill(cairo);*/
|
||||
/*}*/
|
||||
|
||||
src += 3;
|
||||
}
|
||||
}
|
||||
/*src += 3;*/
|
||||
/*}*/
|
||||
/*}*/
|
||||
|
||||
zathura->document->scale = tmp_scale;
|
||||
/*zathura->document->scale = tmp_scale;*/
|
||||
}
|
||||
|
|
2
print.h
2
print.h
|
@ -21,6 +21,6 @@ void print(zathura_t* zathura);
|
|||
* @param zathura Zathura object
|
||||
*/
|
||||
void cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext*
|
||||
context, gint page_number, zathura_t* zathura);
|
||||
context, gint page_number, zathura_t* zathura);
|
||||
|
||||
#endif // PRINT_H
|
||||
|
|
116
render.c
116
render.c
|
@ -151,36 +151,73 @@ render(zathura_t* zathura, zathura_page_t* page)
|
|||
|
||||
gdk_threads_enter();
|
||||
g_static_mutex_lock(&(page->lock));
|
||||
zathura_image_buffer_t* image_buffer = zathura_page_render(page);
|
||||
|
||||
if (image_buffer == NULL) {
|
||||
/* create cairo surface */
|
||||
unsigned int page_width = 0;
|
||||
unsigned int page_height = 0;
|
||||
|
||||
if (page->document->rotate == 0 || page->document->rotate == 180) {
|
||||
page_width = page->width * zathura->document->scale;
|
||||
page_height = page->height * zathura->document->scale;
|
||||
} else {
|
||||
page_width = page->height * zathura->document->scale;
|
||||
page_height = page->width * zathura->document->scale;
|
||||
}
|
||||
|
||||
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height);
|
||||
|
||||
if (surface == NULL) {
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
gdk_threads_leave();
|
||||
return false;
|
||||
}
|
||||
|
||||
/* create cairo surface */
|
||||
unsigned int page_width = page->width * zathura->document->scale;
|
||||
unsigned int page_height = page->height * zathura->document->scale;
|
||||
cairo_t* cairo = cairo_create(surface);
|
||||
|
||||
cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, page_width, page_height);
|
||||
if (cairo == NULL) {
|
||||
cairo_surface_destroy(surface);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
gdk_threads_leave();
|
||||
return false;
|
||||
}
|
||||
|
||||
cairo_save(cairo);
|
||||
cairo_set_source_rgb(cairo, 1, 1, 1);
|
||||
cairo_rectangle(cairo, 0, 0, page_width, page_height);
|
||||
cairo_fill(cairo);
|
||||
cairo_restore(cairo);
|
||||
cairo_save(cairo);
|
||||
|
||||
switch(page->document->rotate) {
|
||||
case 90:
|
||||
cairo_translate(cairo, page_width, 0);
|
||||
break;
|
||||
case 180:
|
||||
cairo_translate(cairo, page_width, page_height);
|
||||
break;
|
||||
case 270:
|
||||
cairo_translate(cairo, 0, page_height);
|
||||
break;
|
||||
}
|
||||
|
||||
if (page->document->rotate != 0) {
|
||||
cairo_rotate(cairo, page->document->rotate * G_PI / 180.0);
|
||||
}
|
||||
|
||||
if (zathura_page_render(page, cairo) == false) {
|
||||
cairo_destroy(cairo);
|
||||
cairo_surface_destroy(surface);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
gdk_threads_leave();
|
||||
return false;
|
||||
}
|
||||
|
||||
cairo_restore(cairo);
|
||||
cairo_destroy(cairo);
|
||||
|
||||
int rowstride = cairo_image_surface_get_stride(surface);
|
||||
unsigned char* image = cairo_image_surface_get_data(surface);
|
||||
|
||||
for (unsigned int y = 0; y < page_height; y++) {
|
||||
unsigned char* dst = image + y * rowstride;
|
||||
unsigned char* src = image_buffer->data + y * image_buffer->rowstride;
|
||||
|
||||
for (unsigned int x = 0; x < page_width; x++) {
|
||||
dst[0] = src[2];
|
||||
dst[1] = src[1];
|
||||
dst[2] = src[0];
|
||||
src += 3;
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* recolor */
|
||||
if (zathura->global.recolor) {
|
||||
/* recolor code based on qimageblitz library flatten() function
|
||||
|
@ -214,49 +251,14 @@ render(zathura_t* zathura, zathura_page_t* page)
|
|||
}
|
||||
}
|
||||
|
||||
/* rotate */
|
||||
unsigned int width = page_width;
|
||||
unsigned int height = page_height;
|
||||
if (page->document->rotate == 90 || page->document->rotate == 270) {
|
||||
width = page_height;
|
||||
height = page_width;
|
||||
}
|
||||
|
||||
cairo_surface_t* final_surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, width, height);
|
||||
cairo_t* cairo = cairo_create(final_surface);
|
||||
|
||||
switch(page->document->rotate)
|
||||
{
|
||||
case 90:
|
||||
cairo_translate(cairo, width, 0);
|
||||
break;
|
||||
case 180:
|
||||
cairo_translate(cairo, width, height);
|
||||
break;
|
||||
case 270:
|
||||
cairo_translate(cairo, 0, height);
|
||||
break;
|
||||
}
|
||||
|
||||
if (page->document->rotate != 0) {
|
||||
cairo_rotate(cairo, page->document->rotate * G_PI / 180.0);
|
||||
}
|
||||
|
||||
cairo_set_source_surface(cairo, surface, 0, 0);
|
||||
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint(cairo);
|
||||
cairo_destroy(cairo);
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
/* draw to gtk widget */
|
||||
page->surface = final_surface;
|
||||
gtk_widget_set_size_request(page->drawing_area, width, height);
|
||||
page->surface = surface;
|
||||
gtk_widget_set_size_request(page->drawing_area, page_width, page_height);
|
||||
gtk_widget_queue_draw(page->drawing_area);
|
||||
|
||||
zathura_image_buffer_free(image_buffer);
|
||||
g_static_mutex_unlock(&(page->lock));
|
||||
|
||||
gdk_threads_leave();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
2
render.h
2
render.h
|
@ -16,7 +16,7 @@ struct render_thread_s
|
|||
GThread* thread; /**> The thread object */
|
||||
GMutex* lock; /**> Lock */
|
||||
GCond* cond; /**> Condition */
|
||||
zathura_t* zathura; /**> Zathura object */
|
||||
zathura_t* zathura; /**> Zathura object */
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
25
utils.c
25
utils.c
|
@ -55,26 +55,21 @@ file_valid_extension(zathura_t* zathura, const char* path)
|
|||
return false;
|
||||
}
|
||||
|
||||
const char* file_extension = file_get_extension(path);
|
||||
|
||||
if (file_extension == NULL) {
|
||||
const gchar* content_type = g_content_type_guess(path, NULL, 0, NULL);
|
||||
if (content_type == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins);
|
||||
if (iter == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||
if (!strcmp(file_extension, plugin->file_extension)) {
|
||||
return true;
|
||||
bool result = false;
|
||||
GIRARA_LIST_FOREACH(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
if (g_content_type_equals(content_type, mapping->type)) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
} while (girara_list_iterator_next(iter));
|
||||
girara_list_iterator_free(iter);
|
||||
GIRARA_LIST_FOREACH_END(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
|
||||
return false;
|
||||
g_free(content_type);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -30,7 +30,7 @@ zathura_init(int argc, char* argv[])
|
|||
/* parse command line options */
|
||||
GdkNativeWindow embed = 0;
|
||||
gchar* config_dir = NULL, *data_dir = NULL, *plugin_path = NULL;
|
||||
GOptionEntry entries[] =
|
||||
GOptionEntry entries[] =
|
||||
{
|
||||
{ "reparent", 'e', 0, G_OPTION_ARG_INT, &embed, "Reparents to window specified by xid", "xid" },
|
||||
{ "config-dir", 'c', 0, G_OPTION_ARG_FILENAME, &config_dir, "Path to the config directory", "path" },
|
||||
|
@ -63,8 +63,11 @@ zathura_init(int argc, char* argv[])
|
|||
|
||||
/* plugins */
|
||||
zathura->plugins.plugins = girara_list_new();
|
||||
girara_list_set_free_function(zathura->plugins.plugins, zathura_document_plugin_free);
|
||||
zathura->plugins.path = girara_list_new();
|
||||
girara_list_set_free_function(zathura->plugins.path, g_free);
|
||||
zathura->plugins.type_plugin_mapping = girara_list_new();
|
||||
girara_list_set_free_function(zathura->plugins.type_plugin_mapping, zathura_type_plugin_mapping_free);
|
||||
|
||||
if (config_dir) {
|
||||
zathura->config.config_dir = g_strdup(config_dir);
|
||||
|
@ -263,7 +266,6 @@ zathura_free(zathura_t* zathura)
|
|||
}
|
||||
|
||||
/* free registered plugins */
|
||||
zathura_document_plugins_free(zathura);
|
||||
girara_list_free(zathura->plugins.plugins);
|
||||
girara_list_free(zathura->plugins.path);
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ typedef struct zathura_s
|
|||
{
|
||||
girara_list_t* plugins; /**> List of plugins */
|
||||
girara_list_t* path; /**> List of plugin paths */
|
||||
girara_list_t* type_plugin_mapping; /**> List of type -> plugin mappings */
|
||||
} plugins;
|
||||
|
||||
struct
|
||||
|
|
Loading…
Reference in a new issue