Auto-adjust on rotate / Update sc_adjust_window

This commit is contained in:
Moritz Lipp 2012-03-28 17:26:20 +02:00
parent 64e9f540fb
commit 9cdd963784

View file

@ -92,7 +92,9 @@ 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_width = 0;
double total_height = 0;
double max_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++) { for (unsigned int page_id = 0; page_id < pages_per_row; page_id++) {
@ -105,17 +107,34 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
goto error_ret; goto error_ret;
} }
if (zathura_page_get_height(page) > max_height) { unsigned int page_height = zathura_page_get_height(page);
max_height = zathura_page_get_height(page); unsigned int page_width = zathura_page_get_width(page);
if (page_height > max_height) {
max_height = page_height;
} }
total_width += zathura_page_get_width(page); 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);
if (argument->n == ZATHURA_ADJUST_WIDTH) { if (argument->n == ZATHURA_ADJUST_WIDTH) {
if (rotation == 0 || rotation == 180) {
zathura_document_set_scale(zathura->document, width / total_width); zathura_document_set_scale(zathura->document, width / total_width);
} else {
zathura_document_set_scale(zathura->document, width / total_height);
}
} else if (argument->n == ZATHURA_ADJUST_BESTFIT) { } else if (argument->n == ZATHURA_ADJUST_BESTFIT) {
if (rotation == 0 || rotation == 180) {
zathura_document_set_scale(zathura->document, height / max_height); zathura_document_set_scale(zathura->document, height / max_height);
} else {
zathura_document_set_scale(zathura->document, width / total_height);
}
} else { } else {
goto error_ret; goto error_ret;
} }
@ -452,6 +471,10 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument,
unsigned int rotation = zathura_document_get_rotation(zathura->document); unsigned int rotation = zathura_document_get_rotation(zathura->document);
zathura_document_set_rotation(zathura->document, (rotation + angle) % 360); zathura_document_set_rotation(zathura->document, (rotation + angle) % 360);
/* update scale */
girara_argument_t new_argument = { zathura_document_get_adjust_mode(zathura->document), NULL };
sc_adjust_window(zathura->ui.session, &new_argument, NULL, 0);
/* render all pages again */ /* render all pages again */
render_all(zathura); render_all(zathura);