From 41f72808a37e318fa822491b6312c1e7a79eef26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Poo-Caama=C3=B1o?= Date: Mon, 28 Oct 2013 22:26:49 -0700 Subject: [PATCH 1/9] glib: Add support for simple line annotations --- glib/poppler-annot.cc | 175 +++++++++++++++++++++++++++++++++++ glib/poppler-annot.h | 31 +++++++ glib/poppler-page.cc | 3 + glib/poppler-private.h | 1 + glib/poppler.h | 1 + glib/reference/poppler-sections.txt | 14 +++ 6 files changed, 225 insertions(+) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 31cc081..20361e9 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -35,6 +35,7 @@ typedef struct _PopplerAnnotTextClass PopplerAnnotTextClass; typedef struct _PopplerAnnotFileAttachmentClass PopplerAnnotFileAttachmentClass; typedef struct _PopplerAnnotMovieClass PopplerAnnotMovieClass; typedef struct _PopplerAnnotScreenClass PopplerAnnotScreenClass; +typedef struct _PopplerAnnotLineClass PopplerAnnotLineClass; struct _PopplerAnnotClass { @@ -105,6 +106,15 @@ struct _PopplerAnnotScreenClass PopplerAnnotClass parent_class; }; +struct _PopplerAnnotLine +{ + PopplerAnnotMarkup parent_instance; +}; + +struct _PopplerAnnotLineClass +{ + PopplerAnnotMarkupClass parent_class; +}; G_DEFINE_TYPE (PopplerAnnot, poppler_annot, G_TYPE_OBJECT) G_DEFINE_TYPE (PopplerAnnotMarkup, poppler_annot_markup, POPPLER_TYPE_ANNOT) @@ -113,6 +123,7 @@ G_DEFINE_TYPE (PopplerAnnotFreeText, poppler_annot_free_text, POPPLER_TYPE_ANNOT G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLER_TYPE_ANNOT_MARKUP) G_DEFINE_TYPE (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT) G_DEFINE_TYPE (PopplerAnnotScreen, poppler_annot_screen, POPPLER_TYPE_ANNOT) +G_DEFINE_TYPE (PopplerAnnotLine, poppler_annot_line, POPPLER_TYPE_ANNOT_MARKUP) static PopplerAnnot * _poppler_create_annot (GType annot_type, Annot *annot) @@ -324,6 +335,48 @@ _poppler_annot_screen_new (Annot *annot) return poppler_annot; } +PopplerAnnot * +_poppler_annot_line_new (Annot *annot) +{ + return _poppler_create_annot (POPPLER_TYPE_ANNOT_LINE, annot); +} + +static void +poppler_annot_line_init (PopplerAnnotLine *poppler_annot) +{ +} + +static void +poppler_annot_line_class_init (PopplerAnnotLineClass *klass) +{ +} + +/** +* poppler_annot_line_new: + * @doc: a #PopplerDocument + * @rect: a #PopplerRectangle + * + * Creates a new Line annotation that will be + * located on @rect when added to a page. See + * poppler_page_add_annot() + * + * Return value: A newly #PopplerAnnotLine annotation + * + * Since: 0.25 +**/ +PopplerAnnot * +poppler_annot_line_new (PopplerDocument *doc, + PopplerRectangle *rect) +{ + Annot *annot; + PDFRectangle pdf_rect(rect->x1, rect->y1, + rect->x2, rect->y2); + + annot = new AnnotLine (doc->doc, &pdf_rect); + + return _poppler_annot_line_new (annot); +} + /* Public methods */ /** @@ -1384,3 +1437,125 @@ poppler_annot_screen_get_action (PopplerAnnotScreen *poppler_annot) { return poppler_annot->action; } + +/* PopplerAnnotLine */ +void +poppler_annot_line_set_width (PopplerAnnotLine *poppler_annot, gdouble width) +{ + AnnotLine *annot; + + g_return_if_fail (POPPLER_IS_ANNOT_LINE (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + annot->setLeaderLineLength(width); + annot->setLeaderLineExtension(width); + // annot->setOpacitiy(0.5); +} + +void +poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot, + gdouble x1, gdouble y1, + gdouble x2, gdouble y2) +{ + AnnotLine *annot; + + g_return_if_fail (POPPLER_IS_ANNOT_LINE (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + annot->setVertices (x1, y1, x2, y2); +} + +static PopplerAnnotLineEndingStyle +_poppler_annot_line_get_style (AnnotLineEndingStyle ending_style) +{ + switch (ending_style) + { + case annotLineEndingSquare: + return POPPLER_ANNOT_LINE_ENDING_STYLE_SQUARE; + case annotLineEndingCircle: + return POPPLER_ANNOT_LINE_ENDING_STYLE_CIRCLE; + case annotLineEndingDiamond: + return POPPLER_ANNOT_LINE_ENDING_STYLE_DIAMOND; + case annotLineEndingOpenArrow: + return POPPLER_ANNOT_LINE_ENDING_STYLE_OPENARROW; + case annotLineEndingClosedArrow: + return POPPLER_ANNOT_LINE_ENDING_STYLE_CLOSEDARROW; + case annotLineEndingNone: + return POPPLER_ANNOT_LINE_ENDING_STYLE_NONE; + case annotLineEndingButt: + return POPPLER_ANNOT_LINE_ENDING_STYLE_BUTT; + case annotLineEndingROpenArrow: + return POPPLER_ANNOT_LINE_ENDING_STYLE_ROPENARROW; + case annotLineEndingRClosedArrow: + return POPPLER_ANNOT_LINE_ENDING_STYLE_RCLOSEDARROW; + case annotLineEndingSlash: + return POPPLER_ANNOT_LINE_ENDING_STYLE_SLASH; + } + + return POPPLER_ANNOT_LINE_ENDING_STYLE_NONE; +} + +/** + * poppler_annot_line_get_start_style: + * @poppler_annot: a #PopplerAnnotLine + * + * Return value: (transfer none): The ending style located at the start of the line. + * + * Since: 0.25 + **/ +PopplerAnnotLineEndingStyle +poppler_annot_line_get_start_style (PopplerAnnotLine *poppler_annot) +{ + AnnotLine *annot; + + g_return_val_if_fail (POPPLER_IS_ANNOT_LINE (poppler_annot), + POPPLER_ANNOT_LINE_ENDING_STYLE_NONE); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + return _poppler_annot_line_get_style (annot->getStartStyle ()); +} + +/** + * poppler_annot_line_get_end_style: + * @poppler_annot: a #PopplerAnnot + * + * Return value: (transfer none): The ending style located at the end of the line. + * + * Since: 0.25 + **/ +PopplerAnnotLineEndingStyle +poppler_annot_line_get_end_style (PopplerAnnotLine *poppler_annot) +{ + AnnotLine *annot; + + g_return_val_if_fail (POPPLER_IS_ANNOT_LINE (poppler_annot), + POPPLER_ANNOT_LINE_ENDING_STYLE_NONE); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + return _poppler_annot_line_get_style (annot->getEndStyle ()); +} + +/** + * poppler_annot_line_set_ending_style: + * @poppler_annot: a #PopplerAnnot + * @start_style: a #PopplerAnnotLineEndingStyle to set the style at the start of the line + * @end_style: a #PopplerAnnotLineEndingStyle to set the style at the end of the line + * + * Since: 0.25 + **/ +void +poppler_annot_line_set_ending_style (PopplerAnnotLine *poppler_annot, + PopplerAnnotLineEndingStyle start_style, + PopplerAnnotLineEndingStyle end_style) +{ + AnnotLine *annot; + + g_return_if_fail (POPPLER_IS_ANNOT_LINE (poppler_annot)); + + annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + + annot->setStartEndStyle ((AnnotLineEndingStyle)start_style, + (AnnotLineEndingStyle)end_style); +} diff --git a/glib/poppler-annot.h b/glib/poppler-annot.h index 88f4e46..9c82f9a 100644 --- a/glib/poppler-annot.h +++ b/glib/poppler-annot.h @@ -54,6 +54,10 @@ G_BEGIN_DECLS #define POPPLER_ANNOT_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_SCREEN, PopplerAnnotScreen)) #define POPPLER_IS_ANNOT_SCREEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_SCREEN)) +#define POPPLER_TYPE_ANNOT_LINE (poppler_annot_line_get_type ()) +#define POPPLER_ANNOT_LINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT_LINE, PopplerAnnotLine)) +#define POPPLER_IS_ANNOT_LINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_LINE)) + #define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ()) @@ -143,6 +147,20 @@ typedef enum POPPLER_ANNOT_FREE_TEXT_QUADDING_RIGHT_JUSTIFIED } PopplerAnnotFreeTextQuadding; +typedef enum +{ + POPPLER_ANNOT_LINE_ENDING_STYLE_SQUARE, + POPPLER_ANNOT_LINE_ENDING_STYLE_CIRCLE, + POPPLER_ANNOT_LINE_ENDING_STYLE_DIAMOND, + POPPLER_ANNOT_LINE_ENDING_STYLE_OPENARROW, + POPPLER_ANNOT_LINE_ENDING_STYLE_CLOSEDARROW, + POPPLER_ANNOT_LINE_ENDING_STYLE_NONE, + POPPLER_ANNOT_LINE_ENDING_STYLE_BUTT, + POPPLER_ANNOT_LINE_ENDING_STYLE_ROPENARROW, + POPPLER_ANNOT_LINE_ENDING_STYLE_RCLOSEDARROW, + POPPLER_ANNOT_LINE_ENDING_STYLE_SLASH +} PopplerAnnotLineEndingStyle; + struct _PopplerAnnotCalloutLine { gboolean multiline; @@ -221,6 +239,19 @@ PopplerMovie *poppler_annot_movie_get_movie ( GType poppler_annot_screen_get_type (void) G_GNUC_CONST; PopplerAction *poppler_annot_screen_get_action (PopplerAnnotScreen *poppler_annot); +/* PopplerAnnotLine */ +GType poppler_annot_line_get_type (void) G_GNUC_CONST; +PopplerAnnot *poppler_annot_line_new (PopplerDocument *doc, + PopplerRectangle *rect); +void poppler_annot_line_set_width (PopplerAnnotLine *poppler_annot, gdouble width); +void poppler_annot_line_set_vertices (PopplerAnnotLine *poppler_annot, gdouble x1, gdouble y1, + gdouble x2, gdouble y2); +PopplerAnnotLineEndingStyle poppler_annot_line_get_start_style (PopplerAnnotLine *poppler_annot); +PopplerAnnotLineEndingStyle poppler_annot_line_get_end_style (PopplerAnnotLine *poppler_annot); +void poppler_annot_line_set_ending_style (PopplerAnnotLine *poppler_annot, + PopplerAnnotLineEndingStyle start_style, + PopplerAnnotLineEndingStyle end_style); + /* PopplerAnnotCalloutLine */ GType poppler_annot_callout_line_get_type (void) G_GNUC_CONST; PopplerAnnotCalloutLine *poppler_annot_callout_line_new (void); diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 9115b78..20fccb6 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1375,6 +1375,9 @@ poppler_page_get_annot_mapping (PopplerPage *page) case Annot::typeScreen: mapping->annot = _poppler_annot_screen_new (annot); break; + case Annot::typeLine: + mapping->annot = _poppler_annot_line_new (annot); + break; default: mapping->annot = _poppler_annot_new (annot); break; diff --git a/glib/poppler-private.h b/glib/poppler-private.h index ab39b49..bebe0c8 100644 --- a/glib/poppler-private.h +++ b/glib/poppler-private.h @@ -120,6 +120,7 @@ PopplerAnnot *_poppler_annot_free_text_new (Annot *annot); PopplerAnnot *_poppler_annot_file_attachment_new (Annot *annot); PopplerAnnot *_poppler_annot_movie_new (Annot *annot); PopplerAnnot *_poppler_annot_screen_new (Annot *annot); +PopplerAnnot *_poppler_annot_line_new (Annot *annot); char *_poppler_goo_string_to_utf8(GooString *s); gboolean _poppler_convert_pdf_date_to_gtime (GooString *date, diff --git a/glib/poppler.h b/glib/poppler.h index 2d190f3..a023515 100644 --- a/glib/poppler.h +++ b/glib/poppler.h @@ -202,6 +202,7 @@ typedef struct _PopplerAnnotFileAttachment PopplerAnnotFileAttachment; typedef struct _PopplerAnnotMovie PopplerAnnotMovie; typedef struct _PopplerAnnotScreen PopplerAnnotScreen; typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; +typedef struct _PopplerAnnotLine PopplerAnnotLine; typedef enum { diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt index 6fb14bc..5e5e413 100644 --- a/glib/reference/poppler-sections.txt +++ b/glib/reference/poppler-sections.txt @@ -372,6 +372,8 @@ PopplerAnnotMarkup PopplerAnnotText PopplerAnnotFreeText PopplerAnnotFileAttachment +PopplerAnnotLine +PopplerAnnotLineEndingStyle PopplerAnnotMovie PopplerAnnotScreen PopplerAnnotType @@ -428,6 +430,13 @@ poppler_annot_movie_get_title poppler_annot_callout_line_new poppler_annot_callout_line_copy poppler_annot_callout_line_free +poppler_annot_line_new +poppler_annot_line_set_vertices +poppler_annot_line_set_width +poppler_annot_line_ending_style_get_type +poppler_annot_line_get_end_style +poppler_annot_line_get_start_style +poppler_annot_line_set_ending_style POPPLER_ANNOT @@ -439,6 +448,9 @@ POPPLER_TYPE_ANNOT_FILE_ATTACHMENT POPPLER_ANNOT_FREE_TEXT POPPLER_IS_ANNOT_FREE_TEXT POPPLER_TYPE_ANNOT_FREE_TEXT +POPPLER_ANNOT_LINE +POPPLER_IS_ANNOT_LINE +POPPLER_TYPE_ANNOT_LINE POPPLER_ANNOT_MARKUP POPPLER_IS_ANNOT_MARKUP POPPLER_TYPE_ANNOT_MARKUP @@ -454,6 +466,7 @@ POPPLER_TYPE_ANNOT_TEXT POPPLER_TYPE_ANNOT_CALLOUT_LINE POPPLER_TYPE_ANNOT_EXTERNAL_DATA_TYPE POPPLER_TYPE_ANNOT_FLAG +POPPLER_TYPE_ANNOT_LINE_ENDING_STYLE POPPLER_TYPE_ANNOT_MARKUP_REPLY_TYPE POPPLER_TYPE_ANNOT_TEXT_STATE POPPLER_TYPE_ANNOT_FREE_TEXT_QUADDING @@ -474,6 +487,7 @@ poppler_annot_markup_reply_type_get_type poppler_annot_callout_line_get_type poppler_annot_text_state_get_type poppler_annot_free_text_quadding_get_type +poppler_annot_line_get_type
-- 1.7.9.5