From f7f19ff8a8de067c7737c42078d20d0b3404cfd9 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Mon, 10 Dec 2007 17:56:44 +0100 Subject: [PATCH] AnnotText support. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Signed-off-by: Iñigo Martínez --- poppler/Annot.cc | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++- poppler/Annot.h | 65 ++++++++++++++++++++++++---- 2 files changed, 177 insertions(+), 11 deletions(-) diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 96dc8fe..3d1a7eb 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -1837,6 +1837,127 @@ void AnnotMarkup::initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *c } //------------------------------------------------------------------------ +// AnnotText +//------------------------------------------------------------------------ + +AnnotText::AnnotText(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj) : + Annot(xrefA, acroForm, dict, catalog, obj), AnnotMarkup(xref, acroForm, dict, catalog, obj) { + + type = typeText; + flags |= flagNoZoom & flagNoRotate; + initialize (xrefA, catalog, dict); +} + +void AnnotText::setModified(GooString* date) { + if(date) { + delete modified; + modified = new GooString(date); + } +} + +void AnnotText::initialize(XRef *xrefA, Catalog *catalog, Dict *dict) { + Object obj1; + + if (dict->lookup("Open", &obj1)->isBool()) + open = obj1.getBool(); + else + open = gFalse; + obj1.free(); + + if (dict->lookup("Name", &obj1)->isName()) { + GooString *iconName = new GooString(obj1.getName()); + + if(!iconName->cmp("Comment")) { + icon = iconComment; + } else if(!iconName->cmp("Key")) { + icon = iconKey; + } else if(!iconName->cmp("Help")) { + icon = iconHelp; + } else if(!iconName->cmp("NewParagraph")) { + icon = iconNewParagraph; + } else if(!iconName->cmp("Paragraph")) { + icon = iconParagraph; + } else if(!iconName->cmp("Insert")) { + icon = iconInsert; + } else { + icon = iconNote; + } + delete iconName; + } else { + icon = iconNote; + } + obj1.free(); + + if (dict->lookup("StateModel", &obj1)->isString()) { + Object obj2; + GooString *modelName = obj1.getString(); + + if (dict->lookup("State", &obj2)->isString()) { + GooString *stateName = obj2.getString(); + + if(!stateName->cmp("Marked")) { + state = stateMarked; + } else if(!stateName->cmp("Unmarked")) { + state = stateUnmarked; + } else if(!stateName->cmp("Accepted")) { + state = stateAccepted; + } else if(!stateName->cmp("Rejected")) { + state = stateRejected; + } else if(!stateName->cmp("Cancelled")) { + state = stateCancelled; + } else if(!stateName->cmp("Completed")) { + state = stateCompleted; + } else if(!stateName->cmp("None")) { + state = stateNone; + } else { + state = stateUnknown; + } + + delete stateName; + } else { + state = stateUnknown; + } + obj2.free(); + + if(!modelName->cmp("Marked")) { + switch (state) { + case stateUnknown: + state = stateMarked; + break; + case stateAccepted: + case stateRejected: + case stateCancelled: + case stateCompleted: + case stateNone: + state = stateUnknown; + break; + default: + break; + } + } else if(!modelName->cmp("Review")) { + switch (state) { + case stateUnknown: + state = stateNone; + break; + case stateMarked: + case stateUnmarked: + state = stateUnknown; + break; + default: + break; + } + } else { + state = stateUnknown; + } + + delete modelName; + } else { + state = stateUnknown; + } + obj1.free(); +} + +//------------------------------------------------------------------------ // Annots //------------------------------------------------------------------------ @@ -1886,7 +2007,7 @@ Annot *Annots::createAnnot(XRef *xref, Dict *acroForm, Dict* dict, Catalog *cata GooString *typeName = new GooString(obj1.getName()); if (!typeName->cmp("Text")) { - annot = new Annot(xref, acroForm, dict, catalog, obj); + annot = new AnnotText(xref, acroForm, dict, catalog, obj); } else if(!typeName->cmp("Link")) { annot = new Annot(xref, acroForm, dict, catalog, obj); } else if(!typeName->cmp("FreeText")) { diff --git a/poppler/Annot.h b/poppler/Annot.h index 18416c5..09faec3 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -40,7 +40,7 @@ public: borderInset, // Inset borderUnderlined, // Underlined }; - + virtual ~AnnotBorder(); virtual double getWidth() { return width; } @@ -80,7 +80,7 @@ protected: class AnnotBorderBS: public AnnotBorder { public: - + AnnotBorderBS(); AnnotBorderBS(Dict *dict); @@ -103,7 +103,7 @@ public: colorRGB = 3, colorCMYK = 4 }; - + AnnotColor(); AnnotColor(Array *array); ~AnnotColor(); @@ -285,7 +285,7 @@ protected: GBool ok; GBool regen, isTextField; GBool isMultiline, isListbox; - + bool hasRef; }; @@ -295,7 +295,6 @@ protected: class AnnotPopup: public Annot { public: - AnnotPopup(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj); virtual ~AnnotPopup(); @@ -303,9 +302,8 @@ public: bool getOpen() { return open; } protected: - void initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog); - + Dict *parent; // Parent bool open; // Open }; @@ -336,7 +334,6 @@ public: AnnotExternalDataType getExData() { return exData; } protected: - GooString *label; // T (Default autor) AnnotPopup *popup; // Popup double opacity; // CA (Default 1.0) @@ -351,11 +348,60 @@ protected: AnnotExternalDataType exData; // ExData private: - void initialize(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj); }; //------------------------------------------------------------------------ +// AnnotText +//------------------------------------------------------------------------ + +class AnnotText: public Annot, public AnnotMarkup { +public: + enum AnnotTextIcon { + iconComment, // Comment + iconKey, // Key + iconNote, // Note + iconHelp, // Help + iconNewParagraph, // NewParagraph + iconParagraph, // Paragraph + iconInsert // Insert + }; + + enum AnnotTextState { + stateUnknown, + // Marked state model + stateMarked, // Marked + stateUnmarked, // Unmarked + // Review state model + stateAccepted, // Accepted + stateRejected, // Rejected + stateCancelled, // Cancelled + stateCompleted, // Completed + stateNone // None + }; + + AnnotText(XRef *xrefA, Dict *acroForm, Dict *dict, Catalog *catalog, Object *obj); + + // getters + bool getOpen() { return open; } + AnnotTextIcon getIcon() { return icon; } + AnnotTextState getState() { return state; } + + // setters + void setModified(GooString *date); + +private: + + void initialize(XRef *xrefA, Catalog *catalog, Dict *dict); + + bool open; // Open (Default false) + AnnotTextIcon icon; // Name (Default Note) + AnnotTextState state; // State (Default Umarked if + // StateModel Marked + // None if StareModel Review) +}; + +//------------------------------------------------------------------------ // Annots //------------------------------------------------------------------------ @@ -375,7 +421,6 @@ public: // to a form field. void generateAppearances(Dict *acroForm); - private: Annot* createAnnot(XRef *xref, Dict *acroForm, Dict* dict, Catalog *catalog, Object *obj); void scanFieldAppearances(Dict *node, Ref *ref, Dict *parent, -- 1.5.2.5