poppler/Annot.cc | 511 ++++++++++++++++++++++++++++++++++++++++++++++++++----- poppler/Annot.h | 49 +++++ poppler/Dict.cc | 5 poppler/Page.h | 2 4 files changed, 523 insertions(+), 44 deletions(-)
New commits: commit 258e2197afa49e60b0b13a05408fc8d484dd8147 Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:25:00 2012 +0100 Added some new setters to AnnotFreeText diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 10ccd14..f6eacbb 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -2346,6 +2346,45 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) { obj1.free(); } +void AnnotFreeText::setQuadding(AnnotFreeTextQuadding new_quadding) { + Object obj1; + quadding = new_quadding; + obj1.initInt((int)quadding); + update ("Q", &obj1); +} + +void AnnotFreeText::setStyleString(GooString *new_string) { + delete styleString; + + if (new_string) { + styleString = new GooString(new_string); + //append the unicode marker <FE FF> if needed + if (!styleString->hasUnicodeMarker()) { + styleString->insert(0, 0xff); + styleString->insert(0, 0xfe); + } + } else { + styleString = new GooString(); + } + + Object obj1; + obj1.initString(styleString->copy()); + update ("DS", &obj1); +} + +void AnnotFreeText::setIntent(AnnotFreeTextIntent new_intent) { + Object obj1; + + intent = new_intent; + if (new_intent == intentFreeText) + obj1.initName("FreeText"); + else if (new_intent == intentFreeTextCallout) + obj1.initName("FreeTextCallout"); + else // intentFreeTextTypeWriter + obj1.initName("FreeTextTypeWriter"); + update ("IT", &obj1); +} + //------------------------------------------------------------------------ // AnnotLine //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index a94b67f..5a2a7bc 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -807,6 +807,10 @@ public: AnnotFreeText(PDFDoc *docA, Dict *dict, Object *obj); ~AnnotFreeText(); + void setQuadding(AnnotFreeTextQuadding new_quadding); + void setStyleString(GooString *new_string); + void setIntent(AnnotFreeTextIntent new_intent); + // getters GooString *getAppearanceString() const { return appearanceString; } AnnotFreeTextQuadding getQuadding() const { return quadding; } commit 84a62ac157e03880c1c1eda60c3927bd4414640e Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:24:28 2012 +0100 Added some new setters to AnnotGeometry, AnnotInk and AnnotCaret diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 95078e5..10ccd14 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -4486,6 +4486,37 @@ void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) { } +void AnnotGeometry::setType(AnnotSubtype new_type) { + Object obj1; + + switch (new_type) { + case typeSquare: + obj1.initName("Square"); + break; + case typeCircle: + obj1.initName("Circle"); + break; + default: + assert(!"Invalid subtype"); + } + + type = new_type; + update("Subtype", &obj1); +} + +void AnnotGeometry::setInteriorColor(AnnotColor *new_color) { + delete interiorColor; + + if (new_color) { + Object obj1; + new_color->writeToObject(xref, &obj1); + update ("IC", &obj1); + interiorColor = new_color; + } else { + interiorColor = NULL; + } +} + void AnnotGeometry::draw(Gfx *gfx, GBool printing) { Object obj; double ca = 1; @@ -4853,6 +4884,13 @@ void AnnotCaret::initialize(PDFDoc *docA, Dict* dict) { } +void AnnotCaret::setSymbol(AnnotCaretSymbol new_symbol) { + Object obj1; + obj1.initName( new_symbol == symbolP ? "P" : "None" ); + symbol = new_symbol; + update("Sy", &obj1); +} + //------------------------------------------------------------------------ // AnnotInk //------------------------------------------------------------------------ @@ -4866,21 +4904,7 @@ AnnotInk::AnnotInk(PDFDoc *docA, PDFRectangle *rect, AnnotPath **paths, int n_pa Object obj2; obj2.initArray (doc->getXRef()); - - for (int i = 0; i < n_paths; ++i) { - AnnotPath *path = paths[i]; - Object obj3; - obj3.initArray (doc->getXRef()); - - for (int j = 0; j < path->getCoordsLength(); ++j) { - Object obj4; - - obj3.arrayAdd (obj4.initReal (path->getX(j))); - obj3.arrayAdd (obj4.initReal (path->getY(j))); - } - - obj2.arrayAdd (&obj3); - } + writeInkList(paths, n_paths, obj2.getArray()); annotObj.dictSet ("InkList", &obj2); @@ -4894,27 +4918,14 @@ AnnotInk::AnnotInk(PDFDoc *docA, Dict *dict, Object *obj) : } AnnotInk::~AnnotInk() { - if (inkList) { - for (int i = 0; i < inkListLength; ++i) - delete inkList[i]; - gfree(inkList); - } + freeInkList(); } void AnnotInk::initialize(PDFDoc *docA, Dict* dict) { Object obj1; if (dict->lookup("InkList", &obj1)->isArray()) { - Array *array = obj1.getArray(); - inkListLength = array->getLength(); - inkList = (AnnotPath **) gmallocn ((inkListLength), sizeof(AnnotPath *)); - memset(inkList, 0, inkListLength * sizeof(AnnotPath *)); - for (int i = 0; i < inkListLength; i++) { - Object obj2; - if (array->get(i, &obj2)->isArray()) - inkList[i] = new AnnotPath(obj2.getArray()); - obj2.free(); - } + parseInkList(obj1.getArray()); } else { inkListLength = 0; inkList = NULL; @@ -4924,6 +4935,51 @@ void AnnotInk::initialize(PDFDoc *docA, Dict* dict) { obj1.free(); } +void AnnotInk::writeInkList(AnnotPath **paths, int n_paths, Array *dest_array) { + Object obj1, obj2; + for (int i = 0; i < n_paths; ++i) { + AnnotPath *path = paths[i]; + obj1.initArray (xref); + for (int j = 0; j < path->getCoordsLength(); ++j) { + obj1.arrayAdd (obj2.initReal (path->getX(j))); + obj1.arrayAdd (obj2.initReal (path->getY(j))); + } + dest_array->add (&obj1); + } +} + +void AnnotInk::parseInkList(Array *array) { + inkListLength = array->getLength(); + inkList = (AnnotPath **) gmallocn ((inkListLength), sizeof(AnnotPath *)); + memset(inkList, 0, inkListLength * sizeof(AnnotPath *)); + for (int i = 0; i < inkListLength; i++) { + Object obj2; + if (array->get(i, &obj2)->isArray()) + inkList[i] = new AnnotPath(obj2.getArray()); + obj2.free(); + } +} + +void AnnotInk::freeInkList() { + if (inkList) { + for (int i = 0; i < inkListLength; ++i) + delete inkList[i]; + gfree(inkList); + } +} + +void AnnotInk::setInkList(AnnotPath **paths, int n_paths) { + Object obj1; + + freeInkList(); + + obj1.initArray (xref); + writeInkList(paths, n_paths, obj1.getArray()); + + parseInkList(obj1.getArray()); + annotObj.dictSet ("InkList", &obj1); +} + //------------------------------------------------------------------------ // AnnotFileAttachment //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index 5c1d9e3..a94b67f 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -975,6 +975,9 @@ public: virtual void draw(Gfx *gfx, GBool printing); + void setType(AnnotSubtype new_type); // typeSquare or typeCircle + void setInteriorColor(AnnotColor *new_color); + // getters AnnotColor *getInteriorColor() const { return interiorColor; } AnnotBorderEffect *getBorderEffect() const { return borderEffect; } @@ -1054,6 +1057,8 @@ public: AnnotCaret(PDFDoc *docA, Dict *dict, Object *obj); ~AnnotCaret(); + void setSymbol(AnnotCaretSymbol new_symbol); + // getters AnnotCaretSymbol getSymbol() const { return symbol; } PDFRectangle *getCaretRect() const { return caretRect; } @@ -1077,6 +1082,8 @@ public: AnnotInk(PDFDoc *docA, Dict *dict, Object *obj); ~AnnotInk(); + void setInkList(AnnotPath **paths, int n_paths); + // getters AnnotPath **getInkList() const { return inkList; } int getInkListLength() const { return inkListLength; } @@ -1084,6 +1091,9 @@ public: private: void initialize(PDFDoc *docA, Dict *dict); + void writeInkList(AnnotPath **paths, int n_paths, Array *dest_array); + void parseInkList(Array *src_array); + void freeInkList(); // required AnnotPath **inkList; // InkList commit 233c9a097bdc382f6a2eb6319ee15528c72e9632 Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:23:59 2012 +0100 Added some new setters to AnnotTextMarkup and AnnotStamp diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 205e402..95078e5 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -394,6 +394,11 @@ AnnotQuadrilaterals::AnnotQuadrilaterals(Array *array, PDFRectangle *rect) { } } +AnnotQuadrilaterals::AnnotQuadrilaterals(AnnotQuadrilaterals::AnnotQuadrilateral **quads, int quadsLength) { + quadrilaterals = quads; + quadrilateralsLength = quadsLength; +} + AnnotQuadrilaterals::~AnnotQuadrilaterals() { if (quadrilaterals) { for(int i = 0; i < quadrilateralsLength; i++) @@ -2761,7 +2766,49 @@ AnnotTextMarkup::~AnnotTextMarkup() { } } +void AnnotTextMarkup::setType(AnnotSubtype new_type) { + Object obj1; + + switch (new_type) { + case typeHighlight: + obj1.initName("Highlight"); + break; + case typeUnderline: + obj1.initName("Underline"); + break; + case typeSquiggly: + obj1.initName("Squiggly"); + break; + case typeStrikeOut: + obj1.initName("StrikeOut"); + break; + default: + assert(!"Invalid subtype"); + } + + type = new_type; + update("Subtype", &obj1); +} + +void AnnotTextMarkup::setQuadrilaterals(AnnotQuadrilaterals *quadPoints) { + Object obj1, obj2; + obj1.initArray (xref); + + for (int i = 0; i < quadPoints->getQuadrilateralsLength(); ++i) { + obj1.arrayAdd (obj2.initReal (quadPoints->getX1(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getY1(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getX2(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getY2(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getX3(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getY3(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getX4(i))); + obj1.arrayAdd (obj2.initReal (quadPoints->getY4(i))); + } + + quadrilaterals = new AnnotQuadrilaterals(obj1.getArray(), rect); + annotObj.dictSet ("QuadPoints", &obj1); +} void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) { Object obj; @@ -4356,6 +4403,20 @@ void AnnotStamp::initialize(PDFDoc *docA, Dict* dict) { } +void AnnotStamp::setIcon(GooString *new_icon) { + delete icon; + + if (new_icon) { + icon = new GooString (new_icon); + } else { + icon = new GooString(); + } + + Object obj1; + obj1.initName (icon->getCString()); + update("Name", &obj1); +} + //------------------------------------------------------------------------ // AnnotGeometry //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index 83133d0..5c1d9e3 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -177,6 +177,7 @@ private: //------------------------------------------------------------------------ class AnnotQuadrilaterals { +public: class AnnotQuadrilateral { public: AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3, @@ -185,9 +186,8 @@ class AnnotQuadrilaterals { AnnotCoord coord1, coord2, coord3, coord4; }; -public: - AnnotQuadrilaterals(Array *array, PDFRectangle *rect); + AnnotQuadrilaterals(AnnotQuadrilateral **quads, int quadsLength); ~AnnotQuadrilaterals(); double getX1(int quadrilateral); @@ -925,6 +925,11 @@ public: virtual void draw(Gfx *gfx, GBool printing); + // typeHighlight, typeUnderline, typeSquiggly or typeStrikeOut + void setType(AnnotSubtype new_type); + + void setQuadrilaterals(AnnotQuadrilaterals *quadPoints); + AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals; } protected: @@ -945,6 +950,8 @@ public: AnnotStamp(PDFDoc *docA, Dict *dict, Object *obj); ~AnnotStamp(); + void setIcon(GooString *new_icon); + // getters GooString *getIcon() const { return icon; } commit 8fb3ac6cf66233b80959ba99a2c706111050f5f1 Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:23:23 2012 +0100 Added Page::getDoc() diff --git a/poppler/Page.h b/poppler/Page.h index 593bea0..70141d0 100644 --- a/poppler/Page.h +++ b/poppler/Page.h @@ -19,6 +19,7 @@ // Copyright (C) 2006, 2011 Carlos Garcia Campos <[email protected]> // Copyright (C) 2007 Julien Rebetez <[email protected]> // Copyright (C) 2008 Iñigo MartÃnez <[email protected]> +// Copyright (C) 2012 Fabio D'Urso <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -161,6 +162,7 @@ public: Stream *getMetadata() { return attrs->getMetadata(); } Dict *getPieceInfo() { return attrs->getPieceInfo(); } Dict *getSeparationInfo() { return attrs->getSeparationInfo(); } + PDFDoc *getDoc() { return doc; } // Get resource dictionary. Dict *getResourceDict() { return attrs->getResourceDict(); } commit dc4cb07c1e735006d5168e0e65f5143d7fc53e12 Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:22:10 2012 +0100 Added some new setters to AnnotLine and AnnotPolygon diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 0a75fed..205e402 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -125,6 +125,31 @@ AnnotLineEndingStyle parseAnnotLineEndingStyle(GooString *string) { } } +const char* convertAnnotLineEndingStyle(AnnotLineEndingStyle style) { + switch (style) { + case annotLineEndingSquare: + return "Square"; + case annotLineEndingCircle: + return "Circle"; + case annotLineEndingDiamond: + return "Diamond"; + case annotLineEndingOpenArrow: + return "OpenArrow"; + case annotLineEndingClosedArrow: + return "ClosedArrow"; + case annotLineEndingButt: + return "Butt"; + case annotLineEndingROpenArrow: + return "ROpenArrow"; + case annotLineEndingRClosedArrow: + return "RClosedArrow"; + case annotLineEndingSlash: + return "Slash"; + default: + return "None"; + } +} + static AnnotExternalDataType parseAnnotExternalData(Dict* dict) { Object obj1; AnnotExternalDataType type; @@ -659,6 +684,19 @@ void AnnotColor::adjustColor(int adjust) { } } +void AnnotColor::writeToObject(XRef *xref, Object *obj1) const { + Object obj2; + int i; + + if (length == 0) { + obj1->initNull(); // Transparent (no color) + } else { + obj1->initArray(xref); + for (i = 0; i < length; ++i) + obj1->arrayAdd( obj2.initReal( values[i] ) ); + } +} + //------------------------------------------------------------------------ // AnnotIconFit //------------------------------------------------------------------------ @@ -1130,12 +1168,8 @@ void Annot::setColor(AnnotColor *new_color) { delete color; if (new_color) { - Object obj1, obj2; - const double *values = new_color->getValues(); - - obj1.initArray(xref); - for (int i = 0; i < (int)new_color->getSpace(); i++) - obj1.arrayAdd(obj2.initReal (values[i])); + Object obj1; + new_color->writeToObject(xref, &obj1); update ("C", &obj1); color = new_color; } else { @@ -2483,6 +2517,88 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) { obj1.free(); } +void AnnotLine::setVertices(double x1, double y1, double x2, double y2) { + Object obj1, obj2; + + delete coord1; + coord1 = new AnnotCoord(x1, y1); + delete coord2; + coord2 = new AnnotCoord(x2, y2); + + obj1.initArray(xref); + obj1.arrayAdd( obj2.initReal(x1) ); + obj1.arrayAdd( obj2.initReal(y1) ); + obj1.arrayAdd( obj2.initReal(x2) ); + obj1.arrayAdd( obj2.initReal(y2) ); + + update("L", &obj1); +} + +void AnnotLine::setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end) { + Object obj1, obj2; + + startStyle = start; + endStyle = end; + + obj1.initArray(xref); + obj1.arrayAdd( obj2.initName(convertAnnotLineEndingStyle( startStyle )) ); + obj1.arrayAdd( obj2.initName(convertAnnotLineEndingStyle( endStyle )) ); + + update("LE", &obj1); +} + +void AnnotLine::setInteriorColor(AnnotColor *new_color) { + delete interiorColor; + + if (new_color) { + Object obj1; + new_color->writeToObject(xref, &obj1); + update ("IC", &obj1); + interiorColor = new_color; + } else { + interiorColor = NULL; + } +} + +void AnnotLine::setLeaderLineLength(double len) { + Object obj1; + + leaderLineLength = len; + obj1.initReal(len); + update ("LL", &obj1); +} + +void AnnotLine::setLeaderLineExtension(double len) { + Object obj1; + + leaderLineExtension = len; + obj1.initReal(len); + update ("LLE", &obj1); + + // LL is required if LLE is present + obj1.initReal(leaderLineLength); + update ("LL", &obj1); +} + +void AnnotLine::setCaption(bool new_cap) { + Object obj1; + + caption = new_cap; + obj1.initBool(new_cap); + update ("Cap", &obj1); +} + +void AnnotLine::setIntent(AnnotLineIntent new_intent) { + Object obj1; + + intent = new_intent; + if (new_intent == intentLineArrow) + obj1.initName("LineArrow"); + else // intentLineDimension + obj1.initName("LineDimension"); + update ("IT", &obj1); +} + void AnnotLine::draw(Gfx *gfx, GBool printing) { Object obj; double ca = 1; @@ -4557,6 +4673,79 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) { obj1.free(); } +void AnnotPolygon::setType(AnnotSubtype new_type) { + Object obj1; + + switch (new_type) { + case typePolygon: + obj1.initName("Polygon"); + break; + case typePolyLine: + obj1.initName("PolyLine"); + break; + default: + assert(!"Invalid subtype"); + } + + type = new_type; + update("Subtype", &obj1); +} + +void AnnotPolygon::setVertices(AnnotPath *path) { + Object obj1, obj2; + delete vertices; + + obj1.initArray(xref); + + for (int i = 0; i < path->getCoordsLength(); i++) { + obj1.arrayAdd (obj2.initReal (path->getX(i))); + obj1.arrayAdd (obj2.initReal (path->getY(i))); + } + + vertices = new AnnotPath(obj1.getArray()); + + update("Vertices", &obj1); +} + +void AnnotPolygon::setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end) { + Object obj1, obj2; + + startStyle = start; + endStyle = end; + + obj1.initArray(xref); + obj1.arrayAdd( obj2.initName(convertAnnotLineEndingStyle( startStyle )) ); + obj1.arrayAdd( obj2.initName(convertAnnotLineEndingStyle( endStyle )) ); + + update("LE", &obj1); +} + +void AnnotPolygon::setInteriorColor(AnnotColor *new_color) { + delete interiorColor; + + if (new_color) { + Object obj1; + new_color->writeToObject(xref, &obj1); + update ("IC", &obj1); + interiorColor = new_color; + } else { + interiorColor = NULL; + } +} + +void AnnotPolygon::setIntent(AnnotPolygonIntent new_intent) { + Object obj1; + + intent = new_intent; + if (new_intent == polygonCloud) + obj1.initName("PolygonCloud"); + else if (new_intent == polylineDimension) + obj1.initName("PolyLineDimension"); + else // polygonDimension + obj1.initName("PolygonDimension"); + update ("IT", &obj1); +} + //------------------------------------------------------------------------ // AnnotCaret //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index 7db884c..83133d0 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -304,6 +304,8 @@ public: AnnotColorSpace getSpace() const { return (AnnotColorSpace) length; } const double *getValues() const { return values; } + void writeToObject(XRef *xref, Object *dest) const; + private: double values[4]; @@ -859,6 +861,14 @@ public: virtual void draw(Gfx *gfx, GBool printing); + void setVertices(double x1, double y1, double x2, double y2); + void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end); + void setInteriorColor(AnnotColor *new_color); + void setLeaderLineLength(double len); + void setLeaderLineExtension(double len); + void setCaption(bool new_cap); + void setIntent(AnnotLineIntent new_intent); + // getters AnnotLineEndingStyle getStartStyle() const { return startStyle; } AnnotLineEndingStyle getEndStyle() const { return endStyle; } @@ -989,6 +999,12 @@ public: AnnotPolygon(PDFDoc *docA, Dict *dict, Object *obj); ~AnnotPolygon(); + void setType(AnnotSubtype new_type); // typePolygon or typePolyLine + void setVertices(AnnotPath *path); + void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end); + void setInteriorColor(AnnotColor *new_color); + void setIntent(AnnotPolygonIntent new_intent); + // getters AnnotPath *getVertices() const { return vertices; } AnnotLineEndingStyle getStartStyle() const { return startStyle; } commit 4931018eecc37dbbe0df1a456347ab200f1b057a Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:21:07 2012 +0100 Make Dict::set remove the entry if object is Null diff --git a/poppler/Dict.cc b/poppler/Dict.cc index 2615fde..c4f667b 100644 --- a/poppler/Dict.cc +++ b/poppler/Dict.cc @@ -18,6 +18,7 @@ // Copyright (C) 2007-2008 Julien Rebetez <[email protected]> // Copyright (C) 2008, 2010 Albert Astals Cid <[email protected]> // Copyright (C) 2010 PaweÅ Wiejacha <[email protected]> +// Copyright (C) 2012 Fabio D'Urso <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -177,6 +178,10 @@ void Dict::remove(const char *key) { void Dict::set(const char *key, Object *val) { DictEntry *e; + if (val->isNull()) { + remove(key); + return; + } e = find (key); if (e) { e->val.free(); commit 13ac2c0bed3fa5515a3c068488cb6a0b17410a97 Author: Fabio D'Urso <[email protected]> Date: Wed Mar 14 23:20:13 2012 +0100 Added some new setters to Annot and AnnotMarkup diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 9f07b2f..0a75fed 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -24,6 +24,7 @@ // Copyright (C) 2008 Hugo Mercier <[email protected]> // Copyright (C) 2009 Ilya Gorenbein <[email protected]> // Copyright (C) 2011 José Aliste <[email protected]> +// Copyright (C) 2012 Fabio D'Urso <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -1020,18 +1021,52 @@ void Annot::getRect(double *x1, double *y1, double *x2, double *y2) const { *y2 = rect->y2; } +void Annot::setRect(PDFRectangle *rect) { + setRect(rect->x1, rect->y1, rect->x2, rect->y2); +} + +void Annot::setRect(double x1, double y1, double x2, double y2) { + Object obj1, obj2; + + if (x1 < x2) { + rect->x1 = x1; + rect->x2 = x2; + } else { + rect->x1 = x2; + rect->x2 = x1; + } + + if (y1 < y2) { + rect->y1 = y1; + rect->y2 = y2; + } else { + rect->y1 = y2; + rect->y2 = y1; + } + + obj1.initArray (xref); + obj1.arrayAdd (obj2.initReal (rect->x1)); + obj1.arrayAdd (obj2.initReal (rect->y1)); + obj1.arrayAdd (obj2.initReal (rect->x2)); + obj1.arrayAdd (obj2.initReal (rect->y2)); + + update("Rect", &obj1); +} + GBool Annot::inRect(double x, double y) const { return rect->contains(x, y); } void Annot::update(const char *key, Object *value) { - /* Set M to current time */ - delete modified; - modified = timeToDateString(NULL); + /* Set M to current time, unless we are updating M itself */ + if (strcmp(key, "M") != 0) { + delete modified; + modified = timeToDateString(NULL); - Object obj1; - obj1.initString (modified->copy()); - annotObj.dictSet("M", &obj1); + Object obj1; + obj1.initString (modified->copy()); + annotObj.dictSet("M", &obj1); + } annotObj.dictSet(const_cast<char*>(key), value); @@ -1057,6 +1092,40 @@ void Annot::setContents(GooString *new_content) { update ("Contents", &obj1); } +void Annot::setName(GooString *new_name) { + delete name; + + if (new_name) { + name = new GooString(new_name); + } else { + name = new GooString(); + } + + Object obj1; + obj1.initString(name->copy()); + update ("NM", &obj1); +} + +void Annot::setModified(GooString *new_modified) { + delete modified; + + if (new_modified) + modified = new GooString(new_modified); + else + modified = new GooString(); + + Object obj1; + obj1.initString(modified->copy()); + update ("M", &obj1); +} + +void Annot::setFlags(Guint new_flags) { + Object obj1; + flags = new_flags; + obj1.initInt(flags); + update ("F", &obj1); +} + void Annot::setColor(AnnotColor *new_color) { delete color; @@ -1554,6 +1623,19 @@ void AnnotMarkup::setOpacity(double opacityA) { update ("CA", &obj1); } +void AnnotMarkup::setDate(GooString *new_date) { + delete date; + + if (new_date) + date = new GooString(new_date); + else + date = new GooString(); + + Object obj1; + obj1.initString(date->copy()); + update ("CreationDate", &obj1); +} + //------------------------------------------------------------------------ // AnnotText //------------------------------------------------------------------------ diff --git a/poppler/Annot.h b/poppler/Annot.h index c1188d0..7db884c 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -22,6 +22,7 @@ // Copyright (C) 2008 Pino Toscano <[email protected]> // Copyright (C) 2008 Tomas Are Haavet <[email protected]> // Copyright (C) 2009-2011 Albert Astals Cid <[email protected]> +// Copyright (C) 2012 Fabio D'Urso <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -474,9 +475,15 @@ public: double getFontSize() { return fontSize; } + void setRect(PDFRectangle *rect); + void setRect(double x1, double y1, double x2, double y2); + // Sets the annot contents to new_content // new_content should never be NULL void setContents(GooString *new_content); + void setName(GooString *new_name); + void setModified(GooString *new_date); + void setFlags(Guint new_flags); // The annotation takes the ownership of // new_color. @@ -620,6 +627,7 @@ public: void setPopup(AnnotPopup *new_popup); void setLabel(GooString *new_label); void setOpacity(double opacityA); + void setDate(GooString *new_date); protected: GooString *label; // T (Default autor)
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
