mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 21:26:01 +01:00
Calculate page offset
This commit is contained in:
parent
a415666cc1
commit
dc7c3d86eb
5 changed files with 93 additions and 1 deletions
2
config.c
2
config.c
|
@ -21,6 +21,8 @@ config_load_default(zathura_t* zathura)
|
|||
/* zathura settings */
|
||||
int_value = 10;
|
||||
girara_setting_add(gsession, "zoom-step", &int_value, INT, false, "Zoom step", NULL);
|
||||
int_value = 1;
|
||||
girara_setting_add(gsession, "page-padding", &int_value, INT, true, "Padding between pages", NULL);
|
||||
int_value = 2;
|
||||
girara_setting_add(gsession, "pages-per-row", &int_value, INT, false, "Number of pages per row", NULL);
|
||||
|
||||
|
|
65
utils.c
65
utils.c
|
@ -178,7 +178,8 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_node_
|
|||
} while ((it = girara_list_iterator_next(it)));
|
||||
}
|
||||
|
||||
char* string_concat(const char* string1, ...)
|
||||
char*
|
||||
string_concat(const char* string1, ...)
|
||||
{
|
||||
if(!string1) {
|
||||
return NULL;
|
||||
|
@ -234,3 +235,65 @@ char* string_concat(const char* string1, ...)
|
|||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
page_offset_t*
|
||||
page_offset_top(zathura_page_t* page)
|
||||
{
|
||||
if (page == NULL || page->document == NULL || page->document->zathura == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
page_offset_t* offset = malloc(sizeof(page_offset_t));
|
||||
|
||||
if (offset == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zathura_document_t* document = page->document;
|
||||
zathura_t* zathura = document->zathura;
|
||||
|
||||
int* tmp = girara_setting_get(zathura->ui.session, "pages-per-row");
|
||||
|
||||
unsigned int page_padding = zathura->global.page_padding;
|
||||
unsigned int pages_per_row = (tmp && *tmp != 0) ? *tmp : 1;
|
||||
unsigned int number_of_rows = (document->number_of_pages / pages_per_row) + 1;
|
||||
|
||||
free(tmp);
|
||||
|
||||
for (unsigned int row = 0; row < number_of_rows; row++) {
|
||||
unsigned int tmp = -1;
|
||||
for (unsigned int column = 0; column < pages_per_row; column++)
|
||||
{
|
||||
unsigned int page_id = row * pages_per_row + column;
|
||||
double page_height = document->pages[page_id]->height * document->scale;
|
||||
|
||||
if (tmp == -1) {
|
||||
tmp = page_height;
|
||||
} else if (page_height > tmp) {
|
||||
tmp = page_height;
|
||||
}
|
||||
}
|
||||
|
||||
offset->y += tmp + (row == (number_of_rows - 1)) ? 0 : page_padding;
|
||||
}
|
||||
|
||||
for (unsigned int column = 0; column < pages_per_row; column++) {
|
||||
unsigned int tmp = -1;
|
||||
for (unsigned int row = 0; row < number_of_rows; row++)
|
||||
{
|
||||
unsigned int page_id = row * pages_per_row + column;
|
||||
double page_width = document->pages[page_id]->width * document->scale;
|
||||
|
||||
if (tmp == -1) {
|
||||
tmp = page_width;
|
||||
} else if (page_width > tmp) {
|
||||
tmp = page_width;
|
||||
}
|
||||
}
|
||||
|
||||
offset->x += tmp + (column == (pages_per_row - 1)) ? 0 : page_padding;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
|
17
utils.h
17
utils.h
|
@ -7,6 +7,14 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <girara.h>
|
||||
|
||||
#include "document.h"
|
||||
|
||||
typedef struct page_offset_s
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
} page_offset_t;
|
||||
|
||||
/**
|
||||
* Checks if the given file exists
|
||||
*
|
||||
|
@ -61,4 +69,13 @@ void document_index_build(GtkTreeModel* model, GtkTreeIter* parent, girara_tree_
|
|||
*/
|
||||
char* string_concat(const char* string1, ...);
|
||||
|
||||
/**
|
||||
* Calculates the offset of the page to the top of the viewing area as
|
||||
* well as to the left side of it. The result has to be freed.
|
||||
*
|
||||
* @param page The Page
|
||||
* @return The calculated offset or NULL if an error occured
|
||||
*/
|
||||
page_offset_t* page_calculate_offset(zathura_page_t* page);
|
||||
|
||||
#endif // UTILS_H
|
||||
|
|
|
@ -148,6 +148,11 @@ zathura_init(int argc, char* argv[])
|
|||
/* configuration */
|
||||
config_load_default(zathura);
|
||||
|
||||
/* save page padding */
|
||||
int* page_padding = girara_setting_get(zathura->ui.session, "page-padding");
|
||||
zathura->global.page_padding = (page_padding) ? *page_padding : 1;
|
||||
|
||||
/* open document if passed */
|
||||
if (argc > 1) {
|
||||
zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t));
|
||||
|
||||
|
|
|
@ -65,6 +65,11 @@ typedef struct zathura_s
|
|||
gchar* data_dir;
|
||||
} config;
|
||||
|
||||
struct
|
||||
{
|
||||
unsigned int page_padding;
|
||||
} global;
|
||||
|
||||
zathura_document_t* document; /**> The current document */
|
||||
} zathura_t;
|
||||
|
||||
|
|
Loading…
Reference in a new issue