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 14 Jun 2007 09:59:30 -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 14 Jun 2007 09:59:30 -0000 @@ -0,0 +1,524 @@ +/* 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_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 = poppler_annot_new (); + *new_annot = *annot; + + new_annot->contents = g_strdup (annot->contents); + new_annot->name = g_strdup (annot->name); + new_annot->modified = g_strdup (annot->modified); + new_annot->appear_state = g_strdup (annot->appear_state); + new_annot->border.dash = (gdouble *) g_memdup (annot->border.dash, + sizeof (gdouble) * annot->border.dash_length); + + switch (annot->type) { + case POPPLER_ANNOT_FREE_TEXT: + new_annot->annot_free_text.appearance_string = g_strdup (annot->annot_free_text.appearance_string); + new_annot->annot_free_text.style_string = g_strdup (annot->annot_free_text.style_string); + break; + case POPPLER_ANNOT_WIDGET: + new_annot->annot_widget.appear_characs.normal_caption = g_strdup (annot->annot_widget.appear_characs.normal_caption); + new_annot->annot_widget.appear_characs.rollover_caption = g_strdup (annot->annot_widget.appear_characs.rollover_caption); + new_annot->annot_widget.appear_characs.alternate_caption = g_strdup (annot->annot_widget.appear_characs.alternate_caption); + break; + default: + break; + } + return new_annot; +} + +void +poppler_annot_free (PopplerAnnot *annot) +{ + if (!annot) + return; + + if (annot->contents) { + g_free (annot->contents); + annot->contents = NULL; + } + + if (annot->name) { + g_free (annot->name); + 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.dash) { + g_free (annot->border.dash); + annot->border.dash = 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_FREE_TEXT: + if (annot->annot_free_text.appearance_string) { + g_free (annot->annot_free_text.appearance_string); + annot->annot_free_text.appearance_string = NULL; + } + + if (annot->annot_free_text.style_string) { + g_free (annot->annot_free_text.style_string); + annot->annot_free_text.style_string = NULL; + } + break; + case POPPLER_ANNOT_POPUP: + if (annot->annot_popup.parent) + annot->annot_popup.parent = NULL; + break; + case POPPLER_ANNOT_WIDGET: + if (annot->annot_widget.appear_characs.normal_caption) { + g_free (annot->annot_widget.appear_characs.normal_caption); + annot->annot_widget.appear_characs.normal_caption = NULL; + } + + if (annot->annot_widget.appear_characs.rollover_caption) { + g_free (annot->annot_widget.appear_characs.rollover_caption); + annot->annot_widget.appear_characs.rollover_caption = NULL; + } + + if (annot->annot_widget.appear_characs.alternate_caption) { + g_free (annot->annot_widget.appear_characs.alternate_caption); + annot->annot_widget.appear_characs.alternate_caption = NULL; + } + break; + default: + break; + } + + g_free (annot); +} + +void +poppler_annot_base (PopplerAnnot *poppler_annot, + Annot *annot) +{ + AnnotColor *color; + AnnotBorder *border; + GooString *contents, *name, *modified, *appear_state; + + contents = annot->getContents (); + if (contents) + poppler_annot->contents = _poppler_goo_string_to_utf8 (contents); + + name = annot->getName (); + if (name) + poppler_annot->name = _poppler_goo_string_to_utf8 (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.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.horizontal_corner = border_array->getHorizontalCorner (); + poppler_annot->border.vertical_corner = border_array->getVerticalCorner (); + } + } + + color = annot->getColor (); + if (color && (color->getSpace () == AnnotColor::colorRGB)) { + 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) +{ + PDFRectangle *rect; + 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.parent = parent_annot; + poppler_annot->annot_popup.open = annot->getOpen (); + + rect = annot->getRect (); + poppler_annot->annot_popup.rect.x1 = rect->x1; + poppler_annot->annot_popup.rect.y1 = rect->y1; + poppler_annot->annot_popup.rect.x2 = rect->x2; + poppler_annot->annot_popup.rect.y2 = rect->y2; + + 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.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.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.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.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.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.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.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_widget (AnnotWidget *annot) +{ + PopplerAnnot *poppler_annot; + AnnotAppearanceCharacs *appear_characs; + + poppler_annot = poppler_annot_new (); + + poppler_annot->type = POPPLER_ANNOT_WIDGET; + poppler_annot->markup = FALSE; + + poppler_annot_base (poppler_annot, + annot); + + poppler_annot->annot_widget.mode = (PopplerAnnotWidgetHighlightMode) annot->getMode (); + + appear_characs = annot->getAppearCharacs (); + if (appear_characs) { + AnnotColor *border_color, *back_color; + AnnotIconFit *icon_fit; + GooString *normal_caption, *rollover_caption, *alternate_caption; + + poppler_annot->annot_widget.appear_characs.rotation = appear_characs->getRotation (); + + border_color = appear_characs->getBorderColor (); + if (border_color && (border_color->getSpace () == AnnotColor::colorRGB)) { + poppler_annot->annot_widget.appear_characs.border_color.red = border_color->getValue (0); + poppler_annot->annot_widget.appear_characs.border_color.green = border_color->getValue (1); + poppler_annot->annot_widget.appear_characs.border_color.blue = border_color->getValue (2); + } + + back_color = appear_characs->getBackColor (); + if (back_color && (back_color->getSpace () == AnnotColor::colorRGB)) { + poppler_annot->annot_widget.appear_characs.back_color.red = back_color->getValue (0); + poppler_annot->annot_widget.appear_characs.back_color.green = back_color->getValue (1); + poppler_annot->annot_widget.appear_characs.back_color.blue = back_color->getValue (2); + } + + normal_caption = appear_characs->getNormalCaption (); + if (normal_caption) + poppler_annot->annot_widget.appear_characs.normal_caption = _poppler_goo_string_to_utf8 (normal_caption); + + rollover_caption = appear_characs->getRolloverCaption (); + if (rollover_caption) + poppler_annot->annot_widget.appear_characs.rollover_caption = _poppler_goo_string_to_utf8 (rollover_caption); + + alternate_caption = appear_characs->getAlternateCaption (); + if (alternate_caption) + poppler_annot->annot_widget.appear_characs.alternate_caption = _poppler_goo_string_to_utf8 (alternate_caption); + + icon_fit = appear_characs->getIconFit (); + if (icon_fit) { + poppler_annot->annot_widget.appear_characs.icon_fit.scale_when = (PopplerAnnotIconFitScaleWhen) icon_fit->getScaleWhen (); + poppler_annot->annot_widget.appear_characs.icon_fit.scale = (PopplerAnnotIconFitScale) icon_fit->getScale (); + poppler_annot->annot_widget.appear_characs.icon_fit.left = icon_fit->getLeft (); + poppler_annot->annot_widget.appear_characs.icon_fit.bottom = icon_fit->getBottom (); + poppler_annot->annot_widget.appear_characs.icon_fit.fully_bounds = icon_fit->getFullyBounds (); + } + + poppler_annot->annot_widget.appear_characs.position = (PopplerAnnotAppearanceCharacsTextPos) (appear_characs->getPosition ()); + } + + 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); + + switch (annot->getType ()) { + case Annot::typeText: + poppler_annot = poppler_annot_text (dynamic_cast (annot)); + break; + case Annot::typeLink: + // TODO: merge with the actual Link implementation + break; + case Annot::typeFreeText: + poppler_annot = poppler_annot_free_text (dynamic_cast (annot)); + break; + case Annot::typeLine: + poppler_annot = poppler_annot_line (dynamic_cast (annot)); + break; + case Annot::typeWidget: + // TODO: merge with the actual Widget implementation from Forms + poppler_annot = poppler_annot_widget (dynamic_cast (annot)); + break; + default: + 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 14 Jun 2007 09:59:31 -0000 @@ -0,0 +1,327 @@ +/* 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 enum { + POPPLER_ANNOT_HIGHLIGHT_MODE_NONE, + POPPLER_ANNOT_HIGHLIGHT_MODE_INVERT, + POPPLER_ANNOT_HIGHLIGHT_MODE_OUTLINE, + POPPLER_ANNOT_HIGHLIGHT_MODE_PUSH +} PopplerAnnotWidgetHighlightMode; + +typedef enum { + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_NO_ICON, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_NO_CAPTION, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_BELOW, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_ABOVE, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_RIGHT, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_LEFT, + POPPLER_ANNOT_APPEARANCE_TEXT_POS_CAPTION_OVERLAID +} PopplerAnnotAppearanceCharacsTextPos; + +typedef enum { + POPPLER_ANNOT_ICON_FIT_SCALE_ALWAYS, + POPPLER_ANNOT_ICON_FIT_SCALE_BIGGER, + POPPLER_ANNOT_ICON_FIT_SCALE_SMALLER, + POPPLER_ANNOT_ICON_FIT_SCALE_NEVER +} PopplerAnnotIconFitScaleWhen; + +typedef enum { + POPPLER_ANNOT_ICON_FIT_SCALE_ANAMORPHIC, + POPPLER_ANNOT_ICON_FIT_SCALE_PROPORTIONAL +} PopplerAnnotIconFitScale; + +typedef struct _PopplerAnnotColor PopplerAnnotColor; +typedef struct _PopplerAnnotIconFit PopplerAnnotIconFit; +typedef struct _PopplerAnnotAppearanceCharacs PopplerAnnotAppearanceCharacs; +typedef struct _PopplerAnnotCalloutLine PopplerAnnotCalloutLine; +typedef struct _PopplerAnnotBorderEffect PopplerAnnotBorderEffect; +typedef struct _PopplerAnnotBorder PopplerAnnotBorder; +typedef struct _PopplerAnnotText PopplerAnnotText; +typedef struct _PopplerAnnotFreeText PopplerAnnotFreeText; +typedef struct _PopplerAnnotLine PopplerAnnotLine; +typedef struct _PopplerAnnotPopup PopplerAnnotPopup; +typedef struct _PopplerAnnotWidget PopplerAnnotWidget; + +struct _PopplerAnnotColor +{ + gdouble red; + gdouble green; + gdouble blue; +}; + +struct _PopplerAnnotIconFit +{ + PopplerAnnotIconFitScaleWhen scale_when; + PopplerAnnotIconFitScale scale; + gdouble left; + gdouble bottom; + gboolean fully_bounds; +}; + +struct _PopplerAnnotAppearanceCharacs +{ + gint rotation; + PopplerAnnotColor border_color; + PopplerAnnotColor back_color; + gchar *normal_caption; + gchar *rollover_caption; + gchar *alternate_caption; + PopplerAnnotIconFit icon_fit; + PopplerAnnotAppearanceCharacsTextPos position; +}; + +struct _PopplerAnnotCalloutLine +{ + gboolean multiline; + gdouble x1; + gdouble y1; + gdouble x2; + gdouble y2; + gdouble x3; + gdouble y3; +}; + +struct _PopplerAnnotBorderEffect +{ + PopplerAnnotBorderEffectType effect_type; + gdouble intensity; +}; + +struct _PopplerAnnotBorder +{ + PopplerAnnotBorderType type; + gdouble width; + gdouble *dash; + gint dash_length; + gdouble horizontal_corner; + gdouble vertical_corner; + 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; + PopplerRectangle rect; +}; + +struct _PopplerAnnotWidget +{ + PopplerAnnotWidgetHighlightMode mode; + PopplerAnnotAppearanceCharacs appear_characs; +}; + +struct _PopplerAnnot +{ + PopplerAnnotType type; + gboolean markup; + + gchar *contents; + gchar *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; + PopplerAnnotWidget annot_widget; + }; +}; + +#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 14 Jun 2007 09:59:35 -0000 @@ -1385,6 +1385,49 @@ g_free (mapping); } +/* Poppler Annot mapping type */ +GType +poppler_annot_mapping_get_type (void) +{ + static GType our_type = 0; + + if (our_type == 0) + our_type = g_boxed_type_register_static ("PopplerAnnotMapping", + (GBoxedCopyFunc) poppler_annot_mapping_copy, + (GBoxedFreeFunc) poppler_annot_mapping_free); + + return our_type; +} + +PopplerAnnotMapping * +poppler_annot_mapping_new (void) +{ + return (PopplerAnnotMapping *) g_new0 (PopplerAnnotMapping, 1); +} + +PopplerAnnotMapping * +poppler_annot_mapping_copy (PopplerAnnotMapping *mapping) +{ + PopplerAnnotMapping *new_mapping; + + new_mapping = poppler_annot_mapping_new (); + + *new_mapping = *mapping; + if (new_mapping->annot) + new_mapping->annot = poppler_annot_copy (mapping->annot); + + return new_mapping; +} + +void +poppler_annot_mapping_free (PopplerAnnotMapping *mapping) +{ + if (mapping->annot) + poppler_annot_free (mapping->annot); + + g_free (mapping); +} + /* Page Transition */ GType poppler_page_transition (void) @@ -1578,3 +1621,107 @@ rect->y2 = cropBox->y2; } +/** + * poppler_page_get_annot_mapping: + * @page: A #PopplerPage + * + * Returns a list of #PopplerAnnotMapping items that map from a + * location on @page to a #PopplerAnnot. This list must be freed + * with poppler_page_free_annot_mapping() when done. + * + * Return value: A #GList of #PopplerAnnotMapping + **/ +GList * +poppler_page_get_annot_mapping (PopplerPage *page) +{ + GList *map_list = NULL; + Annots *annots; + double width, height; + + g_return_val_if_fail (POPPLER_IS_PAGE (page), NULL); + + annots = page->page->getAnnots (page->document->doc->getCatalog ()); + + if(!annots) + return NULL; + + poppler_page_get_size (page, &width, &height); + for(gint i = 0; i < annots->getNumAnnots (); i++) { + PopplerAnnotMapping *mapping; + PopplerRectangle rect; + Annot *annot; + PDFRectangle *annot_rect; + gint rotation = 0; + + annot = annots->getAnnot (i); + + /* Create the mapping */ + mapping = g_new (PopplerAnnotMapping, 1); + mapping->annot = _poppler_annot_new_from_annot (annot); + + annot_rect = annot->getRect (); + rect.x1 = annot_rect->x1; + rect.y1 = annot_rect->y1; + rect.x2 = annot_rect->x2; + rect.y2 = annot_rect->y2; + + if (! (mapping->annot->flags & Annot::flagNoRotate)) + rotation = page->page->getRotate (); + + switch (rotation) + { + case 90: + mapping->area.x1 = rect.y1; + mapping->area.y1 = height - rect.x2; + mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1); + mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1); + break; + case 180: + mapping->area.x1 = width - rect.x2; + mapping->area.y1 = height - rect.y2; + mapping->area.x2 = mapping->area.x1 + (rect.x2 - rect.x1); + mapping->area.y2 = mapping->area.y1 + (rect.y2 - rect.y1); + break; + case 270: + mapping->area.x1 = width - rect.y2; + mapping->area.y1 = rect.x1; + mapping->area.x2 = mapping->area.x1 + (rect.y2 - rect.y1); + mapping->area.y2 = mapping->area.y1 + (rect.x2 - rect.x1); + break; + default: + mapping->area.x1 = rect.x1; + mapping->area.y1 = rect.y1; + mapping->area.x2 = rect.x2; + mapping->area.y2 = rect.y2; + } + + mapping->area.x1 -= page->page->getCropBox()->x1; + mapping->area.x2 -= page->page->getCropBox()->x1; + mapping->area.y1 -= page->page->getCropBox()->y1; + mapping->area.y2 -= page->page->getCropBox()->y1; + + map_list = g_list_prepend (map_list, mapping); + } + + delete annots; + return g_list_reverse (map_list); +} + +/** + * poppler_page_free_annot_mapping: + * @list: A list of #PopplerAnnotMappings + * + * Frees a list of #PopplerAnnotMappings allocated by + * poppler_page_get_annot_mapping(). It also frees the #PopplerAnnots + * that each mapping contains, so if you want to keep them around, you need to + * copy them with poppler_annot_copy(). + **/ +void +poppler_page_free_annot_mapping (GList *list) +{ + if (!list) + return; + + g_list_foreach (list, (GFunc) (poppler_annot_mapping_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 14 Jun 2007 09:59:35 -0000 @@ -98,10 +98,14 @@ 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); - +GList *poppler_page_get_link_mapping (PopplerPage *page); +void poppler_page_free_link_mapping (GList *list); +GList *poppler_page_get_annot_mapping (PopplerPage *page); +void poppler_page_free_annot_mapping (GList *list); + /* A rectangle on a page, with coordinates in PDF points. */ #define POPPLER_TYPE_RECTANGLE (poppler_rectangle_get_type ()) struct _PopplerRectangle @@ -163,6 +167,19 @@ PopplerImageMapping *poppler_image_mapping_copy (PopplerImageMapping *mapping); void poppler_image_mapping_free (PopplerImageMapping *mapping); +/* Mapping between areas on the current page and PopplerAnnot */ +#define POPPLER_TYPE_ANNOT_MAPPING (poppler_annot_mapping_get_type ()) +struct _PopplerAnnotMapping +{ + PopplerRectangle area; + PopplerAnnot *annot; +}; + +GType poppler_annot_mapping_get_type (void) G_GNUC_CONST; +PopplerAnnotMapping *poppler_annot_mapping_new (void); +PopplerAnnotMapping *poppler_annot_mapping_copy (PopplerAnnotMapping *mapping); +void poppler_annot_mapping_free (PopplerAnnotMapping *mapping); + /* FormField */ #define POPPLER_TYPE_FORM_FIELD (poppler_form_field_get_type ()) struct _PopplerTextField 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 14 Jun 2007 09:59:35 -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 14 Jun 2007 09:59:35 -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 14 Jun 2007 09:59:35 -0000 @@ -93,7 +93,9 @@ typedef struct _PopplerLinkMapping PopplerLinkMapping; typedef struct _PopplerPageTransition PopplerPageTransition; typedef struct _PopplerImageMapping PopplerImageMapping; +typedef struct _PopplerAnnotMapping PopplerAnnotMapping; typedef struct _PopplerFormField PopplerFormField; +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__ */