Commit 9d13c751 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Fit page to width / bestfit

parent 9ec22cc1
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment