diff --git a/document.c b/document.c index 6586392..9125f0b 100644 --- a/document.c +++ b/document.c @@ -52,9 +52,13 @@ struct zathura_document_s { int page_offset; /**< Page offset */ double cell_width; /**< width of a page cell in the document (not ransformed by scale and rotation) */ double cell_height; /**< height of a page cell in the document (not ransformed by scale and rotation) */ + unsigned int view_width; /**< width of current viewport */ + unsigned int view_height; /**< height of current viewport */ unsigned int pages_per_row; /**< number of pages in a row */ unsigned int first_page_column; /**< column of the first page */ unsigned int page_padding; /**< padding between pages */ + double position_x; /**< X adjustment */ + double position_y; /**< Y adjustment */ /** * Document pages @@ -131,6 +135,10 @@ zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char* document->adjust_mode = ZATHURA_ADJUST_NONE; document->cell_width = 0.0; document->cell_height = 0.0; + document->view_height = 0; + document->view_width = 0; + document->position_x = 0.0; + document->position_y = 0.0; /* open document */ zathura_plugin_functions_t* functions = zathura_plugin_get_functions(plugin); @@ -326,6 +334,46 @@ zathura_document_set_current_page_number(zathura_document_t* document, unsigned document->current_page_number = current_page; } +double +zathura_document_get_position_x(zathura_document_t* document) +{ + if (document == NULL) { + return 0; + } + + return document->position_x; +} + +double +zathura_document_get_position_y(zathura_document_t* document) +{ + if (document == NULL) { + return 0; + } + + return document->position_y; +} + +void +zathura_document_set_position_x(zathura_document_t* document, double position_x) +{ + if (document == NULL) { + return; + } + + document->position_x = position_x; +} + +void +zathura_document_set_position_y(zathura_document_t* document, double position_y) +{ + if (document == NULL) { + return; + } + + document->position_y = position_y; +} + double zathura_document_get_scale(zathura_document_t* document) { @@ -416,6 +464,33 @@ zathura_document_set_page_offset(zathura_document_t* document, unsigned int page document->page_offset = page_offset; } +void +zathura_document_set_viewport_width(zathura_document_t* document, unsigned int width) +{ + if (document == NULL) { + return; + } + document->view_width = width; +} + +void +zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height) +{ + if (document == NULL) { + return; + } + document->view_height = height; +} + +void +zathura_document_get_viewport_size(zathura_document_t* document, + unsigned int *height, unsigned int* width) +{ + g_return_if_fail(document != NULL && height != NULL && width != NULL); + *height = document->view_height; + *width = document->view_width; +} + void zathura_document_get_cell_size(zathura_document_t* document, unsigned int* height, unsigned int* width) diff --git a/document.h b/document.h index 03cb778..4b23125 100644 --- a/document.h +++ b/document.h @@ -97,6 +97,42 @@ unsigned int zathura_document_get_current_page_number(zathura_document_t* docume void zathura_document_set_current_page_number(zathura_document_t* document, unsigned int current_page); +/** + * Returns the X position, as a value relative to the document width (0=left, + * 1=right). + * + * @param document The document + * @return X adjustment + */ +double zathura_document_get_position_x(zathura_document_t* document); + +/** + * Returns the Y position as value relative to the document height (0=top, + * 1=bottom) + * + * @param document The document + * @return Y adjustment + */ +double zathura_document_get_position_y(zathura_document_t* document); + +/** + * Sets the X position as a value relative to the document width (0=left, + * 1=right) + * + * @param document The document + * @param position_x the X adjustment + */ +void zathura_document_set_position_x(zathura_document_t* document, double position_x); + +/** + * Sets the Y position as a value relative to the document height (0=top, + * 1=bottom) + * + * @param document The document + * @param position_y the Y adjustment + */ +void zathura_document_set_position_y(zathura_document_t* document, double position_y); + /** * Returns the current scale value of the document * @@ -178,9 +214,37 @@ void* zathura_document_get_data(zathura_document_t* document); void zathura_document_set_data(zathura_document_t* document, void* data); /** - * Return the size of a cell in the document's layout table, assuming that - * the table is homogeneous (i.e. every cell has the same dimensions). It takes - * the current scale into account. + * Sets the width of the viewport in pixels. + * + * @param[in] document The document instance + * @param[in] width The width of the viewport + */ +void +zathura_document_set_viewport_width(zathura_document_t* document, unsigned int width); + +/** + * Sets the height of the viewport in pixels. + * + * @param[in] document The document instance + * @param[in] height The height of the viewport + */ +void +zathura_document_set_viewport_height(zathura_document_t* document, unsigned int height); + +/** + * Return the size of the viewport in pixels. + * + * @param[in] document The document instance + * @param[out] height,width The width and height of the viewport + */ +void +zathura_document_get_viewport_size(zathura_document_t* document, + unsigned int *height, unsigned int* width); + +/** + * Return the size of a cell from the document's layout table in pixels. Assumes + * that the table is homogeneous (i.e. every cell has the same dimensions). It + * takes the current scale into account. * * @param[in] document The document instance * @param[out] height,width The computed height and width of the cell @@ -189,10 +253,9 @@ void zathura_document_get_cell_size(zathura_document_t* document, 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. + * Compute the size of the entire document to be displayed in pixels. Takes 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