From 7d2265c294f9cfcbbc48b530896e807aa0e21f71 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 6 Jun 2012 15:45:20 +0200 Subject: [PATCH 1/3] Consider link types in link_new and link_free --- links.c | 31 +++++++++++++++++++++---------- types.h | 3 +-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/links.c b/links.c index 730bf42..6ede9c2 100644 --- a/links.c +++ b/links.c @@ -31,18 +31,16 @@ zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position, switch (type) { case ZATHURA_LINK_GOTO_DEST: - link->target.page_number = target.page_number; + link->target = target; + + if (target.value != NULL) { + link->target.value = g_strdup(target.value); + } break; case ZATHURA_LINK_GOTO_REMOTE: case ZATHURA_LINK_URI: - if (target.value == NULL) { - g_free(link); - return NULL; - } - - link->target.value = g_strdup(target.value); - break; case ZATHURA_LINK_LAUNCH: + case ZATHURA_LINK_NAMED: if (target.value == NULL) { g_free(link); return NULL; @@ -66,8 +64,11 @@ zathura_link_free(zathura_link_t* link) } switch (link->type) { + case ZATHURA_LINK_GOTO_DEST: + case ZATHURA_LINK_GOTO_REMOTE: case ZATHURA_LINK_URI: case ZATHURA_LINK_LAUNCH: + case ZATHURA_LINK_NAMED: if (link->target.value != NULL) { g_free(link->target.value); } @@ -114,13 +115,23 @@ zathura_link_get_target(zathura_link_t* link) void zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) { - if (zathura == NULL || link == NULL) { + if (zathura == NULL || zathura->document == NULL || link == NULL) { return; } switch (link->type) { case ZATHURA_LINK_GOTO_DEST: - page_set_delayed(zathura, link->target.page_number); + switch (link->target.destination_type) { + case ZATHURA_LINK_DESTINATION_XYZ: + if (link->target.scale == 0) { + zathura_document_set_scale(zathura->document, link->target.scale); + } + + page_set_delayed(zathura, link->target.page_number); + break; + default: + break; + } break; case ZATHURA_LINK_GOTO_REMOTE: link_remote(zathura, link->target.value); diff --git a/types.h b/types.h index 10fa150..8aade9a 100644 --- a/types.h +++ b/types.h @@ -150,8 +150,7 @@ typedef enum zathura_link_destination_type_e ZATHURA_LINK_DESTINATION_FITR, ZATHURA_LINK_DESTINATION_FITB, ZATHURA_LINK_DESTINATION_FITBH, - ZATHURA_LINK_DESTINATION_FITBV, - ZATHURA_LINK_DESTINATION_NAMED + ZATHURA_LINK_DESTINATION_FITBV } zathura_link_destination_type_t; typedef struct zathura_link_target_s From dfbd39c59dfd7b7e34e3424f8724e8fa438daf96 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 6 Jun 2012 16:20:12 +0200 Subject: [PATCH 2/3] Evalute ZATHURA_LINK_DESTINATION_XYZ --- links.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/links.c b/links.c index 6ede9c2..a43e84f 100644 --- a/links.c +++ b/links.c @@ -8,6 +8,7 @@ #include "links.h" #include "zathura.h" #include "document.h" +#include "utils.h" struct zathura_link_s { @@ -122,12 +123,32 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link) switch (link->type) { case ZATHURA_LINK_GOTO_DEST: switch (link->target.destination_type) { - case ZATHURA_LINK_DESTINATION_XYZ: - if (link->target.scale == 0) { + case ZATHURA_LINK_DESTINATION_XYZ: { + if (link->target.scale != 0) { zathura_document_set_scale(zathura->document, link->target.scale); } - page_set_delayed(zathura, link->target.page_number); + /* get page */ + zathura_page_t* page = zathura_document_get_page(zathura->document, + link->target.page_number); + if (page == NULL) { + return; + } + + /* get page offset */ + page_offset_t offset; + page_calculate_offset(zathura, page, &offset); + + if (link->target.left != -1) { + offset.x += link->target.left * zathura_document_get_scale(zathura->document); + } + + if (link->target.top != -1) { + offset.y += link->target.top * zathura_document_get_scale(zathura->document); + } + + position_set_delayed(zathura, offset.x, offset.y); + } break; default: break; From 7a1231518e04b2f1d1834bee0a97705699368948 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 6 Jun 2012 17:20:35 +0200 Subject: [PATCH 3/3] Set page orientation while printing automatically --- print.c | 41 +++++++++++++++++++++++++++++++++++------ print.h | 23 ++--------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/print.c b/print.c index c4559c9..0185209 100644 --- a/print.c +++ b/print.c @@ -8,6 +8,14 @@ #include #include +static void cb_print_draw_page(GtkPrintOperation* print_operation, + GtkPrintContext* context, gint page_number, zathura_t* zathura); +static void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext* + context, zathura_t* zathura); +static void cb_print_request_page_setup(GtkPrintOperation* print_operation, + GtkPrintContext* context, gint page_number, GtkPageSetup* setup, zathura_t* + zathura); + void print(zathura_t* zathura) { @@ -31,8 +39,9 @@ print(zathura_t* zathura) gtk_print_operation_set_use_full_page(print_operation, TRUE); /* print operation signals */ - g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); - g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); + g_signal_connect(print_operation, "draw-page", G_CALLBACK(cb_print_draw_page), zathura); + g_signal_connect(print_operation, "end-print", G_CALLBACK(cb_print_end), zathura); + g_signal_connect(print_operation, "request_page_setup", G_CALLBACK(cb_print_request_page_setup), zathura); /* print */ GtkPrintOperationResult result = gtk_print_operation_run(print_operation, @@ -56,7 +65,7 @@ print(zathura_t* zathura) g_object_unref(print_operation); } -void +static void cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* UNUSED(context), zathura_t* zathura) { @@ -72,7 +81,7 @@ cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* } } -void +static void cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* context, gint page_number, zathura_t* zathura) { @@ -88,8 +97,8 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* g_free(tmp); /* render page */ - cairo_t* cairo = gtk_print_context_get_cairo_context(context); - zathura_page_t* page = zathura_document_get_page(zathura->document, page_number); + cairo_t* cairo = gtk_print_context_get_cairo_context(context); + zathura_page_t* page = zathura_document_get_page(zathura->document, page_number); if (cairo == NULL || page == NULL) { return; } @@ -98,3 +107,23 @@ cb_print_draw_page(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext* zathura_page_render(page, cairo, true); render_unlock(zathura->sync.render_thread); } + +static void +cb_print_request_page_setup(GtkPrintOperation* UNUSED(print_operation), + GtkPrintContext* UNUSED(context), gint page_number, GtkPageSetup* setup, + zathura_t* zathura) +{ + if (zathura == NULL || zathura->document == NULL) { + return; + } + + zathura_page_t* page = zathura_document_get_page(zathura->document, page_number); + double width = zathura_page_get_width(page); + double height = zathura_page_get_height(page); + + if (width > height) { + gtk_page_setup_set_orientation(setup, GTK_PAGE_ORIENTATION_LANDSCAPE); + } else { + gtk_page_setup_set_orientation(setup, GTK_PAGE_ORIENTATION_PORTRAIT); + } +} diff --git a/print.h b/print.h index f7b603d..7224e25 100644 --- a/print.h +++ b/print.h @@ -3,6 +3,8 @@ #ifndef PRINT_H #define PRINT_H +#include + #include "zathura.h" /** @@ -12,25 +14,4 @@ */ void print(zathura_t* zathura); -/** - * Callback that is executed for every page that should be printed - * - * @param print_operation Print operation object - * @param context Print context - * @param page_number Current page number - * @param zathura Zathura object - */ -void cb_print_draw_page(GtkPrintOperation* print_operation, GtkPrintContext* - context, gint page_number, zathura_t* zathura); - -/** - * Emitted after all pages have been rendered - * - * @param print_operation Print operation - * @param context Print context - * @param zathura Zathura object - */ -void cb_print_end(GtkPrintOperation* print_operation, GtkPrintContext* context, - zathura_t* zathura); - #endif // PRINT_H