Index: glib/Makefile.am =================================================================== RCS file: /cvs/poppler/poppler/glib/Makefile.am,v retrieving revision 1.18 diff -u -r1.18 Makefile.am --- glib/Makefile.am 15 Mar 2007 20:16:13 -0000 1.18 +++ glib/Makefile.am 10 Jun 2007 23:46:14 -0000 @@ -62,6 +62,7 @@ poppler-document.h \ poppler-page.h \ poppler-attachment.h \ + poppler-annot.h \ poppler.h poppler_glib_includedir = $(includedir)/poppler/glib @@ -78,6 +79,7 @@ poppler-document.cc \ poppler-page.cc \ poppler-attachment.cc \ + poppler-annot.cc \ poppler.cc \ poppler-private.h Index: glib/poppler-annot.cc =================================================================== RCS file: glib/poppler-annot.cc diff -N glib/poppler-annot.cc --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ glib/poppler-annot.cc 10 Jun 2007 23:46:15 -0000 @@ -0,0 +1,862 @@ +/* poppler-annot.cc: glib wrapper for poppler + * Copyright (C) 2007, Iñigo Martinez . + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "poppler.h" +#include "poppler-private.h" + +GType +poppler_annot_color_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotColor", + (GBoxedCopyFunc) poppler_annot_color_copy, + (GBoxedFreeFunc) poppler_annot_color_free); + return our_type; +} + +PopplerAnnotColor * +poppler_annot_color_new (void) +{ + return g_new0 (PopplerAnnotColor, 1); +} + +PopplerAnnotColor * +poppler_annot_color_copy (PopplerAnnotColor *color) +{ + PopplerAnnotColor *new_color; + + g_return_val_if_fail (color, NULL); + + new_color = (PopplerAnnotColor *) g_memdup (color, + sizeof (PopplerAnnotColor)); + return new_color; +} + +void +poppler_annot_color_free (PopplerAnnotColor *color) +{ + if (!color) + return; + + g_free (color); +} + +GType +poppler_annot_callout_line_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotCalloutLine", + (GBoxedCopyFunc) poppler_annot_callout_line_copy, + (GBoxedFreeFunc) poppler_annot_callout_line_free); + return our_type; +} + +PopplerAnnotCalloutLine * +poppler_annot_callout_line_new (void) +{ + return g_new0 (PopplerAnnotCalloutLine, 1); +} + +PopplerAnnotCalloutLine * +poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *line) +{ + PopplerAnnotCalloutLine *new_line; + + g_return_val_if_fail (line, NULL); + + new_line = (PopplerAnnotCalloutLine *) g_memdup (line, + sizeof (PopplerAnnotCalloutLine)); + return new_line; +} + +void +poppler_annot_callout_line_free (PopplerAnnotCalloutLine *line) +{ + if (!line) + return; + + g_free (line); +} + +GType +poppler_annot_border_effect_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotBorderEffect", + (GBoxedCopyFunc) poppler_annot_border_effect_copy, + (GBoxedFreeFunc) poppler_annot_border_effect_free); + return our_type; +} + +PopplerAnnotBorderEffect * +poppler_annot_border_effect_new (void) +{ + return g_new0 (PopplerAnnotBorderEffect, 1); +} + +PopplerAnnotBorderEffect * +poppler_annot_border_effect_copy (PopplerAnnotBorderEffect *effect) +{ + PopplerAnnotBorderEffect *new_effect; + + g_return_val_if_fail (effect, NULL); + + new_effect = (PopplerAnnotBorderEffect *) g_memdup (effect, + sizeof (PopplerAnnotBorderEffect)); + return new_effect; +} + +void +poppler_annot_border_effect_free (PopplerAnnotBorderEffect *effect) +{ + if (!effect) + return; + + g_free (effect); +} + +GType +poppler_annot_border_array_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotBorderArray", + (GBoxedCopyFunc) poppler_annot_border_array_copy, + (GBoxedFreeFunc) poppler_annot_border_array_free); + return our_type; +} + +PopplerAnnotBorderArray * +poppler_annot_border_array_new (void) +{ + return g_new0 (PopplerAnnotBorderArray, 1); +} + +PopplerAnnotBorderArray * +poppler_annot_border_array_copy (PopplerAnnotBorderArray *border) +{ + PopplerAnnotBorderArray *new_border; + + g_return_val_if_fail (border, NULL); + + new_border = (PopplerAnnotBorderArray *) g_memdup (border, + sizeof (PopplerAnnotBorderArray)); + return new_border; +} + +void +poppler_annot_border_array_free (PopplerAnnotBorderArray *border) +{ + if (!border) + return; + + g_free (border); +} + +GType +poppler_annot_border_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotBorder", + (GBoxedCopyFunc) poppler_annot_border_copy, + (GBoxedFreeFunc) poppler_annot_border_free); + return our_type; +} + +PopplerAnnotBorder * +poppler_annot_border_new (void) +{ + return g_new0 (PopplerAnnotBorder, 1); +} + +PopplerAnnotBorder * +poppler_annot_border_copy (PopplerAnnotBorder *border) +{ + PopplerAnnotBorder *new_border; + + g_return_val_if_fail (border, NULL); + + new_border = (PopplerAnnotBorder *) g_memdup (border, + sizeof (PopplerAnnotBorder)); + new_border->dash = (gdouble *) g_memdup (border->dash, + sizeof (gdouble) * border->dash_length); + + if (border->type == POPPLER_ANNOT_BORDER_ARRAY) + new_border->array = poppler_annot_border_array_copy (border->array); + + return new_border; +} + +void +poppler_annot_border_free (PopplerAnnotBorder *border) +{ + if (!border) + return; + + if (border->dash) { + g_free (border->dash); + border->dash = NULL; + } + + switch (border->type) { + case POPPLER_ANNOT_BORDER_ARRAY: + poppler_annot_border_array_free (border->array); + break; + default: + break; + } + + g_free (border); +} + +GType +poppler_annot_text_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotText", + (GBoxedCopyFunc) poppler_annot_text_copy, + (GBoxedFreeFunc) poppler_annot_text_free); + return our_type; +} + +PopplerAnnotText * +poppler_annot_text_new (void) +{ + return g_new0 (PopplerAnnotText, 1); +} + +PopplerAnnotText * +poppler_annot_text_copy (PopplerAnnotText *annot) +{ + PopplerAnnotText *new_annot; + + g_return_val_if_fail (annot, NULL); + + new_annot = (PopplerAnnotText *) g_memdup (annot, + sizeof (PopplerAnnotText)); + + return new_annot; +} + +void +poppler_annot_text_free (PopplerAnnotText *annot) +{ + if (!annot) + return; + + g_free (annot); +} + +GType +poppler_annot_free_text_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotFreeText", + (GBoxedCopyFunc) poppler_annot_free_text_copy, + (GBoxedFreeFunc) poppler_annot_free_text_free); + return our_type; +} + +PopplerAnnotFreeText * +poppler_annot_free_text_new (void) +{ + return g_new0 (PopplerAnnotFreeText, 1); +} + +PopplerAnnotFreeText * +poppler_annot_free_text_copy (PopplerAnnotFreeText *annot) +{ + PopplerAnnotFreeText *new_annot; + + g_return_val_if_fail (annot, NULL); + + new_annot = (PopplerAnnotFreeText *) g_memdup (annot, + sizeof (PopplerAnnotFreeText)); + new_annot->appearance_string = g_strdup (annot->appearance_string); + new_annot->style_string = g_strdup (annot->style_string); + new_annot->callout_line = poppler_annot_callout_line_copy (annot->callout_line); + new_annot->border_effect = poppler_annot_border_effect_copy (annot->border_effect); + new_annot->rectangle = poppler_rectangle_copy (annot->rectangle); + + return new_annot; +} + +void +poppler_annot_free_text_free (PopplerAnnotFreeText *annot) +{ + if (!annot) + return; + + if (annot->appearance_string) { + g_free (annot->appearance_string); + annot->appearance_string = NULL; + } + + if (annot->style_string) { + g_free (annot->style_string); + annot->style_string = NULL; + } + + if (annot->callout_line) { + poppler_annot_callout_line_free (annot->callout_line); + annot->callout_line = NULL; + } + + if (annot->border_effect) { + poppler_annot_border_effect_free (annot->border_effect); + annot->border_effect = NULL; + } + + if (annot->rectangle) { + poppler_rectangle_free (annot->rectangle); + annot->rectangle = NULL; + } + + g_free (annot); +} + +GType +poppler_annot_line_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotLine", + (GBoxedCopyFunc) poppler_annot_line_copy, + (GBoxedFreeFunc) poppler_annot_line_free); + return our_type; +} + +PopplerAnnotLine * +poppler_annot_line_new (void) +{ + return g_new0 (PopplerAnnotLine, 1); +} + +PopplerAnnotLine * +poppler_annot_line_copy (PopplerAnnotLine *annot) +{ + PopplerAnnotLine *new_annot; + + g_return_val_if_fail (annot, NULL); + + new_annot = (PopplerAnnotLine *) g_memdup (annot, + sizeof (PopplerAnnotLine)); + + if (new_annot->interior_color) + new_annot->interior_color = (PopplerAnnotColor *) g_memdup (annot->interior_color, + sizeof (PopplerAnnotColor)); + + return new_annot; +} + +void +poppler_annot_line_free (PopplerAnnotLine *annot) +{ + if (!annot) + return; + + if (annot->interior_color) { + g_free (annot->interior_color); + annot->interior_color = NULL; + } + + g_free (annot); +} + +GType +poppler_annot_popup_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotPopup", + (GBoxedCopyFunc) poppler_annot_popup_copy, + (GBoxedFreeFunc) poppler_annot_popup_free); + return our_type; +} + +PopplerAnnotPopup * +poppler_annot_popup_new (void) +{ + return g_new0 (PopplerAnnotPopup, 1); +} + +PopplerAnnotPopup * +poppler_annot_popup_copy (PopplerAnnotPopup *annot) +{ + PopplerAnnotPopup *new_annot; + + g_return_val_if_fail (annot, NULL); + + new_annot = (PopplerAnnotPopup *) g_memdup (annot, + sizeof (PopplerAnnotPopup)); + + return new_annot; +} + +void +poppler_annot_popup_free (PopplerAnnotPopup *annot) +{ + if (!annot) + return; + + if (annot->parent) + annot->parent = NULL; + + g_free (annot); +} + +GType +poppler_annot_get_type (void) +{ + static GType our_type = 0; + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnot", + (GBoxedCopyFunc) poppler_annot_copy, + (GBoxedFreeFunc) poppler_annot_free); + return our_type; +} + +PopplerAnnot * +poppler_annot_new (void) +{ + return g_new0 (PopplerAnnot, 1); +} + +PopplerAnnot * +poppler_annot_copy (PopplerAnnot *annot) +{ + PopplerAnnot *new_annot; + + g_return_val_if_fail (annot, NULL); + + new_annot = (PopplerAnnot *) g_memdup (annot, + sizeof (PopplerAnnot)); + + new_annot->rect = poppler_rectangle_copy (annot->rect); + new_annot->contents = g_strdup (annot->contents); + new_annot->annot_name = g_strdup (annot->annot_name); + new_annot->modified = g_strdup (annot->modified); + new_annot->appear_state = g_strdup (annot->appear_state); + new_annot->border = poppler_annot_border_copy (annot->border); + new_annot->color = poppler_annot_color_copy (annot->color); + + switch (annot->type) { + case POPPLER_ANNOT_TEXT: + new_annot->annot_text = poppler_annot_text_copy (annot->annot_text); + break; + case POPPLER_ANNOT_FREE_TEXT: + new_annot->annot_free_text = poppler_annot_free_text_copy (annot->annot_free_text); + break; + case POPPLER_ANNOT_LINE: + new_annot->annot_line = poppler_annot_line_copy (annot->annot_line); + break; + case POPPLER_ANNOT_POPUP: + new_annot->annot_popup = poppler_annot_popup_copy (annot->annot_popup); + break; + default: + break; + } + return new_annot; +} + +void +poppler_annot_free (PopplerAnnot *annot) +{ + if (!annot) + return; + + poppler_rectangle_free (annot->rect); + annot->rect = NULL; + + if (annot->contents) { + g_free (annot->contents); + annot->contents = NULL; + } + + if (annot->annot_name) { + g_free (annot->annot_name); + annot->annot_name = NULL; + } + + if (annot->modified) { + g_free (annot->modified); + annot->modified = NULL; + } + + if (annot->appear_state) { + g_free (annot->appear_state); + annot->appear_state = NULL; + } + + if (annot->border) { + poppler_annot_border_free (annot->border); + annot->border = NULL; + } + + if (annot->color) { + poppler_annot_color_free (annot->color); + annot->color = NULL; + } + + if (annot->markup) { + if (annot->label) { + g_free (annot->label); + annot->label = NULL; + } + + if (annot->popup) { + poppler_annot_free (annot->popup); + annot->popup = NULL; + } + + if (annot->date) { + g_free (annot->date); + annot->date = NULL; + } + + if (annot->subject) { + g_free (annot->subject); + annot->subject = NULL; + } + } + + switch (annot->type) { + case POPPLER_ANNOT_TEXT: + poppler_annot_text_free (annot->annot_text); + break; + case POPPLER_ANNOT_FREE_TEXT: + poppler_annot_free_text_free (annot->annot_free_text); + break; + case POPPLER_ANNOT_LINE: + poppler_annot_line_free (annot->annot_line); + break; + case POPPLER_ANNOT_POPUP: + poppler_annot_popup_free (annot->annot_popup); + break; + default: + break; + } + + g_free (annot); +} + +void +poppler_annot_base (PopplerAnnot *poppler_annot, + Annot *annot) +{ + PDFRectangle *rect; + AnnotColor *color; + AnnotBorder *border; + GooString *contents, *annot_name, *modified, *appear_state; + + rect = annot->getRect (); + poppler_annot->rect = poppler_rectangle_new (); + poppler_annot->rect->x1 = rect->x1; + poppler_annot->rect->y1 = rect->y1; + poppler_annot->rect->x2 = rect->x2; + poppler_annot->rect->y2 = rect->y2; + + contents = annot->getContents (); + if (contents) + poppler_annot->contents = _poppler_goo_string_to_utf8 (contents); + + annot_name = annot->getAnnotName (); + if (annot_name) + poppler_annot->annot_name = _poppler_goo_string_to_utf8 (annot_name); + + modified = annot->getModified (); + if (modified) + poppler_annot->modified = _poppler_goo_string_to_utf8 (modified); + + poppler_annot->flags = annot->getFlags (); + + appear_state = annot->getAppearState (); + if (appear_state) + poppler_annot->appear_state = _poppler_goo_string_to_utf8 (appear_state); + + border = annot->getBorder (); + if (border) { + int dash_length; + + dash_length = border->getDashLength (); + + poppler_annot->border = poppler_annot_border_new (); + poppler_annot->border->width = border->getWidth (); + poppler_annot->border->dash_length = dash_length; + poppler_annot->border->dash = (gdouble *) g_memdup (border->getDash (), + sizeof (gdouble) * dash_length); + + if (typeid (AnnotBorderBS) == typeid (*border)) { + AnnotBorderBS *border_bs; + + border_bs = dynamic_cast (border); + + poppler_annot->border->type = POPPLER_ANNOT_BORDER_BS; + poppler_annot->border->style = (PopplerAnnotBorderStyle) border_bs->getStyle (); + } else if (typeid (AnnotBorderArray) == typeid (*border)) { + AnnotBorderArray *border_array; + + border_array = dynamic_cast (border); + + poppler_annot->border->type = POPPLER_ANNOT_BORDER_ARRAY; + poppler_annot->border->array = poppler_annot_border_array_new (); + poppler_annot->border->array->horizontal_corner = border_array->getHorizontalCorner (); + poppler_annot->border->array->vertical_corner = border_array->getVerticalCorner (); + } + } + + color = annot->getColor (); + if (color && (color->getSpace () == AnnotColor::colorRGB)) { + poppler_annot->color = poppler_annot_color_new (); + poppler_annot->color->red = color->getValue (0); + poppler_annot->color->green = color->getValue (1); + poppler_annot->color->blue = color->getValue (2); + } +} + +PopplerAnnot * +poppler_annot_popup (AnnotPopup *annot, PopplerAnnot *parent_annot) +{ + PopplerAnnot *poppler_annot; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = POPPLER_ANNOT_POPUP; + poppler_annot->markup = FALSE; + + poppler_annot_base (poppler_annot, + annot); + + poppler_annot->annot_popup = poppler_annot_popup_new (); + poppler_annot->annot_popup->parent = parent_annot; + poppler_annot->annot_popup->open = annot->getOpen (); + + return poppler_annot; +} + +void +poppler_annot_markup (PopplerAnnot *poppler_annot, + AnnotMarkup *annot) +{ + GooString *label, *date, *subject; + AnnotPopup *popup; + + label = annot->getLabel (); + if (label) + poppler_annot->label = _poppler_goo_string_to_utf8 (label); + + popup = annot->getPopup (); + if (popup) + poppler_annot->popup = poppler_annot_popup (popup, poppler_annot); + + poppler_annot->opacity = annot->getOpacity ();; + + date = annot->getDate (); + if (date) + poppler_annot->date = _poppler_goo_string_to_utf8 (date); + + subject = annot->getSubject (); + if (subject) + poppler_annot->subject = _poppler_goo_string_to_utf8 (date); + + poppler_annot->reply_to = (PopplerAnnotMarkupReplyType) annot->getReplyTo (); + poppler_annot->ex_data = (PopplerAnnotExternalDataType) annot->getExData (); +} + +PopplerAnnot * +poppler_annot_text (AnnotText *annot) +{ + PopplerAnnot *poppler_annot; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = POPPLER_ANNOT_TEXT; + poppler_annot->markup = TRUE; + + poppler_annot_base (poppler_annot, + annot); + + poppler_annot_markup (poppler_annot, + annot); + + poppler_annot->annot_text = poppler_annot_text_new (); + poppler_annot->annot_text->open = annot->getOpen (); + poppler_annot->annot_text->icon = (PopplerAnnotTextIcon) annot->getIcon (); + poppler_annot->annot_text->state = (PopplerAnnotTextState) annot->getState (); + + return poppler_annot; +} + +PopplerAnnot * +poppler_annot_free_text (AnnotFreeText *annot) +{ + PopplerAnnot *poppler_annot; + GooString *style_string; + AnnotCalloutLine *callout_line; + AnnotBorderEffect *border_effect; + PDFRectangle *rectangle; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = POPPLER_ANNOT_FREE_TEXT; + poppler_annot->markup = TRUE; + + poppler_annot_base (poppler_annot, + annot); + + poppler_annot_markup (poppler_annot, + annot); + + poppler_annot->annot_free_text = poppler_annot_free_text_new (); + poppler_annot->annot_free_text->appearance_string = _poppler_goo_string_to_utf8 (annot->getAppearanceString ()); + poppler_annot->annot_free_text->quadding = (PopplerAnnotFreeTextQuadding) annot->getQuadding (); + + style_string = annot->getStyleString (); + if (style_string) + poppler_annot->annot_free_text->style_string = _poppler_goo_string_to_utf8 (style_string); + + callout_line = annot->getCalloutLine (); + if (callout_line) { + poppler_annot->annot_free_text->callout_line = poppler_annot_callout_line_new (); + poppler_annot->annot_free_text->callout_line->x1 = callout_line->getX1 (); + poppler_annot->annot_free_text->callout_line->y1 = callout_line->getY1 (); + poppler_annot->annot_free_text->callout_line->x2 = callout_line->getX2 (); + poppler_annot->annot_free_text->callout_line->y2 = callout_line->getY2 (); + + if (typeid (AnnotCalloutMultiLine) == typeid(*callout_line)) { + AnnotCalloutMultiLine *callout_multiline; + + callout_multiline = dynamic_cast (callout_line); + + poppler_annot->annot_free_text->callout_line->multiline = TRUE; + poppler_annot->annot_free_text->callout_line->x3 = callout_multiline->getX3 (); + poppler_annot->annot_free_text->callout_line->y3 = callout_multiline->getY3 (); + } else { + poppler_annot->annot_free_text->callout_line->multiline = FALSE; + } + } + + poppler_annot->annot_free_text->intent = (PopplerAnnotFreeTextIntent) annot->getIntent (); + + border_effect = annot->getBorderEffect (); + if (border_effect) { + poppler_annot->annot_free_text->border_effect = poppler_annot_border_effect_new (); + poppler_annot->annot_free_text->border_effect->effect_type = (PopplerAnnotBorderEffectType) border_effect->getEffectType (); + poppler_annot->annot_free_text->border_effect->intensity = border_effect->getIntensity (); + } + + rectangle = annot->getRectangle (); + if (rectangle) { + poppler_annot->annot_free_text->rectangle = poppler_rectangle_new (); + poppler_annot->annot_free_text->rectangle->x1 = rectangle->x1; + poppler_annot->annot_free_text->rectangle->y1 = rectangle->y1; + poppler_annot->annot_free_text->rectangle->x2 = rectangle->x2; + poppler_annot->annot_free_text->rectangle->y2 = rectangle->y2; + } + + poppler_annot->annot_free_text->end_style = (PopplerAnnotLineEndingStyle) annot->getEndStyle (); + + return poppler_annot; +} + +PopplerAnnot * +poppler_annot_line (AnnotLine *annot) +{ + PopplerAnnot *poppler_annot; + AnnotColor *interior_color; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = POPPLER_ANNOT_LINE; + poppler_annot->markup = TRUE; + + poppler_annot_base (poppler_annot, + annot); + + poppler_annot_markup (poppler_annot, + annot); + + poppler_annot->annot_line = poppler_annot_line_new (); + + poppler_annot->annot_line->start_style = (PopplerAnnotLineEndingStyle) annot->getStartStyle (); + poppler_annot->annot_line->end_style = (PopplerAnnotLineEndingStyle) annot->getEndStyle (); + + interior_color = annot->getInteriorColor (); + if (interior_color && (interior_color->getSpace () == AnnotColor::colorRGB)) { + + poppler_annot->annot_line->interior_color = poppler_annot_color_new (); + poppler_annot->annot_line->interior_color->red = interior_color->getValue (0); + poppler_annot->annot_line->interior_color->green = interior_color->getValue (1); + poppler_annot->annot_line->interior_color->blue = interior_color->getValue (2); + } + + poppler_annot->annot_line->leader_line_length = annot->getLeaderLineLength (); + poppler_annot->annot_line->leader_line_extension = annot->getLeaderLineExtension (); + poppler_annot->annot_line->caption = annot->getCaption (); + poppler_annot->annot_line->intent = (PopplerAnnotLineIntent) annot->getIntent (); + poppler_annot->annot_line->leader_line_offset = annot->getLeaderLineOffset (); + poppler_annot->annot_line->caption_pos = (PopplerAnnotLineCaptionPos) annot->getCaptionPos (); + poppler_annot->annot_line->caption_text_horizontal = annot->getCaptionTextHorizontal (); + poppler_annot->annot_line->caption_text_vertical = annot->getCaptionTextVertical (); + + return poppler_annot; +} + +PopplerAnnot * +poppler_annot_unknown (Annot *annot) +{ + PopplerAnnot *poppler_annot; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = (PopplerAnnotType) POPPLER_ANNOT_UNKNOWN; + poppler_annot->markup = FALSE; + + poppler_annot_base (poppler_annot, + annot); + + return poppler_annot; +} + +PopplerAnnot * +_poppler_annot_new_from_annot (Annot *annot) +{ + PopplerAnnot *poppler_annot = NULL; + + g_return_val_if_fail (annot, NULL); + + if (annot->getType () == Annot::typeText) { + poppler_annot = poppler_annot_text (dynamic_cast (annot)); + } else if (annot->getType () == Annot::typeFreeText) { + poppler_annot = poppler_annot_free_text (dynamic_cast (annot)); + } else if (annot->getType () == Annot::typeLine) { + poppler_annot = poppler_annot_line (dynamic_cast (annot)); + } else { + poppler_annot = poppler_annot_unknown (annot); + } + + return poppler_annot; +} Index: glib/poppler-annot.h =================================================================== RCS file: glib/poppler-annot.h diff -N glib/poppler-annot.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ glib/poppler-annot.h 10 Jun 2007 23:46:18 -0000 @@ -0,0 +1,329 @@ +/* poppler-annot.h: glib wrapper for poppler + * Copyright (C) 2007, Iñigo Martinez . + * + * 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 + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __POPPLER_ANNOT_H__ +#define __POPPLER_ANNOT_H__ + +#include +#include "poppler.h" + +G_BEGIN_DECLS + +typedef enum { + POPPLER_ANNOT_LINE_ENDING_SQUARE, + POPPLER_ANNOT_LINE_ENDING_CIRCLE, + POPPLER_ANNOT_LINE_ENDING_DIAMOND, + POPPLER_ANNOT_LINE_ENDING_OPEN_ARROW, + POPPLER_ANNOT_LINE_ENDING_CLOSED_ARROW, + POPPLER_ANNOT_LINE_ENDING_NONE, + POPPLER_ANNOT_LINE_ENDING_BUTT, + POPPLER_ANNOT_LINE_ENDING_R_OPEN_ARROW, + POPPLER_ANNOT_LINE_ENDING_R_CLOSED_ARROW, + POPPLER_ANNOT_LINE_ENDING_SLASH +} PopplerAnnotLineEndingStyle; + +typedef enum { + POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_3D, + POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN +} PopplerAnnotExternalDataType; + +typedef enum +{ + POPPLER_ANNOT_TEXT, + POPPLER_ANNOT_LINK, + POPPLER_ANNOT_FREE_TEXT, + POPPLER_ANNOT_LINE, + POPPLER_ANNOT_SQUARE, + POPPLER_ANNOT_CIRCLE, + POPPLER_ANNOT_POLYGON, + POPPLER_ANNOT_POLY_LINE, + POPPLER_ANNOT_HIGHLIGHT, + POPPLER_ANNOT_UNDERLINE, + POPPLER_ANNOT_SQUIGGLY, + POPPLER_ANNOT_STRIKE_OUT, + POPPLER_ANNOT_STAMP, + POPPLER_ANNOT_CARET, + POPPLER_ANNOT_INK, + POPPLER_ANNOT_POPUP, + POPPLER_ANNOT_FILE_ATTACHMENT, + POPPLER_ANNOT_SOUND, + POPPLER_ANNOT_MOVIE, + POPPLER_ANNOT_WIDGET, + POPPLER_ANNOT_SCREEN, + POPPLER_ANNOT_PRINTER_MARK, + POPPLER_ANNOT_TRAP_NET, + POPPLER_ANNOT_WATERMARK, + POPPLER_ANNOT_3D, + POPPLER_ANNOT_UNKNOWN +} PopplerAnnotType; + +typedef enum { + POPPLER_ANNOT_BORDER_EFFECT_NO_EFFECT, + POPPLER_ANNOT_BORDER_EFFECT_CLOUDY +} PopplerAnnotBorderEffectType; + +typedef enum +{ + POPPLER_ANNOT_BORDER_BS, + POPPLER_ANNOT_BORDER_ARRAY +} PopplerAnnotBorderType; + +typedef enum +{ + POPPLER_ANNOT_BORDER_SOLID, + POPPLER_ANNOT_BORDER_DASHED, + POPPLER_ANNOT_BORDER_BEVELED, + POPPLER_ANNOT_BORDER_INSET, + POPPLER_ANNOT_BORDER_UNDERLINED +} PopplerAnnotBorderStyle; + +typedef enum { + POPPLER_ANNOT_MARKUP_REPLY_TYPE_R, + POPPLER_ANNOT_MARKUP_REPLY_TYPE_GROUP +} PopplerAnnotMarkupReplyType; + +typedef enum +{ + POPPLER_ANNOT_TEXT_ICON_COMMENT, + POPPLER_ANNOT_TEXT_ICON_KEY, + POPPLER_ANNOT_TEXT_ICON_NOTE, + POPPLER_ANNOT_TEXT_ICON_HELP, + POPPLER_ANNOT_TEXT_ICON_NEW_PARAGRAPH, + POPPLER_ANNOT_TEXT_ICON_PARAGRAPH, + POPPLER_ANNOT_TEXT_ICON_INSERT +} PopplerAnnotTextIcon; + +typedef enum +{ + POPPLER_ANNOT_TEXT_STATE_MARKED, + POPPLER_ANNOT_TEXT_STATE_UNMARKED, + POPPLER_ANNOT_TEXT_STATE_ACCEPTED, + POPPLER_ANNOT_TEXT_STATE_REJECTED, + POPPLER_ANNOT_TEXT_STATE_CANCELLED, + POPPLER_ANNOT_TEXT_STATE_COMPLETED, + POPPLER_ANNOT_TEXT_STATE_NONE, + POPPLER_ANNOT_TEXT_STATE_UNKNOWN +} PopplerAnnotTextState; + +typedef enum { + POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED, + POPPLER_ANNOT_FREE_TEXT_QUADDING_CENTERED, + POPPLER_ANNOT_FREE_TEXT_QUADDING_RIGHT_JUSTIFIED +} PopplerAnnotFreeTextQuadding; + +typedef enum { + POPPLER_ANNOT_FREE_TEXT_INTENT_FREE_TEXT, + POPPLER_ANNOT_FREE_TEXT_INTENT_FREE_TEXT_CALLOUT, + POPPLER_ANNOT_FREE_TEXT_INTENT_FREE_TEXT_TYPE_WRITER +} PopplerAnnotFreeTextIntent; + +typedef enum { + POPPLER_ANNOT_LINE_INTENT_LINE_ARROW, + POPPLER_ANNOT_LINE_INTENT_LINE_DIMENSION +} PopplerAnnotLineIntent; + +typedef enum { + POPPLER_ANNOT_LINE_CAPTION_POS_INLINE, + POPPLER_ANNOT_LINE_CAPTION_POS_TOP +} PopplerAnnotLineCaptionPos; + +typedef struct _PopplerAnnotColor PopplerAnnotColor; +typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; +typedef struct _PopplerAnnotBorderEffect PopplerAnnotBorderEffect; +typedef struct _PopplerAnnotBorderArray PopplerAnnotBorderArray; +typedef struct _PopplerAnnotBorder PopplerAnnotBorder; +typedef struct _PopplerAnnotText PopplerAnnotText; +typedef struct _PopplerAnnotFreeText PopplerAnnotFreeText; +typedef struct _PopplerAnnotLine PopplerAnnotLine; +typedef struct _PopplerAnnotPopup PopplerAnnotPopup; + +struct _PopplerAnnotColor +{ + gdouble red; + gdouble green; + gdouble blue; +}; + +struct _PopplerAnnotCalloutLine +{ + gboolean multiline; + gdouble x1; + gdouble y1; + gdouble x2; + gdouble y2; + gdouble x3; + gdouble y3; +}; + +struct _PopplerAnnotBorderEffect +{ + PopplerAnnotBorderEffectType effect_type; + gdouble intensity; +}; + +struct _PopplerAnnotBorderArray +{ + gdouble horizontal_corner; + gdouble vertical_corner; +}; + +struct _PopplerAnnotBorder +{ + PopplerAnnotBorderType type; + gdouble width; + gdouble *dash; + gint dash_length; + union { + PopplerAnnotBorderArray *array; + PopplerAnnotBorderStyle style; + }; +}; + +struct _PopplerAnnotText +{ + gboolean open; + PopplerAnnotTextIcon icon; + PopplerAnnotTextState state; +}; + +struct _PopplerAnnotFreeText +{ + gchar *appearance_string; + PopplerAnnotFreeTextQuadding quadding; + gchar *style_string; + PopplerAnnotCalloutLine *callout_line; + PopplerAnnotFreeTextIntent intent; + PopplerAnnotBorderEffect *border_effect; + PopplerRectangle *rectangle; + PopplerAnnotLineEndingStyle end_style; +}; + +struct _PopplerAnnotLine +{ + PopplerAnnotLineEndingStyle start_style; + PopplerAnnotLineEndingStyle end_style; + PopplerAnnotColor *interior_color; + gdouble leader_line_length; + gdouble leader_line_extension; + gboolean caption; + PopplerAnnotLineIntent intent; + gdouble leader_line_offset; + PopplerAnnotLineCaptionPos caption_pos; + gdouble caption_text_horizontal; + gdouble caption_text_vertical; +}; + +struct _PopplerAnnotPopup +{ + PopplerAnnot *parent; + gboolean open; +}; + +struct _PopplerAnnot +{ + PopplerAnnotType type; + gboolean markup; + + PopplerRectangle *rect; + gchar *contents; + gchar *annot_name; + gchar *modified; + guint flags; + gchar *appear_state; + PopplerAnnotBorder *border; + PopplerAnnotColor *color; + + gchar *label; + PopplerAnnot *popup; + gdouble opacity; + gchar *date; + gchar *subject; + PopplerAnnotMarkupReplyType reply_to; + PopplerAnnotExternalDataType ex_data; + + union { + PopplerAnnotText *annot_text; + PopplerAnnotFreeText *annot_free_text; + PopplerAnnotLine *annot_line; + PopplerAnnotPopup *annot_popup; + }; +}; + +#define POPPLER_TYPE_ANNOT_COLOR (poppler_annot_color_get_type ()) +GType poppler_annot_color_get_type (void) G_GNUC_CONST; +PopplerAnnotColor *poppler_annot_color_new (void); +PopplerAnnotColor *poppler_annot_color_copy (PopplerAnnotColor *color); +void poppler_annot_color_free (PopplerAnnotColor *color); + +#define POPPLER_TYPE_ANNOT_CALLOUT_LINE (poppler_annot_callout_line_get_type ()) +GType poppler_annot_callout_line_get_type (void) G_GNUC_CONST; +PopplerAnnotCalloutLine *poppler_annot_callout_line_new (void); +PopplerAnnotCalloutLine *poppler_annot_callout_line_copy (PopplerAnnotCalloutLine *line); +void poppler_annot_callout_line_free (PopplerAnnotCalloutLine *line); + +#define POPPLER_TYPE_ANNOT_BORDER_EFFECT (poppler_annot_border_effect_get_type ()) +GType poppler_annot_border_effect_get_type (void) G_GNUC_CONST; +PopplerAnnotBorderEffect *poppler_annot_border_effect_new (void); +PopplerAnnotBorderEffect *poppler_annot_border_effect_copy (PopplerAnnotBorderEffect *effect); +void poppler_annot_border_effect_free (PopplerAnnotBorderEffect *effect); + +#define POPPLER_TYPE_ANNOT_BORDER_ARRAY (poppler_annot_border_array_get_type ()) +GType poppler_annot_border_array_get_type (void) G_GNUC_CONST; +PopplerAnnotBorderArray *poppler_annot_border_array_new (void); +PopplerAnnotBorderArray *poppler_annot_border_array_copy (PopplerAnnotBorderArray *border); +void poppler_annot_border_array_free (PopplerAnnotBorderArray *border); + +#define POPPLER_TYPE_ANNOT_BORDER (poppler_annot_border_get_type ()) +GType poppler_annot_border_get_type (void) G_GNUC_CONST; +PopplerAnnotBorder *poppler_annot_border_new (void); +PopplerAnnotBorder *poppler_annot_border_copy (PopplerAnnotBorder *border); +void poppler_annot_border_free (PopplerAnnotBorder *border); + +#define POPPLER_TYPE_ANNOT_TEXT (poppler_annot_text_get_type ()) +GType poppler_annot_text_get_type (void) G_GNUC_CONST; +PopplerAnnotText *poppler_annot_text_new (void); +PopplerAnnotText *poppler_annot_text_copy (PopplerAnnotText *annot); +void poppler_annot_text_free (PopplerAnnotText *annot); + +#define POPPLER_TYPE_ANNOT_FREE_TEXT (poppler_annot_free_text_get_type ()) +GType poppler_annot_free_text_get_type (void) G_GNUC_CONST; +PopplerAnnotFreeText *poppler_annot_free_text_new (void); +PopplerAnnotFreeText *poppler_annot_free_text_copy (PopplerAnnotFreeText *annot); +void poppler_annot_free_text_free (PopplerAnnotFreeText *annot); + +#define POPPLER_TYPE_ANNOT_LINE (poppler_annot_line_get_type ()) +GType poppler_annot_line_get_type (void) G_GNUC_CONST; +PopplerAnnotLine *poppler_annot_line_new (void); +PopplerAnnotLine *poppler_annot_line_copy (PopplerAnnotLine *annot); +void poppler_annot_line_free (PopplerAnnotLine *annot); + +#define POPPLER_TYPE_ANNOT_POPUP (poppler_annot_popup_get_type ()) +GType poppler_annot_popup_get_type (void) G_GNUC_CONST; +PopplerAnnotPopup *poppler_annot_popup_new (void); +PopplerAnnotPopup *poppler_annot_popup_copy (PopplerAnnotPopup *annot); +void poppler_annot_popup_free (PopplerAnnotPopup *annot); + +#define POPPLER_TYPE_ANNOT (poppler_annot_get_type ()) +GType poppler_annot_get_type (void) G_GNUC_CONST; +PopplerAnnot *poppler_annot_new (void); +PopplerAnnot *poppler_annot_copy (PopplerAnnot *annot); +void poppler_annot_free (PopplerAnnot *annot); + +G_END_DECLS + +#endif /* __POPPLER_ANNOT_H__ */ Index: glib/poppler-page.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-page.cc,v retrieving revision 1.62 diff -u -r1.62 poppler-page.cc --- glib/poppler-page.cc 27 May 2007 11:24:40 -0000 1.62 +++ glib/poppler-page.cc 10 Jun 2007 23:46:18 -0000 @@ -1578,3 +1578,80 @@ rect->y2 = cropBox->y2; } +gboolean +poppler_page_has_annots (PopplerPage *page) +{ + Annots *annots; + gboolean has_annots; + + g_return_val_if_fail (POPPLER_IS_PAGE (page), FALSE); + + annots = page->page->getAnnots (page->document->doc->getCatalog ()); + + if (annots) { + has_annots = TRUE; + delete annots; + } else { + has_annots = FALSE; + } + + return has_annots; +} + +GList * +poppler_page_get_annots (PopplerPage *page) +{ + Annots *annots; + GList *annot_list = NULL; + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + + annots = page->page->getAnnots (page->document->doc->getCatalog ()); + + if(!annots) + return NULL; + + for(gint i = 0; i < annots->getNumAnnots (); i++) { + PopplerAnnot *poppler_annot; + + poppler_annot = _poppler_annot_new_from_annot (annots->getAnnot (i)); + annot_list = g_list_prepend (annot_list, poppler_annot); + } + + delete annots; + + return g_list_reverse (annot_list); +} + +PopplerAnnot * +poppler_page_get_annot (PopplerPage *page, + gint i) +{ + PopplerAnnot *poppler_annot; + Annots *annots; + + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + + annots = page->page->getAnnots (page->document->doc->getCatalog ()); + + if(!annots) + return NULL; + + if (i > 0 && i < annots->getNumAnnots ()) + poppler_annot = _poppler_annot_new_from_annot (annots->getAnnot (i)); + else + poppler_annot = NULL; + + delete annots; + + return poppler_annot; +} + +void +poppler_page_free_annots (GList *list) +{ + if (!list) + return; + + g_list_foreach (list, (GFunc) (poppler_annot_free), NULL); + g_list_free (list); +} Index: glib/poppler-page.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-page.h,v retrieving revision 1.29 diff -u -r1.29 poppler-page.h --- glib/poppler-page.h 27 May 2007 11:24:40 -0000 1.29 +++ glib/poppler-page.h 10 Jun 2007 23:46:18 -0000 @@ -98,10 +98,15 @@ GList *poppler_page_get_form_fields (PopplerPage *page); void poppler_page_free_form_fields (GList *list); -void poppler_page_get_crop_box (PopplerPage *page, +void poppler_page_get_crop_box (PopplerPage *page, PopplerRectangle *rect); - +gboolean poppler_page_has_annots (PopplerPage *page); +GList *poppler_page_get_annots (PopplerPage *page); +PopplerAnnot *poppler_page_get_annot (PopplerPage *page, + gint i); +void poppler_page_free_annots (GList *list); + /* A rectangle on a page, with coordinates in PDF points. */ #define POPPLER_TYPE_RECTANGLE (poppler_rectangle_get_type ()) struct _PopplerRectangle Index: glib/poppler-private.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler-private.h,v retrieving revision 1.18 diff -u -r1.18 poppler-private.h --- glib/poppler-private.h 21 May 2007 21:35:10 -0000 1.18 +++ glib/poppler-private.h 10 Jun 2007 23:46:18 -0000 @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -66,6 +67,7 @@ PopplerFormField *_form_field_new_from_widget (FormWidget* field); +PopplerAnnot *_poppler_annot_new_from_annot (Annot *annot); PopplerPage *_poppler_page_new (PopplerDocument *document, Page *page, Index: glib/poppler.cc =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler.cc,v retrieving revision 1.4 diff -u -r1.4 poppler.cc --- glib/poppler.cc 31 Dec 2005 02:10:33 -0000 1.4 +++ glib/poppler.cc 10 Jun 2007 23:46:18 -0000 @@ -31,7 +31,6 @@ /** * poppler_get_backend: - * @void: * * Returns the backend compiled into the poppler library. * @@ -53,7 +52,6 @@ /** * poppler_get_version: - * @void: * * Returns the version of poppler in use. This result is not to be freed. * Index: glib/poppler.h =================================================================== RCS file: /cvs/poppler/poppler/glib/poppler.h,v retrieving revision 1.16 diff -u -r1.16 poppler.h --- glib/poppler.h 25 May 2007 17:33:37 -0000 1.16 +++ glib/poppler.h 10 Jun 2007 23:46:18 -0000 @@ -94,6 +94,8 @@ typedef struct _PopplerPageTransition PopplerPageTransition; typedef struct _PopplerImageMapping PopplerImageMapping; typedef struct _PopplerFormField PopplerFormField; +/* typedef union _PopplerAnnot PopplerAnnot; */ +typedef struct _PopplerAnnot PopplerAnnot; typedef struct _PopplerPage PopplerPage; typedef struct _PopplerFontInfo PopplerFontInfo; typedef struct _PopplerPSFile PopplerPSFile; @@ -121,5 +123,6 @@ #include "poppler-action.h" #include "poppler-enums.h" #include "poppler-attachment.h" +#include "poppler-annot.h" #endif /* __POPPLER_GLIB_H__ */ Index: glib/test-poppler-glib.c =================================================================== RCS file: /cvs/poppler/poppler/glib/test-poppler-glib.c,v retrieving revision 1.22 diff -u -r1.22 test-poppler-glib.c --- glib/test-poppler-glib.c 27 May 2007 11:24:40 -0000 1.22 +++ glib/test-poppler-glib.c 10 Jun 2007 23:46:19 -0000 @@ -6,173 +6,156 @@ #define FAIL(msg) \ do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0) - -static void -print_index (PopplerIndexIter *iter) -{ - do - { - PopplerAction *action; - PopplerIndexIter *child; - - action = poppler_index_iter_get_action (iter); - g_print ("Action: %d\n", action->type); - poppler_action_free (action); - child = poppler_index_iter_get_child (iter); - if (child) - print_index (child); - poppler_index_iter_free (child); - } - while (poppler_index_iter_next (iter)); +void +print_annot_text_data (PopplerAnnotText *annot) +{ + g_print ("Open: %s\n", (annot->open ? "yes" : "no")); + g_print ("Icon: %d\n", annot->icon); + g_print ("State: %d\n", annot->state); } -static void -print_document_info (PopplerDocument *document) +void +print_annot_free_text_data (PopplerAnnotFreeText *annot) { - gchar *title, *format, *author, *subject, *keywords, *creator, *producer, *linearized; - GTime creation_date, mod_date; - PopplerPageLayout layout; - PopplerPageMode mode; - PopplerViewerPreferences view_prefs; - PopplerFontInfo *font_info; - PopplerFontsIter *fonts_iter; - PopplerIndexIter *index_iter; - GEnumValue *enum_value; + if (annot->appearance_string) + g_print ("Appearance string: %s\n", annot->appearance_string); + else + g_print ("Appearance string: NULL\n"); - g_object_get (document, - "title", &title, - "format", &format, - "author", &author, - "subject", &subject, - "keywords", &keywords, - "creation-date", &creation_date, - "mod-date", &mod_date, - "creator", &creator, - "producer", &producer, - "linearized", &linearized, - "page-mode", &mode, - "page-layout", &layout, - "viewer-preferences", &view_prefs, - NULL); - - printf ("\t---------------------------------------------------------\n"); - printf ("\tDocument Metadata\n"); - printf ("\t---------------------------------------------------------\n"); - if (title) printf ("\ttitle:\t\t%s\n", title); - if (format) printf ("\tformat:\t\t%s\n", format); - if (author) printf ("\tauthor:\t\t%s\n", author); - if (subject) printf ("\tsubject:\t%s\n", subject); - if (keywords) printf ("\tkeywords:\t%s\n", keywords); - if (creator) printf ("\tcreator:\t%s\n", creator); - if (producer) printf ("\tproducer:\t%s\n", producer); - if (linearized) printf ("\tlinearized:\t%s\n", linearized); + g_print ("Quadding: %d\n", annot->quadding); - enum_value = g_enum_get_value ((GEnumClass *) g_type_class_peek (POPPLER_TYPE_PAGE_MODE), mode); - g_print ("\tpage mode:\t%s\n", enum_value->value_name); - enum_value = g_enum_get_value ((GEnumClass *) g_type_class_peek (POPPLER_TYPE_PAGE_LAYOUT), layout); - g_print ("\tpage layout:\t%s\n", enum_value->value_name); - - g_print ("\tcreation date:\t%d\n", creation_date); - g_print ("\tmodified date:\t%d\n", mod_date); - - g_print ("\tfonts:\n"); - font_info = poppler_font_info_new (document); - while (poppler_font_info_scan (font_info, 20, &fonts_iter)) { - if (fonts_iter) { - do { - g_print ("\t\t\t%s\n", poppler_fonts_iter_get_name (fonts_iter)); - } while (poppler_fonts_iter_next (fonts_iter)); - poppler_fonts_iter_free (fonts_iter); - } + if (annot->style_string) + g_print ("Style string: %s\n", annot->style_string); + + if (annot->callout_line) { + g_print ("Callout : (%f %f %f %f", annot->callout_line->x1, + annot->callout_line->y1, + annot->callout_line->x2, + annot->callout_line->y2); + if (annot->callout_line->multiline) + g_print (" %f %f", annot->callout_line->x3, + annot->callout_line->y3); + g_print (")\n"); } - poppler_font_info_free (font_info); - - index_iter = poppler_index_iter_new (document); - if (index_iter) - { - g_print ("\tindex:\n"); - print_index (index_iter); - poppler_index_iter_free (index_iter); - } + g_print ("Intent: %d\n", annot->intent); - - /* FIXME: print out the view prefs when we support it */ + if (annot->border_effect) { + g_print ("Border effect: %d\n", annot->border_effect->effect_type); + g_print ("Border intensity: %f\n", annot->border_effect->intensity); + } - g_free (title); - g_free (format); - g_free (author); - g_free (subject); - g_free (keywords); - g_free (creator); - g_free (producer); - g_free (linearized); -} + if (annot->rectangle) + g_print ("Rectangle: (%f, %f, %f, %f)\n", annot->rectangle->x1, + annot->rectangle->y1, + annot->rectangle->x2, + annot->rectangle->y2); -static const gchar * -transition_effect_name (PopplerPageTransitionType type) -{ - switch (type) - { - case POPPLER_PAGE_TRANSITION_REPLACE: - return "Replace"; - case POPPLER_PAGE_TRANSITION_SPLIT: - return "Split"; - case POPPLER_PAGE_TRANSITION_BLINDS: - return "Blinds"; - case POPPLER_PAGE_TRANSITION_BOX: - return "Box"; - case POPPLER_PAGE_TRANSITION_WIPE: - return "Wipe"; - case POPPLER_PAGE_TRANSITION_DISSOLVE: - return "Dissolve"; - case POPPLER_PAGE_TRANSITION_GLITTER: - return "Glitter"; - case POPPLER_PAGE_TRANSITION_FLY: - return "Fly"; - case POPPLER_PAGE_TRANSITION_PUSH: - return "Push"; - case POPPLER_PAGE_TRANSITION_COVER: - return "Cover"; - case POPPLER_PAGE_TRANSITION_UNCOVER: - return "Uncover"; - case POPPLER_PAGE_TRANSITION_FADE: - return "Fade"; - } - - return "Unknown"; + g_print ("End style: %d\n", annot->end_style); } -static void -print_page_transition (PopplerPageTransition *transition) +void +print_annot_line_data (PopplerAnnotLine *annot) { - printf ("\t\tEffect: %s\n", transition_effect_name (transition->type)); - printf ("\t\tAlignment: %s\n", - transition->alignment == POPPLER_PAGE_TRANSITION_HORIZONTAL ? - "Horizontal" : "Vertical"); - printf ("\t\tDirection: %s\n", - transition->direction == POPPLER_PAGE_TRANSITION_INWARD ? - "Inward" : "Outward"); - printf ("\t\tDuration: %d\n", transition->duration); - printf ("\t\tAngle: %d\n", transition->angle); - printf ("\t\tScale: %.2f\n", transition->scale); - printf ("\t\tRectangular: %s\n", transition->rectangular ? "Yes" : "No"); -} + g_print ("Start style: %d\n", annot->start_style); + g_print ("End style: %d\n", annot->end_style); -static const gchar * -form_field_get_type_name (PopplerFormFieldType type) -{ - switch (type) - { - case POPPLER_FORM_FIELD_TEXT: - return "Text"; - case POPPLER_FORM_FIELD_BUTTON: - return "Button"; - case POPPLER_FORM_FIELD_CHOICE: - return "Choice"; + if (annot->interior_color) + g_print ("Color: (%d, %d, %d)\n", annot->interior_color->red, + annot->interior_color->green, + annot->interior_color->blue); + + g_print ("Leader line length: %f\n", annot->leader_line_length); + g_print ("Leader line extension: %f\n", annot->leader_line_extension); + g_print ("Caption: %s\n", (annot->caption ? "yes" : "no")); + g_print ("Intent: %d\n", annot->intent); + g_print ("Leader line offset: %f\n", annot->leader_line_offset); + g_print ("Caption pos: %d\n", annot->caption_pos); + g_print ("Caption text horizontal: %f\n", annot->caption_text_horizontal); + g_print ("Caption text vertical: %f\n", annot->caption_text_vertical); +} + +void +print_annot_popup_data (PopplerAnnotPopup *annot) +{ + g_print ("Parent: %s\n", (annot->parent ? "yes" : "no")); + g_print ("Open: %s\n", (annot->open ? "yes" : "no")); +} + +void +print_annot_data (PopplerAnnot *annot) +{ + if (!annot) + g_print ("Annot == NULL\n"); + + g_print ("Type: %d\n", annot->type); + g_print ("Rect data: (%f, %f, %f, %f)\n", annot->rect->x1, + annot->rect->y1, + annot->rect->x2, + annot->rect->y2); + + if (annot->contents) + g_print ("Contents: %s\n", annot->contents); + + if (annot->annot_name) + g_print ("Annot name: %s\n", annot->annot_name); + + if (annot->modified) + g_print ("Modified: %s\n", annot->modified); + + g_print ("Flag value: %d\n", annot->flags); + + if (annot->appear_state) + g_print ("Appear state: %s\n", annot->appear_state); + + if (annot->border) { + g_print ("Border width: %f\n", annot->border->width); + g_print ("Border dash:"); + for(int i = 0; i < annot->border->dash_length; i++) + g_print (" %f", annot->border->dash[i]); + g_print ("\n"); + + if (annot->border->type == POPPLER_ANNOT_BORDER_BS) { + g_print ("Border style: %d\n", annot->border->style); + } else { + g_print ("Border horizontal corner: %f\n", annot->border->array->horizontal_corner); + g_print ("Border vertical corner: %f\n", annot->border->array->vertical_corner); } + } + + if (annot->color) + g_print ("Color: (%f, %f, %f)\n", annot->color->red, + annot->color->green, + annot->color->blue); + + if (annot->markup) { + if (annot->label) + g_print ("Label: %s\n", annot->label); + + if (annot->popup) + print_annot_data (annot->popup); + + g_print ("Opacity: %f\n", annot->opacity); + + if (annot->date) + g_print ("Date: %s\n", annot->date); + + if (annot->subject) + g_print ("Subject: %s\n", annot->subject); + + g_print ("Reply to: %d\n", annot->reply_to); + g_print ("External data: %d\n", annot->ex_data); + } - return "Unknown"; + if (annot->type == POPPLER_ANNOT_TEXT) { + print_annot_text_data (annot->annot_text); + } else if (annot->type == POPPLER_ANNOT_FREE_TEXT) { + print_annot_free_text_data (annot->annot_free_text); + } else if (annot->type == POPPLER_ANNOT_LINE) { + print_annot_line_data (annot->annot_line); + } else if (annot->type == POPPLER_ANNOT_POPUP) { + print_annot_popup_data (annot->annot_popup); + } } int main (int argc, char *argv[]) @@ -180,182 +163,71 @@ PopplerDocument *document; PopplerBackend backend; PopplerPage *page; - PopplerPageTransition *transition; GEnumValue *enum_value; - char *label; GError *error; - GdkPixbuf *pixbuf, *thumb; - double width, height; - GList *list, *l; - char *text; - double duration; - PopplerRectangle area; - gint num_images; - gint num_forms; - - if (argc != 3) - FAIL ("usage: test-poppler-glib file://FILE PAGE"); + gint num_pages; + gchar *file; + gint type; + gboolean parse_type = FALSE; + + if (argc < 2 || argc > 3) + FAIL ("usage: test-poppler-glib file://FILE [TYPE]"); + + if (argc == 3) { + type = atoi (argv[2]); + parse_type = TRUE; + } g_type_init (); - + g_print ("Poppler version %s\n", poppler_get_version ()); backend = poppler_get_backend (); enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_BACKEND), backend); g_print ("Backend is %s\n", enum_value->value_name); error = NULL; - document = poppler_document_new_from_file (argv[1], NULL, &error); + file = argv[1]; + document = poppler_document_new_from_file (file, NULL, &error); if (document == NULL) FAIL (error->message); - print_document_info (document); - - page = poppler_document_get_page_by_label (document, argv[2]); - if (page == NULL) - FAIL ("page not found"); - - poppler_page_get_size (page, &width, &height); - printf ("\tpage size:\t%f inches by %f inches\n", width / 72, height / 72); - - duration = poppler_page_get_duration (page); - if (duration > 0) - printf ("\tpage duration:\t%f second(s)\n", duration); - else - printf ("\tpage duration:\tno duration for page\n"); + num_pages = poppler_document_get_n_pages (document); + g_print ("Num pages: %d\n", num_pages); - transition = poppler_page_get_transition (page); - if (transition) { - printf ("\tpage transition:\n"); - print_page_transition (transition); - poppler_page_transition_free (transition); - } else { - printf ("\tpage transition:no transition effect for page\n"); - } - - thumb = poppler_page_get_thumbnail (page); - if (thumb != NULL) { - gdk_pixbuf_save (thumb, "thumb.png", "png", &error, NULL); - if (error != NULL) - FAIL (error->message); - else - printf ("\tthumbnail:\tsaved as thumb.png\n"); - g_object_unref (G_OBJECT (thumb)); - } - else - printf ("\tthumbnail:\tno thumbnail for page\n"); - - g_object_get (page, "label", &label, NULL); - printf ("\tpage label:\t%s\n", label); - g_free (label); - - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 220, 220); - gdk_pixbuf_fill (pixbuf, 0x00106000); - poppler_page_render_to_pixbuf (page, 100, 100, 200, 200, 1, 0, pixbuf); - - gdk_pixbuf_save (pixbuf, "slice.png", "png", &error, NULL); - printf ("\tslice:\t\tsaved 200x200 slice at (100, 100) as slice.png\n"); - if (error != NULL) { - FAIL (error->message); - g_error_free (error); - } - - g_object_unref (G_OBJECT (pixbuf)); - - area.x1 = 0; - area.y1 = 0; - area.x2 = width; - area.y2 = height; - - text = poppler_page_get_text (page, &area); - if (text) - { - FILE *file = fopen ("dump.txt", "w"); - if (file) - { - fwrite (text, strlen (text), 1, file); - fclose (file); - } - g_free (text); - } + for (gint i = 0; i < num_pages; i++) { + page = poppler_document_get_page (document, i); + + if (page == NULL) { + g_print("Error in page %d\n", i); + } else { + GList *list, *li; + guint counter = 0; + + g_print ("Page %d\n", i); + + list = poppler_page_get_annots (page); + + g_print ("Annots: %d\n", g_list_length (list)); + g_print ("******************************************\n"); + + for (li = list; li; li = li->next) { + PopplerAnnot *annot = (PopplerAnnot *) li->data; + + g_print ("Annot %d\n", counter++); + if (parse_type) { + if (annot->type == type) + print_annot_data (annot); + } else { + print_annot_data (annot); + } + g_print ("******************************************\n"); + } - list = poppler_page_find_text (page, "Bitwise"); - printf ("\n"); - printf ("\tFound text \"Bitwise\" at positions:\n"); - for (l = list; l != NULL; l = l->next) - { - PopplerRectangle *rect = l->data; - - printf (" (%f,%f)-(%f,%f)\n", rect->x1, rect->y1, rect->x2, rect->y2); - } - - list = poppler_page_get_image_mapping (page); - num_images = g_list_length (list); - printf ("\n"); - if (num_images > 0) - printf ("\tFound %d images at positions:\n", num_images); - else - printf ("\tNo images found\n"); - for (l = list; l != NULL; l = l->next) - { - PopplerImageMapping *mapping; + poppler_page_free_annots (list); - mapping = (PopplerImageMapping *)l->data; - printf ("\t\t(%f, %f) - (%f, %f)\n", - mapping->area.x1, - mapping->area.y1, - mapping->area.x2, - mapping->area.y2); - } - poppler_page_free_image_mapping (list); - - list = poppler_page_get_form_fields (page); - num_forms = g_list_length (list); - printf ("\n"); - if (num_forms > 0) - printf ("\tFound %d form fields at positions:\n", num_forms); - else - printf ("\tNo forms fields found\n"); - for (l = list; l != NULL; l = l->next) - { - PopplerFormField *field; - - field = (PopplerFormField *)l->data; - printf ("\t\t%s (id = %d): (%f, %f) - (%f, %f)\n", - form_field_get_type_name (field->type), - field->id, - field->area.x1, - field->area.y1, - field->area.x2, - field->area.y2); - } - poppler_page_free_form_fields (list); - - if (poppler_document_has_attachments (document)) - { - int i = 0; - - g_print ("Attachments found:\n\n"); - - list = poppler_document_get_attachments (document); - for (l = list; l; l = l->next) - { - PopplerAttachment *attachment; - char *name; - - name = g_strdup_printf ("/tmp/attach%d", i); - attachment = l->data; - g_print ("\tname: %s\n", attachment->name); - g_print ("\tdescription: %s\n\n", attachment->description); - poppler_attachment_save (attachment, name, NULL); - i++; - } - g_list_foreach (list, (GFunc) g_object_unref, NULL); - g_list_free (list); + g_object_unref (G_OBJECT (page)); } - else - g_print ("no attachment\n"); - - g_object_unref (G_OBJECT (page)); + } g_object_unref (G_OBJECT (document));