mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-28 19:44:39 +01:00
Account for scrollbars when fitting page into window
The width of the vertical scrollbar (if there is one) needs to be substracted from the width of the GtkScrolledWindow in order to obtain the correct dimensions of the view area. See issue 27 <http://bugs.pwmt.org/issue27>. It also deals better with documents where pages don't all have the same size. Reported-by: Andreas Weinlich <business@weinlich.org> Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
99fbf0d17b
commit
92c26ed28d
1 changed files with 46 additions and 59 deletions
105
shortcuts.c
105
shortcuts.c
|
@ -98,6 +98,9 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
unsigned int first_page_column = 1;
|
unsigned int first_page_column = 1;
|
||||||
girara_setting_get(session, "first-page-column", &first_page_column);
|
girara_setting_get(session, "first-page-column", &first_page_column);
|
||||||
|
|
||||||
|
int padding = 1;
|
||||||
|
girara_setting_get(zathura->ui.session, "page-padding", &padding);
|
||||||
|
|
||||||
if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
|
if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
|
||||||
goto error_ret;
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
@ -112,8 +115,8 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
/* get window size */
|
/* get window size */
|
||||||
GtkAllocation allocation;
|
GtkAllocation allocation;
|
||||||
gtk_widget_get_allocation(session->gtk.view, &allocation);
|
gtk_widget_get_allocation(session->gtk.view, &allocation);
|
||||||
double width = allocation.width;
|
unsigned int width = allocation.width;
|
||||||
double height = allocation.height;
|
unsigned int height = allocation.height;
|
||||||
|
|
||||||
/* scrollbar spacing */
|
/* scrollbar spacing */
|
||||||
gint spacing;
|
gint spacing;
|
||||||
|
@ -126,71 +129,55 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
height += allocation.height;
|
height += allocation.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* calculate total width and max-height */
|
double scale = 1.0;
|
||||||
double total_width = 0;
|
unsigned int cell_height = 0, cell_width = 0;
|
||||||
double total_height = 0;
|
unsigned int document_height = 0, document_width = 0;
|
||||||
double max_height = 0;
|
|
||||||
double max_width = 0;
|
|
||||||
|
|
||||||
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
zathura_document_set_scale(zathura->document, scale);
|
||||||
for (unsigned int page_id = 0; page_id < pages_per_row; page_id++) {
|
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
||||||
if (page_id == number_of_pages) {
|
zathura_get_document_size(zathura, cell_height, cell_width,
|
||||||
break;
|
&document_height, &document_width);
|
||||||
}
|
|
||||||
|
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
double page_ratio = (double)cell_height / (double)document_width;
|
||||||
if (page == NULL) {
|
double window_ratio = (double)height / (double)width;
|
||||||
goto error_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int page_height = zathura_page_get_height(page);
|
if (argument->n == ZATHURA_ADJUST_WIDTH ||
|
||||||
unsigned int page_width = zathura_page_get_width(page);
|
(argument->n == ZATHURA_ADJUST_BESTFIT && page_ratio < window_ratio)) {
|
||||||
|
scale = (double)(width - (pages_per_row - 1) * padding) /
|
||||||
|
(double)(pages_per_row * cell_width);
|
||||||
|
zathura_document_set_scale(zathura->document, scale);
|
||||||
|
|
||||||
if (page_height > max_height) {
|
bool show_scrollbars = false;
|
||||||
max_height = page_height;
|
girara_setting_get(session, "show-scrollbars", &show_scrollbars);
|
||||||
}
|
|
||||||
|
|
||||||
if (page_width > max_width) {
|
if (show_scrollbars) {
|
||||||
max_width = page_width;
|
/* If the document is taller than the view, there's a vertical
|
||||||
}
|
* scrollbar; we need to substract its width from the view's width. */
|
||||||
|
zathura_get_document_size(zathura, cell_height, cell_width,
|
||||||
|
&document_height, &document_width);
|
||||||
|
if (height < document_height) {
|
||||||
|
GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar(
|
||||||
|
GTK_SCROLLED_WINDOW(session->gtk.view));
|
||||||
|
|
||||||
total_width += page_width;
|
if (vscrollbar != NULL) {
|
||||||
total_height += page_height;
|
GtkRequisition requisition;
|
||||||
}
|
gtk_widget_get_requisition(vscrollbar, &requisition);
|
||||||
|
if (0 < requisition.width && (unsigned)requisition.width < width) {
|
||||||
unsigned int rotation = zathura_document_get_rotation(zathura->document);
|
width -= requisition.width;
|
||||||
double page_ratio = max_height / total_width;
|
scale = (double)(width - (pages_per_row - 1) * padding) /
|
||||||
double window_ratio = height / width;
|
(double)(pages_per_row * cell_width);
|
||||||
|
zathura_document_set_scale(zathura->document, scale);
|
||||||
if (rotation == 90 || rotation == 270) {
|
}
|
||||||
page_ratio = max_width / total_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (rotation == 0 || rotation == 180) {
|
|
||||||
if (page_ratio < window_ratio) {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_width);
|
|
||||||
} else {
|
|
||||||
zathura_document_set_scale(zathura->document, height / max_height);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (page_ratio < window_ratio) {
|
|
||||||
zathura_document_set_scale(zathura->document, width / total_height);
|
|
||||||
} else {
|
|
||||||
zathura_document_set_scale(zathura->document, height / max_width);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
}
|
||||||
goto error_ret;
|
else if (argument->n == ZATHURA_ADJUST_BESTFIT) {
|
||||||
|
scale = (double)height / (double)cell_height;
|
||||||
|
zathura_document_set_scale(zathura->document, scale);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
goto error_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep position */
|
/* keep position */
|
||||||
|
|
Loading…
Add table
Reference in a new issue