mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 14:46:00 +01:00
move zathura_get_document_size to document.c
It makes more sense, plus now the document knows about the page layout and can do the computation.
This commit is contained in:
parent
0da491f78b
commit
a0a64832d9
5 changed files with 34 additions and 57 deletions
20
document.c
20
document.c
|
@ -427,6 +427,26 @@ zathura_document_get_cell_size(zathura_document_t* document,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
zathura_document_get_document_size(zathura_document_t* document,
|
||||||
|
unsigned int* height, unsigned int* width)
|
||||||
|
{
|
||||||
|
g_return_if_fail(document != NULL && height != NULL && width != NULL);
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int npag = zathura_document_get_number_of_pages(document);
|
||||||
|
unsigned int ncol = zathura_document_get_pages_per_row(document);
|
||||||
|
unsigned int c0 = zathura_document_get_first_page_column(document);
|
||||||
|
unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */
|
||||||
|
unsigned int pad = zathura_document_get_page_padding(document);
|
||||||
|
|
||||||
|
unsigned int cell_height=0, cell_width=0;
|
||||||
|
zathura_document_get_cell_size(document, &cell_height, &cell_width);
|
||||||
|
|
||||||
|
*width = ncol * cell_width + (ncol - 1) * pad;
|
||||||
|
*height = nrow * cell_height + (nrow - 1) * pad;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
zathura_document_set_page_layout(zathura_document_t* document, unsigned int page_padding,
|
zathura_document_set_page_layout(zathura_document_t* document, unsigned int page_padding,
|
||||||
unsigned int pages_per_row, unsigned int first_page_column)
|
unsigned int pages_per_row, unsigned int first_page_column)
|
||||||
|
|
12
document.h
12
document.h
|
@ -188,6 +188,18 @@ void zathura_document_set_data(zathura_document_t* document, void* data);
|
||||||
void zathura_document_get_cell_size(zathura_document_t* document,
|
void zathura_document_get_cell_size(zathura_document_t* document,
|
||||||
unsigned int* height, unsigned int* width);
|
unsigned int* height, unsigned int* width);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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] document The document
|
||||||
|
* @param[out] height,width The height and width of the document
|
||||||
|
*/
|
||||||
|
void zathura_document_get_document_size(zathura_document_t* document,
|
||||||
|
unsigned int* height, unsigned int* width);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the layout of the pages in the document
|
* Sets the layout of the pages in the document
|
||||||
*
|
*
|
||||||
|
|
|
@ -144,8 +144,7 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
|
|
||||||
zathura_document_set_scale(zathura->document, scale);
|
zathura_document_set_scale(zathura->document, scale);
|
||||||
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
|
||||||
zathura_get_document_size(zathura, cell_height, cell_width,
|
zathura_document_get_document_size(zathura->document, &document_height, &document_width);
|
||||||
&document_height, &document_width);
|
|
||||||
|
|
||||||
double page_ratio = (double)cell_height / (double)document_width;
|
double page_ratio = (double)cell_height / (double)document_width;
|
||||||
double window_ratio = (double)height / (double)width;
|
double window_ratio = (double)height / (double)width;
|
||||||
|
@ -162,8 +161,7 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
|
||||||
if (show_vscrollbar) {
|
if (show_vscrollbar) {
|
||||||
/* If the document is taller than the view, there's a vertical
|
/* If the document is taller than the view, there's a vertical
|
||||||
* scrollbar; we need to substract its width from the view's width. */
|
* scrollbar; we need to substract its width from the view's width. */
|
||||||
zathura_get_document_size(zathura, cell_height, cell_width,
|
zathura_document_get_document_size(zathura->document, &document_height, &document_width);
|
||||||
&document_height, &document_width);
|
|
||||||
if (height < document_height) {
|
if (height < document_height) {
|
||||||
GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar(
|
GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar(
|
||||||
GTK_SCROLLED_WINDOW(session->gtk.view));
|
GTK_SCROLLED_WINDOW(session->gtk.view));
|
||||||
|
|
36
utils.c
36
utils.c
|
@ -262,42 +262,6 @@ page_calc_height_width(zathura_document_t* document, double height, double width
|
||||||
return real_scale;
|
return real_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
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*
|
GtkWidget*
|
||||||
zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page)
|
zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page)
|
||||||
|
|
17
utils.h
17
utils.h
|
@ -99,23 +99,6 @@ double
|
||||||
page_calc_height_width(zathura_document_t* document, double height, double width,
|
page_calc_height_width(zathura_document_t* document, double height, double width,
|
||||||
unsigned int* page_height, unsigned int* page_width, bool rotate);
|
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
|
* Returns the page widget of the page
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue