From 6ec9b4aa1a9957f90c3b35898faf9332e15305c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Sat, 28 Sep 2013 23:18:07 -0700 Subject: [PATCH] glib: Add getter and setter for annotation's rectangle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Annotation objects contain at least two keys, Rect and Subtype. The former has the coordinates where the annotation is placed. The getter and setter allows to obtain and modify the position of a given annotation. Signed-off-by: Germán Poo-Caamaño --- glib/poppler-annot.cc | 58 +++++++++++++++++++++++++++++++++++ glib/poppler-annot.h | 4 +++ glib/reference/poppler-sections.txt | 2 ++ 3 files changed, 64 insertions(+) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index f261ced..1a76fdc 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -2,6 +2,7 @@ * * Copyright (C) 2007 Inigo Martinez * Copyright (C) 2009 Carlos Garcia Campos + * Copyright (C) 2013 German Poo-Caamano * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -674,6 +675,63 @@ poppler_annot_get_page_index (PopplerAnnot *poppler_annot) return page_num <= 0 ? -1 : page_num - 1; } +/** + * poppler_annot_get_rectangle: + * @poppler_annot: a #PopplerAnnot + * @poppler_rect: (out): a #PopplerRectangle to store the annotation's coordinates + * + * Retrieves the rectangle representing the page coordinates where the + * annotation @poppler_annot is placed. + * + * Return value: %TRUE if #PopplerRectangle was correctly filled, %FALSE otherwise + * + * Since: 0.25 + **/ +gboolean +poppler_annot_get_rectangle (PopplerAnnot *poppler_annot, + PopplerRectangle *poppler_rect) +{ + Annot *annot; + PDFRectangle *annot_rect; + + g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), FALSE); + g_return_val_if_fail (poppler_rect != NULL, FALSE); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + annot_rect = annot->getRect (); + poppler_rect->x1 = annot_rect->x1; + poppler_rect->x2 = annot_rect->x2; + poppler_rect->y1 = annot_rect->y1; + poppler_rect->y2 = annot_rect->y2; + + return TRUE; +} + +/** + * poppler_annot_set_rectangle: + * @poppler_annot: a #PopplerAnnot + * @poppler_rect: a #PopplerRectangle with the new annotation's coordinates + * + * Move the annotation to the rectangle representing the page coordinates where the + * annotation @poppler_annot should be placed. + * + * Since: 0.25 + **/ +void +poppler_annot_set_rectangle (PopplerAnnot *poppler_annot, + PopplerRectangle poppler_rect) +{ + Annot *annot; + + g_return_if_fail (POPPLER_IS_ANNOT (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + annot->setRect (poppler_rect.x1, poppler_rect.y1, + poppler_rect.x2, poppler_rect.y2); +} + /* PopplerAnnotMarkup */ /** * poppler_annot_markup_get_label: diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h index cf76973..01c72cd 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -172,6 +172,10 @@ PopplerColor *poppler_annot_get_color ( void poppler_annot_set_color (PopplerAnnot *poppler_annot, PopplerColor *poppler_color); gint poppler_annot_get_page_index (PopplerAnnot *poppler_annot); +gboolean poppler_annot_get_rectangle (PopplerAnnot *poppler_annot, + PopplerRectangle *poppler_rect); +void poppler_annot_set_rectangle (PopplerAnnot *poppler_annot, + PopplerRectangle poppler_rect); /* PopplerAnnotMarkup */ GType poppler_annot_markup_get_type (void) G_GNUC_CONST; diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 4b69112..b77054c 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -390,6 +390,8 @@ poppler_annot_set_color poppler_annot_get_contents poppler_annot_set_contents poppler_annot_get_modified +poppler_annot_get_rectangle +poppler_annot_set_rectangle poppler_annot_markup_get_label poppler_annot_markup_set_label poppler_annot_markup_get_subject -- 1.7.9.5