A document is laid out on a homogeneous gtk table/grid. This new method,
zathura_document_get_cell_size, computes the size of the cells in that
table/grid, at the current scale.
---
 document.c |   28 ++++++++++++++++++++++++++++
 document.h |    9 +++++++++
 2 files changed, 37 insertions(+)

diff --git a/document.c b/document.c
index fb62d6d..ca0f241 100644
--- a/document.c
+++ b/document.c
@@ -389,6 +389,34 @@ zathura_document_set_page_offset(zathura_document_t* 
document, unsigned int page
   }
 }
 
+void
+zathura_document_get_cell_size(zathura_document_t* document,
+                               unsigned int* height, unsigned int* width)
+{
+  g_return_if_fail(document != NULL && height != NULL && width != NULL);
+
+  unsigned int number_of_pages =
+    zathura_document_get_number_of_pages(document);
+  *width = 0;
+  *height = 0;
+
+  /* Get the size of each cell of the table/grid, assuming it is homogeneous
+   * (i.e. each cell has the same dimensions. */
+  for (unsigned int page_id = 0; page_id < number_of_pages; page_id++) {
+    zathura_page_t* page = zathura_document_get_page(document, page_id);
+    if (page == NULL)
+      continue;
+
+    unsigned int page_width = 0, page_height = 0;
+    page_calc_height_width(page, &page_height, &page_width, true);
+
+    if (*width < page_width)
+      *width = page_width;
+    if (*height < page_height)
+      *height = page_height;
+  }
+}
+
 zathura_error_t
 zathura_document_save_as(zathura_document_t* document, const char* path)
 {
diff --git a/document.h b/document.h
index 712fd5b..b4dc6fa 100644
--- a/document.h
+++ b/document.h
@@ -170,6 +170,15 @@ void* zathura_document_get_data(zathura_document_t* 
document);
 void zathura_document_set_data(zathura_document_t* document, void* data);
 
 /**
+ * Computes 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.
+ *
+ * @param[in]  document     The document instance
+ * @param[out] height,width The computed height and width of the cell
+ */
+void zathura_document_get_cell_size(zathura_document_t* document,
+                                    unsigned int* height, unsigned int* width);
+
+/**
  * Save the document
  *
  * @param document The document object
-- 
1.7.10.4

_______________________________________________
zathura mailing list
zathura@lists.pwmt.org
http://lists.pwmt.org/mailman/listinfo/zathura

Reply via email to