Fit page to width / bestfit

This commit is contained in:
Moritz Lipp 2011-10-01 09:40:44 +02:00
parent 9ec22cc1f6
commit 9d13c75153

View File

@ -22,10 +22,64 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
}
bool
sc_adjust_window(girara_session_t* session, girara_argument_t* UNUSED(argument),
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
unsigned int UNUSED(t))
{
g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
g_return_val_if_fail(argument != NULL, false);
unsigned int* pages_per_row = girara_setting_get(session, "pages-per-row");
if (zathura->ui.page_view == NULL || zathura->document == NULL || pages_per_row == NULL) {
goto error_ret;
}
/* get window size */
/* TODO: Get correct size of the view widget */
gint width;
gint height;
gtk_window_get_size(GTK_WINDOW(session->gtk.window), &width, &height);
/* calculate total width and max-height */
double total_width = 0;
double max_height = 0;
for (unsigned int page_id = 0; page_id < *pages_per_row; page_id++) {
if (page_id == zathura->document->number_of_pages) {
break;
}
zathura_page_t* page = zathura->document->pages[page_id];
if (page == NULL) {
goto error_free;
}
if (page->height > max_height) {
max_height = page->height;
}
total_width += page->width;
}
if (argument->n == ADJUST_WIDTH) {
zathura->document->scale = width / total_width;
} else if (argument->n == ADJUST_BESTFIT) {
zathura->document->scale = height / max_height;
} else {
goto error_free;
}
/* re-render all pages */
render_all(zathura);
error_free:
/* cleanup */
free(pages_per_row);
error_ret:
return false;
}