From 13fb90a1f80e842b3f248e87addd20671f3848be 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 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. https://bugs.freedesktop.org/show_bug.cgi?id=70901 --- glib/poppler-annot.cc | 49 +++++++++++++++++++++++++++++++++++ glib/poppler-annot.h | 3 +++ glib/reference/poppler-sections.txt | 2 ++ 3 files changed, 54 insertions(+) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 419f298..b05d124 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 @@ -678,6 +679,54 @@ poppler_annot_get_page_index (PopplerAnnot *poppler_annot) return page_num <= 0 ? -1 : page_num - 1; } +/** + * poppler_annot_get_rectangle: + * @poppler_annot: a #PopplerAnnot + * + * Retrieves the rectangle representing the page coordinates where the + * annotation @poppler_annot is placed. + * + * Return value: A #PopplerRectangle with annotation's coordinates + * + * Since: 0.26 + */ +PopplerRectangle +poppler_annot_get_rectangle (PopplerAnnot *poppler_annot) +{ + PDFRectangle *annot_rect; + PopplerRectangle poppler_rect = { 0, 0, 0, 0 }; + + g_return_val_if_fail (POPPLER_IS_ANNOT (poppler_annot), poppler_rect); + + annot_rect = poppler_annot->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 poppler_rect; +} + +/** + * 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.26 + */ +void +poppler_annot_set_rectangle (PopplerAnnot *poppler_annot, + PopplerRectangle poppler_rect) +{ + g_return_if_fail (POPPLER_IS_ANNOT (poppler_annot)); + + poppler_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 9c82f9a..e88c9b4 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -186,6 +186,9 @@ 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); +PopplerRectangle poppler_annot_get_rectangle (PopplerAnnot *poppler_annot); +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 5e5e413..a2fb25f 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -392,6 +392,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