diff --git a/utils.c b/utils.c index 1cc2be8..06de445 100644 --- a/utils.c +++ b/utils.c @@ -299,6 +299,43 @@ page_calc_height_width(zathura_page_t* page, unsigned int* page_height, unsigned } } +void +zathura_get_document_size(zathura_t* zathura, + unsigned int cell_height, unsigned int cell_width, + unsigned int* height, unsigned int* width) +{ + g_return_if_fail(zathura != NULL && zathura->document != NULL && + height != NULL && width != NULL); + + unsigned int pages_per_row = 1; + girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row); + if (pages_per_row == 0) + pages_per_row = 1; + + unsigned int first_page_column = 1; + girara_setting_get(zathura->ui.session, "first-page-column", &first_page_column); + if (first_page_column < 1) + first_page_column = 1; + if (first_page_column > pages_per_row) + first_page_column = (first_page_column - 1) % pages_per_row + 1; + + int padding = 1; + girara_setting_get(zathura->ui.session, "page-padding", &padding); + + double scale = zathura_document_get_scale(zathura->document); + + cell_height = ceil(cell_height * scale); + cell_width = ceil(cell_width * scale); + + *width = pages_per_row * cell_width + (pages_per_row - 1) * padding; + unsigned int effective_number_of_pages = + zathura_document_get_number_of_pages(zathura->document) + + first_page_column - 1; + unsigned int rows = effective_number_of_pages / pages_per_row + + (effective_number_of_pages % pages_per_row ? 1 : 0); + *height = rows * cell_height + (rows - 1) * padding; +} + GtkWidget* zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page) { diff --git a/utils.h b/utils.h index b531731..45990d0 100644 --- a/utils.h +++ b/utils.h @@ -104,6 +104,23 @@ void set_adjustment(GtkAdjustment* adjust, gdouble value); void page_calc_height_width(zathura_page_t* page, unsigned int* page_height, unsigned int* page_width, bool rotate); +/** + * Compute the size of the entire document to be displayed (in pixels), taking + * into account the scale, the layout of the pages, and the padding between + * them. It should be equal to the allocation of zathura->ui.page_widget once + * it's shown. + * + * @param[in] zathura The zathura instance + * @param[in] cell_height,cell_width The height and width of a cell containing + * a single page; it should be obtained + * using zathura_document_get_cell_size() + * with the document scale set to 1.0 + * @param[out] height,width The height and width of the document + */ +void zathura_get_document_size(zathura_t* zathura, + unsigned int cell_height, unsigned int cell_width, + unsigned int* height, unsigned int* width); + /** * Returns the page widget of the page *