[poppler] 8 commits - glib/poppler-annot.cc poppler/Annot.cc poppler/Annot.h qt5/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 9 09:35:42 UTC 2018


 glib/poppler-annot.cc               |   25 -
 poppler/Annot.cc                    |  893 +++++++++++-------------------------
 poppler/Annot.h                     |  336 ++++++-------
 qt5/src/poppler-annotation-helper.h |    4 
 qt5/src/poppler-annotation.cc       |   41 -
 5 files changed, 472 insertions(+), 827 deletions(-)

New commits:
commit 38b54a6a18d53d7f9e1d290c6cc420744c450d4f
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Oct 8 21:20:18 2018 +0200

    Move 'default' definition of con-/destructors to .cc file

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 22c7f358..38108bca 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -281,6 +281,8 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
 // AnnotPath
 //------------------------------------------------------------------------
 
+AnnotPath::AnnotPath() = default;
+
 AnnotPath::AnnotPath(Array *array) {
   parsePathArray(array);
 }
@@ -289,6 +291,8 @@ AnnotPath::AnnotPath(std::vector<AnnotCoord> &&coords) {
   this->coords = std::move(coords);
 }
 
+AnnotPath::~AnnotPath() = default;
+
 double AnnotPath::getX(int coord) const {
   if (coord >= 0 && coord < getCoordsLength())
     return coords[coord].getX();
@@ -401,6 +405,8 @@ AnnotQuadrilaterals::AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &
   quadrilateralsLength = quadsLength;
 }
 
+AnnotQuadrilaterals::~AnnotQuadrilaterals() = default;
+
 double AnnotQuadrilaterals::getX1(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
     return quadrilaterals[quadrilateral].coord1.getX();
@@ -449,6 +455,8 @@ double AnnotQuadrilaterals::getY4(int quadrilateral) {
   return 0;
 }
 
+AnnotQuadrilaterals::AnnotQuadrilateral::AnnotQuadrilateral() = default;
+
 AnnotQuadrilaterals::AnnotQuadrilateral::AnnotQuadrilateral(double x1, double y1,
     double x2, double y2, double x3, double y3, double x4, double y4)
     : coord1(x1, y1), coord2(x2, y2), coord3(x3, y3), coord4(x4, y4) {
@@ -1070,6 +1078,8 @@ AnnotAppearanceCharacs::AnnotAppearanceCharacs(Dict *dict) {
   }
 }
 
+AnnotAppearanceCharacs::~AnnotAppearanceCharacs() = default;
+
 //------------------------------------------------------------------------
 // AnnotAppearanceBBox
 //------------------------------------------------------------------------
@@ -1814,6 +1824,8 @@ AnnotMarkup::AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict(), obj);
 }
 
+AnnotMarkup::~AnnotMarkup() = default;
+
 void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
   Object obj1, obj2;
 
@@ -1970,6 +1982,8 @@ AnnotText::AnnotText(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize (docA, dictObject->getDict());
 }
 
+AnnotText::~AnnotText() = default;
+
 void AnnotText::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -2396,6 +2410,8 @@ AnnotLink::AnnotLink(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize (docA, dictObject->getDict());
 }
 
+AnnotLink::~AnnotLink() = default;
+
 void AnnotLink::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -2482,6 +2498,8 @@ AnnotFreeText::AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotFreeText::~AnnotFreeText() = default;
+
 void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -2843,6 +2861,8 @@ AnnotLine::AnnotLine(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotLine::~AnnotLine() = default;
+
 void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -3289,6 +3309,8 @@ AnnotTextMarkup::AnnotTextMarkup(PDFDoc *docA, Object *dictObject, Object *obj)
   initialize(docA, dictObject->getDict());
 }
 
+AnnotTextMarkup::~AnnotTextMarkup() = default;
+
 void AnnotTextMarkup::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -3543,6 +3565,8 @@ AnnotWidget::AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormFiel
   initialize(docA, dictObject->getDict());
 }
 
+AnnotWidget::~AnnotWidget() = default;
+
 void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -4807,6 +4831,8 @@ AnnotMovie::AnnotMovie(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotMovie::~AnnotMovie() = default;
+
 void AnnotMovie::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -4925,6 +4951,8 @@ AnnotScreen::AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotScreen::~AnnotScreen() = default;
+
 void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -4975,6 +5003,8 @@ AnnotStamp::AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotStamp::~AnnotStamp() = default;
+
 void AnnotStamp::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("Name");
   if (obj1.isName()) {
@@ -5022,6 +5052,8 @@ AnnotGeometry::AnnotGeometry(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotGeometry::~AnnotGeometry() = default;
+
 void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5222,6 +5254,8 @@ AnnotPolygon::AnnotPolygon(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotPolygon::~AnnotPolygon() = default;
+
 void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5451,6 +5485,8 @@ AnnotCaret::AnnotCaret(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotCaret::~AnnotCaret() = default;
+
 void AnnotCaret::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5653,6 +5689,8 @@ AnnotFileAttachment::AnnotFileAttachment(PDFDoc *docA, Object *dictObject, Objec
   initialize(docA, dictObject->getDict());
 }
 
+AnnotFileAttachment::~AnnotFileAttachment() = default;
+
 void AnnotFileAttachment::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5850,6 +5888,8 @@ AnnotSound::AnnotSound(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotSound::~AnnotSound() = default;
+
 void AnnotSound::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("Sound");
 
@@ -5992,6 +6032,8 @@ Annot3D::Annot3D(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+Annot3D::~Annot3D() = default;
+
 void Annot3D::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("3DA");
   if (obj1.isDict()) {
@@ -6101,6 +6143,8 @@ AnnotRichMedia::AnnotRichMedia(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
+AnnotRichMedia::~AnnotRichMedia() = default;
+
 void AnnotRichMedia::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("RichMediaContent");
   if (obj1.isDict()) {
@@ -6133,6 +6177,8 @@ AnnotRichMedia::Settings::Settings(Dict *dict) {
   }
 }
 
+AnnotRichMedia::Settings::~Settings() = default;
+
 AnnotRichMedia::Activation* AnnotRichMedia::Settings::getActivation() const {
   return activation.get();
 }
@@ -6268,6 +6314,10 @@ AnnotRichMedia::Asset* AnnotRichMedia::Content::getAsset(int index) const {
   return assets[index];
 }
 
+AnnotRichMedia::Asset::Asset() = default;
+
+AnnotRichMedia::Asset::~Asset() = default;
+
 const GooString* AnnotRichMedia::Asset::getName() const {
   return name.get();
 }
@@ -6394,6 +6444,8 @@ AnnotRichMedia::Instance::Instance(Dict *dict)
   }
 }
 
+AnnotRichMedia::Instance::~Instance() = default;
+
 AnnotRichMedia::Instance::Type AnnotRichMedia::Instance::getType() const {
   return type;
 }
@@ -6410,6 +6462,8 @@ AnnotRichMedia::Params::Params(Dict *dict)
   }
 }
 
+AnnotRichMedia::Params::~Params() = default;
+
 const GooString* AnnotRichMedia::Params::getFlashVars() const {
   return flashVars.get();
 }
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 0c0d7d73..bacce742 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -111,10 +111,10 @@ protected:
 
 class AnnotPath {
 public:
-  AnnotPath() = default;
+  AnnotPath();
   AnnotPath(Array *array);
   AnnotPath(std::vector<AnnotCoord> &&coords);
-  ~AnnotPath() = default;
+  ~AnnotPath();
 
   AnnotPath(const AnnotPath &) = delete;
   AnnotPath& operator=(const AnnotPath &other) = delete;
@@ -201,7 +201,7 @@ class AnnotQuadrilaterals {
 public:
   class AnnotQuadrilateral {
   public:
-    AnnotQuadrilateral() = default;
+    AnnotQuadrilateral();
     AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3,
       double y3, double x4, double y4);
 
@@ -210,7 +210,7 @@ public:
 
   AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
   AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
-  ~AnnotQuadrilaterals() = default;
+  ~AnnotQuadrilaterals();
 
   AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
   AnnotQuadrilaterals& operator=(const AnnotQuadrilaterals &other) = delete;
@@ -477,7 +477,7 @@ public:
   };
 
   AnnotAppearanceCharacs(Dict *dict);
-  ~AnnotAppearanceCharacs() = default;
+  ~AnnotAppearanceCharacs();
 
   AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
   AnnotAppearanceCharacs& operator=(const AnnotAppearanceCharacs &) = delete;
@@ -808,7 +808,7 @@ public:
 
   AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
   AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotMarkup() = default;
+  ~AnnotMarkup();
 
   // getters
   const GooString *getLabel() const { return label.get(); }
@@ -868,7 +868,7 @@ public:
 
   AnnotText(PDFDoc *docA, PDFRectangle *rect);
   AnnotText(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotText() = default;
+  ~AnnotText();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -901,7 +901,7 @@ class AnnotMovie: public Annot {
  public:
   AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
   AnnotMovie(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotMovie() = default;
+  ~AnnotMovie();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -925,7 +925,7 @@ class AnnotScreen: public Annot {
 
   AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
   AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotScreen() = default;
+  ~AnnotScreen();
 
   const GooString* getTitle() const { return title.get(); }
 
@@ -961,7 +961,7 @@ public:
 
   AnnotLink(PDFDoc *docA, PDFRectangle *rect);
   AnnotLink(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotLink() = default;
+  ~AnnotLink();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1002,7 +1002,7 @@ public:
 
   AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, const DefaultAppearance &da);
   AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotFreeText() = default;
+  ~AnnotFreeText();
 
   void draw(Gfx *gfx, GBool printing) override;
   Object getAppearanceResDict() override;
@@ -1065,7 +1065,7 @@ public:
 
   AnnotLine(PDFDoc *docA, PDFRectangle *rect);
   AnnotLine(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotLine() = default;
+  ~AnnotLine();
 
   void draw(Gfx *gfx, GBool printing) override;
   Object getAppearanceResDict() override;
@@ -1132,7 +1132,7 @@ public:
 
   AnnotTextMarkup(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotTextMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotTextMarkup() = default;
+  ~AnnotTextMarkup();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1159,7 +1159,7 @@ public:
 
   AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
   AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotStamp() = default;
+  ~AnnotStamp();
 
   void setIcon(GooString *new_icon);
 
@@ -1182,7 +1182,7 @@ public:
 
   AnnotGeometry(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotGeometry(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotGeometry() = default;
+  ~AnnotGeometry();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1218,7 +1218,7 @@ public:
 
   AnnotPolygon(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotPolygon(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotPolygon() = default;
+  ~AnnotPolygon();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1268,7 +1268,7 @@ public:
 
   AnnotCaret(PDFDoc *docA, PDFRectangle *rect);
   AnnotCaret(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotCaret() = default;
+  ~AnnotCaret();
 
   void setSymbol(AnnotCaretSymbol new_symbol);
 
@@ -1328,7 +1328,7 @@ public:
 
   AnnotFileAttachment(PDFDoc *docA, PDFRectangle *rect, GooString *filename);
   AnnotFileAttachment(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotFileAttachment() = default;
+  ~AnnotFileAttachment();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1356,7 +1356,7 @@ public:
 
   AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA);
   AnnotSound(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotSound() = default;
+  ~AnnotSound();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1391,7 +1391,7 @@ public:
 
   AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj);
   AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormField *fieldA);
-  ~AnnotWidget() = default;
+  ~AnnotWidget();
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1470,7 +1470,7 @@ public:
 
   Annot3D(PDFDoc *docA, PDFRectangle *rect);
   Annot3D(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~Annot3D() = default;
+  ~Annot3D();
 
   // getters
 
@@ -1490,7 +1490,7 @@ public:
   class Params {
   public:
     Params(Dict *dict);
-    ~Params() = default;
+    ~Params();
 
     Params(const Params &) = delete;
     Params& operator=(const Params &) = delete;
@@ -1512,7 +1512,7 @@ public:
     };
 
     Instance(Dict *dict);
-    ~Instance() = default;
+    ~Instance();
 
     Instance(const Instance &) = delete;
     Instance& operator=(const Instance &) = delete;
@@ -1558,8 +1558,8 @@ public:
 
   class Asset {
   public:
-    Asset() = default;
-    ~Asset() = default;
+    Asset();
+    ~Asset();
 
     Asset(const Asset &) = delete;
     Asset& operator=(const Asset &) = delete;
@@ -1634,7 +1634,7 @@ public:
   class Settings {
   public:
     Settings(Dict *dict);
-    ~Settings() = default;
+    ~Settings();
 
     Settings(const Settings &) = delete;
     Settings& operator=(const Settings &) = delete;
@@ -1650,7 +1650,7 @@ public:
 
   AnnotRichMedia(PDFDoc *docA, PDFRectangle *rect);
   AnnotRichMedia(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotRichMedia() = default;
+  ~AnnotRichMedia();
 
   Content* getContent() const;
 
commit 602dc4ba8e54977667a0fd884cc3539bc100c963
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Oct 8 16:13:30 2018 +0200

    Make compile again

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index e70be5bd..22c7f358 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1748,7 +1748,7 @@ void Annot::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color, color.get(),
+  gfx->drawAnnot(&obj, nullptr, color.get(),
       rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -2664,39 +2664,6 @@ static GfxFont * createAnnotDrawFont(XRef * xref, Dict *fontResDict, const char*
   return GfxFont::makeFont(xref, resourceName, dummyRef, fontDict);
 }
 
-void AnnotFreeText::parseAppearanceString(GooString *da, double &fontsize, std::unique_ptr<AnnotColor> &fontcolor) {
-  fontsize = -1;
-
-  if (da) {
-    GooList * daToks = new GooList();
-    int i = FormFieldText::tokenizeDA(da, daToks, "Tf");
-
-    if (i >= 1) {
-      fontsize = gatof(( (GooString *)daToks->get(i-1) )->getCString());
-      // TODO: Font name
-    }
-    // Scan backwards: we are looking for the last set value
-    for (i = daToks->getLength()-1; i >= 0; --i) {
-      if (!fontcolor) {
-        if (!((GooString *)daToks->get(i))->cmp("g") && i >= 1) {
-          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-1) )->getCString()));
-        } else if (!((GooString *)daToks->get(i))->cmp("rg") && i >= 3) {
-          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-3) )->getCString()),
-                                                   gatof(( (GooString *)daToks->get(i-2) )->getCString()),
-                                                   gatof(( (GooString *)daToks->get(i-1) )->getCString()));
-        } else if (!((GooString *)daToks->get(i))->cmp("k") && i >= 4) {
-          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-4) )->getCString()),
-                                                   gatof(( (GooString *)daToks->get(i-3) )->getCString()),
-                                                   gatof(( (GooString *)daToks->get(i-2) )->getCString()),
-                                                   gatof(( (GooString *)daToks->get(i-1) )->getCString()));
-        }
-      }
-    }
-    deleteGooList(daToks, GooString);
-  }
->>>>>>> annots: Use std::unique_ptr instead of new/delete
-}
-
 void AnnotFreeText::generateFreeTextAppearance()
 {
   double borderWidth, ca = opacity;
@@ -4178,8 +4145,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
       }
 
       // write the text string
-      const char *s = convertedText->getCString();
-      int len = convertedText->getLength();
+      const char *s = convertedText.getCString();
+      int len = convertedText.getLength();
       i = 0;
       xPrev = w;                // so that first character is placed properly
       while (i < comb && len > 0) {
commit c66dec6154a72dd45430cb40885a9eb19e01eca9
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Oct 8 10:44:59 2018 +0200

    Remove out-commented code

diff --git a/poppler/Annot.h b/poppler/Annot.h
index 9b7940a0..0c0d7d73 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -968,7 +968,6 @@ public:
   // getters
   LinkAction *getAction() const { return action.get(); }
   AnnotLinkEffect getLinkEffect() const { return linkEffect; }
-  /*  Dict *getUriAction() const { return uriAction; } */
   AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
 
 protected:
commit d8ecf4ca7f574fd49bdfc3afd155245fa130cc6e
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Oct 8 10:42:28 2018 +0200

    Fix typo in a comment

diff --git a/poppler/Annot.h b/poppler/Annot.h
index 033a3ba3..9b7940a0 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -930,7 +930,7 @@ class AnnotScreen: public Annot {
   const GooString* getTitle() const { return title.get(); }
 
   AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
-  LinkAction *getAction() { return action.get(); } // The caller should now delete the result
+  LinkAction *getAction() { return action.get(); } // The caller should not delete the result
   LinkAction *getAdditionalAction(AdditionalActionsType type); // The caller should delete the result
 
  private:
commit d52c567551279b2ee8ab8a6ab848e99c5c0021c7
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Sep 3 17:20:51 2018 +0200

    Make my own mess compile again

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 82628b54..e70be5bd 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -2575,9 +2575,7 @@ void AnnotFreeText::setContents(GooString *new_content) {
 }
 
 void AnnotFreeText::setDefaultAppearance(const DefaultAppearance &da) {
-  delete appearanceString;
-
-  appearanceString = da.toAppearanceString();
+  appearanceString = std::unique_ptr<GooString>(da.toAppearanceString());
 
   update ("DA", Object(appearanceString->copy()));
   invalidateAppearance();
@@ -2646,7 +2644,7 @@ void AnnotFreeText::setIntent(AnnotFreeTextIntent new_intent) {
 }
 
 std::unique_ptr<DefaultAppearance> AnnotFreeText::getDefaultAppearance() const {
-  return std::make_unique<DefaultAppearance>(appearanceString);
+  return std::make_unique<DefaultAppearance>(appearanceString.get());
 }
 
 static GfxFont * createAnnotDrawFont(XRef * xref, Dict *fontResDict, const char* resourceName = "AnnotDrawFont", const char* fontname = "Helvetica")
@@ -2715,7 +2713,7 @@ void AnnotFreeText::generateFreeTextAppearance()
   const double height = rect->y2 - rect->y1;
 
   // Parse some properties from the appearance string
-  DefaultAppearance da{appearanceString};
+  DefaultAppearance da{appearanceString.get()};
 
   // Default values
   if (!da.getFontName().isName())
@@ -2798,7 +2796,7 @@ void AnnotFreeText::generateFreeTextAppearance()
   while (i < contents->getLength()) {
     GooString out;
     double linewidth, xpos;
-    layoutText(contents, &out, &i, font, &linewidth, textwidth/da.getFontPtSize(), nullptr, gFalse);
+    layoutText(contents.get(), &out, &i, font, &linewidth, textwidth/da.getFontPtSize(), nullptr, gFalse);
     linewidth *= da.getFontPtSize();
     switch (quadding) {
     case quaddingCentered:
diff --git a/qt5/src/poppler-annotation-helper.h b/qt5/src/poppler-annotation-helper.h
index 28145589..0247ad85 100644
--- a/qt5/src/poppler-annotation-helper.h
+++ b/qt5/src/poppler-annotation-helper.h
@@ -21,6 +21,8 @@
  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
+#include <memory>
+
 #include <QtCore/QDebug>
 
 #include <Object.h>
commit 054022ef5d9531944dee4195cf2b8c31d1c428b4
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Wed Aug 29 23:05:18 2018 +0200

    Port AnnotPath to use std::vector<AnnotCoord> instead of std::unique_ptr<AnnotCoord> to further avoid manual memory management.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 77557346..82628b54 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -281,48 +281,41 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
 // AnnotPath
 //------------------------------------------------------------------------
 
-AnnotPath::AnnotPath() {
-  coordsLength = 0;
-}
-
 AnnotPath::AnnotPath(Array *array) {
-  coordsLength = 0;
   parsePathArray(array);
 }
 
-AnnotPath::AnnotPath(std::unique_ptr<AnnotCoord[]> &&coords, int coordsLength) {
+AnnotPath::AnnotPath(std::vector<AnnotCoord> &&coords) {
   this->coords = std::move(coords);
-  this->coordsLength = coordsLength;
 }
 
 double AnnotPath::getX(int coord) const {
-  if (coord >= 0 && coord < coordsLength)
+  if (coord >= 0 && coord < getCoordsLength())
     return coords[coord].getX();
   return 0;
 }
 
 double AnnotPath::getY(int coord) const {
-  if (coord >= 0 && coord < coordsLength)
+  if (coord >= 0 && coord < getCoordsLength())
     return coords[coord].getY();
   return 0;
 }
 
-AnnotCoord *AnnotPath::getCoord(int coord) const {
-  if (coord >= 0 && coord < coordsLength)
+AnnotCoord *AnnotPath::getCoord(int coord) {
+  if (coord >= 0 && coord < getCoordsLength())
     return &coords[coord];
   return nullptr;
 }
 
 void AnnotPath::parsePathArray(Array *array) {
-  int tempLength;
-
   if (array->getLength() % 2) {
     error(errSyntaxError, -1, "Bad Annot Path");
     return;
   }
 
-  tempLength = array->getLength() / 2;
-  auto tempCoords = std::make_unique<AnnotCoord[]>(tempLength);
+  const auto tempLength = array->getLength() / 2;
+  std::vector<AnnotCoord> tempCoords;
+  tempCoords.reserve(tempLength);
   for (int i = 0; i < tempLength; i++) {
     double x = 0, y = 0;
 
@@ -340,11 +333,10 @@ void AnnotPath::parsePathArray(Array *array) {
       return;
     }
 
-    tempCoords[i] = { x, y };
+    tempCoords.emplace_back(x, y);
   }
 
   coords = std::move(tempCoords);
-  coordsLength = tempLength;
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index ab3b184b..033a3ba3 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -111,9 +111,9 @@ protected:
 
 class AnnotPath {
 public:
-  AnnotPath();
+  AnnotPath() = default;
   AnnotPath(Array *array);
-  AnnotPath(std::unique_ptr<AnnotCoord[]> &&coords, int coordsLength);
+  AnnotPath(std::vector<AnnotCoord> &&coords);
   ~AnnotPath() = default;
 
   AnnotPath(const AnnotPath &) = delete;
@@ -121,11 +121,10 @@ public:
 
   double getX(int coord) const;
   double getY(int coord) const;
-  AnnotCoord *getCoord(int coord) const;
-  int getCoordsLength() const { return coordsLength; }
+  AnnotCoord *getCoord(int coord);
+  int getCoordsLength() const { return coords.size(); }
 protected:
-  std::unique_ptr<AnnotCoord[]> coords;
-  int coordsLength;
+  std::vector<AnnotCoord> coords;
 
   void parsePathArray(Array *array);
 };
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index c05aa22f..ecebe04e 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -355,20 +355,20 @@ PDFRectangle AnnotationPrivate::boundaryToPdfRectangle(const QRectF &r, int rFla
 AnnotPath * AnnotationPrivate::toAnnotPath(const QLinkedList<QPointF> &list) const
 {
     const int count = list.size();
-    auto ac = std::make_unique<AnnotCoord[]>(count);
+    std::vector<AnnotCoord> ac;
+    ac.reserve(count);
 
     double MTX[6];
     fillTransformationMTX(MTX);
 
-    int pos = 0;
     foreach (const QPointF &p, list)
     {
         double x, y;
         XPDFReader::invTransform( MTX, p, x, y );
-        ac[pos++] = AnnotCoord(x, y);
+	ac.emplace_back(x, y);
     }
 
-    return new AnnotPath(std::move(ac), count);
+    return new AnnotPath(std::move(ac));
 }
 
 QList<Annotation*> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentID)
commit 891ba9a47ad837006938a5acdace46049fcb8892
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Wed Aug 29 21:42:28 2018 +0200

    Remove an unnecessary pointer assignment
    
    No need to set a std::unique_ptr to nullptr right before
    it goes out of scope.

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 3bff7b20..77557346 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -4942,7 +4942,6 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
       bbox[2] = width;
       bbox[3] = height;
       appearance = createForm(appearBuf.get(), bbox, gFalse, resDict2);
-      appearBuf = nullptr;
     }
   }
 
commit 9b1032753a57a2aa18f21b3e6770d6788f757cf6
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun May 21 14:14:19 2017 +0200

    annots: Use std::unique_ptr instead of new/delete

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 74e3e66e..4d693869 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -267,25 +267,20 @@ _poppler_annot_text_markup_new (Annot *annot)
 static AnnotQuadrilaterals *
 create_annot_quads_from_poppler_quads (GArray *quads)
 {
-  AnnotQuadrilaterals::AnnotQuadrilateral **quads_array;
-
   g_assert (quads->len > 0);
 
-  quads_array = (AnnotQuadrilaterals::AnnotQuadrilateral **) g_malloc0_n (
-    sizeof (AnnotQuadrilaterals::AnnotQuadrilateral *),
-    quads->len);
-
+  auto quads_array = std::make_unique<AnnotQuadrilaterals::AnnotQuadrilateral[]>(quads->len);
   for (guint i = 0; i < quads->len; i++) {
     PopplerQuadrilateral *quadrilateral = &g_array_index (quads, PopplerQuadrilateral, i);
 
-    quads_array[i] = new AnnotQuadrilaterals::AnnotQuadrilateral (
+    quads_array[i] = AnnotQuadrilaterals::AnnotQuadrilateral (
       quadrilateral->p1.x, quadrilateral->p1.y,
       quadrilateral->p2.x, quadrilateral->p2.y,
       quadrilateral->p3.x, quadrilateral->p3.y,
       quadrilateral->p4.x, quadrilateral->p4.y);
   }
 
-  return new AnnotQuadrilaterals (quads_array, quads->len);
+  return new AnnotQuadrilaterals (std::move(quads_array), quads->len);
 }
 
 static GArray *
@@ -947,15 +942,15 @@ create_poppler_color_from_annot_color (AnnotColor *color)
   return poppler_color;
 }
 
-static AnnotColor *
+static std::unique_ptr<AnnotColor>
 create_annot_color_from_poppler_color (PopplerColor *poppler_color)
 {
   if (!poppler_color)
     return nullptr;
 
-  return new AnnotColor ((double)poppler_color->red / 65535,
-                         (double)poppler_color->green / 65535,
-                         (double)poppler_color->blue / 65535);
+  return std::make_unique<AnnotColor>((double)poppler_color->red / 65535,
+                                      (double)poppler_color->green / 65535,
+                                      (double)poppler_color->blue / 65535);
 }
 
 /**
@@ -988,7 +983,6 @@ void
 poppler_annot_set_color (PopplerAnnot *poppler_annot,
 			 PopplerColor *poppler_color)
 {
-  /* Annot takes ownership of the color */
   poppler_annot->annot->setColor (create_annot_color_from_poppler_color (poppler_color));
 }
 
@@ -1150,15 +1144,13 @@ poppler_annot_markup_set_popup (PopplerAnnotMarkup *poppler_annot,
 				PopplerRectangle   *popup_rect)
 {
   AnnotMarkup *annot;
-  AnnotPopup  *popup;
   PDFRectangle pdf_rect(popup_rect->x1, popup_rect->y1,
 			popup_rect->x2, popup_rect->y2);
 
   g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot));
 
   annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
-  popup = new AnnotPopup (annot->getDoc(), &pdf_rect);
-  annot->setPopup (popup);
+  annot->setPopup (std::make_unique<AnnotPopup>(annot->getDoc(), &pdf_rect));
 }
 
 /**
@@ -1946,7 +1938,6 @@ poppler_annot_geometry_set_interior_color (PopplerAnnot *poppler_annot,
 
   annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT (poppler_annot)->annot);
 
-  /* Annot takes ownership of the color */
   annot->setInteriorColor (create_annot_color_from_poppler_color (poppler_color));
 }
 
diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index b92d929c..3bff7b20 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -183,8 +183,7 @@ static AnnotExternalDataType parseAnnotExternalData(Dict* dict) {
   return type;
 }
 
-static PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) {
-  PDFRectangle *newRect = nullptr;
+static std::unique_ptr<PDFRectangle> parseDiffRectangle(Array *array, PDFRectangle *rect) {
   if (array->getLength() == 4) {
     // deltas
     Object obj1;
@@ -198,14 +197,15 @@ static PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) {
     if (dx1 >= 0 && dy1 >= 0 && dx2 >= 0 && dy2
         && (rect->x2 - rect->x1 - dx1 - dx2) >= 0
         && (rect->y2 - rect->y1 - dy1 - dy2) >= 0) {
-      newRect = new PDFRectangle();
+      auto newRect = std::make_unique<PDFRectangle>();
       newRect->x1 = rect->x1 + dx1;
       newRect->y1 = rect->y1 + dy1;
       newRect->x2 = rect->x2 - dx2;
       newRect->y2 = rect->y2 - dy2;
+      return newRect;
     }
   }
-  return newRect;
+  return nullptr;
 }
 
 static LinkAction* getAdditionalAction(Annot::AdditionalActionsType type, Object *additionalActions, PDFDoc *doc) {
@@ -282,51 +282,39 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
 //------------------------------------------------------------------------
 
 AnnotPath::AnnotPath() {
-  coords = nullptr;
   coordsLength = 0;
 }
 
 AnnotPath::AnnotPath(Array *array) {
-  coords = nullptr;
   coordsLength = 0;
   parsePathArray(array);
 }
 
-AnnotPath::AnnotPath(AnnotCoord **coords, int coordsLength) {
-  this->coords = coords;
+AnnotPath::AnnotPath(std::unique_ptr<AnnotCoord[]> &&coords, int coordsLength) {
+  this->coords = std::move(coords);
   this->coordsLength = coordsLength;
 }
 
-AnnotPath::~AnnotPath() {
-  if (coords) {
-    for (int i = 0; i < coordsLength; ++i)
-      delete coords[i];
-    gfree(coords);
-  }
-}
-
 double AnnotPath::getX(int coord) const {
   if (coord >= 0 && coord < coordsLength)
-    return coords[coord]->getX();
+    return coords[coord].getX();
   return 0;
 }
 
 double AnnotPath::getY(int coord) const {
   if (coord >= 0 && coord < coordsLength)
-    return coords[coord]->getY();
+    return coords[coord].getY();
   return 0;
 }
 
 AnnotCoord *AnnotPath::getCoord(int coord) const {
   if (coord >= 0 && coord < coordsLength)
-    return coords[coord];
+    return &coords[coord];
   return nullptr;
 }
 
 void AnnotPath::parsePathArray(Array *array) {
   int tempLength;
-  AnnotCoord **tempCoords;
-  GBool correct = gTrue;
 
   if (array->getLength() % 2) {
     error(errSyntaxError, -1, "Bad Annot Path");
@@ -334,36 +322,28 @@ void AnnotPath::parsePathArray(Array *array) {
   }
 
   tempLength = array->getLength() / 2;
-  tempCoords = (AnnotCoord **) gmallocn (tempLength, sizeof(AnnotCoord *));
-  memset(tempCoords, 0, tempLength * sizeof(AnnotCoord *));
-  for (int i = 0; i < tempLength && correct; i++) {
+  auto tempCoords = std::make_unique<AnnotCoord[]>(tempLength);
+  for (int i = 0; i < tempLength; i++) {
     double x = 0, y = 0;
 
     Object obj1 = array->get(i * 2);
     if (obj1.isNum()) {
       x = obj1.getNum();
     } else {
-      correct = gFalse;
+      return;
     }
 
     obj1 = array->get((i * 2) + 1);
     if (obj1.isNum()) {
       y = obj1.getNum();
     } else {
-      correct = gFalse;
-    }
-
-    if (!correct) {
-      for (int j = i - 1; j >= 0; j--)
-        delete tempCoords[j];
-      gfree (tempCoords);
       return;
     }
 
-    tempCoords[i] = new AnnotCoord(x, y);
+    tempCoords[i] = { x, y };
   }
 
-  coords = tempCoords;
+  coords = std::move(tempCoords);
   coordsLength = tempLength;
 }
 
@@ -390,114 +370,90 @@ AnnotCalloutMultiLine::AnnotCalloutMultiLine(double x1, double y1, double x2,
 
 AnnotQuadrilaterals::AnnotQuadrilaterals(Array *array, PDFRectangle *rect) {
   int arrayLength = array->getLength();
-  GBool correct = gTrue;
   int quadsLength = 0;
-  AnnotQuadrilateral **quads;
   double quadArray[8];
 
   // default values
-  quadrilaterals = nullptr;
   quadrilateralsLength = 0;
 
   if ((arrayLength % 8) == 0) {
     int i;
 
     quadsLength = arrayLength / 8;
-    quads = (AnnotQuadrilateral **) gmallocn
-        ((quadsLength), sizeof(AnnotQuadrilateral *));
-    memset(quads, 0, quadsLength * sizeof(AnnotQuadrilateral *));
-
+    auto quads = std::make_unique<AnnotQuadrilateral[]>(quadsLength);
     for (i = 0; i < quadsLength; i++) {
       for (int j = 0; j < 8; j++) {
         Object obj = array->get(i * 8 + j);
         if (obj.isNum()) {
           quadArray[j] = obj.getNum();
         } else {
-            correct = gFalse;
 	    error (errSyntaxError, -1, "Invalid QuadPoint in annot");
-	    break;
+	    return;
         }
       }
 
-      if (!correct)
-        break;
-
-      quads[i] = new AnnotQuadrilateral(quadArray[0], quadArray[1],
-					quadArray[2], quadArray[3],
-					quadArray[4], quadArray[5],
-					quadArray[6], quadArray[7]);
+      quads[i] = AnnotQuadrilateral(quadArray[0], quadArray[1],
+                                    quadArray[2], quadArray[3],
+                                    quadArray[4], quadArray[5],
+                                    quadArray[6], quadArray[7]);
     }
 
-    if (correct) {
-      quadrilateralsLength = quadsLength;
-      quadrilaterals = quads;
-    } else {
-      for (int j = 0; j < i; j++)
-        delete quads[j];
-      gfree (quads);
-    }
+
+    quadrilateralsLength = quadsLength;
+    quadrilaterals = std::move(quads);
   }
 }
 
-AnnotQuadrilaterals::AnnotQuadrilaterals(AnnotQuadrilaterals::AnnotQuadrilateral **quads, int quadsLength) {
-  quadrilaterals = quads;
+AnnotQuadrilaterals::AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength) {
+  quadrilaterals = std::move(quads);
   quadrilateralsLength = quadsLength;
 }
 
-AnnotQuadrilaterals::~AnnotQuadrilaterals() {
-  if (quadrilaterals) {
-    for(int i = 0; i < quadrilateralsLength; i++)
-      delete quadrilaterals[i];
-
-    gfree (quadrilaterals);
-  }
-}
-
 double AnnotQuadrilaterals::getX1(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord1.getX();
+    return quadrilaterals[quadrilateral].coord1.getX();
   return 0;
 }
 
 double AnnotQuadrilaterals::getY1(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord1.getY();
+    return quadrilaterals[quadrilateral].coord1.getY();
   return 0;
 }
 
 double AnnotQuadrilaterals::getX2(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord2.getX();
+    return quadrilaterals[quadrilateral].coord2.getX();
   return 0;
 }
 
 double AnnotQuadrilaterals::getY2(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord2.getY();
+    return quadrilaterals[quadrilateral].coord2.getY();
   return 0;
 }
 
 double AnnotQuadrilaterals::getX3(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord3.getX();
+    return quadrilaterals[quadrilateral].coord3.getX();
   return 0;
 }
 
 double AnnotQuadrilaterals::getY3(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord3.getY();
+    return quadrilaterals[quadrilateral].coord3.getY();
   return 0;
 }
 
 double AnnotQuadrilaterals::getX4(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord4.getX();
+    return quadrilaterals[quadrilateral].coord4.getX();
   return 0;
 }
 
 double AnnotQuadrilaterals::getY4(int quadrilateral) {
   if (quadrilateral >= 0  && quadrilateral < quadrilateralsLength)
-    return quadrilaterals[quadrilateral]->coord4.getY();
+    return quadrilaterals[quadrilateral].coord4.getY();
   return 0;
 }
 
@@ -958,12 +914,11 @@ Object AnnotAppearance::getAppearanceStream(AnnotAppearanceType type, const char
   return res;
 }
 
-GooString * AnnotAppearance::getStateKey(int i) {
-  GooString * res = nullptr;
+std::unique_ptr<GooString> AnnotAppearance::getStateKey(int i) {
   Object obj1 = appearDict.dictLookupNF("N");
   if (obj1.isDict())
-    res = new GooString(obj1.dictGetKey(i));
-  return res;
+    return std::make_unique<GooString>(obj1.dictGetKey(i));
+  return nullptr;
 }
 
 int AnnotAppearance::getNumStates() {
@@ -1083,52 +1038,36 @@ AnnotAppearanceCharacs::AnnotAppearanceCharacs(Dict *dict) {
   if (obj1.isArray()) {
     Array *colorComponents = obj1.getArray();
     if (colorComponents->getLength() > 0) {
-      borderColor = new AnnotColor(colorComponents);
-    } else {
-      borderColor = nullptr;
+      borderColor = std::make_unique<AnnotColor>(colorComponents);
     }
-  } else {
-    borderColor = nullptr;
   }
 
   obj1 = dict->lookup("BG");
   if (obj1.isArray()) {
     Array *colorComponents = obj1.getArray();
     if (colorComponents->getLength() > 0) {
-      backColor = new AnnotColor(colorComponents);
-    } else {
-      backColor = nullptr;
+      backColor = std::make_unique<AnnotColor>(colorComponents);
     }
-  } else {
-    backColor = nullptr;
   }
 
   obj1 = dict->lookup("CA");
   if (obj1.isString()) {
-    normalCaption = new GooString(obj1.getString());
-  } else {
-    normalCaption = nullptr;
+    normalCaption = std::make_unique<GooString>(obj1.getString());
   }
 
   obj1 = dict->lookup("RC");
   if (obj1.isString()) {
-    rolloverCaption = new GooString(obj1.getString());
-  } else {
-    rolloverCaption = nullptr;
+    rolloverCaption = std::make_unique<GooString>(obj1.getString());
   }
 
   obj1 = dict->lookup("AC");
   if (obj1.isString()) {
-    alternateCaption = new GooString(obj1.getString());
-  } else {
-    alternateCaption = nullptr;
+    alternateCaption = std::make_unique<GooString>(obj1.getString());
   }
 
   obj1 = dict->lookup("IF");
   if (obj1.isDict()) {
-    iconFit = new AnnotIconFit(obj1.getDict());
-  } else {
-    iconFit = nullptr;
+    iconFit = std::make_unique<AnnotIconFit>(obj1.getDict());
   }
 
   obj1 = dict->lookup("TP");
@@ -1139,26 +1078,6 @@ AnnotAppearanceCharacs::AnnotAppearanceCharacs(Dict *dict) {
   }
 }
 
-AnnotAppearanceCharacs::~AnnotAppearanceCharacs() {
-  if (borderColor)
-    delete borderColor;
-
-  if (backColor)
-    delete backColor;
-
-  if (normalCaption)
-    delete normalCaption;
-
-  if (rolloverCaption)
-    delete rolloverCaption;
-
-  if (alternateCaption)
-    delete alternateCaption;
-
-  if (iconFit)
-    delete iconFit;
-}
-
 //------------------------------------------------------------------------
 // AnnotAppearanceBBox
 //------------------------------------------------------------------------
@@ -1267,14 +1186,11 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
   ok = gTrue;
   doc = docA;
   xref = doc->getXRef();
-  appearStreams = nullptr;
-  appearBBox = nullptr;
-  appearState = nullptr;
 
   appearance.setToNull();
 
   //----- parse the rectangle
-  rect = new PDFRectangle();
+  rect = std::make_unique<PDFRectangle>();
   obj1 = dict->lookup("Rect");
   if (obj1.isArray() && obj1.arrayGetLength() == 4) {
     Object obj2;
@@ -1303,9 +1219,9 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("Contents");
   if (obj1.isString()) {
-    contents = obj1.getString()->copy();
+    contents.reset(obj1.getString()->copy());
   } else {
-    contents = new GooString();
+    contents = std::make_unique<GooString>();
   }
 
   // Note: This value is overwritten by Annots ctor
@@ -1320,16 +1236,12 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("NM");
   if (obj1.isString()) {
-    name = obj1.getString()->copy();
-  } else {
-    name = nullptr;
+    name.reset(obj1.getString()->copy());
   }
 
   obj1 = dict->lookup("M");
   if (obj1.isString()) {
-    modified = obj1.getString()->copy();
-  } else {
-    modified = nullptr;
+    modified.reset(obj1.getString()->copy());
   }
 
   //----- get the flags
@@ -1343,13 +1255,13 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
   //----- get the annotation appearance dictionary
   apObj = dict->lookup("AP");
   if (apObj.isDict()) {
-    appearStreams = new AnnotAppearance(doc, &apObj);
+    appearStreams = std::make_unique<AnnotAppearance>(doc, &apObj);
   }
 
   //----- get the appearance state
   asObj = dict->lookup("AS");
   if (asObj.isName()) {
-    appearState = new GooString(asObj.getName());
+    appearState = std::make_unique<GooString>(asObj.getName());
   } else if (appearStreams && appearStreams->getNumStates() != 0) {
     error (errSyntaxError, -1, "Invalid or missing AS value in annotation containing one or more appearance subdictionaries");
     // AS value is required in this case, but if the
@@ -1360,7 +1272,7 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
     }
   }
   if (!appearState) {
-    appearState = new GooString("Off");
+    appearState = std::make_unique<GooString>("Off");
   }
 
   //----- get the annotation appearance
@@ -1374,16 +1286,13 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
   // seems to ignore the Border entry for annots that can't have a BS entry. So, we only
   // follow this rule for annots tha can have a BS entry.
   obj1 = dict->lookup("Border");
-  if (obj1.isArray())
-    border = new AnnotBorderArray(obj1.getArray());
-  else
-    border = nullptr;
+  if (obj1.isArray()) {
+    border = std::make_unique<AnnotBorderArray>(obj1.getArray());
+  }
 
   obj1 = dict->lookup("C");
   if (obj1.isArray()) {
-    color = new AnnotColor(obj1.getArray());
-  } else {
-    color = nullptr;
+    color = std::make_unique<AnnotColor>(obj1.getArray());
   }
 
   obj1 = dict->lookup("StructParent");
@@ -1442,8 +1351,7 @@ void Annot::update(const char *key, Object &&value) {
   annotLocker();
   /* Set M to current time, unless we are updating M itself */
   if (strcmp(key, "M") != 0) {
-    delete modified;
-    modified = timeToDateString(nullptr);
+    modified.reset(timeToDateString(nullptr));
 
     annotObj.dictSet("M", Object(modified->copy()));
   }
@@ -1455,16 +1363,15 @@ void Annot::update(const char *key, Object &&value) {
 
 void Annot::setContents(GooString *new_content) {
   annotLocker();
-  delete contents;
 
   if (new_content) {
-    contents = new GooString(new_content);
+    contents = std::make_unique<GooString>(new_content);
     //append the unicode marker <FE FF> if needed	
     if (!contents->hasUnicodeMarker()) {
       contents->prependUnicodeMarker();
     }
   } else {
-    contents = new GooString();
+    contents = std::make_unique<GooString>();
   }
   
   update ("Contents", Object(contents->copy()));
@@ -1472,12 +1379,11 @@ void Annot::setContents(GooString *new_content) {
 
 void Annot::setName(GooString *new_name) {
   annotLocker();
-  delete name;
 
   if (new_name) {
-    name = new GooString(new_name);
+    name = std::make_unique<GooString>(new_name);
   } else {
-    name = new GooString();
+    name = std::make_unique<GooString>();
   }
 
   update ("NM", Object(name->copy()));
@@ -1485,12 +1391,11 @@ void Annot::setName(GooString *new_name) {
 
 void Annot::setModified(GooString *new_modified) {
   annotLocker();
-  delete modified;
 
   if (new_modified)
-    modified = new GooString(new_modified);
+    modified = std::make_unique<GooString>(new_modified);
   else
-    modified = new GooString();
+    modified = std::make_unique<GooString>();
 
   update ("M", Object(modified->copy()));
 }
@@ -1501,28 +1406,26 @@ void Annot::setFlags(Guint new_flags) {
   update ("F", Object(int(flags)));
 }
 
-void Annot::setBorder(AnnotBorder *new_border) {
+void Annot::setBorder(std::unique_ptr<AnnotBorder> &&new_border) {
   annotLocker();
-  delete border;
 
   if (new_border) {
     Object obj1 = new_border->writeToObject(xref);
     update(new_border->getType() == AnnotBorder::typeArray ? "Border" : "BS", std::move(obj1));
-    border = new_border;
+    border = std::move(new_border);
   } else {
     border = nullptr;
   }
   invalidateAppearance();
 }
 
-void Annot::setColor(AnnotColor *new_color) {
+void Annot::setColor(std::unique_ptr<AnnotColor> &&new_color) {
   annotLocker();
-  delete color;
 
   if (new_color) {
     Object obj1 = new_color->writeToObject(xref);
     update ("C", std::move(obj1));
-    color = new_color;
+    color = std::move(new_color);
   } else {
     color = nullptr;
   }
@@ -1552,10 +1455,7 @@ void Annot::setAppearanceState(const char *state) {
   if (!state)
     return;
 
-  delete appearState;
-  appearState = new GooString(state);
-
-  delete appearBBox;
+  appearState = std::make_unique<GooString>(state);
   appearBBox = nullptr;
 
   update ("AS", Object(objName, state));
@@ -1573,15 +1473,9 @@ void Annot::invalidateAppearance() {
   if (appearStreams) { // Remove existing appearance streams
     appearStreams->removeAllStreams();
   }
-  delete appearStreams;
   appearStreams = nullptr;
-
-  delete appearState;
   appearState = nullptr;
-
-  delete appearBBox;
   appearBBox = nullptr;
-
   appearance.setToNull();
 
   Object obj2 = annotObj.dictLookup("AP");
@@ -1634,28 +1528,7 @@ void Annot::decRefCnt() {
   }
 }
 
-Annot::~Annot() {
-  delete rect;
-  delete contents;
-
-  if (name)
-    delete name;
-
-  if (modified)
-    delete modified;
-
-  delete appearStreams;
-  delete appearBBox;
-
-  if (appearState)
-    delete appearState;
-
-  if (border)
-    delete border;
-
-  if (color)
-    delete color;
-}
+Annot::~Annot() {}
 
 void AnnotAppearanceBuilder::setDrawColor(const AnnotColor *drawColor, GBool fill) {
   const double *values = drawColor->getValues();
@@ -1883,7 +1756,7 @@ void Annot::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color, color.get(),
       rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -1949,36 +1822,18 @@ AnnotMarkup::AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict(), obj);
 }
 
-AnnotMarkup::~AnnotMarkup() {
-  if (label)
-    delete label;
-
-  if (popup)
-    delete popup;
-
-  if (date)
-    delete date;
-
-  if (subject)
-    delete subject;
-}
-
 void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
   Object obj1, obj2;
 
   obj1 = dict->lookup("T");
   if (obj1.isString()) {
-    label = obj1.getString()->copy();
-  } else {
-    label = nullptr;
+    label.reset(obj1.getString()->copy());
   }
 
   obj1 = dict->lookup("Popup");
   obj2 = dict->lookupNF("Popup");
   if (obj1.isDict() && obj2.isRef()) {
-    popup = new AnnotPopup(docA, &obj1, &obj2);
-  } else {
-    popup = nullptr;
+    popup = std::make_unique<AnnotPopup>(docA, &obj1, &obj2);
   }
 
   obj1 = dict->lookup("CA");
@@ -1990,9 +1845,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
 
   obj1 = dict->lookup("CreationDate");
   if (obj1.isString()) {
-    date = obj1.getString()->copy();
-  } else {
-    date = nullptr;
+    date.reset(obj1.getString()->copy());
   }
 
   obj1 = dict->lookupNF("IRT");
@@ -2005,9 +1858,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
 
   obj1 = dict->lookup("Subj");
   if (obj1.isString()) {
-    subject = obj1.getString()->copy();
-  } else {
-    subject = nullptr;
+    subject.reset(obj1.getString()->copy());
   }
 
   obj1 = dict->lookup("RT");
@@ -2034,40 +1885,37 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
 }
 
 void AnnotMarkup::setLabel(GooString *new_label) {
-  delete label;
-
   if (new_label) {
-    label = new GooString(new_label);
+    label = std::make_unique<GooString>(new_label);
     //append the unicode marker <FE FF> if needed
     if (!label->hasUnicodeMarker()) {
       label->prependUnicodeMarker();
     }
   } else {
-    label = new GooString();
+    label = std::make_unique<GooString>();
   }
 
   update ("T", Object(label->copy()));
 }
 
-void AnnotMarkup::setPopup(AnnotPopup *new_popup) {
+void AnnotMarkup::setPopup(std::unique_ptr<AnnotPopup> &&new_popup) {
   // If there exists an old popup annotation that is already
   // associated with a page, then we need to remove that
   // popup annotation from the page. Otherwise we would have
   // dangling references to it.
-  if (popup != nullptr && popup->getPageNum() != 0) {
+  if (popup && popup->getPageNum() != 0) {
     Page *pageobj = doc->getPage(popup->getPageNum());
     if (pageobj) {
-      pageobj->removeAnnot(popup);
+      pageobj->removeAnnot(popup.get());
     }
   }
-  delete popup;
 
   if (new_popup) {
     const Ref popupRef = new_popup->getRef();
     update ("Popup", Object(popupRef.num, popupRef.gen));
 
     new_popup->setParent(this);
-    popup = new_popup;
+    popup = std::move(new_popup);
 
     // If this annotation is already added to a page, then we
     // add the new popup annotation to the same page.
@@ -2075,7 +1923,7 @@ void AnnotMarkup::setPopup(AnnotPopup *new_popup) {
       Page *pageobj = doc->getPage(page);
       assert(pageobj != nullptr); // pageobj should exist in doc (see setPage())
 
-      pageobj->addAnnot(popup);
+      pageobj->addAnnot(popup.get());
     }
   } else {
     popup = nullptr;
@@ -2089,12 +1937,10 @@ void AnnotMarkup::setOpacity(double opacityA) {
 }
 
 void AnnotMarkup::setDate(GooString *new_date) {
-  delete date;
-
   if (new_date)
-    date = new GooString(new_date);
+    date = std::make_unique<GooString>(new_date);
   else
-    date = new GooString();
+    date = std::make_unique<GooString>();
 
   update ("CreationDate", Object(date->copy()));
 }
@@ -2105,7 +1951,7 @@ void AnnotMarkup::removeReferencedObjects() {
 
   // Remove popup
   if (popup) {
-    pageobj->removeAnnot(popup);
+    pageobj->removeAnnot(popup.get());
   }
 
   Annot::removeReferencedObjects();
@@ -2132,10 +1978,6 @@ AnnotText::AnnotText(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize (docA, dictObject->getDict());
 }
 
-AnnotText::~AnnotText() {
-  delete icon;
-}
-
 void AnnotText::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -2147,9 +1989,9 @@ void AnnotText::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("Name");
   if (obj1.isName()) {
-    icon = new GooString(obj1.getName());
+    icon = std::make_unique<GooString>(obj1.getName());
   } else {
-    icon = new GooString("Note");
+    icon = std::make_unique<GooString>("Note");
   }
 
   obj1 = dict->lookup("StateModel");
@@ -2225,12 +2067,10 @@ void AnnotText::setIcon(GooString *new_icon) {
   if (new_icon && icon->cmp(new_icon) == 0)
     return;
 
-  delete icon;
-
   if (new_icon) {
-    icon = new GooString (new_icon);
+    icon = std::make_unique<GooString>(new_icon);
   } else {
-    icon = new GooString("Note");
+    icon = std::make_unique<GooString>("Note");
   }
 
   update("Name", Object(objName, icon->getCString()));
@@ -2495,7 +2335,7 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
 
     appearBuilder.append ("q\n");
     if (color)
-      appearBuilder.setDrawColor(color, gTrue);
+      appearBuilder.setDrawColor(color.get(), gTrue);
     else
       appearBuilder.append ("1 1 1 rg\n");
     if (!icon->cmp("Note"))
@@ -2520,7 +2360,7 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
 
     // Force 24x24 rectangle
     PDFRectangle fixedRect(rect->x1, rect->y2 - 24, rect->x1 + 24, rect->y2);
-    appearBBox = new AnnotAppearanceBBox(&fixedRect);
+    appearBBox = std::make_unique<AnnotAppearanceBBox>(&fixedRect);
     double bbox[4];
     appearBBox->getBBoxRect(bbox);
     if (ca == 1) {
@@ -2537,12 +2377,12 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
   if (appearBBox) {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    appearBBox->getPageXMin(), appearBBox->getPageYMin(),
                    appearBBox->getPageXMax(), appearBBox->getPageYMax(),
                    getRotation());
   } else {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   }
 }
@@ -2564,30 +2404,18 @@ AnnotLink::AnnotLink(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize (docA, dictObject->getDict());
 }
 
-AnnotLink::~AnnotLink() {
-  delete action;
-  /*
-  if (uriAction)
-    delete uriAction;
-  */
-  if (quadrilaterals)
-    delete quadrilaterals;
-}
-
 void AnnotLink::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
-  action = nullptr;
-
   // look for destination
   obj1 = dict->lookup("Dest");
   if (!obj1.isNull()) {
-    action = LinkAction::parseDest(&obj1);
+    action.reset(LinkAction::parseDest(&obj1));
   // look for action
   } else {
     obj1 = dict->lookup("A");
     if (obj1.isDict()) {
-      action = LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI());
+      action.reset(LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI()));
     }
   }
 
@@ -2620,17 +2448,14 @@ void AnnotLink::initialize(PDFDoc *docA, Dict *dict) {
   */
   obj1 = dict->lookup("QuadPoints");
   if (obj1.isArray()) {
-    quadrilaterals = new AnnotQuadrilaterals(obj1.getArray(), rect);
-  } else {
-    quadrilaterals = nullptr;
+    quadrilaterals = std::make_unique<AnnotQuadrilaterals>(obj1.getArray(), rect.get());
   }
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 }
 
@@ -2641,7 +2466,7 @@ void AnnotLink::draw(Gfx *gfx, GBool printing) {
   annotLocker();
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, border, color,
+  gfx->drawAnnot(&obj, border.get(), color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -2665,30 +2490,14 @@ AnnotFreeText::AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotFreeText::~AnnotFreeText() {
-  delete appearanceString;
-
-  if (styleString)
-    delete styleString;
-
-  if (calloutLine)
-    delete calloutLine;
-
-  if (borderEffect)
-    delete borderEffect;
-
-  if (rectangle)
-    delete rectangle;
-}
-
 void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
   obj1 = dict->lookup("DA");
   if (obj1.isString()) {
-    appearanceString = obj1.getString()->copy();
+    appearanceString.reset(obj1.getString()->copy());
   } else {
-    appearanceString = new GooString();
+    appearanceString = std::make_unique<GooString>();
     error(errSyntaxError, -1, "Bad appearance for annotation");
     ok = gFalse;
   }
@@ -2702,9 +2511,7 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("DS");
   if (obj1.isString()) {
-    styleString = obj1.getString()->copy();
-  } else {
-    styleString = nullptr;
+    styleString.reset(obj1.getString()->copy());
   }
 
   obj1 = dict->lookup("CL");
@@ -2721,12 +2528,10 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
       double x3, y3;
       (obj2 = obj1.arrayGet(4), obj2.isNum() ? x3 = obj2.getNum() : x3 = 0);
       (obj2 = obj1.arrayGet(5), obj2.isNum() ? y3 = obj2.getNum() : y3 = 0);
-      calloutLine = new AnnotCalloutMultiLine(x1, y1, x2, y2, x3, y3);
+      calloutLine = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3);
     } else {
-      calloutLine = new AnnotCalloutLine(x1, y1, x2, y2);
+      calloutLine = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2);
     }
-  } else {
-    calloutLine = nullptr;
   }
 
   obj1 = dict->lookup("IT");
@@ -2748,24 +2553,19 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 
   obj1 = dict->lookup("BE");
   if (obj1.isDict()) {
-    borderEffect = new AnnotBorderEffect(obj1.getDict());
-  } else {
-    borderEffect = nullptr;
+    borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
   }
 
   obj1 = dict->lookup("RD");
   if (obj1.isArray()) {
-    rectangle = parseDiffRectangle(obj1.getArray(), rect);
-  } else {
-    rectangle = nullptr;
+    rectangle = parseDiffRectangle(obj1.getArray(), rect.get());
   }
 
   obj1 = dict->lookup("LE");
@@ -2798,24 +2598,20 @@ void AnnotFreeText::setQuadding(AnnotFreeTextQuadding new_quadding) {
 }
 
 void AnnotFreeText::setStyleString(GooString *new_string) {
-  delete styleString;
-
   if (new_string) {
-    styleString = new GooString(new_string);
+    styleString = std::make_unique<GooString>(new_string);
     //append the unicode marker <FE FF> if needed
     if (!styleString->hasUnicodeMarker()) {
       styleString->prependUnicodeMarker();
     }
   } else {
-    styleString = new GooString();
+    styleString = std::make_unique<GooString>();
   }
 
   update ("DS", Object(styleString->copy()));
 }
 
 void AnnotFreeText::setCalloutLine(AnnotCalloutLine *line) {
-  delete calloutLine;
-
   Object obj1;
   if (line == nullptr) {
     obj1.setToNull();
@@ -2834,9 +2630,9 @@ void AnnotFreeText::setCalloutLine(AnnotCalloutLine *line) {
       double x3 = mline->getX3(), y3 = mline->getY3();
       obj1.arrayAdd( Object(x3) );
       obj1.arrayAdd( Object(y3) );
-      calloutLine = new AnnotCalloutMultiLine(x1, y1, x2, y2, x3, y3);
+      calloutLine = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3);
     } else {
-      calloutLine = new AnnotCalloutLine(x1, y1, x2, y2);
+      calloutLine = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2);
     }
   }
 
@@ -2878,6 +2674,39 @@ static GfxFont * createAnnotDrawFont(XRef * xref, Dict *fontResDict, const char*
   return GfxFont::makeFont(xref, resourceName, dummyRef, fontDict);
 }
 
+void AnnotFreeText::parseAppearanceString(GooString *da, double &fontsize, std::unique_ptr<AnnotColor> &fontcolor) {
+  fontsize = -1;
+
+  if (da) {
+    GooList * daToks = new GooList();
+    int i = FormFieldText::tokenizeDA(da, daToks, "Tf");
+
+    if (i >= 1) {
+      fontsize = gatof(( (GooString *)daToks->get(i-1) )->getCString());
+      // TODO: Font name
+    }
+    // Scan backwards: we are looking for the last set value
+    for (i = daToks->getLength()-1; i >= 0; --i) {
+      if (!fontcolor) {
+        if (!((GooString *)daToks->get(i))->cmp("g") && i >= 1) {
+          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-1) )->getCString()));
+        } else if (!((GooString *)daToks->get(i))->cmp("rg") && i >= 3) {
+          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-3) )->getCString()),
+                                                   gatof(( (GooString *)daToks->get(i-2) )->getCString()),
+                                                   gatof(( (GooString *)daToks->get(i-1) )->getCString()));
+        } else if (!((GooString *)daToks->get(i))->cmp("k") && i >= 4) {
+          fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-4) )->getCString()),
+                                                   gatof(( (GooString *)daToks->get(i-3) )->getCString()),
+                                                   gatof(( (GooString *)daToks->get(i-2) )->getCString()),
+                                                   gatof(( (GooString *)daToks->get(i-1) )->getCString()));
+        }
+      }
+    }
+    deleteGooList(daToks, GooString);
+  }
+>>>>>>> annots: Use std::unique_ptr instead of new/delete
+}
+
 void AnnotFreeText::generateFreeTextAppearance()
 {
   double borderWidth, ca = opacity;
@@ -2887,7 +2716,7 @@ void AnnotFreeText::generateFreeTextAppearance()
 
   borderWidth = border->getWidth();
   if (borderWidth > 0)
-    appearBuilder.setLineStyleForBorder(border);
+    appearBuilder.setLineStyleForBorder(border.get());
 
   // Box size
   const double width = rect->x2 - rect->x1;
@@ -2904,7 +2733,7 @@ void AnnotFreeText::generateFreeTextAppearance()
   if (!da.getFontColor())
     da.setFontColor(std::make_unique<AnnotColor>(0, 0, 0));
   if (!contents)
-    contents = new GooString ();
+    contents = std::make_unique<GooString>();
 
   // Draw box
   GBool doFill = (color && color->getSpace() != AnnotColor::colorTransparent);
@@ -2915,7 +2744,7 @@ void AnnotFreeText::generateFreeTextAppearance()
     }
     appearBuilder.appendf ("{0:.2f} {0:.2f} {1:.2f} {2:.2f} re\n", borderWidth/2, width-borderWidth, height-borderWidth);
     if (doFill) {
-      appearBuilder.setDrawColor(color, gTrue);
+      appearBuilder.setDrawColor(color.get(), gTrue);
       appearBuilder.append(doStroke ? "B\n" : "f\n");
     } else {
       appearBuilder.append("S\n");
@@ -3026,7 +2855,7 @@ void AnnotFreeText::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
                  rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -3057,17 +2886,6 @@ AnnotLine::AnnotLine(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotLine::~AnnotLine() {
-  delete coord1;
-  delete coord2;
-
-  if (interiorColor)
-    delete interiorColor;
-
-  if (measure)
-    delete measure;
-}
-
 void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -3081,11 +2899,11 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
     (obj2 = obj1.arrayGet(2), obj2.isNum() ? x2 = obj2.getNum() : x2 = 0);
     (obj2 = obj1.arrayGet(3), obj2.isNum() ? y2 = obj2.getNum() : y2 = 0);
 
-    coord1 = new AnnotCoord(x1, y1);
-    coord2 = new AnnotCoord(x2, y2);
+    coord1 = std::make_unique<AnnotCoord>(x1, y1);
+    coord2 = std::make_unique<AnnotCoord>(x2, y2);
   } else {
-    coord1 = new AnnotCoord();
-    coord2 = new AnnotCoord();
+    coord1 = std::make_unique<AnnotCoord>();
+    coord2 = std::make_unique<AnnotCoord>();
   }
 
   obj1 = dict->lookup("LE");
@@ -3110,9 +2928,7 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("IC");
   if (obj1.isArray()) {
-    interiorColor = new AnnotColor(obj1.getArray());
-  } else {
-    interiorColor = nullptr;
+    interiorColor = std::make_unique<AnnotColor>(obj1.getArray());
   }
 
   obj1 = dict->lookup("LL");
@@ -3200,10 +3016,9 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 }
 
@@ -3214,10 +3029,8 @@ void AnnotLine::setContents(GooString *new_content) {
 }
 
 void AnnotLine::setVertices(double x1, double y1, double x2, double y2) {
-  delete coord1;
-  coord1 = new AnnotCoord(x1, y1);
-  delete coord2;
-  coord2 = new AnnotCoord(x2, y2);
+  coord1 = std::make_unique<AnnotCoord>(x1, y1);
+  coord2 = std::make_unique<AnnotCoord>(x2, y2);
 
   Array *lArray = new Array(xref);
   lArray->add( Object(x1) );
@@ -3241,13 +3054,11 @@ void AnnotLine::setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyl
   invalidateAppearance();
 }
 
-void AnnotLine::setInteriorColor(AnnotColor *new_color) {
-  delete interiorColor;
-
+void AnnotLine::setInteriorColor(std::unique_ptr<AnnotColor> &&new_color) {
   if (new_color) {
     Object obj1 = new_color->writeToObject(xref);
     update ("IC", std::move(obj1));
-    interiorColor = new_color;
+    interiorColor = std::move(new_color);
   } else {
     interiorColor = nullptr;
   }
@@ -3290,14 +3101,14 @@ void AnnotLine::generateLineAppearance()
 {
   double borderWidth, ca = opacity;
 
-  appearBBox = new AnnotAppearanceBBox(rect);
+  appearBBox = std::make_unique<AnnotAppearanceBBox>(rect.get());
   AnnotAppearanceBuilder appearBuilder;
   appearBuilder.append ("q\n");
   if (color) {
-    appearBuilder.setDrawColor(color, gFalse);
+    appearBuilder.setDrawColor(color.get(), gFalse);
   }
 
-  appearBuilder.setLineStyleForBorder(border);
+  appearBuilder.setLineStyleForBorder(border.get());
   borderWidth = border->getWidth();
   appearBBox->setBorderWidth(std::max(1., borderWidth));
 
@@ -3336,7 +3147,7 @@ void AnnotLine::generateLineAppearance()
     while (i < contents->getLength()) {
       GooString out;
       double linewidth;
-      layoutText(contents, &out, &i, font, &linewidth, 0, nullptr, gFalse);
+      layoutText(contents.get(), &out, &i, font, &linewidth, 0, nullptr, gFalse);
       linewidth *= fontsize;
       if (linewidth > captionwidth) {
         captionwidth = linewidth;
@@ -3405,7 +3216,7 @@ void AnnotLine::generateLineAppearance()
     while (i < contents->getLength()) {
       GooString out;
       double linewidth, xpos;
-      layoutText(contents, &out, &i, font, &linewidth, 0, nullptr, gFalse);
+      layoutText(contents.get(), &out, &i, font, &linewidth, 0, nullptr, gFalse);
       linewidth *= fontsize;
       xpos = (captionwidth - linewidth) / 2;
       appearBuilder.appendf("{0:.2f} {1:.2f} Td\n", xpos - xposPrev, -fontsize);
@@ -3463,12 +3274,12 @@ void AnnotLine::draw(Gfx *gfx, GBool printing) {
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
   if (appearBBox) {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    appearBBox->getPageXMin(), appearBBox->getPageYMin(),
                    appearBBox->getPageXMax(), appearBBox->getPageYMax(),
                    getRotation());
   } else {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   }
 }
@@ -3540,18 +3351,13 @@ void AnnotTextMarkup::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("QuadPoints");
   if (obj1.isArray()) {
-    quadrilaterals = new AnnotQuadrilaterals(obj1.getArray(), rect);
+    quadrilaterals = std::make_unique<AnnotQuadrilaterals>(obj1.getArray(), rect.get());
   } else {
     error(errSyntaxError, -1, "Bad Annot Text Markup QuadPoints");
-    quadrilaterals = nullptr;
     ok = gFalse;
   }
 }
 
-AnnotTextMarkup::~AnnotTextMarkup() {
-  delete quadrilaterals;
-}
-
 void AnnotTextMarkup::setType(AnnotSubtype new_type) {
   const char *typeName = nullptr; /* squelch bogus compiler warning */
 
@@ -3591,8 +3397,7 @@ void AnnotTextMarkup::setQuadrilaterals(AnnotQuadrilaterals *quadPoints) {
     a->add(Object(quadPoints->getY4(i)));
   }
 
-  delete quadrilaterals;
-  quadrilaterals = new AnnotQuadrilaterals(a, rect);
+  quadrilaterals = std::make_unique<AnnotQuadrilaterals>(a, rect.get());
 
   annotObj.dictSet ("QuadPoints", Object(a));
   invalidateAppearance();
@@ -3614,8 +3419,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
     appearBuilder.append ("q\n");
 
     /* Adjust BBox */
-    delete appearBBox;
-    appearBBox = new AnnotAppearanceBBox(rect);
+    appearBBox = std::make_unique<AnnotAppearanceBBox>(rect.get());
     for (i = 0; i < quadrilaterals->getQuadrilateralsLength(); ++i) {
       appearBBox->extendTo (quadrilaterals->getX1(i) - rect->x1, quadrilaterals->getY1(i) - rect->y1);
       appearBBox->extendTo (quadrilaterals->getX2(i) - rect->x1, quadrilaterals->getY2(i) - rect->y1);
@@ -3626,7 +3430,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
     switch (type) {
     case typeUnderline:
       if (color) {
-        appearBuilder.setDrawColor(color, gFalse);
+        appearBuilder.setDrawColor(color.get(), gFalse);
       }
       appearBuilder.append ("[] 0 d 1 w\n");
 
@@ -3645,7 +3449,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
       break;
     case typeStrikeOut:
       if (color) {
-        appearBuilder.setDrawColor(color, gFalse);
+        appearBuilder.setDrawColor(color.get(), gFalse);
       }
       blendMultiply = gFalse;
       appearBuilder.append ("[] 0 d 1 w\n");
@@ -3671,7 +3475,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
       break;
     case typeSquiggly:
       if (color) {
-        appearBuilder.setDrawColor(color, gFalse);
+        appearBuilder.setDrawColor(color.get(), gFalse);
       }
       appearBuilder.append ("[] 0 d 1 w\n");
 
@@ -3698,7 +3502,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
     default:
     case typeHighlight:
       if (color)
-        appearBuilder.setDrawColor(color, gTrue);
+        appearBuilder.setDrawColor(color.get(), gTrue);
 
       double biggestBorder = 0;
       for (i = 0; i < quadrilaterals->getQuadrilateralsLength(); ++i) {
@@ -3754,12 +3558,12 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
   if (appearBBox) {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    appearBBox->getPageXMin(), appearBBox->getPageYMin(),
                    appearBBox->getPageXMax(), appearBBox->getPageYMax(),
                    getRotation());
   } else {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   }
 }
@@ -3782,17 +3586,6 @@ AnnotWidget::AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormFiel
   initialize(docA, dictObject->getDict());
 }
 
-AnnotWidget::~AnnotWidget() {
-  if (appearCharacs)
-    delete appearCharacs;
-  
-  if (action)
-    delete action;
-
-  if (parent)
-    delete parent;
-}
-
 void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
   Object obj1;
 
@@ -3817,15 +3610,12 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("MK");
   if (obj1.isDict()) {
-    appearCharacs = new AnnotAppearanceCharacs(obj1.getDict());
-  } else {
-    appearCharacs = nullptr;
+    appearCharacs = std::make_unique<AnnotAppearanceCharacs>(obj1.getDict());
   }
 
-  action = nullptr;
   obj1 = dict->lookup("A");
   if (obj1.isDict()) {
-    action = LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI());
+    action.reset(LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI()));
   }
 
   additionalActions = dict->lookupNF("AA");
@@ -3839,8 +3629,7 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   }
 
   updatedAppearanceStream.num = updatedAppearanceStream.gen = -1;
@@ -4104,7 +3893,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
     XRef *xref, bool *addedDingbatsResource,
     GBool password) {
   GooList *daToks;
-  GooString *tok, *convertedText;
+  GooString *tok;
+  GooString convertedText;
   const GfxFont *font;
   double dx, dy;
   double fontSize, fontSize2, borderWidth, x, xPrev, y, w, wMax;
@@ -4214,8 +4004,6 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
     freeText = gTrue;
   }
 
-  convertedText = new GooString;
-
   // setup
   if (txField) {
     appearBuf->append("/Tx BMC\n");
@@ -4257,7 +4045,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
         y = dy - 3;
         i = 0;
         while (i < text->getLength()) {
-          Annot::layoutText(text, convertedText, &i, font, &w, wMax / fontSize, nullptr,
+          Annot::layoutText(text, &convertedText, &i, font, &w, wMax / fontSize, nullptr,
                      forceZapfDingbats);
           y -= fontSize;
         }
@@ -4304,7 +4092,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
     i = 0;
     xPrev = 0;
     while (i < text->getLength()) {
-      Annot::layoutText(text, convertedText, &i, font, &w, wMax / fontSize, nullptr,
+      Annot::layoutText(text, &convertedText, &i, font, &w, wMax / fontSize, nullptr,
                  forceZapfDingbats);
       w *= fontSize;
 
@@ -4324,7 +4112,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
 
       // draw the line
       appearBuf->appendf("{0:.2f} {1:.2f} Td\n", x - xPrev, -fontSize);
-      writeString(*convertedText);
+      writeString(convertedText);
       appearBuf->append(" Tj\n");
 
       // next line
@@ -4357,7 +4145,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
       }
 
       i = 0;
-      Annot::layoutText(text, convertedText, &i, font, nullptr, 0.0, &charCount,
+      Annot::layoutText(text, &convertedText, &i, font, nullptr, 0.0, &charCount,
                  forceZapfDingbats);
       if (charCount > comb)
         charCount = comb;
@@ -4433,7 +4221,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
       // regular (non-comb) formatting
     } else {
       i = 0;
-      Annot::layoutText(text, convertedText, &i, font, &w, 0.0, nullptr,
+      Annot::layoutText(text, &convertedText, &i, font, &w, 0.0, nullptr,
                  forceZapfDingbats);
 
       // compute font autosize
@@ -4490,7 +4278,7 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
       }
 
       // write the text string
-      writeString(*convertedText);
+      writeString(convertedText);
       appearBuf->append(" Tj\n");
     }
   }
@@ -4506,7 +4294,6 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
   if (freeText) {
     delete text;
   }
-  delete convertedText;
   if (fontToFree) {
     fontToFree->decRefCnt();
   }
@@ -4518,7 +4305,8 @@ bool AnnotAppearanceBuilder::drawText(const GooString *text, const GooString *da
 bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, const AnnotBorder *border, const PDFRectangle *rect,
 			      const GooString *da, const GfxResources *resources, int quadding) {
   GooList *daToks;
-  GooString *tok, *convertedText;
+  GooString *tok;
+  GooString convertedText;
   const GfxFont *font;
   double fontSize, fontSize2, borderWidth, x, y, w, wMax;
   int tfPos, tmPos, i, j;
@@ -4579,8 +4367,6 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
     return false;
   }
 
-  convertedText = new GooString;
-
   // get the border width
   borderWidth = border ? border->getWidth() : 0;
 
@@ -4594,10 +4380,9 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
         if (daToks) {
 	  deleteGooList<GooString>(daToks);
         }
-        delete convertedText;
         return false;
       }
-      Annot::layoutText(fieldChoice->getChoice(i), convertedText, &j, font, &w, 0.0, nullptr, gFalse);
+      Annot::layoutText(fieldChoice->getChoice(i), &convertedText, &j, font, &w, 0.0, nullptr, gFalse);
       if (w > wMax) {
         wMax = w;
       }
@@ -4635,7 +4420,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
 
     // compute text width and start position
     j = 0;
-    Annot::layoutText(fieldChoice->getChoice(i), convertedText, &j, font, &w, 0.0, nullptr, gFalse);
+    Annot::layoutText(fieldChoice->getChoice(i), &convertedText, &j, font, &w, 0.0, nullptr, gFalse);
     w *= fontSize;
     switch (quadding) {
     case quaddingLeftJustified:
@@ -4678,7 +4463,7 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
     }
 
     // write the text string
-    writeString(*convertedText);
+    writeString(convertedText);
     appearBuf->append(" Tj\n");
 
     // cleanup
@@ -4693,8 +4478,6 @@ bool AnnotAppearanceBuilder::drawListBox(const FormFieldChoice *fieldChoice, con
     deleteGooList<GooString>(daToks);
   }
 
-  delete convertedText;
-
   return true;
 }
 
@@ -4927,7 +4710,7 @@ void AnnotWidget::generateFieldAppearance(bool *addedDingbatsResource) {
 
   // draw the border
   if (appearCharacs && border && border->getWidth() > 0)
-    appearBuilder.drawFieldBorder(field, border, appearCharacs, rect);
+    appearBuilder.drawFieldBorder(field, border.get(), appearCharacs.get(), rect.get());
 
   da = field->getDefaultAppearance();
   if (!da)
@@ -4935,10 +4718,10 @@ void AnnotWidget::generateFieldAppearance(bool *addedDingbatsResource) {
 
   resources = form->getDefaultResources();
 
-  const bool success = appearBuilder.drawFormField(field, form, resources, da, border, appearCharacs, rect, appearState, xref, addedDingbatsResource);
+  const bool success = appearBuilder.drawFormField(field, form, resources, da, border.get(), appearCharacs.get(), rect.get(), appearState.get(), xref, addedDingbatsResource);
   if (!success && da != form->getDefaultAppearance()) {
     da = form->getDefaultAppearance();
-    appearBuilder.drawFormField(field, form, resources, da, border, appearCharacs, rect, appearState, xref, addedDingbatsResource);
+    appearBuilder.drawFormField(field, form, resources, da, border.get(), appearCharacs.get(), rect.get(), appearState.get(), xref, addedDingbatsResource);
   }
 
   const GooString *appearBuf = appearBuilder.buffer();
@@ -4998,7 +4781,7 @@ void AnnotWidget::updateAppearanceStream()
     obj1.dictAdd("N", Object(updatedAppearanceStream.num, updatedAppearanceStream.gen));
 
     // Update our internal pointers to the appearance dictionary
-    appearStreams = new AnnotAppearance(doc, &obj1);
+    appearStreams = std::make_unique<AnnotAppearance>(doc, &obj1);
 
     update("AP", std::move(obj1));
   } else {
@@ -5039,7 +4822,7 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
     gfx->pushResources(dict);
     delete dict;
   }
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   if (addDingbatsResource) {
     gfx->popResources();
@@ -5055,7 +4838,7 @@ AnnotMovie::AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA) :
   type = typeMovie;
   annotObj.dictSet ("Subtype", Object(objName, "Movie"));
 
-  movie = movieA->copy();
+  movie.reset(movieA->copy());
   // TODO: create movie dict from movieA
 
   initialize(docA, annotObj.getDict());
@@ -5067,37 +4850,27 @@ AnnotMovie::AnnotMovie(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotMovie::~AnnotMovie() {
-  if (title)
-    delete title;
-  delete movie;
-}
-
 void AnnotMovie::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
   obj1 = dict->lookup("T");
   if (obj1.isString()) {
-    title = obj1.getString()->copy();
-  } else {
-    title = nullptr;
+    title.reset(obj1.getString()->copy());
   }
 
   Object movieDict = dict->lookup("Movie");
   if (movieDict.isDict()) {
     Object obj2 = dict->lookup("A");
     if (obj2.isDict())
-      movie = new Movie (&movieDict, &obj2);
+      movie = std::make_unique<Movie>(&movieDict, &obj2);
     else
-      movie = new Movie (&movieDict);
+      movie = std::make_unique<Movie>(&movieDict);
     if (!movie->isOk()) {
-      delete movie;
       movie = nullptr;
       ok = gFalse;
     }
   } else {
     error(errSyntaxError, -1, "Bad Annot Movie");
-    movie = nullptr;
     ok = gFalse;
   }
 }
@@ -5113,7 +4886,7 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
     movie->getAspect(&width, &height);
 
     if (width != -1 && height != -1 && !poster.isNone()) {
-      GooString *appearBuf = new GooString ();
+      auto appearBuf = std::make_unique<GooString>();
       appearBuf->append ("q\n");
       appearBuf->appendf ("{0:d} 0 0 {1:d} 0 0 cm\n", width, height);
       appearBuf->append ("/MImg Do\n");
@@ -5147,7 +4920,6 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
 
       Stream *mStream = new AutoFreeMemStream(copyString(appearBuf->getCString()), 0,
 			      appearBuf->getLength(), Object(formDict));
-      delete appearBuf;
 
       Dict *dict = new Dict(gfx->getXRef());
       dict->set("FRM", Object(mStream));
@@ -5155,7 +4927,7 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
       Dict *resDict2 = new Dict(gfx->getXRef());
       resDict2->set("XObject", Object(dict));
 
-      appearBuf = new GooString ();
+      appearBuf = std::make_unique<GooString>();
       appearBuf->append ("q\n");
       appearBuf->appendf ("0 0 {0:d} {1:d} re W n\n", width, height);
       appearBuf->append ("q\n");
@@ -5169,14 +4941,14 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
       bbox[0] = bbox[1] = 0;
       bbox[2] = width;
       bbox[3] = height;
-      appearance = createForm(appearBuf, bbox, gFalse, resDict2);
-      delete appearBuf;
+      appearance = createForm(appearBuf.get(), bbox, gFalse, resDict2);
+      appearBuf = nullptr;
     }
   }
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -5197,28 +4969,19 @@ AnnotScreen::AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotScreen::~AnnotScreen() {
-  delete title;
-  delete appearCharacs;
-  delete action;
-}
-
 void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
-  title = nullptr;
   obj1 = dict->lookup("T");
   if (obj1.isString()) {
-    title = obj1.getString()->copy();
+    title.reset(obj1.getString()->copy());
   }
 
-  action = nullptr;
   obj1 = dict->lookup("A");
   if (obj1.isDict()) {
-    action = LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI());
+    action.reset(LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI()));
     if (action && action->getKind() == actionRendition && page == 0) {
       error (errSyntaxError, -1, "Invalid Rendition action: associated screen annotation without P");
-      delete action;
       action = nullptr;
       ok = gFalse;
     }
@@ -5226,10 +4989,9 @@ void AnnotScreen::initialize(PDFDoc *docA, Dict* dict) {
 
   additionalActions = dict->lookupNF("AA");
 
-  appearCharacs = nullptr;
   obj1 = dict->lookup("MK");
   if (obj1.isDict()) {
-    appearCharacs = new AnnotAppearanceCharacs(obj1.getDict());
+    appearCharacs = std::make_unique<AnnotAppearanceCharacs>(obj1.getDict());
   }
 }
 
@@ -5257,27 +5019,21 @@ AnnotStamp::AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotStamp::~AnnotStamp() {
-  delete icon;
-}
-
 void AnnotStamp::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("Name");
   if (obj1.isName()) {
-    icon = new GooString(obj1.getName());
+    icon = std::make_unique<GooString>(obj1.getName());
   } else {
-    icon = new GooString("Draft");
+    icon = std::make_unique<GooString>("Draft");
   }
 
 }
 
 void AnnotStamp::setIcon(GooString *new_icon) {
-  delete icon;
-
   if (new_icon) {
-    icon = new GooString (new_icon);
+    icon = std::make_unique<GooString>(new_icon);
   } else {
-    icon = new GooString();
+    icon = std::make_unique<GooString>();
   }
 
   update("Name", Object(objName, icon->getCString()));
@@ -5310,12 +5066,6 @@ AnnotGeometry::AnnotGeometry(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotGeometry::~AnnotGeometry() {
-  delete interiorColor;
-  delete borderEffect;
-  delete geometryRect;
-}
-
 void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5331,30 +5081,24 @@ void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("IC");
   if (obj1.isArray()) {
-    interiorColor = new AnnotColor(obj1.getArray());
-  } else {
-    interiorColor = nullptr;
+    interiorColor = std::make_unique<AnnotColor>(obj1.getArray());
   }
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 
   obj1 = dict->lookup("BE");
   if (obj1.isDict()) {
-    borderEffect = new AnnotBorderEffect(obj1.getDict());
-  } else {
-    borderEffect = nullptr;
+    borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
   }
 
-  geometryRect = nullptr;
   obj1 = dict->lookup("RD");
   if (obj1.isArray()) {
-    geometryRect = parseDiffRectangle(obj1.getArray(), rect);
+    geometryRect = parseDiffRectangle(obj1.getArray(), rect.get());
   }
 }
 
@@ -5377,13 +5121,11 @@ void AnnotGeometry::setType(AnnotSubtype new_type) {
   invalidateAppearance();
 }
 
-void AnnotGeometry::setInteriorColor(AnnotColor *new_color) {
-  delete interiorColor;
-
+void AnnotGeometry::setInteriorColor(std::unique_ptr<AnnotColor> &&new_color) {
   if (new_color) {
     Object obj1 = new_color->writeToObject(xref);
     update ("IC", std::move(obj1));
-    interiorColor = new_color;
+    interiorColor = std::move(new_color);
   } else {
     interiorColor = nullptr;
   }
@@ -5403,13 +5145,13 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
     AnnotAppearanceBuilder appearBuilder;
     appearBuilder.append ("q\n");
     if (color)
-      appearBuilder.setDrawColor(color, gFalse);
+      appearBuilder.setDrawColor(color.get(), gFalse);
 
     double borderWidth = border->getWidth();
-    appearBuilder.setLineStyleForBorder(border);
+    appearBuilder.setLineStyleForBorder(border.get());
 
     if (interiorColor)
-      appearBuilder.setDrawColor(interiorColor, gTrue);
+      appearBuilder.setDrawColor(interiorColor.get(), gTrue);
 
     if (type == typeSquare) {
       appearBuilder.appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} re\n",
@@ -5488,7 +5230,7 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -5524,16 +5266,6 @@ AnnotPolygon::AnnotPolygon(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotPolygon::~AnnotPolygon() {
-  delete vertices;
-
-  if (interiorColor)
-    delete interiorColor;
-
-  if (borderEffect)
-    delete borderEffect;
-}
-
 void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5549,9 +5281,9 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("Vertices");
   if (obj1.isArray()) {
-    vertices = new AnnotPath(obj1.getArray());
+    vertices = std::make_unique<AnnotPath>(obj1.getArray());
   } else {
-    vertices = new AnnotPath();
+    vertices = std::make_unique<AnnotPath>();
     error(errSyntaxError, -1, "Bad Annot Polygon Vertices");
     ok = gFalse;
   }
@@ -5576,24 +5308,19 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("IC");
   if (obj1.isArray()) {
-    interiorColor = new AnnotColor(obj1.getArray());
-  } else {
-    interiorColor = nullptr;
+    interiorColor = std::make_unique<AnnotColor>(obj1.getArray());
   }
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 
   obj1 = dict->lookup("BE");
   if (obj1.isDict()) {
-    borderEffect = new AnnotBorderEffect(obj1.getDict());
-  } else {
-    borderEffect = nullptr;
+    borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
   }
 
   obj1 = dict->lookup("IT");
@@ -5632,15 +5359,13 @@ void AnnotPolygon::setType(AnnotSubtype new_type) {
 }
 
 void AnnotPolygon::setVertices(AnnotPath *path) {
-  delete vertices;
-
   Array *a = new Array(xref);
   for (int i = 0; i < path->getCoordsLength(); i++) {
     a->add(Object(path->getX(i)));
     a->add(Object(path->getY(i)));
   }
 
-  vertices = new AnnotPath(a);
+  vertices = std::make_unique<AnnotPath>(a);
 
   update("Vertices", Object(a));
   invalidateAppearance();
@@ -5658,15 +5383,11 @@ void AnnotPolygon::setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingS
   invalidateAppearance();
 }
 
-void AnnotPolygon::setInteriorColor(AnnotColor *new_color) {
-  delete interiorColor;
-
+void AnnotPolygon::setInteriorColor(std::unique_ptr<AnnotColor> &&new_color) {
   if (new_color) {
     Object obj1 = new_color->writeToObject(xref);
     update ("IC", std::move(obj1));
-    interiorColor = new_color;
-  } else {
-    interiorColor = nullptr;
+    interiorColor = std::move(new_color);
   }
   invalidateAppearance();
 }
@@ -5692,21 +5413,21 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) {
 
   annotLocker();
   if (appearance.isNull()) {
-    appearBBox = new AnnotAppearanceBBox(rect);
+    appearBBox = std::make_unique<AnnotAppearanceBBox>(rect.get());
     ca = opacity;
 
     AnnotAppearanceBuilder appearBuilder;
     appearBuilder.append ("q\n");
 
     if (color) {
-      appearBuilder.setDrawColor(color, gFalse);
+      appearBuilder.setDrawColor(color.get(), gFalse);
     }
 
-    appearBuilder.setLineStyleForBorder(border);
+    appearBuilder.setLineStyleForBorder(border.get());
     appearBBox->setBorderWidth(std::max(1., border->getWidth()));
 
     if (interiorColor) {
-      appearBuilder.setDrawColor(interiorColor, gTrue);
+      appearBuilder.setDrawColor(interiorColor.get(), gTrue);
     }
 
     if (vertices->getCoordsLength() != 0) {
@@ -5747,12 +5468,12 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) {
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
   if (appearBBox) {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    appearBBox->getPageXMin(), appearBBox->getPageYMin(),
                    appearBBox->getPageXMax(), appearBBox->getPageYMax(),
                    getRotation());
   } else {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   }
 }
@@ -5774,10 +5495,6 @@ AnnotCaret::AnnotCaret(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotCaret::~AnnotCaret() {
-  delete caretRect;
-}
-
 void AnnotCaret::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -5794,9 +5511,7 @@ void AnnotCaret::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("RD");
   if (obj1.isArray()) {
-    caretRect = parseDiffRectangle(obj1.getArray(), rect);
-  } else {
-    caretRect = nullptr;
+    caretRect = parseDiffRectangle(obj1.getArray(), rect.get());
   }
 }
 
@@ -5851,10 +5566,9 @@ void AnnotInk::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("BS");
   if (obj1.isDict()) {
-    delete border;
-    border = new AnnotBorderBS(obj1.getDict());
+    border = std::make_unique<AnnotBorderBS>(obj1.getDict());
   } else if (!border) {
-    border = new AnnotBorderBS();
+    border = std::make_unique<AnnotBorderBS>();
   }
 }
 
@@ -5908,17 +5622,17 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) {
 
   annotLocker();
   if (appearance.isNull()) {
-    appearBBox = new AnnotAppearanceBBox(rect);
+    appearBBox = std::make_unique<AnnotAppearanceBBox>(rect.get());
     ca = opacity;
 
     AnnotAppearanceBuilder appearBuilder;
     appearBuilder.append ("q\n");
 
     if (color) {
-      appearBuilder.setDrawColor(color, gFalse);
+      appearBuilder.setDrawColor(color.get(), gFalse);
     }
 
-    appearBuilder.setLineStyleForBorder(border);
+    appearBuilder.setLineStyleForBorder(border.get());
     appearBBox->setBorderWidth(std::max(1., border->getWidth()));
 
     for (int i = 0; i < inkListLength; ++i) {
@@ -5954,12 +5668,12 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) {
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
   if (appearBBox) {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    appearBBox->getPageXMin(), appearBBox->getPageYMin(),
                    appearBBox->getPageXMax(), appearBBox->getPageYMax(),
                    getRotation());
   } else {
-    gfx->drawAnnot(&obj, nullptr, color,
+    gfx->drawAnnot(&obj, nullptr, color.get(),
                    rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
   }
 }
@@ -5983,10 +5697,6 @@ AnnotFileAttachment::AnnotFileAttachment(PDFDoc *docA, Object *dictObject, Objec
   initialize(docA, dictObject->getDict());
 }
 
-AnnotFileAttachment::~AnnotFileAttachment() {
-  delete name;
-}
-
 void AnnotFileAttachment::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1;
 
@@ -6000,9 +5710,9 @@ void AnnotFileAttachment::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("Name");
   if (obj1.isName()) {
-    name = new GooString(obj1.getName());
+    name = std::make_unique<GooString>(obj1.getName());
   } else {
-    name = new GooString("PushPin");
+    name = std::make_unique<GooString>("PushPin");
   }
 }
 
@@ -6132,7 +5842,7 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
 
     appearBuilder.append ("q\n");
     if (color)
-      appearBuilder.setDrawColor(color, gTrue);
+      appearBuilder.setDrawColor(color.get(), gTrue);
     else
       appearBuilder.append ("1 1 1 rg\n");
     if (!name->cmp("PushPin"))
@@ -6161,7 +5871,7 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   Object obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -6184,16 +5894,10 @@ AnnotSound::AnnotSound(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotSound::~AnnotSound() {
-  delete sound;
-
-  delete name;
-}
-
 void AnnotSound::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("Sound");
 
-  sound = Sound::parseSound(&obj1);
+  sound.reset(Sound::parseSound(&obj1));
   if (!sound) {
     error(errSyntaxError, -1, "Bad Annot Sound");
     ok = gFalse;
@@ -6201,9 +5905,9 @@ void AnnotSound::initialize(PDFDoc *docA, Dict* dict) {
 
   obj1 = dict->lookup("Name");
   if (obj1.isName()) {
-    name = new GooString(obj1.getName());
+    name = std::make_unique<GooString>(obj1.getName());
   } else {
-    name = new GooString("Speaker");
+    name = std::make_unique<GooString>("Speaker");
   }
 }
 
@@ -6285,7 +5989,7 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
 
     appearBuilder.append ("q\n");
     if (color)
-      appearBuilder.setDrawColor(color, gTrue);
+      appearBuilder.setDrawColor(color.get(), gTrue);
     else
       appearBuilder.append ("1 1 1 rg\n");
     if (!name->cmp("Speaker"))
@@ -6310,7 +6014,7 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
 
   // draw the appearance stream
   obj = appearance.fetch(gfx->getXRef());
-  gfx->drawAnnot(&obj, nullptr, color,
+  gfx->drawAnnot(&obj, nullptr, color.get(),
 		 rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
 }
 
@@ -6332,17 +6036,10 @@ Annot3D::Annot3D(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-Annot3D::~Annot3D() {
-  if (activation)
-    delete activation;
-}
-
 void Annot3D::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("3DA");
   if (obj1.isDict()) {
-    activation = new Activation(obj1.getDict());
-  } else {
-    activation = nullptr;
+    activation = std::make_unique<Activation>(obj1.getDict());
   }
 }
 
@@ -6448,62 +6145,44 @@ AnnotRichMedia::AnnotRichMedia(PDFDoc *docA, Object *dictObject, Object *obj) :
   initialize(docA, dictObject->getDict());
 }
 
-AnnotRichMedia::~AnnotRichMedia() {
-  delete content;
-  delete settings;
-}
-
 void AnnotRichMedia::initialize(PDFDoc *docA, Dict* dict) {
   Object obj1 = dict->lookup("RichMediaContent");
   if (obj1.isDict()) {
-    content = new AnnotRichMedia::Content(obj1.getDict());
-  } else {
-    content = nullptr;
+    content = std::make_unique<AnnotRichMedia::Content>(obj1.getDict());
   }
 
   obj1 = dict->lookup("RichMediaSettings");
   if (obj1.isDict()) {
-    settings = new AnnotRichMedia::Settings(obj1.getDict());
-  } else {
-    settings = nullptr;
+    settings = std::make_unique<AnnotRichMedia::Settings>(obj1.getDict());
   }
 }
 
 AnnotRichMedia::Content* AnnotRichMedia::getContent() const {
-  return content;
+  return content.get();
 }
 
 AnnotRichMedia::Settings* AnnotRichMedia::getSettings() const {
-  return settings;
+  return settings.get();
 }
 
 AnnotRichMedia::Settings::Settings(Dict *dict) {
   Object obj1 = dict->lookup("Activation");
   if (obj1.isDict()) {
-    activation = new AnnotRichMedia::Activation(obj1.getDict());
-  } else {
-    activation = nullptr;
+    activation = std::make_unique<AnnotRichMedia::Activation>(obj1.getDict());
   }
 
   obj1 = dict->lookup("Deactivation");
   if (obj1.isDict()) {
-    deactivation = new AnnotRichMedia::Deactivation(obj1.getDict());
-  } else {
-    deactivation = nullptr;
+    deactivation = std::make_unique<AnnotRichMedia::Deactivation>(obj1.getDict());
   }
 }
 
-AnnotRichMedia::Settings::~Settings() {
-  delete activation;
-  delete deactivation;
-}
-
 AnnotRichMedia::Activation* AnnotRichMedia::Settings::getActivation() const {
-  return activation;
+  return activation.get();
 }
 
 AnnotRichMedia::Deactivation* AnnotRichMedia::Settings::getDeactivation() const {
-  return deactivation;
+  return deactivation.get();
 }
 
 AnnotRichMedia::Activation::Activation(Dict *dict) {
@@ -6589,7 +6268,7 @@ AnnotRichMedia::Content::Content(Dict *dict) {
         Object objKey = obj2.arrayGet(i * 2);
         assets[counter]->fileSpec = obj2.arrayGet(i * 2 + 1);
 
-        assets[counter]->name = new GooString( objKey.getString() );
+        assets[counter]->name = std::make_unique<GooString>( objKey.getString() );
         ++counter;
 
       }
@@ -6633,18 +6312,8 @@ AnnotRichMedia::Asset* AnnotRichMedia::Content::getAsset(int index) const {
   return assets[index];
 }
 
-AnnotRichMedia::Asset::Asset()
-  : name(nullptr)
-{
-}
-
-AnnotRichMedia::Asset::~Asset()
-{
-  delete name;
-}
-
 const GooString* AnnotRichMedia::Asset::getName() const {
-  return name;
+  return name.get();
 }
 
 Object* AnnotRichMedia::Asset::getFileSpec() const {
@@ -6673,9 +6342,7 @@ AnnotRichMedia::Configuration::Configuration(Dict *dict)
 
   obj1 = dict->lookup("Name");
   if (obj1.isString()) {
-    name = new GooString(obj1.getString());
-  } else {
-    name = nullptr;
+    name = std::make_unique<GooString>(obj1.getString());
   }
 
   obj1 = dict->lookup("Subtype");
@@ -6727,8 +6394,6 @@ AnnotRichMedia::Configuration::~Configuration()
       delete instances[i];
     gfree(instances);
   }
-
-  delete name;
 }
 
 int AnnotRichMedia::Configuration::getInstancesCount() const {
@@ -6743,7 +6408,7 @@ AnnotRichMedia::Instance* AnnotRichMedia::Configuration::getInstance(int index)
 }
 
 const GooString* AnnotRichMedia::Configuration::getName() const {
-  return name;
+  return name.get();
 }
 
 AnnotRichMedia::Configuration::Type AnnotRichMedia::Configuration::getType() const {
@@ -6769,42 +6434,28 @@ AnnotRichMedia::Instance::Instance(Dict *dict)
 
   obj1 = dict->lookup("Params");
   if (obj1.isDict()) {
-    params = new AnnotRichMedia::Params(obj1.getDict());
-  } else {
-    params = nullptr;
+    params = std::make_unique<AnnotRichMedia::Params>(obj1.getDict());
   }
 }
 
-AnnotRichMedia::Instance::~Instance()
-{
-  delete params;
-}
-
 AnnotRichMedia::Instance::Type AnnotRichMedia::Instance::getType() const {
   return type;
 }
 
 AnnotRichMedia::Params* AnnotRichMedia::Instance::getParams() const {
-  return params;
+  return params.get();
 }
 
 AnnotRichMedia::Params::Params(Dict *dict)
 {
   Object obj1 = dict->lookup("FlashVars");
   if (obj1.isString()) {
-    flashVars = new GooString(obj1.getString());
-  } else {
-    flashVars = nullptr;
+    flashVars = std::make_unique<GooString>(obj1.getString());
   }
 }
 
-AnnotRichMedia::Params::~Params()
-{
-  delete flashVars;
-}
-
 const GooString* AnnotRichMedia::Params::getFlashVars() const {
-  return flashVars;
+  return flashVars.get();
 }
 
 //------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 7934c4f0..ab3b184b 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -99,7 +99,7 @@ public:
 
   double getX() const { return x; }
   double getY() const { return y; }
-  
+
 protected:
 
   double x, y;
@@ -113,8 +113,8 @@ class AnnotPath {
 public:
   AnnotPath();
   AnnotPath(Array *array);
-  AnnotPath(AnnotCoord **coords, int coordLength);
-  ~AnnotPath();
+  AnnotPath(std::unique_ptr<AnnotCoord[]> &&coords, int coordsLength);
+  ~AnnotPath() = default;
 
   AnnotPath(const AnnotPath &) = delete;
   AnnotPath& operator=(const AnnotPath &other) = delete;
@@ -124,7 +124,7 @@ public:
   AnnotCoord *getCoord(int coord) const;
   int getCoordsLength() const { return coordsLength; }
 protected:
-  AnnotCoord **coords;
+  std::unique_ptr<AnnotCoord[]> coords;
   int coordsLength;
 
   void parsePathArray(Array *array);
@@ -202,6 +202,7 @@ class AnnotQuadrilaterals {
 public:
   class AnnotQuadrilateral {
   public:
+    AnnotQuadrilateral() = default;
     AnnotQuadrilateral(double x1, double y1, double x2, double y2, double x3,
       double y3, double x4, double y4);
 
@@ -209,8 +210,8 @@ public:
   };
 
   AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
-  AnnotQuadrilaterals(AnnotQuadrilateral **quads, int quadsLength);
-  ~AnnotQuadrilaterals();
+  AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
+  ~AnnotQuadrilaterals() = default;
 
   AnnotQuadrilaterals(const AnnotQuadrilaterals &) = delete;
   AnnotQuadrilaterals& operator=(const AnnotQuadrilaterals &other) = delete;
@@ -226,7 +227,7 @@ public:
   int getQuadrilateralsLength() const { return quadrilateralsLength; }
 protected:
 
-  AnnotQuadrilateral** quadrilaterals;
+  std::unique_ptr<AnnotQuadrilateral[]> quadrilaterals;
   int quadrilateralsLength;
 };
 
@@ -438,7 +439,7 @@ public:
   Object getAppearanceStream(AnnotAppearanceType type, const char *state);
 
   // Access keys in normal appearance subdictionary (N)
-  GooString * getStateKey(int i);
+  std::unique_ptr<GooString> getStateKey(int i);
   int getNumStates();
 
   // Removes all associated streams in the xref table. Caller is required to
@@ -477,33 +478,33 @@ public:
   };
 
   AnnotAppearanceCharacs(Dict *dict);
-  ~AnnotAppearanceCharacs();
+  ~AnnotAppearanceCharacs() = default;
 
   AnnotAppearanceCharacs(const AnnotAppearanceCharacs &) = delete;
   AnnotAppearanceCharacs& operator=(const AnnotAppearanceCharacs &) = delete;
 
   int getRotation() const { return rotation; }
-  const AnnotColor *getBorderColor() const { return borderColor; }
-  const AnnotColor *getBackColor() const { return backColor; }
-  const GooString *getNormalCaption() const { return normalCaption; }
-  const GooString *getRolloverCaption() const { return rolloverCaption; }
-  const GooString *getAlternateCaption() const { return alternateCaption; }
-  const AnnotIconFit *getIconFit() const { return iconFit; }
+  const AnnotColor *getBorderColor() const { return borderColor.get(); }
+  const AnnotColor *getBackColor() const { return backColor.get(); }
+  const GooString *getNormalCaption() const { return normalCaption.get(); }
+  const GooString *getRolloverCaption() { return rolloverCaption.get(); }
+  const GooString *getAlternateCaption() { return alternateCaption.get(); }
+  const AnnotIconFit *getIconFit() { return iconFit.get(); }
   AnnotAppearanceCharacsTextPos getPosition() const { return position; }
 
 protected:
 
-  int rotation;                           // R  (Default 0)
-  AnnotColor *borderColor;                // BC
-  AnnotColor *backColor;                  // BG
-  GooString *normalCaption;               // CA
-  GooString *rolloverCaption;             // RC
-  GooString *alternateCaption;            // AC
+  int rotation;                                // R  (Default 0)
+  std::unique_ptr<AnnotColor> borderColor;     // BC
+  std::unique_ptr<AnnotColor> backColor;       // BG
+  std::unique_ptr<GooString> normalCaption;    // CA
+  std::unique_ptr<GooString> rolloverCaption;  // RC
+  std::unique_ptr<GooString> alternateCaption; // AC
   // I
   // RI
   // IX
-  AnnotIconFit *iconFit;                  // IF
-  AnnotAppearanceCharacsTextPos position; // TP (Default 0)
+  std::unique_ptr<AnnotIconFit> iconFit;       // IF
+  AnnotAppearanceCharacsTextPos position;      // TP (Default 0)
 };
 
 //------------------------------------------------------------------------
@@ -681,11 +682,8 @@ public:
   void setModified(GooString *new_date);
   void setFlags(Guint new_flags);
 
-  void setBorder(AnnotBorder *new_border); // Takes ownership
-
-  // The annotation takes the ownership of
-  // new_color. 
-  void setColor(AnnotColor *new_color);
+  void setBorder(std::unique_ptr<AnnotBorder> &&new_border);
+  void setColor(std::unique_ptr<AnnotColor> &&new_color);
 
   void setAppearanceState(const char *state);
 
@@ -695,17 +693,17 @@ public:
   GBool getHasRef() const { return hasRef; }
   Ref getRef() const { return ref; }
   AnnotSubtype getType() const { return type; }
-  PDFRectangle *getRect() const { return rect; }
+  PDFRectangle *getRect() const { return rect.get(); }
   void getRect(double *x1, double *y1, double *x2, double *y2) const;
-  const GooString *getContents() const { return contents; }
+  const GooString *getContents() const { return contents.get(); }
   int getPageNum() const { return page; }
-  const GooString *getName() const { return name; }
-  const GooString *getModified() const { return modified; }
+  const GooString *getName() const { return name.get(); }
+  const GooString *getModified() const { return modified.get(); }
   Guint getFlags() const { return flags; }
-  AnnotAppearance *getAppearStreams() const { return appearStreams; }
-  const GooString *getAppearState() const { return appearState; }
-  AnnotBorder *getBorder() const { return border; }
-  AnnotColor *getColor() const { return color; }
+  AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
+  const GooString *getAppearState() const { return appearState.get(); }
+  AnnotBorder *getBorder() const { return border.get(); }
+  AnnotColor *getColor() const { return color.get(); }
   int getTreeKey() const { return treeKey; }
 
   int getId() { return ref.num; }
@@ -747,28 +745,28 @@ protected:
   std::atomic_int refCnt;
   
   // required data
-  AnnotSubtype type;                // Annotation type
-  PDFRectangle *rect;               // Rect
+  AnnotSubtype type;                                // Annotation type
+  std::unique_ptr<PDFRectangle> rect;               // Rect
 
   // optional data
-  GooString *contents;              // Contents
-  GooString *name;                  // NM
-  GooString *modified;              // M
-  int       page;                   // P
-  Guint flags;                      // F (must be a 32 bit unsigned int)
-  AnnotAppearance *appearStreams;   // AP
-  Object appearance;     // a reference to the Form XObject stream
-                         //   for the normal appearance
-  AnnotAppearanceBBox *appearBBox;  // BBox of generated appearance
-  GooString *appearState;           // AS
-  int treeKey;                      // Struct Parent;
-  Object oc;                        // OC
+  std::unique_ptr<GooString> contents;              // Contents
+  std::unique_ptr<GooString> name;                  // NM
+  std::unique_ptr<GooString> modified;              // M
+  int       page;                                   // P
+  Guint flags;                                      // F (must be a 32 bit unsigned int)
+  std::unique_ptr<AnnotAppearance> appearStreams;   // AP
+  Object appearance;                                // a reference to the Form XObject stream
+                                                    //   for the normal appearance
+  std::unique_ptr<AnnotAppearanceBBox> appearBBox;  // BBox of generated appearance
+  std::unique_ptr<GooString> appearState;           // AS
+  int treeKey;                                      // Struct Parent;
+  Object oc;                                        // OC
 
   PDFDoc *doc;
   XRef *xref;			// the xref table for this PDF file
   Ref ref;                      // object ref identifying this annotation
-  AnnotBorder *border;          // Border, BS
-  AnnotColor *color;            // C
+  std::unique_ptr<AnnotBorder> border;              // Border, BS
+  std::unique_ptr<AnnotColor> color;                // C
   GBool ok;
 
   bool hasRef;
@@ -811,21 +809,21 @@ public:
 
   AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
   AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotMarkup();
+  ~AnnotMarkup() = default;
 
   // getters
-  const GooString *getLabel() const { return label; }
-  AnnotPopup *getPopup() const { return popup; }
+  const GooString *getLabel() const { return label.get(); }
+  AnnotPopup *getPopup() const { return popup.get(); }
   double getOpacity() const { return opacity; }
   // getRC
-  const GooString *getDate() const { return date; }
+  const GooString *getDate() const { return date.get(); }
   int getInReplyToID() const { return inReplyTo.num; }
-  const GooString *getSubject() const { return subject; }
+  const GooString *getSubject() const { return subject.get(); }
   AnnotMarkupReplyType getReplyTo() const { return replyTo; }
   AnnotExternalDataType getExData() const { return exData; }
 
   // The annotation takes the ownership of new_popup
-  void setPopup(AnnotPopup *new_popup);
+  void setPopup(std::unique_ptr<AnnotPopup> &&new_popup);
   void setLabel(GooString *new_label);
   void setOpacity(double opacityA);
   void setDate(GooString *new_date);
@@ -833,18 +831,18 @@ public:
 protected:
   void removeReferencedObjects() override;
 
-  GooString *label;             // T            (Default autor)
-  AnnotPopup *popup;            // Popup
-  double opacity;               // CA           (Default 1.0)
+  std::unique_ptr<GooString> label;   // T            (Default autor)
+  std::unique_ptr<AnnotPopup> popup;  // Popup
+  double opacity;                     // CA           (Default 1.0)
   // RC
-  GooString *date;              // CreationDate
-  Ref inReplyTo;                // IRT
-  GooString *subject;           // Subj
-  AnnotMarkupReplyType replyTo; // RT           (Default R)
+  std::unique_ptr<GooString> date;    // CreationDate
+  Ref inReplyTo;                      // IRT
+  std::unique_ptr<GooString> subject; // Subj
+  AnnotMarkupReplyType replyTo;       // RT           (Default R)
   // this object is overrided by the custom intent fields defined in some
   // annotation types.
-  //GooString *intent;          // IT
-  AnnotExternalDataType exData; // ExData
+  //GooString *intent;                // IT
+  AnnotExternalDataType exData;       // ExData
 
 private:
   void initialize(PDFDoc *docA, Dict *dict, Object *obj);
@@ -871,13 +869,13 @@ public:
 
   AnnotText(PDFDoc *docA, PDFRectangle *rect);
   AnnotText(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotText();
+  ~AnnotText() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   // getters
   GBool getOpen() const { return open; }
-  const GooString *getIcon() const { return icon; }
+  const GooString *getIcon() const { return icon.get(); }
   AnnotTextState getState() const { return state; }
 
   void setOpen(GBool openA);
@@ -888,7 +886,7 @@ private:
   void initialize(PDFDoc *docA, Dict *dict);
 
   GBool open;                       // Open       (Default false)
-  GooString *icon;                  // Name       (Default Note)
+  std::unique_ptr<GooString> icon;  // Name       (Default Note)
   AnnotTextState state;             // State      (Default Umarked if
                                     //             StateModel Marked
                                     //             None if StareModel Review)
@@ -904,18 +902,18 @@ class AnnotMovie: public Annot {
  public:
   AnnotMovie(PDFDoc *docA, PDFRectangle *rect, Movie *movieA);
   AnnotMovie(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotMovie();
+  ~AnnotMovie() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
-  const GooString* getTitle() const { return title; }
-  Movie* getMovie() { return movie; }
+  const GooString* getTitle() const { return title.get(); }
+  Movie* getMovie() { return movie.get(); }
 
  private:
   void initialize(PDFDoc *docA, Dict *dict);
 
-  GooString* title;      // T
-  Movie* movie;          // Movie + A
+  std::unique_ptr<GooString> title; // T
+  std::unique_ptr<Movie> movie;     // Movie + A
 };
 
 
@@ -928,24 +926,24 @@ class AnnotScreen: public Annot {
 
   AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
   AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotScreen();
+  ~AnnotScreen() = default;
 
-  const GooString* getTitle() const { return title; }
+  const GooString* getTitle() const { return title.get(); }
 
-  AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; }
-  LinkAction* getAction() { return action; } // The caller should now delete the result
+  AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
+  LinkAction *getAction() { return action.get(); } // The caller should now delete the result
   LinkAction *getAdditionalAction(AdditionalActionsType type); // The caller should delete the result
 
  private:
   void initialize(PDFDoc *docA, Dict *dict);
 
 
-  GooString* title;                      // T
+  std::unique_ptr<GooString> title;                      // T
 
-  AnnotAppearanceCharacs* appearCharacs; // MK
+  std::unique_ptr<AnnotAppearanceCharacs> appearCharacs; // MK
 
-  LinkAction *action;                    // A
-  Object additionalActions;              // AA
+  std::unique_ptr<LinkAction> action;                    // A
+  Object additionalActions;                              // AA
 };
 
 //------------------------------------------------------------------------
@@ -964,25 +962,25 @@ public:
 
   AnnotLink(PDFDoc *docA, PDFRectangle *rect);
   AnnotLink(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotLink();
+  ~AnnotLink() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   // getters
-  LinkAction *getAction() const { return action; }
+  LinkAction *getAction() const { return action.get(); }
   AnnotLinkEffect getLinkEffect() const { return linkEffect; }
-  Dict *getUriAction() const { return uriAction; }
-  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals; }
+  /*  Dict *getUriAction() const { return uriAction; } */
+  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
 
 protected:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
-  LinkAction *action;                  // A, Dest
-  AnnotLinkEffect linkEffect;          // H          (Default I)
-  Dict *uriAction;                     // PA
+  std::unique_ptr<LinkAction> action;                  // A, Dest
+  AnnotLinkEffect linkEffect;                          // H          (Default I)
+  //Dict *uriAction;                                   // PA
 
-  AnnotQuadrilaterals *quadrilaterals; // QuadPoints
+  std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
 };
 
 //------------------------------------------------------------------------
@@ -1006,7 +1004,7 @@ public:
 
   AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, const DefaultAppearance &da);
   AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotFreeText();
+  ~AnnotFreeText() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
   Object getAppearanceResDict() override;
@@ -1022,11 +1020,11 @@ public:
   std::unique_ptr<DefaultAppearance> getDefaultAppearance() const;
   AnnotFreeTextQuadding getQuadding() const { return quadding; }
   // return rc
-  const GooString *getStyleString() const { return styleString; }
-  AnnotCalloutLine *getCalloutLine() const {  return calloutLine; }
+  const GooString *getStyleString() const { return styleString.get(); }
+  AnnotCalloutLine *getCalloutLine() const {  return calloutLine.get(); }
   AnnotFreeTextIntent getIntent() const { return intent; }
-  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
-  PDFRectangle *getRectangle() const { return rectangle; }
+  AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
+  PDFRectangle *getRectangle() const { return rectangle.get(); }
   AnnotLineEndingStyle getEndStyle() const { return endStyle; }
 
 protected:
@@ -1035,19 +1033,19 @@ protected:
   void generateFreeTextAppearance();
 
   // required
-  GooString *appearanceString;      // DA
+  std::unique_ptr<GooString> appearanceString;      // DA
 
   // optional
-  AnnotFreeTextQuadding quadding;   // Q  (Default 0)
+  AnnotFreeTextQuadding quadding;                   // Q  (Default 0)
   // RC
-  GooString *styleString;           // DS
-  AnnotCalloutLine *calloutLine;    // CL
-  AnnotFreeTextIntent intent;       // IT
-  AnnotBorderEffect *borderEffect;  // BE
-  PDFRectangle *rectangle;          // RD
+  std::unique_ptr<GooString> styleString;           // DS
+  std::unique_ptr<AnnotCalloutLine> calloutLine;    // CL
+  AnnotFreeTextIntent intent;                       // IT
+  std::unique_ptr<AnnotBorderEffect> borderEffect;  // BE
+  std::unique_ptr<PDFRectangle> rectangle;          // RD
   // inherited  from Annot
-  // AnnotBorderBS border;          // BS
-  AnnotLineEndingStyle endStyle;    // LE (Default None)
+  // AnnotBorderBS border;                          // BS
+  AnnotLineEndingStyle endStyle;                    // LE (Default None)
 };
 
 //------------------------------------------------------------------------
@@ -1069,7 +1067,7 @@ public:
 
   AnnotLine(PDFDoc *docA, PDFRectangle *rect);
   AnnotLine(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotLine();
+  ~AnnotLine() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
   Object getAppearanceResDict() override;
@@ -1077,7 +1075,7 @@ public:
 
   void setVertices(double x1, double y1, double x2, double y2);
   void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
-  void setInteriorColor(AnnotColor *new_color);
+  void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
   void setLeaderLineLength(double len);
   void setLeaderLineExtension(double len);
   void setCaption(bool new_cap);
@@ -1086,7 +1084,7 @@ public:
   // getters
   AnnotLineEndingStyle getStartStyle() const { return startStyle; }
   AnnotLineEndingStyle getEndStyle() const { return endStyle; }
-  AnnotColor *getInteriorColor() const { return interiorColor; }
+  AnnotColor *getInteriorColor() const { return interiorColor.get(); }
   double getLeaderLineLength() const { return leaderLineLength; }
   double getLeaderLineExtension() const { return leaderLineExtension; }
   bool getCaption() const { return caption; }
@@ -1107,23 +1105,24 @@ protected:
   void generateLineAppearance();
 
   // required
-  AnnotCoord *coord1, *coord2;
-  
+  std::unique_ptr<AnnotCoord> coord1;
+  std::unique_ptr<AnnotCoord> coord2;
+
   // optional
   // inherited  from Annot
-  // AnnotBorderBS border;          // BS
-  AnnotLineEndingStyle startStyle;  // LE       (Default [/None /None])
-  AnnotLineEndingStyle endStyle;    //
-  AnnotColor *interiorColor;        // IC
-  double leaderLineLength;          // LL       (Default 0)
-  double leaderLineExtension;       // LLE      (Default 0)
-  bool caption;                     // Cap      (Default false)
-  AnnotLineIntent intent;           // IT
-  double leaderLineOffset;          // LLO
-  AnnotLineCaptionPos captionPos;   // CP       (Default Inline)
-  Dict *measure;                    // Measure
-  double captionTextHorizontal;     // CO       (Default [0, 0])
-  double captionTextVertical;       //
+  // AnnotBorderBS border;                   // BS
+  AnnotLineEndingStyle startStyle;           // LE       (Default [/None /None])
+  AnnotLineEndingStyle endStyle;             //
+  std::unique_ptr<AnnotColor> interiorColor; // IC
+  double leaderLineLength;                   // LL       (Default 0)
+  double leaderLineExtension;                // LLE      (Default 0)
+  bool caption;                              // Cap      (Default false)
+  AnnotLineIntent intent;                    // IT
+  double leaderLineOffset;                   // LLO
+  AnnotLineCaptionPos captionPos;            // CP       (Default Inline)
+  Dict *measure;                             // Measure
+  double captionTextHorizontal;              // CO       (Default [0, 0])
+  double captionTextVertical;                //
 };
 
 //------------------------------------------------------------------------
@@ -1135,7 +1134,7 @@ public:
 
   AnnotTextMarkup(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotTextMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotTextMarkup();
+  ~AnnotTextMarkup() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1144,13 +1143,13 @@ public:
 
   void setQuadrilaterals(AnnotQuadrilaterals *quadPoints);
 
-  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals; }
+  AnnotQuadrilaterals *getQuadrilaterals() const { return quadrilaterals.get(); }
 
 protected:
 
   void initialize(PDFDoc *docA, Dict *dict);
-  
-  AnnotQuadrilaterals *quadrilaterals; // QuadPoints
+
+  std::unique_ptr<AnnotQuadrilaterals> quadrilaterals; // QuadPoints
 };
 
 //------------------------------------------------------------------------
@@ -1162,18 +1161,18 @@ public:
 
   AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
   AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotStamp();
+  ~AnnotStamp() = default;
 
   void setIcon(GooString *new_icon);
 
   // getters
-  const GooString *getIcon() const { return icon; }
+  const GooString *getIcon() const { return icon.get(); }
 
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
-  GooString *icon;                  // Name       (Default Draft)
+  std::unique_ptr<GooString> icon; // Name       (Default Draft)
 };
 
 //------------------------------------------------------------------------
@@ -1185,25 +1184,25 @@ public:
 
   AnnotGeometry(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotGeometry(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotGeometry();
+  ~AnnotGeometry() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   void setType(AnnotSubtype new_type); // typeSquare or typeCircle
-  void setInteriorColor(AnnotColor *new_color);
+  void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
 
   // getters
-  AnnotColor *getInteriorColor() const { return interiorColor; }
-  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
-  PDFRectangle *getGeometryRect() const { return geometryRect; }
+  AnnotColor *getInteriorColor() const { return interiorColor.get(); }
+  AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
+  PDFRectangle *getGeometryRect() const { return geometryRect.get(); }
 
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
-  AnnotColor *interiorColor;        // IC
-  AnnotBorderEffect *borderEffect;  // BE
-  PDFRectangle *geometryRect;       // RD (combined with Rect)
+  std::unique_ptr<AnnotColor> interiorColor;       // IC
+  std::unique_ptr<AnnotBorderEffect> borderEffect; // BE
+  std::unique_ptr<PDFRectangle> geometryRect;      // RD (combined with Rect)
 };
 
 //------------------------------------------------------------------------
@@ -1221,22 +1220,22 @@ public:
 
   AnnotPolygon(PDFDoc *docA, PDFRectangle *rect, AnnotSubtype subType);
   AnnotPolygon(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotPolygon();
+  ~AnnotPolygon() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   void setType(AnnotSubtype new_type); // typePolygon or typePolyLine
   void setVertices(AnnotPath *path);
   void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end);
-  void setInteriorColor(AnnotColor *new_color);
+  void setInteriorColor(std::unique_ptr<AnnotColor> &&new_color);
   void setIntent(AnnotPolygonIntent new_intent);
 
   // getters
-  AnnotPath *getVertices() const { return vertices; }
+  AnnotPath *getVertices() const { return vertices.get(); }
   AnnotLineEndingStyle getStartStyle() const { return startStyle; }
   AnnotLineEndingStyle getEndStyle() const { return endStyle; }
-  AnnotColor *getInteriorColor() const { return interiorColor; }
-  AnnotBorderEffect *getBorderEffect() const { return borderEffect; }
+  AnnotColor *getInteriorColor() const { return interiorColor.get(); }
+  AnnotBorderEffect *getBorderEffect() const { return borderEffect.get(); }
   AnnotPolygonIntent getIntent() const { return intent; }
 
 private:
@@ -1244,16 +1243,16 @@ private:
   void initialize(PDFDoc *docA, Dict *dict);
 
   // required
-  AnnotPath *vertices;              // Vertices
+  std::unique_ptr<AnnotPath> vertices;              // Vertices
 
   // optional
-  AnnotLineEndingStyle startStyle;  // LE       (Default [/None /None])
-  AnnotLineEndingStyle endStyle;    //
+  AnnotLineEndingStyle startStyle;                  // LE       (Default [/None /None])
+  AnnotLineEndingStyle endStyle;                    //
   // inherited  from Annot
-  // AnnotBorderBS border;          // BS
-  AnnotColor *interiorColor;        // IC
-  AnnotBorderEffect *borderEffect;  // BE
-  AnnotPolygonIntent intent;        // IT
+  // AnnotBorderBS border;                          // BS
+  std::unique_ptr<AnnotColor> interiorColor;        // IC
+  std::unique_ptr<AnnotBorderEffect> borderEffect;  // BE
+  AnnotPolygonIntent intent;                        // IT
   // Measure
 };
 
@@ -1271,20 +1270,20 @@ public:
 
   AnnotCaret(PDFDoc *docA, PDFRectangle *rect);
   AnnotCaret(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotCaret();
+  ~AnnotCaret() = default;
 
   void setSymbol(AnnotCaretSymbol new_symbol);
 
   // getters
   AnnotCaretSymbol getSymbol() const { return symbol; }
-  PDFRectangle *getCaretRect() const { return caretRect; }
+  PDFRectangle *getCaretRect() const { return caretRect.get(); }
 
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
-  AnnotCaretSymbol symbol;       // Sy         (Default None)
-  PDFRectangle *caretRect;       // RD (combined with Rect)
+  AnnotCaretSymbol symbol;                 // Sy         (Default None)
+  std::unique_ptr<PDFRectangle> caretRect; // RD (combined with Rect)
 };
 
 //------------------------------------------------------------------------
@@ -1331,23 +1330,23 @@ public:
 
   AnnotFileAttachment(PDFDoc *docA, PDFRectangle *rect, GooString *filename);
   AnnotFileAttachment(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotFileAttachment();
+  ~AnnotFileAttachment() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   // getters
   Object *getFile() { return &file; }
-  const GooString *getName() const { return name; }
+  const GooString *getName() const { return name.get(); }
 
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
   // required
-  Object file;      // FS
+  Object file;                      // FS
 
   // optional
-  GooString *name;  // Name
+  std::unique_ptr<GooString> name;  // Name
 };
 
 //------------------------------------------------------------------------
@@ -1359,23 +1358,23 @@ public:
 
   AnnotSound(PDFDoc *docA, PDFRectangle *rect, Sound *soundA);
   AnnotSound(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotSound();
+  ~AnnotSound() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
   // getters
-  Sound *getSound() { return sound; }
-  const GooString *getName() const { return name; }
+  Sound *getSound() { return sound.get(); }
+  const GooString *getName() const { return name.get(); }
 
 private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
   // required
-  Sound *sound;                  // Sound
+  std::unique_ptr<Sound> sound;    // Sound
 
   // optional
-  GooString *name;               // Name
+  std::unique_ptr<GooString> name; // Name
 };
 
 //------------------------------------------------------------------------
@@ -1394,7 +1393,7 @@ public:
 
   AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj);
   AnnotWidget(PDFDoc *docA, Object *dictObject, Object *obj, FormField *fieldA);
-  ~AnnotWidget();
+  ~AnnotWidget() = default;
 
   void draw(Gfx *gfx, GBool printing) override;
 
@@ -1402,8 +1401,8 @@ public:
   void updateAppearanceStream ();
 
   AnnotWidgetHighlightMode getMode() { return mode; }
-  AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs; }
-  LinkAction *getAction() { return action; }  // The caller should not delete the result
+  AnnotAppearanceCharacs *getAppearCharacs() { return appearCharacs.get(); }
+  LinkAction *getAction() { return action.get(); }  // The caller should not delete the result
   LinkAction *getAdditionalAction(AdditionalActionsType type); // The caller should delete the result
   LinkAction *getFormAdditionalAction(FormAdditionalActionsType type); // The caller should delete the result
   Dict *getParent() { return parent; }
@@ -1413,14 +1412,15 @@ private:
   void initialize(PDFDoc *docA, Dict *dict);
 
   Form *form;
-  FormField *field;                       // FormField object for this annotation
-  AnnotWidgetHighlightMode mode;          // H  (Default I)
-  AnnotAppearanceCharacs *appearCharacs;  // MK
-  LinkAction *action;                     // A
-  Object additionalActions;               // AA
+  FormField *field;                                       // FormField object for this annotation
+  AnnotWidgetHighlightMode mode;                          // H  (Default I)
+  std::unique_ptr<AnnotAppearanceCharacs> appearCharacs;  // MK
+  std::unique_ptr<LinkAction> action;                     // A
+  Object additionalActions;                               // AA
   // inherited  from Annot
   // AnnotBorderBS border;                // BS
   Dict *parent;                           // Parent
+//  GBool addDingbatsResource;
   Ref updatedAppearanceStream; // {-1,-1} if updateAppearanceStream has never been called
 };
 
@@ -1472,7 +1472,7 @@ public:
 
   Annot3D(PDFDoc *docA, PDFRectangle *rect);
   Annot3D(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~Annot3D();
+  ~Annot3D() = default;
 
   // getters
 
@@ -1480,7 +1480,7 @@ private:
 
   void initialize(PDFDoc *docA, Dict *dict);
 
-  Activation *activation;  // 3DA
+  std::unique_ptr<Activation> activation;  // 3DA
 };
 
 //------------------------------------------------------------------------
@@ -1492,7 +1492,7 @@ public:
   class Params {
   public:
     Params(Dict *dict);
-    ~Params();
+    ~Params() = default;
 
     Params(const Params &) = delete;
     Params& operator=(const Params &) = delete;
@@ -1501,7 +1501,7 @@ public:
 
   private:
     // optional
-    GooString *flashVars; // FlashVars
+    std::unique_ptr<GooString> flashVars; // FlashVars
   };
 
   class Instance {
@@ -1514,7 +1514,7 @@ public:
     };
 
     Instance(Dict *dict);
-    ~Instance();
+    ~Instance() = default;
 
     Instance(const Instance &) = delete;
     Instance& operator=(const Instance &) = delete;
@@ -1524,8 +1524,8 @@ public:
 
   private:
     // optional
-    Type type;     // Subtype
-    Params *params; // Params
+    Type type;                      // Subtype
+    std::unique_ptr<Params> params; // Params
   };
 
   class Configuration {
@@ -1550,9 +1550,9 @@ public:
 
   private:
     // optional
-    Type type;            // Subtype
-    GooString *name;      // Name
-    Instance **instances; // Instances
+    Type type;                       // Subtype
+    std::unique_ptr<GooString> name; // Name
+    Instance **instances;            // Instances
     int nInstances;
   };
 
@@ -1560,8 +1560,8 @@ public:
 
   class Asset {
   public:
-    Asset();
-    ~Asset();
+    Asset() = default;
+    ~Asset() = default;
 
     Asset(const Asset &) = delete;
     Asset& operator=(const Asset &) = delete;
@@ -1572,7 +1572,7 @@ public:
   private:
     friend class AnnotRichMedia::Content;
 
-    GooString *name;
+    std::unique_ptr<GooString> name;
     Object fileSpec;
   };
 
@@ -1592,7 +1592,7 @@ public:
 
   private:
     // optional
-    Configuration **configurations; // Configurations
+    Configuration** configurations; // Configurations
     int nConfigurations;
 
     Asset **assets; // Assets
@@ -1636,7 +1636,7 @@ public:
   class Settings {
   public:
     Settings(Dict *dict);
-    ~Settings();
+    ~Settings() = default;
 
     Settings(const Settings &) = delete;
     Settings& operator=(const Settings &) = delete;
@@ -1646,13 +1646,13 @@ public:
 
   private:
     // optional
-    Activation *activation;
-    Deactivation *deactivation;
+    std::unique_ptr<Activation> activation;
+    std::unique_ptr<Deactivation> deactivation;
   };
 
   AnnotRichMedia(PDFDoc *docA, PDFRectangle *rect);
   AnnotRichMedia(PDFDoc *docA, Object *dictObject, Object *obj);
-  ~AnnotRichMedia();
+  ~AnnotRichMedia() = default;
 
   Content* getContent() const;
 
@@ -1662,10 +1662,10 @@ private:
   void initialize(PDFDoc *docA, Dict *dict);
 
   // required
-  Content *content;     // RichMediaContent
+  std::unique_ptr<Content> content;     // RichMediaContent
 
   // optional
-  Settings *settings;   // RichMediaSettings
+  std::unique_ptr<Settings> settings;   // RichMediaSettings
 };
 
 
diff --git a/qt5/src/poppler-annotation-helper.h b/qt5/src/poppler-annotation-helper.h
index 1c8ab8c9..28145589 100644
--- a/qt5/src/poppler-annotation-helper.h
+++ b/qt5/src/poppler-annotation-helper.h
@@ -177,6 +177,6 @@ void XPDFReader::invTransform( double * M, const QPointF &p, double &x, double &
 }
 
 QColor convertAnnotColor( const AnnotColor *color );
-AnnotColor* convertQColor( const QColor &color );
+std::unique_ptr<AnnotColor> convertQColor( const QColor &color );
 
 }
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc
index 8fc35a91..c05aa22f 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -355,7 +355,7 @@ PDFRectangle AnnotationPrivate::boundaryToPdfRectangle(const QRectF &r, int rFla
 AnnotPath * AnnotationPrivate::toAnnotPath(const QLinkedList<QPointF> &list) const
 {
     const int count = list.size();
-    AnnotCoord **ac = (AnnotCoord **) gmallocn(count, sizeof(AnnotCoord*));
+    auto ac = std::make_unique<AnnotCoord[]>(count);
 
     double MTX[6];
     fillTransformationMTX(MTX);
@@ -365,10 +365,10 @@ AnnotPath * AnnotationPrivate::toAnnotPath(const QLinkedList<QPointF> &list) con
     {
         double x, y;
         XPDFReader::invTransform( MTX, p, x, y );
-        ac[pos++] = new AnnotCoord(x, y);
+        ac[pos++] = AnnotCoord(x, y);
     }
 
-    return new AnnotPath(ac, count);
+    return new AnnotPath(std::move(ac), count);
 }
 
 QList<Annotation*> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentID)
@@ -1643,11 +1643,11 @@ void Annotation::setStyle( const Annotation::Style& style )
     if (markupann)
         markupann->setOpacity( style.opacity() );
 
-    AnnotBorderArray * border = new AnnotBorderArray();
+    auto border = std::make_unique<AnnotBorderArray>();
     border->setWidth( style.width() );
     border->setHorizontalCorner( style.xCorners() );
     border->setVerticalCorner( style.yCorners() );
-    d->pdfAnnot->setBorder(border);
+    d->pdfAnnot->setBorder(std::move(border));
 }
 
 Annotation::Popup Annotation::popup() const
@@ -2727,17 +2727,17 @@ void LineAnnotation::setLineInnerColor( const QColor &color )
         return;
     }
 
-    AnnotColor * c = convertQColor(color);
+    auto c = convertQColor(color);
 
     if (d->pdfAnnot->getType() == Annot::typeLine)
     {
         AnnotLine *lineann = static_cast<AnnotLine*>(d->pdfAnnot);
-        lineann->setInteriorColor(c);
+        lineann->setInteriorColor(std::move(c));
     }
     else
     {
         AnnotPolygon *polyann = static_cast<AnnotPolygon*>(d->pdfAnnot);
-        polyann->setInteriorColor(c);
+        polyann->setInteriorColor(std::move(c));
     }
 }
 
@@ -3138,9 +3138,7 @@ QList< HighlightAnnotation::Quad > HighlightAnnotationPrivate::fromQuadrilateral
 AnnotQuadrilaterals * HighlightAnnotationPrivate::toQuadrilaterals(const QList< HighlightAnnotation::Quad > &quads) const
 {
     const int count = quads.size();
-    AnnotQuadrilaterals::AnnotQuadrilateral **ac =
-        (AnnotQuadrilaterals::AnnotQuadrilateral**)
-            gmallocn( count, sizeof(AnnotQuadrilaterals::AnnotQuadrilateral*) );
+    std::unique_ptr<AnnotQuadrilaterals::AnnotQuadrilateral[]> ac;
 
     double MTX[6];
     fillTransformationMTX(MTX);
@@ -3154,10 +3152,10 @@ AnnotQuadrilaterals * HighlightAnnotationPrivate::toQuadrilaterals(const QList<
         // Swap points 3 and 4 (see HighlightAnnotationPrivate::fromQuadrilaterals)
         XPDFReader::invTransform( MTX, q.points[3], x3, y3 );
         XPDFReader::invTransform( MTX, q.points[2], x4, y4 );
-        ac[pos++] = new AnnotQuadrilaterals::AnnotQuadrilateral(x1, y1, x2, y2, x3, y3, x4, y4);
+        ac[pos++] = AnnotQuadrilaterals::AnnotQuadrilateral(x1, y1, x2, y2, x3, y3, x4, y4);
     }
 
-    return new AnnotQuadrilaterals(ac, count);
+    return new AnnotQuadrilaterals(std::move(ac), count);
 }
 
 Annot* HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
@@ -5108,28 +5106,23 @@ QColor convertAnnotColor( const AnnotColor *color )
     return newcolor;
 }
 
-AnnotColor* convertQColor( const QColor &c )
+std::unique_ptr<AnnotColor> convertQColor( const QColor &c )
 {
     if ( c.alpha() == 0 )
-        return new AnnotColor(); // Transparent
+        return {}; // Transparent
 
-    AnnotColor *newcolor;
     switch ( c.spec() )
     {
         case QColor::Rgb:
         case QColor::Hsl:
         case QColor::Hsv:
-            newcolor = new AnnotColor( c.redF(), c.greenF(), c.blueF() );
-            break;
+            return std::make_unique<AnnotColor>( c.redF(), c.greenF(), c.blueF() );
         case QColor::Cmyk:
-            newcolor = new AnnotColor( c.cyanF(), c.magentaF(), c.yellowF(), c.blackF() );
-            break;
+            return std::make_unique<AnnotColor>( c.cyanF(), c.magentaF(), c.yellowF(), c.blackF() );
         case QColor::Invalid:
         default:
-            newcolor = new AnnotColor();
-            break;
+            return {};
     }
-    return newcolor;
 }
 //END utility annotation functions
 


More information about the poppler mailing list