mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-14 06:43:47 +01:00
Save scale level per page
This commit is contained in:
parent
122ea70e16
commit
1f49e0e59a
@ -73,12 +73,12 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
|
|||||||
center.height = center.width = (2 * page_padding) + 1;
|
center.height = center.width = (2 * page_padding) + 1;
|
||||||
|
|
||||||
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
||||||
double scale = zathura_document_get_scale(zathura->document);
|
|
||||||
|
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
/* find page that fits */
|
/* find page that fits */
|
||||||
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
|
for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
||||||
|
double scale = zathura_page_get_scale(page);
|
||||||
|
|
||||||
GdkRectangle page_rect;
|
GdkRectangle page_rect;
|
||||||
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
|
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
|
||||||
|
@ -309,6 +309,15 @@ zathura_document_set_scale(zathura_document_t* document, double scale)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) {
|
||||||
|
zathura_page_t* page = zathura_document_get_page(document, page_id);
|
||||||
|
if (page == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_page_set_scale(page, scale);
|
||||||
|
}
|
||||||
|
|
||||||
document->scale = scale;
|
document->scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,7 +599,7 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
|
|||||||
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
|
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
|
||||||
zathura_rectangle_t tmp = priv->mouse.selection;
|
zathura_rectangle_t tmp = priv->mouse.selection;
|
||||||
|
|
||||||
double scale = zathura_document_get_scale(document);
|
double scale = zathura_page_get_scale(priv->page);
|
||||||
tmp.x1 /= scale;
|
tmp.x1 /= scale;
|
||||||
tmp.x2 /= scale;
|
tmp.x2 /= scale;
|
||||||
tmp.y1 /= scale;
|
tmp.y1 /= scale;
|
||||||
|
22
page.c
22
page.c
@ -17,6 +17,7 @@ struct zathura_page_s {
|
|||||||
unsigned int index; /**< Page number */
|
unsigned int index; /**< Page number */
|
||||||
void* data; /**< Custom data */
|
void* data; /**< Custom data */
|
||||||
bool visible; /**< Page is visible */
|
bool visible; /**< Page is visible */
|
||||||
|
double scale; /**< Scale */
|
||||||
zathura_document_t* document; /**< Document */
|
zathura_document_t* document; /**< Document */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error
|
|||||||
page->index = index;
|
page->index = index;
|
||||||
page->visible = false;
|
page->visible = false;
|
||||||
page->document = document;
|
page->document = document;
|
||||||
|
page->scale = 1.0;
|
||||||
|
|
||||||
/* init plugin */
|
/* init plugin */
|
||||||
zathura_plugin_t* plugin = zathura_document_get_plugin(document);
|
zathura_plugin_t* plugin = zathura_document_get_plugin(document);
|
||||||
@ -171,6 +173,26 @@ zathura_page_set_visibility(zathura_page_t* page, bool visibility)
|
|||||||
page->visible = visibility;
|
page->visible = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double
|
||||||
|
zathura_page_get_scale(zathura_page_t* page)
|
||||||
|
{
|
||||||
|
if (page == NULL) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return page->scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zathura_page_set_scale(zathura_page_t* page, double scale)
|
||||||
|
{
|
||||||
|
if (page == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
page->scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
zathura_page_get_data(zathura_page_t* page)
|
zathura_page_get_data(zathura_page_t* page)
|
||||||
{
|
{
|
||||||
|
16
page.h
16
page.h
@ -96,6 +96,22 @@ bool zathura_page_get_visibility(zathura_page_t* page);
|
|||||||
*/
|
*/
|
||||||
void zathura_page_set_visibility(zathura_page_t* page, bool visibility);
|
void zathura_page_set_visibility(zathura_page_t* page, bool visibility);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the scale value of the page
|
||||||
|
*
|
||||||
|
* @param page The page
|
||||||
|
* @return The scale value
|
||||||
|
*/
|
||||||
|
double zathura_page_get_scale(zathura_page_t* page);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new scale level of the page
|
||||||
|
*
|
||||||
|
* @param page The page
|
||||||
|
* @param scale The new scale value
|
||||||
|
*/
|
||||||
|
void zathura_page_set_scale(zathura_page_t* page, double scale);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the custom data
|
* Returns the custom data
|
||||||
*
|
*
|
||||||
|
2
render.c
2
render.c
@ -114,7 +114,7 @@ render(zathura_t* zathura, zathura_page_t* page)
|
|||||||
cairo_restore(cairo);
|
cairo_restore(cairo);
|
||||||
cairo_save(cairo);
|
cairo_save(cairo);
|
||||||
|
|
||||||
double scale = zathura_document_get_scale(zathura->document);
|
double scale = zathura_page_get_scale(page);
|
||||||
if (fabs(scale - 1.0f) > FLT_EPSILON) {
|
if (fabs(scale - 1.0f) > FLT_EPSILON) {
|
||||||
cairo_scale(cairo, scale, scale);
|
cairo_scale(cairo, scale, scale);
|
||||||
}
|
}
|
||||||
|
131
shortcuts.c
131
shortcuts.c
@ -6,6 +6,8 @@
|
|||||||
#include <girara/shortcuts.h>
|
#include <girara/shortcuts.h>
|
||||||
#include <girara/utils.h>
|
#include <girara/utils.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <math.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
|
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
@ -87,64 +89,87 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* calculate total width and max-height */
|
/* calculate total width and max-height */
|
||||||
double total_width = 0;
|
|
||||||
double total_height = 0;
|
|
||||||
double max_height = 0;
|
|
||||||
double max_width = 0;
|
|
||||||
|
|
||||||
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
||||||
for (unsigned int page_id = 0; page_id < pages_per_row; page_id++) {
|
unsigned int number_of_rows = ceil(number_of_pages / pages_per_row);
|
||||||
if (page_id == number_of_pages) {
|
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
for (unsigned int row = 0; row < number_of_rows; row++) {
|
||||||
if (page == NULL) {
|
double total_width = 0;
|
||||||
goto error_ret;
|
double total_height = 0;
|
||||||
}
|
double max_height = 0;
|
||||||
|
double max_width = 0;
|
||||||
|
|
||||||
unsigned int page_height = zathura_page_get_height(page);
|
/* calculate total width and max-height */
|
||||||
unsigned int page_width = zathura_page_get_width(page);
|
for (unsigned int column = 0; column < pages_per_row; column++) {
|
||||||
|
unsigned int page_id = row * pages_per_row + column;
|
||||||
if (page_height > max_height) {
|
if (page_id == number_of_pages) {
|
||||||
max_height = page_height;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if (page_width > max_width) {
|
|
||||||
max_width = page_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
total_width += page_width;
|
|
||||||
total_height += page_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
|
||||||
switch (argument->n) {
|
|
||||||
case ZATHURA_ADJUST_WIDTH:
|
|
||||||
if (rotation == 0 || rotation == 180) {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_width);
|
|
||||||
} else {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_height);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ZATHURA_ADJUST_BESTFIT:
|
|
||||||
if (total_width < total_height) {
|
|
||||||
if (rotation == 0 || rotation == 180) {
|
|
||||||
zathura_document_set_scale(zathura->document, height / max_height);
|
|
||||||
} else {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_height);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (rotation == 0 || rotation == 180) {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_width);
|
|
||||||
} else {
|
|
||||||
zathura_document_set_scale(zathura->document, height / total_width);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
||||||
default:
|
if (page == NULL) {
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int page_height = zathura_page_get_height(page);
|
||||||
|
unsigned int page_width = zathura_page_get_width(page);
|
||||||
|
|
||||||
|
if (page_height > max_height) {
|
||||||
|
max_height = page_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page_width > max_width) {
|
||||||
|
max_width = page_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
total_width += page_width;
|
||||||
|
total_height += page_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
double new_scale = 1.0;
|
||||||
|
|
||||||
|
switch (argument->n) {
|
||||||
|
case ZATHURA_ADJUST_WIDTH:
|
||||||
|
if (rotation == 0 || rotation == 180) {
|
||||||
|
new_scale = width / total_width;
|
||||||
|
} else {
|
||||||
|
new_scale = width / total_height;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ZATHURA_ADJUST_BESTFIT:
|
||||||
|
if (total_width < total_height) {
|
||||||
|
if (rotation == 0 || rotation == 180) {
|
||||||
|
new_scale = height / max_height;
|
||||||
|
} else {
|
||||||
|
new_scale = width / total_height;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (rotation == 0 || rotation == 180) {
|
||||||
|
new_scale = width / total_width;
|
||||||
|
} else {
|
||||||
|
new_scale = height / total_width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* apply new scale */
|
||||||
|
for (unsigned int column = 0; column < pages_per_row; column++) {
|
||||||
|
unsigned int page_id = row * pages_per_row + column;
|
||||||
|
if (page_id == number_of_pages) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
||||||
|
if (page == NULL) {
|
||||||
|
goto error_ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
zathura_page_set_scale(page, new_scale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep position */
|
/* keep position */
|
||||||
|
4
utils.c
4
utils.c
@ -231,7 +231,7 @@ recalc_rectangle(zathura_page_t* page, zathura_rectangle_t rectangle)
|
|||||||
|
|
||||||
double page_height = zathura_page_get_height(page);
|
double page_height = zathura_page_get_height(page);
|
||||||
double page_width = zathura_page_get_width(page);
|
double page_width = zathura_page_get_width(page);
|
||||||
double scale = zathura_document_get_scale(document);
|
double scale = zathura_page_get_scale(page);
|
||||||
|
|
||||||
zathura_rectangle_t tmp;
|
zathura_rectangle_t tmp;
|
||||||
|
|
||||||
@ -287,7 +287,7 @@ page_calc_height_width(zathura_page_t* page, unsigned int* page_height, unsigned
|
|||||||
|
|
||||||
double height = zathura_page_get_height(page);
|
double height = zathura_page_get_height(page);
|
||||||
double width = zathura_page_get_width(page);
|
double width = zathura_page_get_width(page);
|
||||||
double scale = zathura_document_get_scale(document);
|
double scale = zathura_page_get_scale(page);
|
||||||
|
|
||||||
if (rotate && zathura_document_get_rotation(document) % 180) {
|
if (rotate && zathura_document_get_rotation(document) % 180) {
|
||||||
*page_width = ceil(height * scale);
|
*page_width = ceil(height * scale);
|
||||||
|
Loading…
Reference in New Issue
Block a user