mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 20:33:46 +01:00
Add function to get the size of the laid out document
zathura_get_document_size computes the size of the document to be displayed (in pixels), given the size of the individual cells. It takes padding between the cells into account. Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
27d7973586
commit
99fbf0d17b
37
utils.c
37
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)
|
||||
{
|
||||
|
17
utils.h
17
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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user