From aaa5467305018706bf037f5bb63525f0cc28c37a Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 23 Jun 2014 21:13:54 +0200 Subject: [PATCH] Document nrow computation Signed-off-by: Sebastian Ramacher --- adjustment.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/adjustment.c b/adjustment.c index 8d2b513..f8392fb 100644 --- a/adjustment.c +++ b/adjustment.c @@ -63,9 +63,17 @@ position_to_page_number(zathura_document_t* document, double pos_x, unsigned int c0 = zathura_document_get_first_page_column(document); unsigned int npag = zathura_document_get_number_of_pages(document); unsigned int ncol = zathura_document_get_pages_per_row(document); - unsigned int nrow = (npag + c0 - 1 + ncol - 1) / ncol; /* number of rows */ + unsigned int nrow = 0; unsigned int pad = zathura_document_get_page_padding(document); + if (c0 == 1) { + /* There is no offset, so this is easy. */ + nrow = (npag + ncol - 1) / ncol; + } else { + /* If there is a offset, we handle the first row extra. */ + nrow = 1 + (npag - (ncol - c0 - 1) + (ncol - 1)) / ncol; + } + unsigned int col = floor(pos_x * (double)doc_width / (double)(cell_width + pad)); unsigned int row = floor(pos_y * (double)doc_height / (double)(cell_height + pad));