summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glib/poppler-annot.cc27
-rw-r--r--poppler/Annot.cc1008
-rw-r--r--poppler/Annot.h397
-rw-r--r--qt4/src/poppler-annotation-helper.h2
-rw-r--r--qt4/src/poppler-annotation.cc22
-rw-r--r--qt5/src/poppler-annotation-helper.h2
-rw-r--r--qt5/src/poppler-annotation.cc22
7 files changed, 532 insertions, 948 deletions
diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 312aa317..936cc074 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 NULL;
+ 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 7e1941c3..68327358 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -184,8 +184,7 @@ static AnnotExternalDataType parseAnnotExternalData(Dict* dict) {
return type;
}
-PDFRectangle *parseDiffRectangle(Array *array, PDFRectangle *rect) {
- PDFRectangle *newRect = NULL;
+static std::unique_ptr<PDFRectangle> parseDiffRectangle(Array *array, PDFRectangle *rect) {
if (array->getLength() == 4) {
// deltas
Object obj1;
@@ -199,14 +198,15 @@ 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) {
@@ -283,51 +283,39 @@ AnnotBorderEffect::AnnotBorderEffect(Dict *dict) {
//------------------------------------------------------------------------
AnnotPath::AnnotPath() {
- coords = NULL;
coordsLength = 0;
}
AnnotPath::AnnotPath(Array *array) {
- coords = NULL;
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 NULL;
}
void AnnotPath::parsePathArray(Array *array) {
int tempLength;
- AnnotCoord **tempCoords;
- GBool correct = gTrue;
if (array->getLength() % 2) {
error(errSyntaxError, -1, "Bad Annot Path");
@@ -335,36 +323,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;
}
@@ -391,114 +371,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 = NULL;
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;
}
@@ -890,12 +846,11 @@ Object AnnotAppearance::getAppearanceStream(AnnotAppearanceType type, const char
return res;
}
-GooString * AnnotAppearance::getStateKey(int i) {
- GooString * res = NULL;
+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() {
@@ -1015,52 +970,36 @@ AnnotAppearanceCharacs::AnnotAppearanceCharacs(Dict *dict) {
if (obj1.isArray()) {
Array *colorComponents = obj1.getArray();
if (colorComponents->getLength() > 0) {
- borderColor = new AnnotColor(colorComponents);
- } else {
- borderColor = NULL;
+ borderColor = std::make_unique<AnnotColor>(colorComponents);
}
- } else {
- borderColor = NULL;
}
obj1 = dict->lookup("BG");
if (obj1.isArray()) {
Array *colorComponents = obj1.getArray();
if (colorComponents->getLength() > 0) {
- backColor = new AnnotColor(colorComponents);
- } else {
- backColor = NULL;
+ backColor = std::make_unique<AnnotColor>(colorComponents);
}
- } else {
- backColor = NULL;
}
obj1 = dict->lookup("CA");
if (obj1.isString()) {
- normalCaption = new GooString(obj1.getString());
- } else {
- normalCaption = NULL;
+ normalCaption = std::make_unique<GooString>(obj1.getString());
}
obj1 = dict->lookup("RC");
if (obj1.isString()) {
- rolloverCaption = new GooString(obj1.getString());
- } else {
- rolloverCaption = NULL;
+ rolloverCaption = std::make_unique<GooString>(obj1.getString());
}
obj1 = dict->lookup("AC");
if (obj1.isString()) {
- alternateCaption = new GooString(obj1.getString());
- } else {
- alternateCaption = NULL;
+ alternateCaption = std::make_unique<GooString>(obj1.getString());
}
obj1 = dict->lookup("IF");
if (obj1.isDict()) {
- iconFit = new AnnotIconFit(obj1.getDict());
- } else {
- iconFit = NULL;
+ iconFit = std::make_unique<AnnotIconFit>(obj1.getDict());
}
obj1 = dict->lookup("TP");
@@ -1071,26 +1010,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
//------------------------------------------------------------------------
@@ -1197,16 +1116,12 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
ok = gTrue;
doc = docA;
xref = doc->getXRef();
- appearStreams = NULL;
- appearBBox = NULL;
- appearState = NULL;
- appearBuf = NULL;
fontSize = 0;
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;
@@ -1235,9 +1150,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
@@ -1252,16 +1167,12 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
obj1 = dict->lookup("NM");
if (obj1.isString()) {
- name = obj1.getString()->copy();
- } else {
- name = NULL;
+ name.reset(obj1.getString()->copy());
}
obj1 = dict->lookup("M");
if (obj1.isString()) {
- modified = obj1.getString()->copy();
- } else {
- modified = NULL;
+ modified.reset(obj1.getString()->copy());
}
//----- get the flags
@@ -1275,13 +1186,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
@@ -1292,7 +1203,7 @@ void Annot::initialize(PDFDoc *docA, Dict *dict) {
}
}
if (!appearState) {
- appearState = new GooString("Off");
+ appearState = std::make_unique<GooString>("Off");
}
//----- get the annotation appearance
@@ -1306,16 +1217,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 = NULL;
+ if (obj1.isArray()) {
+ border = std::make_unique<AnnotBorderArray>(obj1.getArray());
+ }
obj1 = dict->lookup("C");
if (obj1.isArray()) {
- color = new AnnotColor(obj1.getArray());
- } else {
- color = NULL;
+ color = std::make_unique<AnnotColor>(obj1.getArray());
}
obj1 = dict->lookup("StructParent");
@@ -1378,8 +1286,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(NULL);
+ modified.reset(timeToDateString(nullptr));
annotObj.dictSet("M", Object(modified->copy()));
}
@@ -1391,17 +1298,16 @@ 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->insert(0, 0xff);
contents->insert(0, 0xfe);
}
} else {
- contents = new GooString();
+ contents = std::make_unique<GooString>();
}
update ("Contents", Object(contents->copy()));
@@ -1409,12 +1315,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()));
@@ -1422,12 +1327,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()));
}
@@ -1438,30 +1342,28 @@ 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 = NULL;
+ 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 = NULL;
+ color = nullptr;
}
invalidateAppearance();
}
@@ -1489,11 +1391,8 @@ void Annot::setAppearanceState(const char *state) {
if (!state)
return;
- delete appearState;
- appearState = new GooString(state);
-
- delete appearBBox;
- appearBBox = NULL;
+ appearState = std::make_unique<GooString>(state);
+ appearBBox = nullptr;
update ("AS", Object(objName, state));
@@ -1510,15 +1409,9 @@ void Annot::invalidateAppearance() {
if (appearStreams) { // Remove existing appearance streams
appearStreams->removeAllStreams();
}
- delete appearStreams;
- appearStreams = NULL;
-
- delete appearState;
- appearState = NULL;
-
- delete appearBBox;
- appearBBox = NULL;
-
+ appearStreams = nullptr;
+ appearState = nullptr;
+ appearBBox = nullptr;
appearance.setToNull();
Object obj2 = annotObj.dictLookup("AP");
@@ -1583,27 +1476,6 @@ 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;
-
#if MULTITHREADED
gDestroyMutex(&mutex);
#endif
@@ -1827,7 +1699,7 @@ void Annot::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -1895,36 +1767,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 = NULL;
+ 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 = NULL;
+ popup = std::make_unique<AnnotPopup>(docA, &obj1, &obj2);
}
obj1 = dict->lookup("CA");
@@ -1936,9 +1790,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
obj1 = dict->lookup("CreationDate");
if (obj1.isString()) {
- date = obj1.getString()->copy();
- } else {
- date = NULL;
+ date.reset(obj1.getString()->copy());
}
obj1 = dict->lookupNF("IRT");
@@ -1951,9 +1803,7 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict, Object *obj) {
obj1 = dict->lookup("Subj");
if (obj1.isString()) {
- subject = obj1.getString()->copy();
- } else {
- subject = NULL;
+ subject.reset(obj1.getString()->copy());
}
obj1 = dict->lookup("RT");
@@ -1980,41 +1830,38 @@ 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->insert(0, 0xff);
label->insert(0, 0xfe);
}
} 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 != NULL && 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.
@@ -2022,10 +1869,10 @@ void AnnotMarkup::setPopup(AnnotPopup *new_popup) {
Page *pageobj = doc->getPage(page);
assert(pageobj != NULL); // pageobj should exist in doc (see setPage())
- pageobj->addAnnot(popup);
+ pageobj->addAnnot(popup.get());
}
} else {
- popup = NULL;
+ popup = nullptr;
}
}
@@ -2036,12 +1883,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()));
}
@@ -2052,7 +1897,7 @@ void AnnotMarkup::removeReferencedObjects() {
// Remove popup
if (popup) {
- pageobj->removeAnnot(popup);
+ pageobj->removeAnnot(popup.get());
}
Annot::removeReferencedObjects();
@@ -2079,10 +1924,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;
@@ -2094,9 +1935,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");
@@ -2174,12 +2015,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()));
@@ -2440,11 +2279,11 @@ void AnnotText::draw(Gfx *gfx, GBool printing) {
if (appearance.isNull()) {
ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color)
- setColor(color, gTrue);
+ setColor(color.get(), gTrue);
else
appearBuf->append ("1 1 1 rg\n");
if (!icon->cmp("Note"))
@@ -2469,31 +2308,29 @@ 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) {
appearance = createForm(bbox, gFalse, nullptr);
} else {
Object aStream = createForm(bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
if (appearBBox) {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
appearBBox->getPageXMin(), appearBBox->getPageYMin(),
appearBBox->getPageXMax(), appearBBox->getPageYMax(),
getRotation());
} else {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
}
@@ -2517,30 +2354,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 = NULL;
-
// 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()));
}
}
@@ -2573,17 +2398,14 @@ void AnnotLink::initialize(PDFDoc *docA, Dict *dict) {
*/
obj1 = dict->lookup("QuadPoints");
if (obj1.isArray()) {
- quadrilaterals = new AnnotQuadrilaterals(obj1.getArray(), rect);
- } else {
- quadrilaterals = NULL;
+ 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>();
}
}
@@ -2594,7 +2416,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());
}
@@ -2619,30 +2441,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;
}
@@ -2656,9 +2462,7 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) {
obj1 = dict->lookup("DS");
if (obj1.isString()) {
- styleString = obj1.getString()->copy();
- } else {
- styleString = NULL;
+ styleString.reset(obj1.getString()->copy());
}
obj1 = dict->lookup("CL");
@@ -2675,12 +2479,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 = NULL;
}
obj1 = dict->lookup("IT");
@@ -2702,24 +2504,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 = NULL;
+ borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
}
obj1 = dict->lookup("RD");
if (obj1.isArray()) {
- rectangle = parseDiffRectangle(obj1.getArray(), rect);
- } else {
- rectangle = NULL;
+ rectangle = parseDiffRectangle(obj1.getArray(), rect.get());
}
obj1 = dict->lookup("LE");
@@ -2737,12 +2534,10 @@ void AnnotFreeText::setContents(GooString *new_content) {
}
void AnnotFreeText::setAppearanceString(GooString *new_string) {
- delete appearanceString;
-
if (new_string) {
- appearanceString = new GooString(new_string);
+ appearanceString = std::make_unique<GooString>(new_string);
} else {
- appearanceString = new GooString();
+ appearanceString = std::make_unique<GooString>();
}
update ("DA", Object(appearanceString->copy()));
@@ -2757,29 +2552,25 @@ 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->insert(0, 0xff);
styleString->insert(0, 0xfe);
}
} 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 == NULL) {
obj1.setToNull();
- calloutLine = NULL;
+ calloutLine = nullptr;
} else {
double x1 = line->getX1(), y1 = line->getY1();
double x2 = line->getX2(), y2 = line->getY2();
@@ -2794,9 +2585,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);
}
}
@@ -2834,9 +2625,9 @@ static GfxFont * createAnnotDrawFont(XRef * xref, Dict *fontResDict)
return GfxFont::makeFont(xref, "AnnotDrawFont", dummyRef, fontDict);
}
-void AnnotFreeText::parseAppearanceString(GooString *da, double &fontsize, AnnotColor* &fontcolor) {
+void AnnotFreeText::parseAppearanceString(GooString *da, double &fontsize, std::unique_ptr<AnnotColor> &fontcolor) {
fontsize = -1;
- fontcolor = NULL;
+
if (da) {
GooList * daToks = new GooList();
int j, i = 0;
@@ -2862,18 +2653,18 @@ void AnnotFreeText::parseAppearanceString(GooString *da, double &fontsize, Annot
fontsize = gatof(( (GooString *)daToks->get(i-1) )->getCString());
}
}
- if (fontcolor == NULL) {
+ if (!fontcolor) {
if (!((GooString *)daToks->get(i))->cmp("g") && i >= 1) {
- fontcolor = new AnnotColor(gatof(( (GooString *)daToks->get(i-1) )->getCString()));
+ fontcolor = std::make_unique<AnnotColor>(gatof(( (GooString *)daToks->get(i-1) )->getCString()));
} else if (!((GooString *)daToks->get(i))->cmp("rg") && i >= 3) {
- fontcolor = new AnnotColor(gatof(( (GooString *)daToks->get(i-3) )->getCString()),
- gatof(( (GooString *)daToks->get(i-2) )->getCString()),
- gatof(( (GooString *)daToks->get(i-1) )->getCString()));
+ 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 = new 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()));
+ 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()));
}
}
}
@@ -2885,12 +2676,12 @@ void AnnotFreeText::generateFreeTextAppearance()
{
double borderWidth, ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
borderWidth = border->getWidth();
if (borderWidth > 0)
- setLineStyleForBorder(border);
+ setLineStyleForBorder(border.get());
// Box size
const double width = rect->x2 - rect->x1;
@@ -2898,26 +2689,26 @@ void AnnotFreeText::generateFreeTextAppearance()
// Parse some properties from the appearance string
double fontsize;
- AnnotColor *fontcolor;
- parseAppearanceString(appearanceString, fontsize, fontcolor);
+ std::unique_ptr<AnnotColor> fontcolor;
+ parseAppearanceString(appearanceString.get(), fontsize, fontcolor);
// Default values
if (fontsize <= 0)
fontsize = 10;
- if (fontcolor == NULL)
- fontcolor = new AnnotColor(0, 0, 0); // Black
+ if (!fontcolor)
+ fontcolor = std::make_unique<AnnotColor>(0, 0, 0); // Black
if (!contents)
- contents = new GooString ();
+ contents = std::make_unique<GooString>();
// Draw box
GBool doFill = (color && color->getSpace() != AnnotColor::colorTransparent);
GBool doStroke = (borderWidth != 0);
if (doFill || doStroke) {
if (doStroke) {
- setColor(fontcolor, gFalse); // Border color: same as font color
+ setColor(fontcolor.get(), gFalse); // Border color: same as font color
}
appearBuf->appendf ("{0:.2f} {0:.2f} {1:.2f} {2:.2f} re\n", borderWidth/2, width-borderWidth, height-borderWidth);
if (doFill) {
- setColor(color, gTrue);
+ setColor(color.get(), gTrue);
appearBuf->append(doStroke ? "B\n" : "f\n");
} else {
appearBuf->append("S\n");
@@ -2933,7 +2724,7 @@ void AnnotFreeText::generateFreeTextAppearance()
GfxFont *font = createAnnotDrawFont(xref, fontResDict);
// Set font state
- setColor(fontcolor, gTrue);
+ setColor(fontcolor.get(), gTrue);
appearBuf->appendf ("BT 1 0 0 1 {0:.2f} {1:.2f} Tm\n", textmargin, height - textmargin - fontsize * font->getDescent());
appearBuf->appendf ("/AnnotDrawFont {0:.2f} Tf\n", fontsize);
@@ -2942,7 +2733,7 @@ void AnnotFreeText::generateFreeTextAppearance()
while (i < contents->getLength()) {
GooString out;
double linewidth, xpos;
- layoutText(contents, &out, &i, font, &linewidth, textwidth/fontsize, NULL, gFalse);
+ layoutText(contents.get(), &out, &i, font, &linewidth, textwidth/fontsize, NULL, gFalse);
linewidth *= fontsize;
switch (quadding) {
case quaddingCentered:
@@ -2956,13 +2747,13 @@ void AnnotFreeText::generateFreeTextAppearance()
break;
}
appearBuf->appendf("{0:.2f} {1:.2f} Td\n", xpos - xposPrev, -fontsize);
- writeString(&out, appearBuf);
+ writeString(&out, appearBuf.get());
appearBuf->append("Tj\n");
xposPrev = xpos;
}
font->decRefCnt();
- delete fontcolor;
+ fontcolor = nullptr;
appearBuf->append ("ET Q\n");
double bbox[4];
@@ -2974,13 +2765,11 @@ void AnnotFreeText::generateFreeTextAppearance()
appearance = createForm(bbox, gFalse, fontResDict);
} else {
Object aStream = createForm(bbox, gTrue, fontResDict);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
void AnnotFreeText::draw(Gfx *gfx, GBool printing) {
@@ -2994,7 +2783,7 @@ void AnnotFreeText::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -3027,17 +2816,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;
@@ -3051,11 +2829,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");
@@ -3080,9 +2858,7 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) {
obj1 = dict->lookup("IC");
if (obj1.isArray()) {
- interiorColor = new AnnotColor(obj1.getArray());
- } else {
- interiorColor = NULL;
+ interiorColor = std::make_unique<AnnotColor>(obj1.getArray());
}
obj1 = dict->lookup("LL");
@@ -3170,10 +2946,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>();
}
}
@@ -3184,10 +2959,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) );
@@ -3211,15 +2984,13 @@ 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 = NULL;
+ interiorColor = nullptr;
}
invalidateAppearance();
}
@@ -3260,14 +3031,14 @@ void AnnotLine::generateLineAppearance()
{
double borderWidth, ca = opacity;
- appearBBox = new AnnotAppearanceBBox(rect);
- appearBuf = new GooString ();
+ appearBBox = std::make_unique<AnnotAppearanceBBox>(rect.get());
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
- setLineStyleForBorder(border);
+ setLineStyleForBorder(border.get());
borderWidth = border->getWidth();
appearBBox->setBorderWidth(std::max(1., borderWidth));
@@ -3306,7 +3077,7 @@ void AnnotLine::generateLineAppearance()
while (i < contents->getLength()) {
GooString out;
double linewidth;
- layoutText(contents, &out, &i, font, &linewidth, 0, NULL, gFalse);
+ layoutText(contents.get(), &out, &i, font, &linewidth, 0, NULL, gFalse);
linewidth *= fontsize;
if (linewidth > captionwidth) {
captionwidth = linewidth;
@@ -3375,11 +3146,11 @@ void AnnotLine::generateLineAppearance()
while (i < contents->getLength()) {
GooString out;
double linewidth, xpos;
- layoutText(contents, &out, &i, font, &linewidth, 0, NULL, gFalse);
+ layoutText(contents.get(), &out, &i, font, &linewidth, 0, NULL, gFalse);
linewidth *= fontsize;
xpos = (captionwidth - linewidth) / 2;
appearBuf->appendf("{0:.2f} {1:.2f} Td\n", xpos - xposPrev, -fontsize);
- writeString(&out, appearBuf);
+ writeString(&out, appearBuf.get());
appearBuf->append ("Tj\n");
xposPrev = xpos;
}
@@ -3414,13 +3185,11 @@ void AnnotLine::generateLineAppearance()
appearance = createForm(bbox, gFalse, fontResDict);
} else {
Object aStream = createForm(bbox, gTrue, fontResDict);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
void AnnotLine::draw(Gfx *gfx, GBool printing) {
@@ -3435,12 +3204,12 @@ void AnnotLine::draw(Gfx *gfx, GBool printing) {
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
if (appearBBox) {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
appearBBox->getPageXMin(), appearBBox->getPageYMin(),
appearBBox->getPageXMax(), appearBBox->getPageYMax(),
getRotation());
} else {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
}
@@ -3514,18 +3283,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 = NULL;
ok = gFalse;
}
}
-AnnotTextMarkup::~AnnotTextMarkup() {
- delete quadrilaterals;
-}
-
void AnnotTextMarkup::setType(AnnotSubtype new_type) {
const char *typeName;
@@ -3565,8 +3329,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();
@@ -3584,12 +3347,11 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
GBool blendMultiply = gTrue;
ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->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);
@@ -3600,7 +3362,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
switch (type) {
case typeUnderline:
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
appearBuf->append ("[] 0 d 1 w\n");
@@ -3619,7 +3381,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
break;
case typeStrikeOut:
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
blendMultiply = gFalse;
appearBuf->append ("[] 0 d 1 w\n");
@@ -3645,7 +3407,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
break;
case typeSquiggly:
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
appearBuf->append ("[] 0 d 1 w\n");
@@ -3672,7 +3434,7 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
default:
case typeHighlight:
if (color)
- setColor(color, gTrue);
+ setColor(color.get(), gTrue);
double biggestBorder = 0;
for (i = 0; i < quadrilaterals->getQuadrilateralsLength(); ++i) {
@@ -3713,32 +3475,28 @@ void AnnotTextMarkup::draw(Gfx *gfx, GBool printing) {
bbox[2] = appearBBox->getPageXMax();
bbox[3] = appearBBox->getPageYMax();
aStream = createForm(bbox, gTrue, NULL);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", 1, blendMultiply ? "Multiply" : NULL);
if (ca == 1) {
appearance = createForm(bbox, gFalse, resDict);
} else {
aStream = createForm(bbox, gTrue, resDict);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict2 = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict2);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
if (appearBBox) {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
appearBBox->getPageXMin(), appearBBox->getPageYMin(),
appearBBox->getPageXMax(), appearBBox->getPageYMax(),
getRotation());
} else {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
}
@@ -3761,17 +3519,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;
@@ -3796,15 +3543,12 @@ void AnnotWidget::initialize(PDFDoc *docA, Dict *dict) {
obj1 = dict->lookup("MK");
if (obj1.isDict()) {
- appearCharacs = new AnnotAppearanceCharacs(obj1.getDict());
- } else {
- appearCharacs = NULL;
+ appearCharacs = std::make_unique<AnnotAppearanceCharacs>(obj1.getDict());
}
- action = NULL;
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");
@@ -3818,8 +3562,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;
@@ -4083,7 +3826,8 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
GBool txField, GBool forceZapfDingbats,
GBool password) {
GooList *daToks;
- GooString *tok, *convertedText;
+ GooString *tok;
+ GooString convertedText;
GfxFont *font;
double dx, dy;
double fontSize, fontSize2, borderWidth, x, xPrev, y, w, wMax;
@@ -4188,8 +3932,6 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
freeText = gTrue;
}
- convertedText = new GooString;
-
// setup
if (txField) {
appearBuf->append("/Tx BMC\n");
@@ -4231,7 +3973,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
y = dy - 3;
i = 0;
while (i < text->getLength()) {
- layoutText(text, convertedText, &i, font, &w, wMax / fontSize, NULL,
+ layoutText(text, &convertedText, &i, font, &w, wMax / fontSize, NULL,
forceZapfDingbats);
y -= fontSize;
}
@@ -4278,7 +4020,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
i = 0;
xPrev = 0;
while (i < text->getLength()) {
- layoutText(text, convertedText, &i, font, &w, wMax / fontSize, NULL,
+ layoutText(text, &convertedText, &i, font, &w, wMax / fontSize, NULL,
forceZapfDingbats);
w *= fontSize;
@@ -4298,7 +4040,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
// draw the line
appearBuf->appendf("{0:.2f} {1:.2f} Td\n", x - xPrev, -fontSize);
- writeString(convertedText, appearBuf);
+ writeString(&convertedText, appearBuf.get());
appearBuf->append(" Tj\n");
// next line
@@ -4331,7 +4073,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
}
i = 0;
- layoutText(text, convertedText, &i, font, NULL, 0.0, &charCount,
+ layoutText(text, &convertedText, &i, font, NULL, 0.0, &charCount,
forceZapfDingbats);
if (charCount > comb)
charCount = comb;
@@ -4374,8 +4116,8 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
}
// write the text string
- char *s = convertedText->getCString();
- int len = convertedText->getLength();
+ char *s = convertedText.getCString();
+ int len = convertedText.getLength();
i = 0;
xPrev = w; // so that first character is placed properly
while (i < comb && len > 0) {
@@ -4394,10 +4136,9 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
x = 0.5 * (w - dx);
appearBuf->appendf("{0:.2f} 0 Td\n", x - xPrev + w);
- GooString *charBuf = new GooString(s, n);
- writeString(charBuf, appearBuf);
+ GooString charBuf(s, n);
+ writeString(&charBuf, appearBuf.get());
appearBuf->append(" Tj\n");
- delete charBuf;
i++;
s += n;
@@ -4408,7 +4149,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
// regular (non-comb) formatting
} else {
i = 0;
- layoutText(text, convertedText, &i, font, &w, 0.0, NULL,
+ layoutText(text, &convertedText, &i, font, &w, 0.0, NULL,
forceZapfDingbats);
// compute font autosize
@@ -4465,7 +4206,7 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
}
// write the text string
- writeString(convertedText, appearBuf);
+ writeString(&convertedText, appearBuf.get());
appearBuf->append(" Tj\n");
}
}
@@ -4481,7 +4222,6 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
if (freeText) {
delete text;
}
- delete convertedText;
if (freeFont) {
font->decRefCnt();
}
@@ -4491,7 +4231,8 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxResources *resourc
void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
GooString *da, GfxResources *resources, int quadding) {
GooList *daToks;
- GooString *tok, *convertedText;
+ GooString *tok;
+ GooString convertedText;
GfxFont *font;
double fontSize, fontSize2, borderWidth, x, y, w, wMax;
int tfPos, tmPos, i, j;
@@ -4552,8 +4293,6 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
return;
}
- convertedText = new GooString;
-
// get the border width
borderWidth = border ? border->getWidth() : 0;
@@ -4567,10 +4306,9 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
if (daToks) {
deleteGooList(daToks, GooString);
}
- delete convertedText;
return;
}
- layoutText(fieldChoice->getChoice(i), convertedText, &j, font, &w, 0.0, NULL, gFalse);
+ layoutText(fieldChoice->getChoice(i), &convertedText, &j, font, &w, 0.0, NULL, gFalse);
if (w > wMax) {
wMax = w;
}
@@ -4608,7 +4346,7 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
// compute text width and start position
j = 0;
- layoutText(fieldChoice->getChoice(i), convertedText, &j, font, &w, 0.0, NULL, gFalse);
+ layoutText(fieldChoice->getChoice(i), &convertedText, &j, font, &w, 0.0, NULL, gFalse);
w *= fontSize;
switch (quadding) {
case quaddingLeftJustified:
@@ -4651,7 +4389,7 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
}
// write the text string
- writeString(convertedText, appearBuf);
+ writeString(&convertedText, appearBuf.get());
appearBuf->append(" Tj\n");
// cleanup
@@ -4665,8 +4403,6 @@ void AnnotWidget::drawListBox(FormFieldChoice *fieldChoice,
if (daToks) {
deleteGooList(daToks, GooString);
}
-
- delete convertedText;
}
void AnnotWidget::drawBorder() {
@@ -4856,7 +4592,7 @@ void AnnotWidget::generateFieldAppearance() {
GfxResources *resources;
GooString *da;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
// draw the background
if (appearCharacs) {
@@ -4918,7 +4654,7 @@ void AnnotWidget::generateFieldAppearance() {
MemStream *appearStream = new MemStream(copyString(appearBuf->getCString()), 0,
appearBuf->getLength(), Object(appearDict));
appearance = Object(static_cast<Stream*>(appearStream));
- delete appearBuf;
+ appearBuf = nullptr;
appearStream->setNeedFree(gTrue);
}
@@ -4954,7 +4690,7 @@ void AnnotWidget::updateAppearanceStream()
obj1.dictAdd(copyString("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 {
@@ -4995,7 +4731,7 @@ void AnnotWidget::draw(Gfx *gfx, GBool printing) {
gfx->pushResources(dict);
delete dict;
}
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
if (addDingbatsResource) {
gfx->popResources();
@@ -5013,7 +4749,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());
@@ -5025,37 +4761,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 = NULL;
+ 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 = NULL;
+ movie = nullptr;
ok = gFalse;
}
} else {
error(errSyntaxError, -1, "Bad Annot Movie");
- movie = NULL;
ok = gFalse;
}
}
@@ -5071,7 +4797,7 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
movie->getAspect(&width, &height);
if (width != -1 && height != -1 && !poster.isNone()) {
- appearBuf = new GooString ();
+ 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");
@@ -5106,7 +4832,6 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
MemStream *mStream = new MemStream(copyString(appearBuf->getCString()), 0,
appearBuf->getLength(), Object(formDict));
mStream->setNeedFree(gTrue);
- delete appearBuf;
Dict *dict = new Dict(gfx->getXRef());
dict->set("FRM", Object(static_cast<Stream*>(mStream)));
@@ -5114,7 +4839,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");
@@ -5129,13 +4854,13 @@ void AnnotMovie::draw(Gfx *gfx, GBool printing) {
bbox[2] = width;
bbox[3] = height;
appearance = createForm(bbox, gFalse, resDict2);
- delete appearBuf;
+ appearBuf = nullptr;
}
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -5158,39 +4883,29 @@ 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 = NULL;
obj1 = dict->lookup("T");
if (obj1.isString()) {
- title = obj1.getString()->copy();
+ title.reset(obj1.getString()->copy());
}
- action = NULL;
obj1 = dict->lookup("A");
if (obj1.isDict()) {
- action = LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI());
+ action.reset(LinkAction::parseAction(&obj1, doc->getCatalog()->getBaseURI()));
if (action->getKind() == actionRendition && page == 0) {
error (errSyntaxError, -1, "Invalid Rendition action: associated screen annotation without P");
- delete action;
- action = NULL;
+ action = nullptr;
ok = gFalse;
}
}
additionalActions = dict->lookupNF("AA");
- appearCharacs = NULL;
obj1 = dict->lookup("MK");
if (obj1.isDict()) {
- appearCharacs = new AnnotAppearanceCharacs(obj1.getDict());
+ appearCharacs = std::make_unique<AnnotAppearanceCharacs>(obj1.getDict());
}
}
@@ -5220,27 +4935,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()));
@@ -5275,12 +4984,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;
@@ -5296,30 +4999,24 @@ void AnnotGeometry::initialize(PDFDoc *docA, Dict* dict) {
obj1 = dict->lookup("IC");
if (obj1.isArray()) {
- interiorColor = new AnnotColor(obj1.getArray());
- } else {
- interiorColor = NULL;
+ 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 = NULL;
+ borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
}
- geometryRect = NULL;
obj1 = dict->lookup("RD");
if (obj1.isArray()) {
- geometryRect = parseDiffRectangle(obj1.getArray(), rect);
+ geometryRect = parseDiffRectangle(obj1.getArray(), rect.get());
}
}
@@ -5342,15 +5039,13 @@ 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 = NULL;
+ interiorColor = nullptr;
}
invalidateAppearance();
}
@@ -5365,16 +5060,16 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
if (appearance.isNull()) {
ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color)
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
double borderWidth = border->getWidth();
- setLineStyleForBorder(border);
+ setLineStyleForBorder(border.get());
if (interiorColor)
- setColor(interiorColor, gTrue);
+ setColor(interiorColor.get(), gTrue);
if (type == typeSquare) {
appearBuf->appendf ("{0:.2f} {1:.2f} {2:.2f} {3:.2f} re\n",
@@ -5444,18 +5139,16 @@ void AnnotGeometry::draw(Gfx *gfx, GBool printing) {
appearance = createForm(bbox, gFalse, nullptr);
} else {
Object aStream = createForm(bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -5493,16 +5186,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;
@@ -5518,9 +5201,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;
}
@@ -5545,24 +5228,19 @@ void AnnotPolygon::initialize(PDFDoc *docA, Dict* dict) {
obj1 = dict->lookup("IC");
if (obj1.isArray()) {
- interiorColor = new AnnotColor(obj1.getArray());
- } else {
- interiorColor = NULL;
+ 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 = NULL;
+ borderEffect = std::make_unique<AnnotBorderEffect>(obj1.getDict());
}
obj1 = dict->lookup("IT");
@@ -5601,15 +5279,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();
@@ -5627,15 +5303,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 = NULL;
+ interiorColor = std::move(new_color);
}
invalidateAppearance();
}
@@ -5661,21 +5333,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;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
- setLineStyleForBorder(border);
+ setLineStyleForBorder(border.get());
appearBBox->setBorderWidth(std::max(1., border->getWidth()));
if (interiorColor) {
- setColor(interiorColor, gTrue);
+ setColor(interiorColor.get(), gTrue);
}
if (vertices->getCoordsLength() != 0) {
@@ -5706,24 +5378,22 @@ void AnnotPolygon::draw(Gfx *gfx, GBool printing) {
appearance = createForm(bbox, gFalse, nullptr);
} else {
Object aStream = createForm(bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
if (appearBBox) {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
appearBBox->getPageXMin(), appearBBox->getPageYMin(),
appearBBox->getPageXMax(), appearBBox->getPageYMax(),
getRotation());
} else {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
}
@@ -5747,10 +5417,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;
@@ -5767,9 +5433,7 @@ void AnnotCaret::initialize(PDFDoc *docA, Dict* dict) {
obj1 = dict->lookup("RD");
if (obj1.isArray()) {
- caretRect = parseDiffRectangle(obj1.getArray(), rect);
- } else {
- caretRect = NULL;
+ caretRect = parseDiffRectangle(obj1.getArray(), rect.get());
}
}
@@ -5827,10 +5491,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>();
}
}
@@ -5884,17 +5547,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;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color) {
- setColor(color, gFalse);
+ setColor(color.get(), gFalse);
}
- setLineStyleForBorder(border);
+ setLineStyleForBorder(border.get());
appearBBox->setBorderWidth(std::max(1., border->getWidth()));
for (int i = 0; i < inkListLength; ++i) {
@@ -5920,24 +5583,22 @@ void AnnotInk::draw(Gfx *gfx, GBool printing) {
appearance = createForm(bbox, gFalse, nullptr);
} else {
Object aStream = createForm(bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
if (appearBBox) {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
appearBBox->getPageXMin(), appearBBox->getPageYMin(),
appearBBox->getPageXMax(), appearBBox->getPageYMax(),
getRotation());
} else {
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
}
@@ -5963,10 +5624,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;
@@ -5980,9 +5637,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");
}
}
@@ -6108,11 +5765,11 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
if (appearance.isNull()) {
ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color)
- setColor(color, gTrue);
+ setColor(color.get(), gTrue);
else
appearBuf->append ("1 1 1 rg\n");
if (!name->cmp("PushPin"))
@@ -6132,18 +5789,16 @@ void AnnotFileAttachment::draw(Gfx *gfx, GBool printing) {
appearance = createForm (bbox, gFalse, nullptr);
} else {
Object aStream = createForm (bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
Object obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -6168,16 +5823,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;
@@ -6185,9 +5834,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");
}
}
@@ -6265,11 +5914,11 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
if (appearance.isNull()) {
ca = opacity;
- appearBuf = new GooString ();
+ appearBuf = std::make_unique<GooString>();
appearBuf->append ("q\n");
if (color)
- setColor(color, gTrue);
+ setColor(color.get(), gTrue);
else
appearBuf->append ("1 1 1 rg\n");
if (!name->cmp("Speaker"))
@@ -6285,18 +5934,16 @@ void AnnotSound::draw(Gfx *gfx, GBool printing) {
appearance = createForm(bbox, gFalse, nullptr);
} else {
Object aStream = createForm(bbox, gTrue, nullptr);
- delete appearBuf;
-
- appearBuf = new GooString ("/GS0 gs\n/Fm0 Do");
+ appearBuf = std::make_unique<GooString>("/GS0 gs\n/Fm0 Do");
Dict *resDict = createResourcesDict("Fm0", std::move(aStream), "GS0", ca, NULL);
appearance = createForm(bbox, gFalse, resDict);
}
- delete appearBuf;
+ appearBuf = nullptr;
}
// draw the appearance stream
obj = appearance.fetch(gfx->getXRef());
- gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color,
+ gfx->drawAnnot(&obj, (AnnotBorder *)NULL, color.get(),
rect->x1, rect->y1, rect->x2, rect->y2, getRotation());
}
@@ -6320,17 +5967,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 = NULL;
+ activation = std::make_unique<Activation>(obj1.getDict());
}
}
@@ -6438,62 +6078,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 = NULL;
+ content = std::make_unique<AnnotRichMedia::Content>(obj1.getDict());
}
obj1 = dict->lookup("RichMediaSettings");
if (obj1.isDict()) {
- settings = new AnnotRichMedia::Settings(obj1.getDict());
- } else {
- settings = NULL;
+ 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 = NULL;
+ activation = std::make_unique<AnnotRichMedia::Activation>(obj1.getDict());
}
obj1 = dict->lookup("Deactivation");
if (obj1.isDict()) {
- deactivation = new AnnotRichMedia::Deactivation(obj1.getDict());
- } else {
- deactivation = NULL;
+ 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) {
@@ -6579,7 +6201,7 @@ AnnotRichMedia::Content::Content(Dict *dict) {
Object objKey = obj2.arrayGet(i);
assets[counter]->fileSpec = obj2.arrayGet(i + 1);
- assets[counter]->name = new GooString( objKey.getString() );
+ assets[counter]->name = std::make_unique<GooString>( objKey.getString() );
++counter;
}
@@ -6623,18 +6245,8 @@ AnnotRichMedia::Asset* AnnotRichMedia::Content::getAsset(int index) const {
return assets[index];
}
-AnnotRichMedia::Asset::Asset()
- : name(NULL)
-{
-}
-
-AnnotRichMedia::Asset::~Asset()
-{
- delete name;
-}
-
GooString* AnnotRichMedia::Asset::getName() const {
- return name;
+ return name.get();
}
Object* AnnotRichMedia::Asset::getFileSpec() const {
@@ -6663,9 +6275,7 @@ AnnotRichMedia::Configuration::Configuration(Dict *dict)
obj1 = dict->lookup("Name");
if (obj1.isString()) {
- name = new GooString(obj1.getString());
- } else {
- name = NULL;
+ name = std::make_unique<GooString>(obj1.getString());
}
obj1 = dict->lookup("Subtype");
@@ -6713,8 +6323,6 @@ AnnotRichMedia::Configuration::~Configuration()
delete instances[i];
gfree(instances);
}
-
- delete name;
}
int AnnotRichMedia::Configuration::getInstancesCount() const {
@@ -6729,7 +6337,7 @@ AnnotRichMedia::Instance* AnnotRichMedia::Configuration::getInstance(int index)
}
GooString* AnnotRichMedia::Configuration::getName() const {
- return name;
+ return name.get();
}
AnnotRichMedia::Configuration::Type AnnotRichMedia::Configuration::getType() const {
@@ -6755,42 +6363,28 @@ AnnotRichMedia::Instance::Instance(Dict *dict)
obj1 = dict->lookup("Params");
if (obj1.isDict()) {
- params = new AnnotRichMedia::Params(obj1.getDict());
- } else {
- params = NULL;
+ 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 = NULL;
+ flashVars = std::unique_ptr<GooString>(obj1.getString());
}
}
-AnnotRichMedia::Params::~Params()
-{
- delete flashVars;
-}
-
GooString* AnnotRichMedia::Params::getFlashVars() const {
- return flashVars;
+ return flashVars.get();
}
//------------------------------------------------------------------------
diff --git a/poppler/Annot.h b/poppler/Annot.h
index 171494a9..2e333157 100644
--- a/poppler/Annot.h
+++ b/poppler/Annot.h
@@ -88,7 +88,7 @@ public:
double getX() const { return x; }
double getY() const { return y; }
-
+
protected:
double x, y;
@@ -102,15 +102,15 @@ class AnnotPath {
public:
AnnotPath();
AnnotPath(Array *array);
- AnnotPath(AnnotCoord **coords, int coordLength);
- ~AnnotPath();
+ AnnotPath(std::unique_ptr<AnnotCoord[]> &&coords, int coordsLength);
+ ~AnnotPath() = default;
double getX(int coord) const;
double getY(int coord) const;
AnnotCoord *getCoord(int coord) const;
int getCoordsLength() const { return coordsLength; }
protected:
- AnnotCoord **coords;
+ std::unique_ptr<AnnotCoord[]> coords;
int coordsLength;
void parsePathArray(Array *array);
@@ -185,6 +185,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);
@@ -192,8 +193,8 @@ public:
};
AnnotQuadrilaterals(Array *array, PDFRectangle *rect);
- AnnotQuadrilaterals(AnnotQuadrilateral **quads, int quadsLength);
- ~AnnotQuadrilaterals();
+ AnnotQuadrilaterals(std::unique_ptr<AnnotQuadrilateral[]> &&quads, int quadsLength);
+ ~AnnotQuadrilaterals() = default;
double getX1(int quadrilateral);
double getY1(int quadrilateral);
@@ -206,7 +207,7 @@ public:
int getQuadrilateralsLength() const { return quadrilateralsLength; }
protected:
- AnnotQuadrilateral** quadrilaterals;
+ std::unique_ptr<AnnotQuadrilateral[]> quadrilaterals;
int quadrilateralsLength;
};
@@ -388,7 +389,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
@@ -427,30 +428,30 @@ public:
};
AnnotAppearanceCharacs(Dict *dict);
- ~AnnotAppearanceCharacs();
+ ~AnnotAppearanceCharacs() = default;
int getRotation() { return rotation; }
- AnnotColor *getBorderColor() { return borderColor; }
- AnnotColor *getBackColor() { return backColor; }
- GooString *getNormalCaption() { return normalCaption; }
- GooString *getRolloverCaption() { return rolloverCaption; }
- GooString *getAlternateCaption() { return alternateCaption; }
- AnnotIconFit *getIconFit() { return iconFit; }
+ AnnotColor *getBorderColor() { return borderColor.get(); }
+ AnnotColor *getBackColor() { return backColor.get(); }
+ GooString *getNormalCaption() { return normalCaption.get(); }
+ GooString *getRolloverCaption() { return rolloverCaption.get(); }
+ GooString *getAlternateCaption() { return alternateCaption.get(); }
+ AnnotIconFit *getIconFit() { return iconFit.get(); }
AnnotAppearanceCharacsTextPos getPosition() { 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)
};
//------------------------------------------------------------------------
@@ -586,11 +587,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);
@@ -600,17 +598,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;
- GooString *getContents() const { return contents; }
+ GooString *getContents() const { return contents.get(); }
int getPageNum() const { return page; }
- GooString *getName() const { return name; }
- GooString *getModified() const { return modified; }
+ GooString *getName() const { return name.get(); }
+ GooString *getModified() const { return modified.get(); }
Guint getFlags() const { return flags; }
- AnnotAppearance *getAppearStreams() const { return appearStreams; }
- GooString *getAppearState() const { return appearState; }
- AnnotBorder *getBorder() const { return border; }
- AnnotColor *getColor() const { return color; }
+ AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
+ 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; }
@@ -656,30 +654,30 @@ protected:
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
- GooString *appearBuf;
- AnnotBorder *border; // Border, BS
- AnnotColor *color; // C
- double fontSize;
+ XRef *xref; // the xref table for this PDF file
+ Ref ref; // object ref identifying this annotation
+ std::unique_ptr<GooString> appearBuf;
+ std::unique_ptr<AnnotBorder> border; // Border, BS
+ std::unique_ptr<AnnotColor> color; // C
+ double fontSize;
GBool ok;
bool hasRef;
@@ -724,21 +722,21 @@ public:
AnnotMarkup(PDFDoc *docA, PDFRectangle *rect);
AnnotMarkup(PDFDoc *docA, Object *dictObject, Object *obj);
- ~AnnotMarkup();
+ ~AnnotMarkup() = default;
// getters
- GooString *getLabel() const { return label; }
- AnnotPopup *getPopup() const { return popup; }
+ GooString *getLabel() const { return label.get(); }
+ AnnotPopup *getPopup() const { return popup.get(); }
double getOpacity() const { return opacity; }
// getRC
- GooString *getDate() const { return date; }
+ GooString *getDate() const { return date.get(); }
int getInReplyToID() const { return inReplyTo.num; }
- GooString *getSubject() const { return subject; }
+ 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);
@@ -746,18 +744,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);
@@ -784,13 +782,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; }
- GooString *getIcon() const { return icon; }
+ GooString *getIcon() const { return icon.get(); }
AnnotTextState getState() const { return state; }
void setOpen(GBool openA);
@@ -801,7 +799,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)
@@ -817,18 +815,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;
- GooString* getTitle() { return title; }
- Movie* getMovie() { return movie; }
+ GooString* getTitle() { 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
};
@@ -841,24 +839,24 @@ class AnnotScreen: public Annot {
AnnotScreen(PDFDoc *docA, PDFRectangle *rect);
AnnotScreen(PDFDoc *docA, Object *dictObject, Object *obj);
- ~AnnotScreen();
+ ~AnnotScreen() = default;
- GooString* getTitle() { return title; }
+ GooString* getTitle() { 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
};
//------------------------------------------------------------------------
@@ -877,25 +875,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
};
//------------------------------------------------------------------------
@@ -919,7 +917,7 @@ public:
AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, GooString *da);
AnnotFreeText(PDFDoc *docA, Object *dictObject, Object *obj);
- ~AnnotFreeText();
+ ~AnnotFreeText() = default;
void draw(Gfx *gfx, GBool printing) override;
Object getAppearanceResDict() override;
@@ -932,36 +930,36 @@ public:
void setIntent(AnnotFreeTextIntent new_intent);
// getters
- GooString *getAppearanceString() const { return appearanceString; }
+ GooString *getAppearanceString() const { return appearanceString.get(); }
AnnotFreeTextQuadding getQuadding() const { return quadding; }
// return rc
- GooString *getStyleString() const { return styleString; }
- AnnotCalloutLine *getCalloutLine() const { return calloutLine; }
+ 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:
void initialize(PDFDoc *docA, Dict *dict);
- static void parseAppearanceString(GooString *da, double &fontsize, AnnotColor* &fontcolor);
+ static void parseAppearanceString(GooString *da, double &fontsize, std::unique_ptr<AnnotColor> &fontcolor);
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)
};
//------------------------------------------------------------------------
@@ -983,7 +981,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;
@@ -991,7 +989,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);
@@ -1000,7 +998,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; }
@@ -1021,23 +1019,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; //
};
//------------------------------------------------------------------------
@@ -1049,7 +1048,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;
@@ -1058,13 +1057,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
};
//------------------------------------------------------------------------
@@ -1076,18 +1075,18 @@ public:
AnnotStamp(PDFDoc *docA, PDFRectangle *rect);
AnnotStamp(PDFDoc *docA, Object *dictObject, Object *obj);
- ~AnnotStamp();
+ ~AnnotStamp() = default;
void setIcon(GooString *new_icon);
// getters
- GooString *getIcon() const { return icon; }
+ 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)
};
//------------------------------------------------------------------------
@@ -1099,25 +1098,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)
};
//------------------------------------------------------------------------
@@ -1135,22 +1134,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:
@@ -1158,16 +1157,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
};
@@ -1185,20 +1184,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)
};
//------------------------------------------------------------------------
@@ -1245,23 +1244,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; }
- GooString *getName() const { return name; }
+ 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
};
//------------------------------------------------------------------------
@@ -1273,23 +1272,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; }
- GooString *getName() const { return name; }
+ Sound *getSound() { return sound.get(); }
+ 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
};
//------------------------------------------------------------------------
@@ -1308,7 +1307,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;
@@ -1320,8 +1319,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; }
@@ -1338,14 +1337,14 @@ private:
GooString *da, GfxResources *resources, int quadding);
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
+ // AnnotBorderBS border; // BS
+ Dict *parent; // Parent
GBool addDingbatsResource;
Ref updatedAppearanceStream; // {-1,-1} if updateAppearanceStream has never been called
};
@@ -1398,7 +1397,7 @@ public:
Annot3D(PDFDoc *docA, PDFRectangle *rect);
Annot3D(PDFDoc *docA, Object *dictObject, Object *obj);
- ~Annot3D();
+ ~Annot3D() = default;
// getters
@@ -1406,7 +1405,7 @@ private:
void initialize(PDFDoc *docA, Dict *dict);
- Activation *activation; // 3DA
+ std::unique_ptr<Activation> activation; // 3DA
};
//------------------------------------------------------------------------
@@ -1418,13 +1417,13 @@ public:
class Params {
public:
Params(Dict *dict);
- ~Params();
+ ~Params() = default;
GooString* getFlashVars() const;
private:
// optional
- GooString *flashVars; // FlashVars
+ std::unique_ptr<GooString> flashVars; // FlashVars
};
class Instance {
@@ -1437,15 +1436,15 @@ public:
};
Instance(Dict *dict);
- ~Instance();
+ ~Instance() = default;
Type getType() const;
Params* getParams() const;
private:
// optional
- Type type; // Subtype
- Params *params; // Params
+ Type type; // Subtype
+ std::unique_ptr<Params> params; // Params
};
class Configuration {
@@ -1467,9 +1466,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;
};
@@ -1477,8 +1476,8 @@ public:
class Asset {
public:
- Asset();
- ~Asset();
+ Asset() = default;
+ ~Asset() = default;
GooString* getName() const;
Object* getFileSpec() const;
@@ -1486,7 +1485,7 @@ public:
private:
friend class AnnotRichMedia::Content;
- GooString *name;
+ std::unique_ptr<GooString> name;
Object fileSpec;
};
@@ -1503,7 +1502,7 @@ public:
private:
// optional
- Configuration **configurations; // Configurations
+ Configuration** configurations; // Configurations
int nConfigurations;
Asset **assets; // Assets
@@ -1547,20 +1546,20 @@ public:
class Settings {
public:
Settings(Dict *dict);
- ~Settings();
+ ~Settings() = default;
Activation* getActivation() const;
Deactivation* getDeactivation() const;
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;
@@ -1570,10 +1569,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/qt4/src/poppler-annotation-helper.h b/qt4/src/poppler-annotation-helper.h
index 3150569c..8419b0bd 100644
--- a/qt4/src/poppler-annotation-helper.h
+++ b/qt4/src/poppler-annotation-helper.h
@@ -176,6 +176,6 @@ void XPDFReader::invTransform( double * M, const QPointF &p, double &x, double &
}
QColor convertAnnotColor( AnnotColor *color );
-AnnotColor* convertQColor( const QColor &color );
+std::unique_ptr<AnnotColor> convertQColor( const QColor &color );
}
diff --git a/qt4/src/poppler-annotation.cc b/qt4/src/poppler-annotation.cc
index 8a7f60b1..f4733b89 100644
--- a/qt4/src/poppler-annotation.cc
+++ b/qt4/src/poppler-annotation.cc
@@ -350,7 +350,7 @@ PDFRectangle AnnotationPrivate::boundaryToPdfRectangle(const QRectF &r, int flag
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);
@@ -360,10 +360,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)
@@ -1653,11 +1653,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
@@ -2721,17 +2721,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));
}
}
@@ -5077,12 +5077,12 @@ QColor convertAnnotColor( AnnotColor *color )
return newcolor;
}
-AnnotColor* convertQColor( const QColor &c )
+std::unique_ptr<AnnotColor> convertQColor( const QColor &c )
{
if (!c.isValid() || c.alpha() == 0)
- return new AnnotColor(); // Transparent
+ return std::make_unique<AnnotColor>(); // Transparent
else
- return new AnnotColor(c.redF(), c.greenF(), c.blueF());
+ return std::make_unique<AnnotColor>(c.redF(), c.greenF(), c.blueF());
}
//END utility annotation functions
diff --git a/qt5/src/poppler-annotation-helper.h b/qt5/src/poppler-annotation-helper.h
index 3150569c..8419b0bd 100644
--- a/qt5/src/poppler-annotation-helper.h
+++ b/qt5/src/poppler-annotation-helper.h
@@ -176,6 +176,6 @@ void XPDFReader::invTransform( double * M, const QPointF &p, double &x, double &
}
QColor convertAnnotColor( 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 dfd56906..459689af 100644
--- a/qt5/src/poppler-annotation.cc
+++ b/qt5/src/poppler-annotation.cc
@@ -350,7 +350,7 @@ PDFRectangle AnnotationPrivate::boundaryToPdfRectangle(const QRectF &r, int flag
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);
@@ -360,10 +360,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)
@@ -1650,11 +1650,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
@@ -2708,17 +2708,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));
}
}
@@ -5065,12 +5065,12 @@ QColor convertAnnotColor( AnnotColor *color )
return newcolor;
}
-AnnotColor* convertQColor( const QColor &c )
+std::unique_ptr<AnnotColor> convertQColor( const QColor &c )
{
if (!c.isValid() || c.alpha() == 0)
- return new AnnotColor(); // Transparent
+ return std::make_unique<AnnotColor>(); // Transparent
else
- return new AnnotColor(c.redF(), c.greenF(), c.blueF());
+ return std::make_unique<AnnotColor>(c.redF(), c.greenF(), c.blueF());
}
//END utility annotation functions