From 8ce61ed633107121e1209f8245f1a19ebc022f83 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Thu, 19 Jan 2012 00:37:58 +0100 Subject: [PATCH] Implement recalc_rectangle This function should be used to recalculate the coordinates of a rectangle to its new coordinates on the rendered page (depending on the current scale and rotation value) --- utils.c | 38 ++++++++++++++++++++++++++++++++++++++ utils.h | 10 ++++++++++ 2 files changed, 48 insertions(+) diff --git a/utils.c b/utils.c index 4c36d5a..01406e9 100644 --- a/utils.c +++ b/utils.c @@ -201,3 +201,41 @@ page_calculate_offset(zathura_page_t* page) return offset; } + +zathura_rectangle_t +recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle) +{ + if (page == NULL || page->document == NULL) { + return rectangle; + } + + zathura_rectangle_t tmp; + + switch (page->document->rotate) { + case 90: + tmp.x1 = rectangle.y2 * page->document->scale; + tmp.x2 = rectangle.y1 * page->document->scale; + tmp.y1 = rectangle.x1 * page->document->scale; + tmp.y2 = rectangle.x2 * page->document->scale; + break; + case 180: + tmp.x1 = (page->width - rectangle.x2) * page->document->scale; + tmp.x2 = (page->width - rectangle.x1) * page->document->scale; + tmp.y1 = rectangle.y2 * page->document->scale; + tmp.y2 = rectangle.y1 * page->document->scale; + break; + case 270: + tmp.x1 = (page->height - rectangle.y1) * page->document->scale; + tmp.x2 = (page->height - rectangle.y2) * page->document->scale; + tmp.y1 = (page->width - rectangle.x2) * page->document->scale; + tmp.y2 = (page->width - rectangle.x1) * page->document->scale; + break; + default: + tmp.x1 = rectangle.x1 * page->document->scale; + tmp.x2 = rectangle.x2 * page->document->scale; + tmp.y1 = (page->height - rectangle.y1) * page->document->scale; + tmp.y2 = (page->height - rectangle.y2) * page->document->scale; + } + + return tmp; +} diff --git a/utils.h b/utils.h index 499e654..733f833 100644 --- a/utils.h +++ b/utils.h @@ -71,4 +71,14 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_ */ page_offset_t* page_calculate_offset(zathura_page_t* page); +/** + * Calculates the new coordinates based on the rotation and scale level of the + * document for the given rectangle + * + * @param page Page where the rectangle should be + * @param rectangle The rectangle + * @return New rectangle + */ +zathura_rectangle_t recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle); + #endif // UTILS_H