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)
This commit is contained in:
Moritz Lipp 2012-01-19 00:37:58 +01:00
parent 9ae81c0000
commit 8ce61ed633
2 changed files with 48 additions and 0 deletions

38
utils.c
View file

@ -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;
}

10
utils.h
View file

@ -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