diff options
3 files changed, 4385 insertions, 0 deletions
diff --git a/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0001.patch b/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0001.patch new file mode 100644 index 0000000000..4f0dc61a8b --- /dev/null +++ b/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0001.patch | |||
@@ -0,0 +1,4325 @@ | |||
1 | From f2f933100eb18ade38ece640343007290c609e21 Mon Sep 17 00:00:00 2001 | ||
2 | From: Sune Vuorela <sune@vuorela.dk> | ||
3 | Date: Wed, 2 Apr 2025 16:19:28 +0200 | ||
4 | Subject: [PATCH] Annot: Do refcount with shared_ptr | ||
5 | |||
6 | Manage annots by shared_ptr rather than the manual ref/deref usage. | ||
7 | |||
8 | Also do a bit more documentation of ownerships with unique ptr's | ||
9 | |||
10 | CVE: CVE-2025-52886 | ||
11 | Upstream-Status: Backport [https://gitlab.freedesktop.org/poppler/poppler/-/commit/3449a16d3b1389870eb3e20795e802c6ae8bc04f] | ||
12 | |||
13 | Signed-off-by: Yogita Urade <yogita.urade@windriver.com> | ||
14 | --- | ||
15 | glib/poppler-annot.cc | 158 +++++------ | ||
16 | glib/poppler-page.cc | 8 +- | ||
17 | glib/poppler-private.h | 24 +- | ||
18 | poppler/Annot.cc | 143 ++++------ | ||
19 | poppler/Annot.h | 34 +-- | ||
20 | poppler/FontInfo.cc | 2 +- | ||
21 | poppler/Form.cc | 11 +- | ||
22 | poppler/Form.h | 6 +- | ||
23 | poppler/JSInfo.cc | 8 +- | ||
24 | poppler/Link.cc | 14 +- | ||
25 | poppler/Link.h | 4 +- | ||
26 | poppler/PDFDoc.cc | 2 +- | ||
27 | poppler/PSOutputDev.cc | 2 +- | ||
28 | poppler/Page.cc | 39 ++- | ||
29 | poppler/Page.h | 8 +- | ||
30 | qt5/src/poppler-annotation-private.h | 10 +- | ||
31 | qt5/src/poppler-annotation.cc | 393 +++++++++++++-------------- | ||
32 | qt5/src/poppler-form.cc | 4 +- | ||
33 | qt6/src/poppler-annotation-private.h | 10 +- | ||
34 | qt6/src/poppler-annotation.cc | 393 +++++++++++++-------------- | ||
35 | qt6/src/poppler-form.cc | 4 +- | ||
36 | utils/HtmlOutputDev.cc | 4 +- | ||
37 | utils/pdfdetach.cc | 4 +- | ||
38 | utils/pdfinfo.cc | 2 +- | ||
39 | 24 files changed, 582 insertions(+), 705 deletions(-) | ||
40 | |||
41 | diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc | ||
42 | index b995f03..6fb7807 100644 | ||
43 | --- a/glib/poppler-annot.cc | ||
44 | +++ b/glib/poppler-annot.cc | ||
45 | @@ -19,6 +19,7 @@ | ||
46 | * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. | ||
47 | */ | ||
48 | |||
49 | +#include "AnnotStampImageHelper.h" | ||
50 | #include "config.h" | ||
51 | #include "poppler.h" | ||
52 | #include "poppler-private.h" | ||
53 | @@ -26,7 +27,7 @@ | ||
54 | #define ZERO_CROPBOX(c) (!(c && (c->x1 > 0.01 || c->y1 > 0.01))) | ||
55 | |||
56 | const PDFRectangle *_poppler_annot_get_cropbox_and_page(PopplerAnnot *poppler_annot, Page **page_out); | ||
57 | -AnnotStampImageHelper *_poppler_convert_cairo_image_to_stamp_image_helper(cairo_surface_t *image, PDFDoc *doc, GError **error); | ||
58 | +std::unique_ptr<AnnotStampImageHelper> _poppler_convert_cairo_image_to_stamp_image_helper(cairo_surface_t *image, PDFDoc *doc, GError **error); | ||
59 | |||
60 | /** | ||
61 | * SECTION:poppler-annot | ||
62 | @@ -177,13 +178,12 @@ G_DEFINE_TYPE(PopplerAnnotCircle, poppler_annot_circle, POPPLER_TYPE_ANNOT_MARKU | ||
63 | G_DEFINE_TYPE(PopplerAnnotSquare, poppler_annot_square, POPPLER_TYPE_ANNOT_MARKUP) | ||
64 | G_DEFINE_TYPE(PopplerAnnotStamp, poppler_annot_stamp, POPPLER_TYPE_ANNOT) | ||
65 | |||
66 | -static PopplerAnnot *_poppler_create_annot(GType annot_type, Annot *annot) | ||
67 | +static PopplerAnnot *_poppler_create_annot(GType annot_type, std::shared_ptr<Annot> annot) | ||
68 | { | ||
69 | PopplerAnnot *poppler_annot; | ||
70 | |||
71 | poppler_annot = POPPLER_ANNOT(g_object_new(annot_type, nullptr)); | ||
72 | - poppler_annot->annot = annot; | ||
73 | - annot->incRefCnt(); | ||
74 | + poppler_annot->annot = std::move(annot); | ||
75 | |||
76 | return poppler_annot; | ||
77 | } | ||
78 | @@ -193,8 +193,7 @@ static void poppler_annot_finalize(GObject *object) | ||
79 | PopplerAnnot *poppler_annot = POPPLER_ANNOT(object); | ||
80 | |||
81 | if (poppler_annot->annot) { | ||
82 | - poppler_annot->annot->decRefCnt(); | ||
83 | - poppler_annot->annot = nullptr; | ||
84 | + poppler_annot->annot.reset(); | ||
85 | } | ||
86 | |||
87 | G_OBJECT_CLASS(poppler_annot_parent_class)->finalize(object); | ||
88 | @@ -209,7 +208,7 @@ static void poppler_annot_class_init(PopplerAnnotClass *klass) | ||
89 | gobject_class->finalize = poppler_annot_finalize; | ||
90 | } | ||
91 | |||
92 | -PopplerAnnot *_poppler_annot_new(Annot *annot) | ||
93 | +PopplerAnnot *_poppler_annot_new(const std::shared_ptr<Annot> &annot) | ||
94 | { | ||
95 | return _poppler_create_annot(POPPLER_TYPE_ANNOT, annot); | ||
96 | } | ||
97 | @@ -222,7 +221,7 @@ static void poppler_annot_text_init(PopplerAnnotText *poppler_annot) { } | ||
98 | |||
99 | static void poppler_annot_text_class_init(PopplerAnnotTextClass *klass) { } | ||
100 | |||
101 | -PopplerAnnot *_poppler_annot_text_new(Annot *annot) | ||
102 | +PopplerAnnot *_poppler_annot_text_new(const std::shared_ptr<Annot> &annot) | ||
103 | { | ||
104 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_TEXT, annot); | ||
105 | } | ||
106 | @@ -242,15 +241,14 @@ PopplerAnnot *_poppler_annot_text_new(Annot *annot) | ||
107 | */ | ||
108 | PopplerAnnot *poppler_annot_text_new(PopplerDocument *doc, PopplerRectangle *rect) | ||
109 | { | ||
110 | - Annot *annot; | ||
111 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
112 | |||
113 | - annot = new AnnotText(doc->doc, &pdf_rect); | ||
114 | + auto annot = std::make_shared<AnnotText>(doc->doc, &pdf_rect); | ||
115 | |||
116 | return _poppler_annot_text_new(annot); | ||
117 | } | ||
118 | |||
119 | -PopplerAnnot *_poppler_annot_text_markup_new(Annot *annot) | ||
120 | +PopplerAnnot *_poppler_annot_text_markup_new(const std::shared_ptr<Annot> &annot) | ||
121 | { | ||
122 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_TEXT_MARKUP, annot); | ||
123 | } | ||
124 | @@ -323,10 +321,9 @@ static void poppler_annot_text_markup_class_init(PopplerAnnotTextMarkupClass *kl | ||
125 | PopplerAnnot *poppler_annot_text_markup_new_highlight(PopplerDocument *doc, PopplerRectangle *rect, GArray *quadrilaterals) | ||
126 | { | ||
127 | PopplerAnnot *poppler_annot; | ||
128 | - AnnotTextMarkup *annot; | ||
129 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
130 | |||
131 | - annot = new AnnotTextMarkup(doc->doc, &pdf_rect, Annot::typeHighlight); | ||
132 | + auto annot = std::make_shared<AnnotTextMarkup>(doc->doc, &pdf_rect, Annot::typeHighlight); | ||
133 | |||
134 | poppler_annot = _poppler_annot_text_markup_new(annot); | ||
135 | poppler_annot_text_markup_set_quadrilaterals(POPPLER_ANNOT_TEXT_MARKUP(poppler_annot), quadrilaterals); | ||
136 | @@ -350,12 +347,11 @@ PopplerAnnot *poppler_annot_text_markup_new_highlight(PopplerDocument *doc, Popp | ||
137 | PopplerAnnot *poppler_annot_text_markup_new_squiggly(PopplerDocument *doc, PopplerRectangle *rect, GArray *quadrilaterals) | ||
138 | { | ||
139 | PopplerAnnot *poppler_annot; | ||
140 | - AnnotTextMarkup *annot; | ||
141 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
142 | |||
143 | g_return_val_if_fail(quadrilaterals != nullptr && quadrilaterals->len > 0, NULL); | ||
144 | |||
145 | - annot = new AnnotTextMarkup(doc->doc, &pdf_rect, Annot::typeSquiggly); | ||
146 | + auto annot = std::make_shared<AnnotTextMarkup>(doc->doc, &pdf_rect, Annot::typeSquiggly); | ||
147 | |||
148 | poppler_annot = _poppler_annot_text_markup_new(annot); | ||
149 | poppler_annot_text_markup_set_quadrilaterals(POPPLER_ANNOT_TEXT_MARKUP(poppler_annot), quadrilaterals); | ||
150 | @@ -379,12 +375,11 @@ PopplerAnnot *poppler_annot_text_markup_new_squiggly(PopplerDocument *doc, Poppl | ||
151 | PopplerAnnot *poppler_annot_text_markup_new_strikeout(PopplerDocument *doc, PopplerRectangle *rect, GArray *quadrilaterals) | ||
152 | { | ||
153 | PopplerAnnot *poppler_annot; | ||
154 | - AnnotTextMarkup *annot; | ||
155 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
156 | |||
157 | g_return_val_if_fail(quadrilaterals != nullptr && quadrilaterals->len > 0, NULL); | ||
158 | |||
159 | - annot = new AnnotTextMarkup(doc->doc, &pdf_rect, Annot::typeStrikeOut); | ||
160 | + auto annot = std::make_shared<AnnotTextMarkup>(doc->doc, &pdf_rect, Annot::typeStrikeOut); | ||
161 | |||
162 | poppler_annot = _poppler_annot_text_markup_new(annot); | ||
163 | poppler_annot_text_markup_set_quadrilaterals(POPPLER_ANNOT_TEXT_MARKUP(poppler_annot), quadrilaterals); | ||
164 | @@ -408,12 +403,11 @@ PopplerAnnot *poppler_annot_text_markup_new_strikeout(PopplerDocument *doc, Popp | ||
165 | PopplerAnnot *poppler_annot_text_markup_new_underline(PopplerDocument *doc, PopplerRectangle *rect, GArray *quadrilaterals) | ||
166 | { | ||
167 | PopplerAnnot *poppler_annot; | ||
168 | - AnnotTextMarkup *annot; | ||
169 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
170 | |||
171 | g_return_val_if_fail(quadrilaterals != nullptr && quadrilaterals->len > 0, NULL); | ||
172 | |||
173 | - annot = new AnnotTextMarkup(doc->doc, &pdf_rect, Annot::typeUnderline); | ||
174 | + auto annot = std::make_shared<AnnotTextMarkup>(doc->doc, &pdf_rect, Annot::typeUnderline); | ||
175 | |||
176 | poppler_annot = _poppler_annot_text_markup_new(annot); | ||
177 | poppler_annot_text_markup_set_quadrilaterals(POPPLER_ANNOT_TEXT_MARKUP(poppler_annot), quadrilaterals); | ||
178 | @@ -424,7 +418,7 @@ static void poppler_annot_free_text_init(PopplerAnnotFreeText *poppler_annot) { | ||
179 | |||
180 | static void poppler_annot_free_text_class_init(PopplerAnnotFreeTextClass *klass) { } | ||
181 | |||
182 | -PopplerAnnot *_poppler_annot_free_text_new(Annot *annot) | ||
183 | +PopplerAnnot *_poppler_annot_free_text_new(const std::shared_ptr<Annot> &annot) | ||
184 | { | ||
185 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_FREE_TEXT, annot); | ||
186 | } | ||
187 | @@ -433,7 +427,7 @@ static void poppler_annot_file_attachment_init(PopplerAnnotFileAttachment *poppl | ||
188 | |||
189 | static void poppler_annot_file_attachment_class_init(PopplerAnnotFileAttachmentClass *klass) { } | ||
190 | |||
191 | -PopplerAnnot *_poppler_annot_file_attachment_new(Annot *annot) | ||
192 | +PopplerAnnot *_poppler_annot_file_attachment_new(const std::shared_ptr<Annot> &annot) | ||
193 | { | ||
194 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_FILE_ATTACHMENT, annot); | ||
195 | } | ||
196 | @@ -459,13 +453,13 @@ static void poppler_annot_movie_class_init(PopplerAnnotMovieClass *klass) | ||
197 | gobject_class->finalize = poppler_annot_movie_finalize; | ||
198 | } | ||
199 | |||
200 | -PopplerAnnot *_poppler_annot_movie_new(Annot *annot) | ||
201 | +PopplerAnnot *_poppler_annot_movie_new(const std::shared_ptr<Annot> &annot) | ||
202 | { | ||
203 | PopplerAnnot *poppler_annot; | ||
204 | AnnotMovie *annot_movie; | ||
205 | |||
206 | poppler_annot = _poppler_create_annot(POPPLER_TYPE_ANNOT_MOVIE, annot); | ||
207 | - annot_movie = static_cast<AnnotMovie *>(poppler_annot->annot); | ||
208 | + annot_movie = static_cast<AnnotMovie *>(poppler_annot->annot.get()); | ||
209 | POPPLER_ANNOT_MOVIE(poppler_annot)->movie = _poppler_movie_new(annot_movie->getMovie()); | ||
210 | |||
211 | return poppler_annot; | ||
212 | @@ -492,14 +486,14 @@ static void poppler_annot_screen_class_init(PopplerAnnotScreenClass *klass) | ||
213 | gobject_class->finalize = poppler_annot_screen_finalize; | ||
214 | } | ||
215 | |||
216 | -PopplerAnnot *_poppler_annot_screen_new(PopplerDocument *doc, Annot *annot) | ||
217 | +PopplerAnnot *_poppler_annot_screen_new(PopplerDocument *doc, const std::shared_ptr<Annot> &annot) | ||
218 | { | ||
219 | PopplerAnnot *poppler_annot; | ||
220 | AnnotScreen *annot_screen; | ||
221 | LinkAction *action; | ||
222 | |||
223 | poppler_annot = _poppler_create_annot(POPPLER_TYPE_ANNOT_SCREEN, annot); | ||
224 | - annot_screen = static_cast<AnnotScreen *>(poppler_annot->annot); | ||
225 | + annot_screen = static_cast<AnnotScreen *>(poppler_annot->annot.get()); | ||
226 | action = annot_screen->getAction(); | ||
227 | if (action) { | ||
228 | POPPLER_ANNOT_SCREEN(poppler_annot)->action = _poppler_action_new(doc, action, nullptr); | ||
229 | @@ -508,7 +502,7 @@ PopplerAnnot *_poppler_annot_screen_new(PopplerDocument *doc, Annot *annot) | ||
230 | return poppler_annot; | ||
231 | } | ||
232 | |||
233 | -PopplerAnnot *_poppler_annot_line_new(Annot *annot) | ||
234 | +PopplerAnnot *_poppler_annot_line_new(const std::shared_ptr<Annot> &annot) | ||
235 | { | ||
236 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_LINE, annot); | ||
237 | } | ||
238 | @@ -535,17 +529,16 @@ static void poppler_annot_line_class_init(PopplerAnnotLineClass *klass) { } | ||
239 | PopplerAnnot *poppler_annot_line_new(PopplerDocument *doc, PopplerRectangle *rect, PopplerPoint *start, PopplerPoint *end) | ||
240 | { | ||
241 | PopplerAnnot *poppler_annot; | ||
242 | - Annot *annot; | ||
243 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
244 | |||
245 | - annot = new AnnotLine(doc->doc, &pdf_rect); | ||
246 | + auto annot = std::make_shared<AnnotLine>(doc->doc, &pdf_rect); | ||
247 | |||
248 | poppler_annot = _poppler_annot_line_new(annot); | ||
249 | poppler_annot_line_set_vertices(POPPLER_ANNOT_LINE(poppler_annot), start, end); | ||
250 | return poppler_annot; | ||
251 | } | ||
252 | |||
253 | -PopplerAnnot *_poppler_annot_circle_new(Annot *annot) | ||
254 | +PopplerAnnot *_poppler_annot_circle_new(const std::shared_ptr<Annot> &annot) | ||
255 | { | ||
256 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_CIRCLE, annot); | ||
257 | } | ||
258 | @@ -569,15 +562,14 @@ static void poppler_annot_circle_class_init(PopplerAnnotCircleClass *klass) { } | ||
259 | **/ | ||
260 | PopplerAnnot *poppler_annot_circle_new(PopplerDocument *doc, PopplerRectangle *rect) | ||
261 | { | ||
262 | - Annot *annot; | ||
263 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
264 | |||
265 | - annot = new AnnotGeometry(doc->doc, &pdf_rect, Annot::typeCircle); | ||
266 | + auto annot = std::make_shared<AnnotGeometry>(doc->doc, &pdf_rect, Annot::typeCircle); | ||
267 | |||
268 | return _poppler_annot_circle_new(annot); | ||
269 | } | ||
270 | |||
271 | -PopplerAnnot *_poppler_annot_square_new(Annot *annot) | ||
272 | +PopplerAnnot *_poppler_annot_square_new(const std::shared_ptr<Annot> &annot) | ||
273 | { | ||
274 | return _poppler_create_annot(POPPLER_TYPE_ANNOT_SQUARE, annot); | ||
275 | } | ||
276 | @@ -601,10 +593,9 @@ static void poppler_annot_square_class_init(PopplerAnnotSquareClass *klass) { } | ||
277 | **/ | ||
278 | PopplerAnnot *poppler_annot_square_new(PopplerDocument *doc, PopplerRectangle *rect) | ||
279 | { | ||
280 | - Annot *annot; | ||
281 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
282 | |||
283 | - annot = new AnnotGeometry(doc->doc, &pdf_rect, Annot::typeSquare); | ||
284 | + auto annot = std::make_shared<AnnotGeometry>(doc->doc, &pdf_rect, Annot::typeSquare); | ||
285 | |||
286 | return _poppler_annot_square_new(annot); | ||
287 | } | ||
288 | @@ -623,7 +614,7 @@ static void poppler_annot_stamp_class_init(PopplerAnnotStampClass *klass) | ||
289 | gobject_class->finalize = poppler_annot_stamp_finalize; | ||
290 | } | ||
291 | |||
292 | -PopplerAnnot *_poppler_annot_stamp_new(Annot *annot) | ||
293 | +PopplerAnnot *_poppler_annot_stamp_new(const std::shared_ptr<Annot> &annot) | ||
294 | { | ||
295 | PopplerAnnot *poppler_annot; | ||
296 | |||
297 | @@ -647,10 +638,9 @@ PopplerAnnot *_poppler_annot_stamp_new(Annot *annot) | ||
298 | **/ | ||
299 | PopplerAnnot *poppler_annot_stamp_new(PopplerDocument *doc, PopplerRectangle *rect) | ||
300 | { | ||
301 | - Annot *annot; | ||
302 | PDFRectangle pdf_rect(rect->x1, rect->y1, rect->x2, rect->y2); | ||
303 | |||
304 | - annot = new AnnotStamp(doc->doc, &pdf_rect); | ||
305 | + auto annot = std::make_shared<AnnotStamp>(doc->doc, &pdf_rect); | ||
306 | |||
307 | return _poppler_annot_stamp_new(annot); | ||
308 | } | ||
309 | @@ -699,9 +689,9 @@ static gboolean get_raw_data_from_cairo_image(cairo_surface_t *image, cairo_form | ||
310 | return FALSE; | ||
311 | } | ||
312 | |||
313 | -AnnotStampImageHelper *_poppler_convert_cairo_image_to_stamp_image_helper(cairo_surface_t *image, PDFDoc *doc, GError **error) | ||
314 | +std::unique_ptr<AnnotStampImageHelper> _poppler_convert_cairo_image_to_stamp_image_helper(cairo_surface_t *image, PDFDoc *doc, GError **error) | ||
315 | { | ||
316 | - AnnotStampImageHelper *annotImg; | ||
317 | + std::unique_ptr<AnnotStampImageHelper> annotImg; | ||
318 | GByteArray *data; | ||
319 | GByteArray *sMaskData; | ||
320 | |||
321 | @@ -733,9 +723,9 @@ AnnotStampImageHelper *_poppler_convert_cairo_image_to_stamp_image_helper(cairo_ | ||
322 | |||
323 | if (sMaskData->len > 0) { | ||
324 | AnnotStampImageHelper sMask(doc, width, height, ColorSpace::DeviceGray, 8, (char *)sMaskData->data, (int)sMaskData->len); | ||
325 | - annotImg = new AnnotStampImageHelper(doc, width, height, colorSpace, bitsPerComponent, (char *)data->data, (int)data->len, sMask.getRef()); | ||
326 | + annotImg = std::make_unique<AnnotStampImageHelper>(doc, width, height, colorSpace, bitsPerComponent, (char *)data->data, (int)data->len, sMask.getRef()); | ||
327 | } else { | ||
328 | - annotImg = new AnnotStampImageHelper(doc, width, height, colorSpace, bitsPerComponent, (char *)data->data, (int)data->len); | ||
329 | + annotImg = std::make_unique<AnnotStampImageHelper>(doc, width, height, colorSpace, bitsPerComponent, (char *)data->data, (int)data->len); | ||
330 | } | ||
331 | |||
332 | g_byte_array_unref(data); | ||
333 | @@ -1128,7 +1118,7 @@ void poppler_annot_set_rectangle(PopplerAnnot *poppler_annot, PopplerRectangle * | ||
334 | if (page && SUPPORTED_ROTATION(page->getRotate())) { | ||
335 | /* annot is inside a rotated page, as core poppler rect must be saved | ||
336 | * un-rotated, let's proceed to un-rotate rect before saving */ | ||
337 | - _unrotate_rect_for_annot_and_page(page, poppler_annot->annot, &x1, &y1, &x2, &y2); | ||
338 | + _unrotate_rect_for_annot_and_page(page, poppler_annot->annot.get(), &x1, &y1, &x2, &y2); | ||
339 | } | ||
340 | |||
341 | poppler_annot->annot->setRect(x1 + crop_box->x1, y1 + crop_box->y1, x2 + crop_box->x1, y2 + crop_box->y1); | ||
342 | @@ -1150,7 +1140,7 @@ gchar *poppler_annot_markup_get_label(PopplerAnnotMarkup *poppler_annot) | ||
343 | |||
344 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), NULL); | ||
345 | |||
346 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
347 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
348 | |||
349 | text = annot->getLabel(); | ||
350 | |||
351 | @@ -1174,7 +1164,7 @@ void poppler_annot_markup_set_label(PopplerAnnotMarkup *poppler_annot, const gch | ||
352 | |||
353 | g_return_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot)); | ||
354 | |||
355 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
356 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
357 | |||
358 | tmp = label ? g_convert(label, -1, "UTF-16BE", "UTF-8", nullptr, &length, nullptr) : nullptr; | ||
359 | annot->setLabel(std::make_unique<GooString>(tmp, length)); | ||
360 | @@ -1197,7 +1187,7 @@ gboolean poppler_annot_markup_has_popup(PopplerAnnotMarkup *poppler_annot) | ||
361 | |||
362 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), FALSE); | ||
363 | |||
364 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
365 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
366 | |||
367 | return annot->getPopup() != nullptr; | ||
368 | } | ||
369 | @@ -1219,8 +1209,8 @@ void poppler_annot_markup_set_popup(PopplerAnnotMarkup *poppler_annot, PopplerRe | ||
370 | |||
371 | g_return_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot)); | ||
372 | |||
373 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
374 | - annot->setPopup(std::make_unique<AnnotPopup>(annot->getDoc(), &pdf_rect)); | ||
375 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
376 | + annot->setPopup(std::make_shared<AnnotPopup>(annot->getDoc(), &pdf_rect)); | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | @@ -1239,9 +1229,9 @@ gboolean poppler_annot_markup_get_popup_is_open(PopplerAnnotMarkup *poppler_anno | ||
381 | |||
382 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), FALSE); | ||
383 | |||
384 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
385 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
386 | |||
387 | - if ((annot_popup = annot->getPopup())) { | ||
388 | + if ((annot_popup = annot->getPopup().get())) { | ||
389 | return annot_popup->getOpen(); | ||
390 | } | ||
391 | |||
392 | @@ -1264,9 +1254,9 @@ void poppler_annot_markup_set_popup_is_open(PopplerAnnotMarkup *poppler_annot, g | ||
393 | |||
394 | g_return_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot)); | ||
395 | |||
396 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
397 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
398 | |||
399 | - annot_popup = annot->getPopup(); | ||
400 | + annot_popup = annot->getPopup().get(); | ||
401 | if (!annot_popup) { | ||
402 | return; | ||
403 | } | ||
404 | @@ -1295,8 +1285,8 @@ gboolean poppler_annot_markup_get_popup_rectangle(PopplerAnnotMarkup *poppler_an | ||
405 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), FALSE); | ||
406 | g_return_val_if_fail(poppler_rect != nullptr, FALSE); | ||
407 | |||
408 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
409 | - annot_popup = annot->getPopup(); | ||
410 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
411 | + annot_popup = annot->getPopup().get(); | ||
412 | if (!annot_popup) { | ||
413 | return FALSE; | ||
414 | } | ||
415 | @@ -1330,8 +1320,8 @@ void poppler_annot_markup_set_popup_rectangle(PopplerAnnotMarkup *poppler_annot, | ||
416 | g_return_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot)); | ||
417 | g_return_if_fail(poppler_rect != nullptr); | ||
418 | |||
419 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
420 | - annot_popup = annot->getPopup(); | ||
421 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
422 | + annot_popup = annot->getPopup().get(); | ||
423 | if (!annot_popup) { | ||
424 | return; | ||
425 | } | ||
426 | @@ -1354,7 +1344,7 @@ gdouble poppler_annot_markup_get_opacity(PopplerAnnotMarkup *poppler_annot) | ||
427 | |||
428 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), 0); | ||
429 | |||
430 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
431 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
432 | |||
433 | return annot->getOpacity(); | ||
434 | } | ||
435 | @@ -1376,7 +1366,7 @@ void poppler_annot_markup_set_opacity(PopplerAnnotMarkup *poppler_annot, gdouble | ||
436 | |||
437 | g_return_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot)); | ||
438 | |||
439 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
440 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
441 | annot->setOpacity(opacity); | ||
442 | } | ||
443 | |||
444 | @@ -1397,7 +1387,7 @@ GDate *poppler_annot_markup_get_date(PopplerAnnotMarkup *poppler_annot) | ||
445 | |||
446 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), NULL); | ||
447 | |||
448 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
449 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
450 | annot_date = annot->getDate(); | ||
451 | if (!annot_date) { | ||
452 | return nullptr; | ||
453 | @@ -1430,7 +1420,7 @@ gchar *poppler_annot_markup_get_subject(PopplerAnnotMarkup *poppler_annot) | ||
454 | |||
455 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), NULL); | ||
456 | |||
457 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
458 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
459 | |||
460 | text = annot->getSubject(); | ||
461 | |||
462 | @@ -1451,7 +1441,7 @@ PopplerAnnotMarkupReplyType poppler_annot_markup_get_reply_to(PopplerAnnotMarkup | ||
463 | |||
464 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), POPPLER_ANNOT_MARKUP_REPLY_TYPE_R); | ||
465 | |||
466 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
467 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
468 | |||
469 | switch (annot->getReplyTo()) { | ||
470 | case AnnotMarkup::replyTypeR: | ||
471 | @@ -1479,7 +1469,7 @@ PopplerAnnotExternalDataType poppler_annot_markup_get_external_data(PopplerAnnot | ||
472 | |||
473 | g_return_val_if_fail(POPPLER_IS_ANNOT_MARKUP(poppler_annot), POPPLER_ANNOT_EXTERNAL_DATA_MARKUP_UNKNOWN); | ||
474 | |||
475 | - annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
476 | + annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
477 | |||
478 | switch (annot->getExData()) { | ||
479 | case annotExternalDataMarkup3D: | ||
480 | @@ -1509,7 +1499,7 @@ gboolean poppler_annot_text_get_is_open(PopplerAnnotText *poppler_annot) | ||
481 | |||
482 | g_return_val_if_fail(POPPLER_IS_ANNOT_TEXT(poppler_annot), FALSE); | ||
483 | |||
484 | - annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
485 | + annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
486 | |||
487 | return annot->getOpen(); | ||
488 | } | ||
489 | @@ -1529,7 +1519,7 @@ void poppler_annot_text_set_is_open(PopplerAnnotText *poppler_annot, gboolean is | ||
490 | |||
491 | g_return_if_fail(POPPLER_IS_ANNOT_TEXT(poppler_annot)); | ||
492 | |||
493 | - annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
494 | + annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
495 | annot->setOpen(is_open); | ||
496 | } | ||
497 | |||
498 | @@ -1548,7 +1538,7 @@ gchar *poppler_annot_text_get_icon(PopplerAnnotText *poppler_annot) | ||
499 | |||
500 | g_return_val_if_fail(POPPLER_IS_ANNOT_TEXT(poppler_annot), NULL); | ||
501 | |||
502 | - annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
503 | + annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
504 | |||
505 | text = annot->getIcon(); | ||
506 | |||
507 | @@ -1601,7 +1591,7 @@ void poppler_annot_text_set_icon(PopplerAnnotText *poppler_annot, const gchar *i | ||
508 | |||
509 | g_return_if_fail(POPPLER_IS_ANNOT_TEXT(poppler_annot)); | ||
510 | |||
511 | - annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
512 | + annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
513 | |||
514 | text = new GooString(icon); | ||
515 | annot->setIcon(text); | ||
516 | @@ -1622,7 +1612,7 @@ PopplerAnnotTextState poppler_annot_text_get_state(PopplerAnnotText *poppler_ann | ||
517 | |||
518 | g_return_val_if_fail(POPPLER_IS_ANNOT_TEXT(poppler_annot), POPPLER_ANNOT_TEXT_STATE_UNKNOWN); | ||
519 | |||
520 | - annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
521 | + annot = static_cast<AnnotText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
522 | |||
523 | switch (annot->getState()) { | ||
524 | case AnnotText::stateUnknown: | ||
525 | @@ -1669,7 +1659,7 @@ void poppler_annot_text_markup_set_quadrilaterals(PopplerAnnotTextMarkup *popple | ||
526 | g_return_if_fail(POPPLER_IS_ANNOT_TEXT_MARKUP(poppler_annot)); | ||
527 | g_return_if_fail(quadrilaterals != nullptr && quadrilaterals->len > 0); | ||
528 | |||
529 | - annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
530 | + annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
531 | crop_box = _poppler_annot_get_cropbox_and_page(POPPLER_ANNOT(poppler_annot), &page); | ||
532 | quads = create_annot_quads_from_poppler_quads(quadrilaterals); | ||
533 | |||
534 | @@ -1708,7 +1698,7 @@ GArray *poppler_annot_text_markup_get_quadrilaterals(PopplerAnnotTextMarkup *pop | ||
535 | |||
536 | g_return_val_if_fail(POPPLER_IS_ANNOT_TEXT_MARKUP(poppler_annot), NULL); | ||
537 | |||
538 | - annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
539 | + annot = static_cast<AnnotTextMarkup *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
540 | crop_box = _poppler_annot_get_cropbox(POPPLER_ANNOT(poppler_annot)); | ||
541 | AnnotQuadrilaterals *quads = annot->getQuadrilaterals(); | ||
542 | |||
543 | @@ -1730,7 +1720,7 @@ PopplerAnnotFreeTextQuadding poppler_annot_free_text_get_quadding(PopplerAnnotFr | ||
544 | |||
545 | g_return_val_if_fail(POPPLER_IS_ANNOT_FREE_TEXT(poppler_annot), POPPLER_ANNOT_FREE_TEXT_QUADDING_LEFT_JUSTIFIED); | ||
546 | |||
547 | - annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
548 | + annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
549 | |||
550 | switch (annot->getQuadding()) { | ||
551 | case VariableTextQuadding::leftJustified: | ||
552 | @@ -1764,7 +1754,7 @@ PopplerAnnotCalloutLine *poppler_annot_free_text_get_callout_line(PopplerAnnotFr | ||
553 | |||
554 | g_return_val_if_fail(POPPLER_IS_ANNOT_FREE_TEXT(poppler_annot), NULL); | ||
555 | |||
556 | - annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
557 | + annot = static_cast<AnnotFreeText *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
558 | |||
559 | if ((line = annot->getCalloutLine())) { | ||
560 | AnnotCalloutMultiLine *multiline; | ||
561 | @@ -1808,11 +1798,10 @@ PopplerAttachment *poppler_annot_file_attachment_get_attachment(PopplerAnnotFile | ||
562 | |||
563 | g_return_val_if_fail(POPPLER_IS_ANNOT_FILE_ATTACHMENT(poppler_annot), NULL); | ||
564 | |||
565 | - annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
566 | + annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
567 | |||
568 | - FileSpec *file = new FileSpec(annot->getFile()); | ||
569 | - attachment = _poppler_attachment_new(file); | ||
570 | - delete file; | ||
571 | + FileSpec file { annot->getFile() }; | ||
572 | + attachment = _poppler_attachment_new(&file); | ||
573 | |||
574 | return attachment; | ||
575 | } | ||
576 | @@ -1834,7 +1823,7 @@ gchar *poppler_annot_file_attachment_get_name(PopplerAnnotFileAttachment *popple | ||
577 | |||
578 | g_return_val_if_fail(POPPLER_IS_ANNOT_FILE_ATTACHMENT(poppler_annot), NULL); | ||
579 | |||
580 | - annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
581 | + annot = static_cast<AnnotFileAttachment *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
582 | name = annot->getName(); | ||
583 | |||
584 | return name ? _poppler_goo_string_to_utf8(name) : nullptr; | ||
585 | @@ -1906,7 +1895,7 @@ gchar *poppler_annot_movie_get_title(PopplerAnnotMovie *poppler_annot) | ||
586 | |||
587 | g_return_val_if_fail(POPPLER_IS_ANNOT_MOVIE(poppler_annot), NULL); | ||
588 | |||
589 | - annot = static_cast<AnnotMovie *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
590 | + annot = static_cast<AnnotMovie *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
591 | |||
592 | title = annot->getTitle(); | ||
593 | |||
594 | @@ -1965,7 +1954,7 @@ void poppler_annot_line_set_vertices(PopplerAnnotLine *poppler_annot, PopplerPoi | ||
595 | g_return_if_fail(start != nullptr); | ||
596 | g_return_if_fail(end != nullptr); | ||
597 | |||
598 | - annot = static_cast<AnnotLine *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
599 | + annot = static_cast<AnnotLine *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
600 | annot->setVertices(start->x, start->y, end->x, end->y); | ||
601 | } | ||
602 | |||
603 | @@ -1974,7 +1963,7 @@ static PopplerColor *poppler_annot_geometry_get_interior_color(PopplerAnnot *pop | ||
604 | { | ||
605 | AnnotGeometry *annot; | ||
606 | |||
607 | - annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
608 | + annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
609 | |||
610 | return create_poppler_color_from_annot_color(annot->getInteriorColor()); | ||
611 | } | ||
612 | @@ -1983,7 +1972,7 @@ static void poppler_annot_geometry_set_interior_color(PopplerAnnot *poppler_anno | ||
613 | { | ||
614 | AnnotGeometry *annot; | ||
615 | |||
616 | - annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
617 | + annot = static_cast<AnnotGeometry *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
618 | |||
619 | annot->setInteriorColor(create_annot_color_from_poppler_color(poppler_color)); | ||
620 | } | ||
621 | @@ -2073,7 +2062,7 @@ PopplerAnnotStampIcon poppler_annot_stamp_get_icon(PopplerAnnotStamp *poppler_an | ||
622 | |||
623 | g_return_val_if_fail(POPPLER_IS_ANNOT_STAMP(poppler_annot), POPPLER_ANNOT_STAMP_ICON_UNKNOWN); | ||
624 | |||
625 | - annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
626 | + annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
627 | |||
628 | text = annot->getIcon(); | ||
629 | |||
630 | @@ -2129,7 +2118,7 @@ void poppler_annot_stamp_set_icon(PopplerAnnotStamp *poppler_annot, PopplerAnnot | ||
631 | |||
632 | g_return_if_fail(POPPLER_IS_ANNOT_STAMP(poppler_annot)); | ||
633 | |||
634 | - annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
635 | + annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
636 | |||
637 | if (icon == POPPLER_ANNOT_STAMP_ICON_NONE) { | ||
638 | annot->setIcon(nullptr); | ||
639 | @@ -2186,16 +2175,15 @@ void poppler_annot_stamp_set_icon(PopplerAnnotStamp *poppler_annot, PopplerAnnot | ||
640 | gboolean poppler_annot_stamp_set_custom_image(PopplerAnnotStamp *poppler_annot, cairo_surface_t *image, GError **error) | ||
641 | { | ||
642 | AnnotStamp *annot; | ||
643 | - AnnotStampImageHelper *annot_image_helper; | ||
644 | |||
645 | g_return_val_if_fail(POPPLER_IS_ANNOT_STAMP(poppler_annot), FALSE); | ||
646 | |||
647 | - annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot); | ||
648 | - annot_image_helper = _poppler_convert_cairo_image_to_stamp_image_helper(image, annot->getDoc(), error); | ||
649 | + annot = static_cast<AnnotStamp *>(POPPLER_ANNOT(poppler_annot)->annot.get()); | ||
650 | + std::unique_ptr<AnnotStampImageHelper> annot_image_helper = _poppler_convert_cairo_image_to_stamp_image_helper(image, annot->getDoc(), error); | ||
651 | if (!annot_image_helper) { | ||
652 | return FALSE; | ||
653 | } | ||
654 | - annot->setCustomImage(annot_image_helper); | ||
655 | + annot->setCustomImage(std::move(annot_image_helper)); | ||
656 | |||
657 | return TRUE; | ||
658 | } | ||
659 | diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc | ||
660 | index 7f47cd5..1ccc423 100644 | ||
661 | --- a/glib/poppler-page.cc | ||
662 | +++ b/glib/poppler-page.cc | ||
663 | @@ -1132,7 +1132,7 @@ GList *poppler_page_get_link_mapping(PopplerPage *page) | ||
664 | |||
665 | poppler_page_get_size(page, &width, &height); | ||
666 | |||
667 | - for (AnnotLink *link : links->getLinks()) { | ||
668 | + for (const std::shared_ptr<AnnotLink> &link : links->getLinks()) { | ||
669 | PopplerLinkMapping *mapping; | ||
670 | PopplerRectangle rect; | ||
671 | LinkAction *link_action; | ||
672 | @@ -1295,7 +1295,7 @@ GList *poppler_page_get_annot_mapping(PopplerPage *page) | ||
673 | poppler_page_get_size(page, &width, &height); | ||
674 | crop_box = page->page->getCropBox(); | ||
675 | |||
676 | - for (Annot *annot : annots->getAnnots()) { | ||
677 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
678 | PopplerAnnotMapping *mapping; | ||
679 | PopplerRectangle rect; | ||
680 | gboolean flag_no_rotate; | ||
681 | @@ -1572,12 +1572,12 @@ void poppler_page_add_annot(PopplerPage *page, PopplerAnnot *annot) | ||
682 | if (page_is_rotated) { | ||
683 | /* annot is inside a rotated page, as core poppler rect must be saved | ||
684 | * un-rotated, let's proceed to un-rotate rect before saving */ | ||
685 | - _unrotate_rect_for_annot_and_page(page->page, annot->annot, &x1, &y1, &x2, &y2); | ||
686 | + _unrotate_rect_for_annot_and_page(page->page, annot->annot.get(), &x1, &y1, &x2, &y2); | ||
687 | } | ||
688 | |||
689 | annot->annot->setRect(x1 + page_crop_box->x1, y1 + page_crop_box->y1, x2 + page_crop_box->x1, y2 + page_crop_box->y1); | ||
690 | |||
691 | - AnnotTextMarkup *annot_markup = dynamic_cast<AnnotTextMarkup *>(annot->annot); | ||
692 | + AnnotTextMarkup *annot_markup = dynamic_cast<AnnotTextMarkup *>(annot->annot.get()); | ||
693 | if (annot_markup) { | ||
694 | AnnotQuadrilaterals *quads; | ||
695 | crop_box = _poppler_annot_get_cropbox(annot); | ||
696 | diff --git a/glib/poppler-private.h b/glib/poppler-private.h | ||
697 | index 758c702..1b51b76 100644 | ||
698 | --- a/glib/poppler-private.h | ||
699 | +++ b/glib/poppler-private.h | ||
700 | @@ -85,7 +85,7 @@ struct _PopplerFormField | ||
701 | struct _PopplerAnnot | ||
702 | { | ||
703 | GObject parent_instance; | ||
704 | - Annot *annot; | ||
705 | + std::shared_ptr<Annot> annot; | ||
706 | }; | ||
707 | |||
708 | typedef struct _Layer | ||
709 | @@ -146,17 +146,17 @@ PopplerFormField *_poppler_form_field_new(PopplerDocument *document, FormWidget | ||
710 | PopplerAttachment *_poppler_attachment_new(FileSpec *file); | ||
711 | PopplerMovie *_poppler_movie_new(const Movie *movie); | ||
712 | PopplerMedia *_poppler_media_new(const MediaRendition *media); | ||
713 | -PopplerAnnot *_poppler_annot_new(Annot *annot); | ||
714 | -PopplerAnnot *_poppler_annot_text_new(Annot *annot); | ||
715 | -PopplerAnnot *_poppler_annot_free_text_new(Annot *annot); | ||
716 | -PopplerAnnot *_poppler_annot_text_markup_new(Annot *annot); | ||
717 | -PopplerAnnot *_poppler_annot_file_attachment_new(Annot *annot); | ||
718 | -PopplerAnnot *_poppler_annot_movie_new(Annot *annot); | ||
719 | -PopplerAnnot *_poppler_annot_screen_new(PopplerDocument *doc, Annot *annot); | ||
720 | -PopplerAnnot *_poppler_annot_line_new(Annot *annot); | ||
721 | -PopplerAnnot *_poppler_annot_circle_new(Annot *annot); | ||
722 | -PopplerAnnot *_poppler_annot_square_new(Annot *annot); | ||
723 | -PopplerAnnot *_poppler_annot_stamp_new(Annot *annot); | ||
724 | +PopplerAnnot *_poppler_annot_new(const std::shared_ptr<Annot> &annot); | ||
725 | +PopplerAnnot *_poppler_annot_text_new(const std::shared_ptr<Annot> &annot); | ||
726 | +PopplerAnnot *_poppler_annot_free_text_new(const std::shared_ptr<Annot> &annot); | ||
727 | +PopplerAnnot *_poppler_annot_text_markup_new(const std::shared_ptr<Annot> &annot); | ||
728 | +PopplerAnnot *_poppler_annot_file_attachment_new(const std::shared_ptr<Annot> &annot); | ||
729 | +PopplerAnnot *_poppler_annot_movie_new(const std::shared_ptr<Annot> &annot); | ||
730 | +PopplerAnnot *_poppler_annot_screen_new(PopplerDocument *doc, const std::shared_ptr<Annot> &annot); | ||
731 | +PopplerAnnot *_poppler_annot_line_new(const std::shared_ptr<Annot> &annot); | ||
732 | +PopplerAnnot *_poppler_annot_circle_new(const std::shared_ptr<Annot> &annot); | ||
733 | +PopplerAnnot *_poppler_annot_square_new(const std::shared_ptr<Annot> &annot); | ||
734 | +PopplerAnnot *_poppler_annot_stamp_new(const std::shared_ptr<Annot> &annot); | ||
735 | |||
736 | const PDFRectangle *_poppler_annot_get_cropbox(PopplerAnnot *poppler_annot); | ||
737 | |||
738 | diff --git a/poppler/Annot.cc b/poppler/Annot.cc | ||
739 | index 5716ea5..b98df5d 100644 | ||
740 | --- a/poppler/Annot.cc | ||
741 | +++ b/poppler/Annot.cc | ||
742 | @@ -1064,7 +1064,7 @@ void AnnotAppearance::removeStream(Ref refToStream) | ||
743 | continue; | ||
744 | } | ||
745 | Annots *annots = page->getAnnots(); | ||
746 | - for (Annot *annot : annots->getAnnots()) { | ||
747 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
748 | AnnotAppearance *annotAp = annot->getAppearStreams(); | ||
749 | if (annotAp && annotAp != this && annotAp->referencesStream(refToStream)) { | ||
750 | return; // Another annotation points to the stream -> Don't delete it | ||
751 | @@ -1263,7 +1263,6 @@ double AnnotAppearanceBBox::getPageYMax() const | ||
752 | Annot::Annot(PDFDoc *docA, PDFRectangle *rectA) | ||
753 | { | ||
754 | |||
755 | - refCnt = 1; | ||
756 | flags = flagUnknown; | ||
757 | type = typeUnknown; | ||
758 | |||
759 | @@ -1284,7 +1283,6 @@ Annot::Annot(PDFDoc *docA, PDFRectangle *rectA) | ||
760 | |||
761 | Annot::Annot(PDFDoc *docA, Object &&dictObject) | ||
762 | { | ||
763 | - refCnt = 1; | ||
764 | hasRef = false; | ||
765 | flags = flagUnknown; | ||
766 | type = typeUnknown; | ||
767 | @@ -1294,7 +1292,6 @@ Annot::Annot(PDFDoc *docA, Object &&dictObject) | ||
768 | |||
769 | Annot::Annot(PDFDoc *docA, Object &&dictObject, const Object *obj) | ||
770 | { | ||
771 | - refCnt = 1; | ||
772 | if (obj->isRef()) { | ||
773 | hasRef = true; | ||
774 | ref = obj->getRef(); | ||
775 | @@ -1670,18 +1667,6 @@ void Annot::removeReferencedObjects() | ||
776 | invalidateAppearance(); | ||
777 | } | ||
778 | |||
779 | -void Annot::incRefCnt() | ||
780 | -{ | ||
781 | - refCnt++; | ||
782 | -} | ||
783 | - | ||
784 | -void Annot::decRefCnt() | ||
785 | -{ | ||
786 | - if (--refCnt == 0) { | ||
787 | - delete this; | ||
788 | - } | ||
789 | -} | ||
790 | - | ||
791 | Annot::~Annot() { } | ||
792 | |||
793 | void AnnotAppearanceBuilder::setDrawColor(const AnnotColor *drawColor, bool fill) | ||
794 | @@ -2218,7 +2203,7 @@ void AnnotMarkup::setLabel(std::unique_ptr<GooString> &&new_label) | ||
795 | update("T", Object(label->copy())); | ||
796 | } | ||
797 | |||
798 | -void AnnotMarkup::setPopup(std::unique_ptr<AnnotPopup> &&new_popup) | ||
799 | +void AnnotMarkup::setPopup(std::shared_ptr<AnnotPopup> new_popup) | ||
800 | { | ||
801 | // If there exists an old popup annotation that is already | ||
802 | // associated with a page, then we need to remove that | ||
803 | @@ -2227,7 +2212,7 @@ void AnnotMarkup::setPopup(std::unique_ptr<AnnotPopup> &&new_popup) | ||
804 | if (popup && popup->getPageNum() != 0) { | ||
805 | Page *pageobj = doc->getPage(popup->getPageNum()); | ||
806 | if (pageobj) { | ||
807 | - pageobj->removeAnnot(popup.get()); | ||
808 | + pageobj->removeAnnot(popup); | ||
809 | } | ||
810 | } | ||
811 | |||
812 | @@ -2244,7 +2229,7 @@ void AnnotMarkup::setPopup(std::unique_ptr<AnnotPopup> &&new_popup) | ||
813 | Page *pageobj = doc->getPage(page); | ||
814 | assert(pageobj != nullptr); // pageobj should exist in doc (see setPage()) | ||
815 | |||
816 | - pageobj->addAnnot(popup.get()); | ||
817 | + pageobj->addAnnot(popup); | ||
818 | } | ||
819 | } else { | ||
820 | popup = nullptr; | ||
821 | @@ -2276,7 +2261,7 @@ void AnnotMarkup::removeReferencedObjects() | ||
822 | |||
823 | // Remove popup | ||
824 | if (popup) { | ||
825 | - pageobj->removeAnnot(popup.get()); | ||
826 | + pageobj->removeAnnot(popup); | ||
827 | } | ||
828 | |||
829 | Annot::removeReferencedObjects(); | ||
830 | @@ -2943,7 +2928,7 @@ void AnnotFreeText::setStyleString(GooString *new_string) | ||
831 | update("DS", Object(styleString->copy())); | ||
832 | } | ||
833 | |||
834 | -void AnnotFreeText::setCalloutLine(AnnotCalloutLine *line) | ||
835 | +void AnnotFreeText::setCalloutLine(std::unique_ptr<AnnotCalloutLine> &&line) | ||
836 | { | ||
837 | Object obj1; | ||
838 | if (line == nullptr) { | ||
839 | @@ -2958,15 +2943,13 @@ void AnnotFreeText::setCalloutLine(AnnotCalloutLine *line) | ||
840 | obj1.arrayAdd(Object(x2)); | ||
841 | obj1.arrayAdd(Object(y2)); | ||
842 | |||
843 | - AnnotCalloutMultiLine *mline = dynamic_cast<AnnotCalloutMultiLine *>(line); | ||
844 | + AnnotCalloutMultiLine *mline = dynamic_cast<AnnotCalloutMultiLine *>(line.get()); | ||
845 | if (mline) { | ||
846 | double x3 = mline->getX3(), y3 = mline->getY3(); | ||
847 | obj1.arrayAdd(Object(x3)); | ||
848 | obj1.arrayAdd(Object(y3)); | ||
849 | - calloutLine = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3); | ||
850 | - } else { | ||
851 | - calloutLine = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2); | ||
852 | } | ||
853 | + calloutLine = std::move(line); | ||
854 | } | ||
855 | |||
856 | update("CL", std::move(obj1)); | ||
857 | @@ -5715,10 +5698,7 @@ AnnotStamp::AnnotStamp(PDFDoc *docA, Object &&dictObject, const Object *obj) : A | ||
858 | initialize(docA, annotObj.getDict()); | ||
859 | } | ||
860 | |||
861 | -AnnotStamp::~AnnotStamp() | ||
862 | -{ | ||
863 | - delete stampImageHelper; | ||
864 | -} | ||
865 | +AnnotStamp::~AnnotStamp() = default; | ||
866 | |||
867 | void AnnotStamp::initialize(PDFDoc *docA, Dict *dict) | ||
868 | { | ||
869 | @@ -5729,7 +5709,6 @@ void AnnotStamp::initialize(PDFDoc *docA, Dict *dict) | ||
870 | icon = std::make_unique<GooString>("Draft"); | ||
871 | } | ||
872 | |||
873 | - stampImageHelper = nullptr; | ||
874 | updatedAppearanceStream = Ref::INVALID(); | ||
875 | } | ||
876 | |||
877 | @@ -5887,16 +5866,18 @@ void AnnotStamp::setIcon(GooString *new_icon) | ||
878 | invalidateAppearance(); | ||
879 | } | ||
880 | |||
881 | -void AnnotStamp::setCustomImage(AnnotStampImageHelper *stampImageHelperA) | ||
882 | +void AnnotStamp::setCustomImage(std::unique_ptr<AnnotStampImageHelper> &&stampImageHelperA) | ||
883 | { | ||
884 | if (!stampImageHelperA) { | ||
885 | return; | ||
886 | } | ||
887 | |||
888 | annotLocker(); | ||
889 | - clearCustomImage(); | ||
890 | + if (stampImageHelper) { | ||
891 | + stampImageHelper->removeAnnotStampImageObject(); | ||
892 | + } | ||
893 | |||
894 | - stampImageHelper = stampImageHelperA; | ||
895 | + stampImageHelper = std::move(stampImageHelperA); | ||
896 | generateStampCustomAppearance(); | ||
897 | |||
898 | if (updatedAppearanceStream == Ref::INVALID()) { | ||
899 | @@ -5911,16 +5892,6 @@ void AnnotStamp::setCustomImage(AnnotStampImageHelper *stampImageHelperA) | ||
900 | update("AP", std::move(obj1)); | ||
901 | } | ||
902 | |||
903 | -void AnnotStamp::clearCustomImage() | ||
904 | -{ | ||
905 | - if (stampImageHelper != nullptr) { | ||
906 | - stampImageHelper->removeAnnotStampImageObject(); | ||
907 | - delete stampImageHelper; | ||
908 | - stampImageHelper = nullptr; | ||
909 | - invalidateAppearance(); | ||
910 | - } | ||
911 | -} | ||
912 | - | ||
913 | //------------------------------------------------------------------------ | ||
914 | // AnnotGeometry | ||
915 | //------------------------------------------------------------------------ | ||
916 | @@ -7467,96 +7438,90 @@ const GooString *AnnotRichMedia::Params::getFlashVars() const | ||
917 | |||
918 | Annots::Annots(PDFDoc *docA, int page, Object *annotsObj) | ||
919 | { | ||
920 | - Annot *annot; | ||
921 | - int i; | ||
922 | - | ||
923 | doc = docA; | ||
924 | |||
925 | if (annotsObj->isArray()) { | ||
926 | - for (i = 0; i < annotsObj->arrayGetLength(); ++i) { | ||
927 | + for (int i = 0; i < annotsObj->arrayGetLength(); ++i) { | ||
928 | // get the Ref to this annot and pass it to Annot constructor | ||
929 | // this way, it'll be possible for the annot to retrieve the corresponding | ||
930 | // form widget | ||
931 | Object obj1 = annotsObj->arrayGet(i); | ||
932 | if (obj1.isDict()) { | ||
933 | const Object &obj2 = annotsObj->arrayGetNF(i); | ||
934 | - annot = createAnnot(std::move(obj1), &obj2); | ||
935 | + std::shared_ptr<Annot> annot = createAnnot(std::move(obj1), &obj2); | ||
936 | if (annot) { | ||
937 | if (annot->isOk()) { | ||
938 | annot->setPage(page, false); // Don't change /P | ||
939 | appendAnnot(annot); | ||
940 | } | ||
941 | - annot->decRefCnt(); | ||
942 | } | ||
943 | } | ||
944 | } | ||
945 | } | ||
946 | } | ||
947 | |||
948 | -void Annots::appendAnnot(Annot *annot) | ||
949 | +void Annots::appendAnnot(std::shared_ptr<Annot> annot) | ||
950 | { | ||
951 | if (annot && annot->isOk()) { | ||
952 | - annots.push_back(annot); | ||
953 | - annot->incRefCnt(); | ||
954 | + annots.push_back(std::move(annot)); | ||
955 | } | ||
956 | } | ||
957 | |||
958 | -bool Annots::removeAnnot(Annot *annot) | ||
959 | +bool Annots::removeAnnot(const std::shared_ptr<Annot> &annot) | ||
960 | { | ||
961 | auto idx = std::find(annots.begin(), annots.end(), annot); | ||
962 | |||
963 | if (idx == annots.end()) { | ||
964 | return false; | ||
965 | } else { | ||
966 | - annot->decRefCnt(); | ||
967 | annots.erase(idx); | ||
968 | return true; | ||
969 | } | ||
970 | } | ||
971 | |||
972 | -Annot *Annots::createAnnot(Object &&dictObject, const Object *obj) | ||
973 | +std::shared_ptr<Annot> Annots::createAnnot(Object &&dictObject, const Object *obj) | ||
974 | { | ||
975 | - Annot *annot = nullptr; | ||
976 | + std::shared_ptr<Annot> annot = nullptr; | ||
977 | Object obj1 = dictObject.dictLookup("Subtype"); | ||
978 | if (obj1.isName()) { | ||
979 | const char *typeName = obj1.getName(); | ||
980 | |||
981 | if (!strcmp(typeName, "Text")) { | ||
982 | - annot = new AnnotText(doc, std::move(dictObject), obj); | ||
983 | + annot = std::make_shared<AnnotText>(doc, std::move(dictObject), obj); | ||
984 | } else if (!strcmp(typeName, "Link")) { | ||
985 | - annot = new AnnotLink(doc, std::move(dictObject), obj); | ||
986 | + annot = std::make_shared<AnnotLink>(doc, std::move(dictObject), obj); | ||
987 | } else if (!strcmp(typeName, "FreeText")) { | ||
988 | - annot = new AnnotFreeText(doc, std::move(dictObject), obj); | ||
989 | + annot = std::make_shared<AnnotFreeText>(doc, std::move(dictObject), obj); | ||
990 | } else if (!strcmp(typeName, "Line")) { | ||
991 | - annot = new AnnotLine(doc, std::move(dictObject), obj); | ||
992 | + annot = std::make_shared<AnnotLine>(doc, std::move(dictObject), obj); | ||
993 | } else if (!strcmp(typeName, "Square")) { | ||
994 | - annot = new AnnotGeometry(doc, std::move(dictObject), obj); | ||
995 | + annot = std::make_shared<AnnotGeometry>(doc, std::move(dictObject), obj); | ||
996 | } else if (!strcmp(typeName, "Circle")) { | ||
997 | - annot = new AnnotGeometry(doc, std::move(dictObject), obj); | ||
998 | + annot = std::make_shared<AnnotGeometry>(doc, std::move(dictObject), obj); | ||
999 | } else if (!strcmp(typeName, "Polygon")) { | ||
1000 | - annot = new AnnotPolygon(doc, std::move(dictObject), obj); | ||
1001 | + annot = std::make_shared<AnnotPolygon>(doc, std::move(dictObject), obj); | ||
1002 | } else if (!strcmp(typeName, "PolyLine")) { | ||
1003 | - annot = new AnnotPolygon(doc, std::move(dictObject), obj); | ||
1004 | + annot = std::make_shared<AnnotPolygon>(doc, std::move(dictObject), obj); | ||
1005 | } else if (!strcmp(typeName, "Highlight")) { | ||
1006 | - annot = new AnnotTextMarkup(doc, std::move(dictObject), obj); | ||
1007 | + annot = std::make_shared<AnnotTextMarkup>(doc, std::move(dictObject), obj); | ||
1008 | } else if (!strcmp(typeName, "Underline")) { | ||
1009 | - annot = new AnnotTextMarkup(doc, std::move(dictObject), obj); | ||
1010 | + annot = std::make_shared<AnnotTextMarkup>(doc, std::move(dictObject), obj); | ||
1011 | } else if (!strcmp(typeName, "Squiggly")) { | ||
1012 | - annot = new AnnotTextMarkup(doc, std::move(dictObject), obj); | ||
1013 | + annot = std::make_shared<AnnotTextMarkup>(doc, std::move(dictObject), obj); | ||
1014 | } else if (!strcmp(typeName, "StrikeOut")) { | ||
1015 | - annot = new AnnotTextMarkup(doc, std::move(dictObject), obj); | ||
1016 | + annot = std::make_shared<AnnotTextMarkup>(doc, std::move(dictObject), obj); | ||
1017 | } else if (!strcmp(typeName, "Stamp")) { | ||
1018 | - annot = new AnnotStamp(doc, std::move(dictObject), obj); | ||
1019 | + annot = std::make_shared<AnnotStamp>(doc, std::move(dictObject), obj); | ||
1020 | } else if (!strcmp(typeName, "Caret")) { | ||
1021 | - annot = new AnnotCaret(doc, std::move(dictObject), obj); | ||
1022 | + annot = std::make_shared<AnnotCaret>(doc, std::move(dictObject), obj); | ||
1023 | } else if (!strcmp(typeName, "Ink")) { | ||
1024 | - annot = new AnnotInk(doc, std::move(dictObject), obj); | ||
1025 | + annot = std::make_shared<AnnotInk>(doc, std::move(dictObject), obj); | ||
1026 | } else if (!strcmp(typeName, "FileAttachment")) { | ||
1027 | - annot = new AnnotFileAttachment(doc, std::move(dictObject), obj); | ||
1028 | + annot = std::make_shared<AnnotFileAttachment>(doc, std::move(dictObject), obj); | ||
1029 | } else if (!strcmp(typeName, "Sound")) { | ||
1030 | - annot = new AnnotSound(doc, std::move(dictObject), obj); | ||
1031 | + annot = std::make_shared<AnnotSound>(doc, std::move(dictObject), obj); | ||
1032 | } else if (!strcmp(typeName, "Movie")) { | ||
1033 | - annot = new AnnotMovie(doc, std::move(dictObject), obj); | ||
1034 | + annot = std::make_shared<AnnotMovie>(doc, std::move(dictObject), obj); | ||
1035 | } else if (!strcmp(typeName, "Widget")) { | ||
1036 | // Find the annot in forms | ||
1037 | if (obj->isRef()) { | ||
1038 | @@ -7565,25 +7530,24 @@ Annot *Annots::createAnnot(Object &&dictObject, const Object *obj) | ||
1039 | FormWidget *widget = form->findWidgetByRef(obj->getRef()); | ||
1040 | if (widget) { | ||
1041 | annot = widget->getWidgetAnnotation(); | ||
1042 | - annot->incRefCnt(); | ||
1043 | } | ||
1044 | } | ||
1045 | } | ||
1046 | if (!annot) { | ||
1047 | - annot = new AnnotWidget(doc, std::move(dictObject), obj); | ||
1048 | + annot = std::make_shared<AnnotWidget>(doc, std::move(dictObject), obj); | ||
1049 | } | ||
1050 | } else if (!strcmp(typeName, "Screen")) { | ||
1051 | - annot = new AnnotScreen(doc, std::move(dictObject), obj); | ||
1052 | + annot = std::make_shared<AnnotScreen>(doc, std::move(dictObject), obj); | ||
1053 | } else if (!strcmp(typeName, "PrinterMark")) { | ||
1054 | - annot = new Annot(doc, std::move(dictObject), obj); | ||
1055 | + annot = std::make_shared<Annot>(doc, std::move(dictObject), obj); | ||
1056 | } else if (!strcmp(typeName, "TrapNet")) { | ||
1057 | - annot = new Annot(doc, std::move(dictObject), obj); | ||
1058 | + annot = std::make_shared<Annot>(doc, std::move(dictObject), obj); | ||
1059 | } else if (!strcmp(typeName, "Watermark")) { | ||
1060 | - annot = new Annot(doc, std::move(dictObject), obj); | ||
1061 | + annot = std::make_shared<Annot>(doc, std::move(dictObject), obj); | ||
1062 | } else if (!strcmp(typeName, "3D")) { | ||
1063 | - annot = new Annot3D(doc, std::move(dictObject), obj); | ||
1064 | + annot = std::make_shared<Annot3D>(doc, std::move(dictObject), obj); | ||
1065 | } else if (!strcmp(typeName, "RichMedia")) { | ||
1066 | - annot = new AnnotRichMedia(doc, std::move(dictObject), obj); | ||
1067 | + annot = std::make_shared<AnnotRichMedia>(doc, std::move(dictObject), obj); | ||
1068 | } else if (!strcmp(typeName, "Popup")) { | ||
1069 | /* Popup annots are already handled by markup annots | ||
1070 | * Here we only care about popup annots without a | ||
1071 | @@ -7591,21 +7555,21 @@ Annot *Annots::createAnnot(Object &&dictObject, const Object *obj) | ||
1072 | */ | ||
1073 | Object obj2 = dictObject.dictLookup("Parent"); | ||
1074 | if (obj2.isNull()) { | ||
1075 | - annot = new AnnotPopup(doc, std::move(dictObject), obj); | ||
1076 | + annot = std::make_shared<AnnotPopup>(doc, std::move(dictObject), obj); | ||
1077 | } else { | ||
1078 | annot = nullptr; | ||
1079 | } | ||
1080 | } else { | ||
1081 | - annot = new Annot(doc, std::move(dictObject), obj); | ||
1082 | + annot = std::make_shared<Annot>(doc, std::move(dictObject), obj); | ||
1083 | } | ||
1084 | } | ||
1085 | |||
1086 | return annot; | ||
1087 | } | ||
1088 | |||
1089 | -Annot *Annots::findAnnot(Ref *ref) | ||
1090 | +std::shared_ptr<Annot> Annots::findAnnot(Ref *ref) | ||
1091 | { | ||
1092 | - for (auto *annot : annots) { | ||
1093 | + for (const auto &annot : annots) { | ||
1094 | if (annot->match(ref)) { | ||
1095 | return annot; | ||
1096 | } | ||
1097 | @@ -7613,12 +7577,7 @@ Annot *Annots::findAnnot(Ref *ref) | ||
1098 | return nullptr; | ||
1099 | } | ||
1100 | |||
1101 | -Annots::~Annots() | ||
1102 | -{ | ||
1103 | - for (auto *annot : annots) { | ||
1104 | - annot->decRefCnt(); | ||
1105 | - } | ||
1106 | -} | ||
1107 | +Annots::~Annots() = default; | ||
1108 | |||
1109 | //------------------------------------------------------------------------ | ||
1110 | // AnnotAppearanceBuilder | ||
1111 | diff --git a/poppler/Annot.h b/poppler/Annot.h | ||
1112 | index 819877d..ad40d5e 100644 | ||
1113 | --- a/poppler/Annot.h | ||
1114 | +++ b/poppler/Annot.h | ||
1115 | @@ -716,9 +716,6 @@ public: | ||
1116 | Annot(PDFDoc *docA, Object &&dictObject, const Object *obj); | ||
1117 | bool isOk() { return ok; } | ||
1118 | |||
1119 | - void incRefCnt(); | ||
1120 | - void decRefCnt(); | ||
1121 | - | ||
1122 | virtual void draw(Gfx *gfx, bool printing); | ||
1123 | // Get the resource dict of the appearance stream | ||
1124 | virtual Object getAppearanceResDict(); | ||
1125 | @@ -774,6 +771,8 @@ public: | ||
1126 | // If newFontNeeded is not null, it will contain whether the given font has glyphs to represent the needed text | ||
1127 | static void layoutText(const GooString *text, GooString *outBuf, int *i, const GfxFont &font, double *width, double widthLimit, int *charCount, bool noReencode, bool *newFontNeeded = nullptr); | ||
1128 | |||
1129 | + virtual ~Annot(); | ||
1130 | + | ||
1131 | private: | ||
1132 | void readArrayNum(Object *pdfArray, int key, double *value); | ||
1133 | // write vStr[i:j[ in appearBuf | ||
1134 | @@ -782,7 +781,6 @@ private: | ||
1135 | void setPage(int pageIndex, bool updateP); // Called by Page::addAnnot and Annots ctor | ||
1136 | |||
1137 | protected: | ||
1138 | - virtual ~Annot(); | ||
1139 | virtual void removeReferencedObjects(); // Called by Page::removeAnnot | ||
1140 | Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Dict *resDict); | ||
1141 | Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef | ||
1142 | @@ -799,8 +797,6 @@ protected: | ||
1143 | |||
1144 | Object annotObj; | ||
1145 | |||
1146 | - std::atomic_int refCnt; | ||
1147 | - | ||
1148 | // required data | ||
1149 | AnnotSubtype type; // Annotation type | ||
1150 | std::unique_ptr<PDFRectangle> rect; // Rect | ||
1151 | @@ -873,7 +869,7 @@ public: | ||
1152 | |||
1153 | // getters | ||
1154 | const GooString *getLabel() const { return label.get(); } | ||
1155 | - AnnotPopup *getPopup() const { return popup.get(); } | ||
1156 | + std::shared_ptr<AnnotPopup> getPopup() const { return popup; } | ||
1157 | double getOpacity() const { return opacity; } | ||
1158 | // getRC | ||
1159 | const GooString *getDate() const { return date.get(); } | ||
1160 | @@ -884,7 +880,7 @@ public: | ||
1161 | AnnotExternalDataType getExData() const { return exData; } | ||
1162 | |||
1163 | // The annotation takes the ownership of new_popup | ||
1164 | - void setPopup(std::unique_ptr<AnnotPopup> &&new_popup); | ||
1165 | + void setPopup(std::shared_ptr<AnnotPopup> new_popup); | ||
1166 | void setLabel(std::unique_ptr<GooString> &&new_label); | ||
1167 | void setOpacity(double opacityA); | ||
1168 | void setDate(GooString *new_date); | ||
1169 | @@ -893,7 +889,7 @@ protected: | ||
1170 | void removeReferencedObjects() override; | ||
1171 | |||
1172 | std::unique_ptr<GooString> label; // T (Default author) | ||
1173 | - std::unique_ptr<AnnotPopup> popup; // Popup | ||
1174 | + std::shared_ptr<AnnotPopup> popup; // Popup | ||
1175 | double opacity; // CA (Default 1.0) | ||
1176 | // RC | ||
1177 | std::unique_ptr<GooString> date; // CreationDate | ||
1178 | @@ -1068,7 +1064,7 @@ public: | ||
1179 | void setDefaultAppearance(const DefaultAppearance &da); | ||
1180 | void setQuadding(VariableTextQuadding new_quadding); | ||
1181 | void setStyleString(GooString *new_string); | ||
1182 | - void setCalloutLine(AnnotCalloutLine *line); | ||
1183 | + void setCalloutLine(std::unique_ptr<AnnotCalloutLine> &&line); | ||
1184 | void setIntent(AnnotFreeTextIntent new_intent); | ||
1185 | |||
1186 | // getters | ||
1187 | @@ -1224,9 +1220,7 @@ public: | ||
1188 | |||
1189 | void setIcon(GooString *new_icon); | ||
1190 | |||
1191 | - void setCustomImage(AnnotStampImageHelper *stampImageHelperA); | ||
1192 | - | ||
1193 | - void clearCustomImage(); | ||
1194 | + void setCustomImage(std::unique_ptr<AnnotStampImageHelper> &&stampImageHelperA); | ||
1195 | |||
1196 | // getters | ||
1197 | const GooString *getIcon() const { return icon.get(); } | ||
1198 | @@ -1237,7 +1231,7 @@ private: | ||
1199 | void generateStampCustomAppearance(); | ||
1200 | |||
1201 | std::unique_ptr<GooString> icon; // Name (Default Draft) | ||
1202 | - AnnotStampImageHelper *stampImageHelper; | ||
1203 | + std::unique_ptr<AnnotStampImageHelper> stampImageHelper; | ||
1204 | Ref updatedAppearanceStream; | ||
1205 | }; | ||
1206 | |||
1207 | @@ -1768,17 +1762,17 @@ public: | ||
1208 | Annots(const Annots &) = delete; | ||
1209 | Annots &operator=(const Annots &) = delete; | ||
1210 | |||
1211 | - const std::vector<Annot *> &getAnnots() { return annots; } | ||
1212 | + const std::vector<std::shared_ptr<Annot>> &getAnnots() { return annots; } | ||
1213 | |||
1214 | - void appendAnnot(Annot *annot); | ||
1215 | - bool removeAnnot(Annot *annot); | ||
1216 | + void appendAnnot(std::shared_ptr<Annot> annot); | ||
1217 | + bool removeAnnot(const std::shared_ptr<Annot> &annot); | ||
1218 | |||
1219 | private: | ||
1220 | - Annot *createAnnot(Object &&dictObject, const Object *obj); | ||
1221 | - Annot *findAnnot(Ref *ref); | ||
1222 | + std::shared_ptr<Annot> createAnnot(Object &&dictObject, const Object *obj); | ||
1223 | + std::shared_ptr<Annot> findAnnot(Ref *ref); | ||
1224 | |||
1225 | PDFDoc *doc; | ||
1226 | - std::vector<Annot *> annots; | ||
1227 | + std::vector<std::shared_ptr<Annot>> annots; | ||
1228 | }; | ||
1229 | |||
1230 | #endif | ||
1231 | diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc | ||
1232 | index 309ec6d..c8c1bdf 100644 | ||
1233 | --- a/poppler/FontInfo.cc | ||
1234 | +++ b/poppler/FontInfo.cc | ||
1235 | @@ -82,7 +82,7 @@ std::vector<FontInfo *> FontInfoScanner::scan(int nPages) | ||
1236 | delete resDict; | ||
1237 | } | ||
1238 | annots = page->getAnnots(); | ||
1239 | - for (Annot *annot : annots->getAnnots()) { | ||
1240 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1241 | Object obj1 = annot->getAppearanceResDict(); | ||
1242 | if (obj1.isDict()) { | ||
1243 | scanFonts(xrefA.get(), obj1.getDict(), &result); | ||
1244 | diff --git a/poppler/Form.cc b/poppler/Form.cc | ||
1245 | index 2c0c35a..ca73a35 100644 | ||
1246 | --- a/poppler/Form.cc | ||
1247 | +++ b/poppler/Form.cc | ||
1248 | @@ -123,12 +123,7 @@ FormWidget::FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormF | ||
1249 | widget = nullptr; | ||
1250 | } | ||
1251 | |||
1252 | -FormWidget::~FormWidget() | ||
1253 | -{ | ||
1254 | - if (widget) { | ||
1255 | - widget->decRefCnt(); | ||
1256 | - } | ||
1257 | -} | ||
1258 | +FormWidget::~FormWidget() = default; | ||
1259 | |||
1260 | void FormWidget::print(int indent) | ||
1261 | { | ||
1262 | @@ -142,7 +137,7 @@ void FormWidget::createWidgetAnnotation() | ||
1263 | } | ||
1264 | |||
1265 | Object obj1(ref); | ||
1266 | - widget = new AnnotWidget(doc, &obj, &obj1, field); | ||
1267 | + widget = std::make_shared<AnnotWidget>(doc, &obj, &obj1, field); | ||
1268 | } | ||
1269 | |||
1270 | bool FormWidget::inRect(double x, double y) const | ||
1271 | @@ -3114,7 +3109,7 @@ FormPageWidgets::FormPageWidgets(Annots *annots, unsigned int page, Form *form) | ||
1272 | |||
1273 | /* For each entry in the page 'Annots' dict, try to find | ||
1274 | a matching form field */ | ||
1275 | - for (Annot *annot : annots->getAnnots()) { | ||
1276 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1277 | |||
1278 | if (annot->getType() != Annot::typeWidget) { | ||
1279 | continue; | ||
1280 | diff --git a/poppler/Form.h b/poppler/Form.h | ||
1281 | index 80be38e..5a0af10 100644 | ||
1282 | --- a/poppler/Form.h | ||
1283 | +++ b/poppler/Form.h | ||
1284 | @@ -146,8 +146,8 @@ public: | ||
1285 | static void decodeID(unsigned id, unsigned *pageNum, unsigned *fieldNum); | ||
1286 | |||
1287 | void createWidgetAnnotation(); | ||
1288 | - AnnotWidget *getWidgetAnnotation() const { return widget; } | ||
1289 | - void setWidgetAnnotation(AnnotWidget *_widget) { widget = _widget; } | ||
1290 | + std::shared_ptr<AnnotWidget> getWidgetAnnotation() const { return widget; } | ||
1291 | + void setWidgetAnnotation(std::shared_ptr<AnnotWidget> _widget) { widget = std::move(widget); } | ||
1292 | |||
1293 | virtual void updateWidgetAppearance() = 0; | ||
1294 | |||
1295 | @@ -156,7 +156,7 @@ public: | ||
1296 | protected: | ||
1297 | FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormField *fieldA); | ||
1298 | |||
1299 | - AnnotWidget *widget; | ||
1300 | + std::shared_ptr<AnnotWidget> widget; | ||
1301 | FormField *field; | ||
1302 | FormFieldType type; | ||
1303 | Object obj; | ||
1304 | diff --git a/poppler/JSInfo.cc b/poppler/JSInfo.cc | ||
1305 | index eaef33e..e4c4f37 100644 | ||
1306 | --- a/poppler/JSInfo.cc | ||
1307 | +++ b/poppler/JSInfo.cc | ||
1308 | @@ -191,15 +191,15 @@ void JSInfo::scan(int nPages) | ||
1309 | } | ||
1310 | // annotation actions (links, screen, widget) | ||
1311 | annots = page->getAnnots(); | ||
1312 | - for (Annot *a : annots->getAnnots()) { | ||
1313 | + for (const std::shared_ptr<Annot> &a : annots->getAnnots()) { | ||
1314 | if (a->getType() == Annot::typeLink) { | ||
1315 | - AnnotLink *annot = static_cast<AnnotLink *>(a); | ||
1316 | + AnnotLink *annot = static_cast<AnnotLink *>(a.get()); | ||
1317 | scanLinkAction(annot->getAction(), "Link Annotation Activated"); | ||
1318 | if (onlyFirstJS && hasJS) { | ||
1319 | return; | ||
1320 | } | ||
1321 | } else if (a->getType() == Annot::typeScreen) { | ||
1322 | - AnnotScreen *annot = static_cast<AnnotScreen *>(a); | ||
1323 | + AnnotScreen *annot = static_cast<AnnotScreen *>(a.get()); | ||
1324 | scanLinkAction(annot->getAction(), "Screen Annotation Activated"); | ||
1325 | scanLinkAction(annot->getAdditionalAction(Annot::actionCursorEntering).get(), "Screen Annotation Cursor Enter"); | ||
1326 | scanLinkAction(annot->getAdditionalAction(Annot::actionCursorLeaving).get(), "Screen Annotation Cursor Leave"); | ||
1327 | @@ -216,7 +216,7 @@ void JSInfo::scan(int nPages) | ||
1328 | return; | ||
1329 | } | ||
1330 | } else if (a->getType() == Annot::typeWidget) { | ||
1331 | - AnnotWidget *annot = static_cast<AnnotWidget *>(a); | ||
1332 | + AnnotWidget *annot = static_cast<AnnotWidget *>(a.get()); | ||
1333 | scanLinkAction(annot->getAction(), "Widget Annotation Activated"); | ||
1334 | scanLinkAction(annot->getAdditionalAction(Annot::actionCursorEntering).get(), "Widget Annotation Cursor Enter"); | ||
1335 | scanLinkAction(annot->getAdditionalAction(Annot::actionCursorLeaving).get(), "Widget Annotation Cursor Leave"); | ||
1336 | diff --git a/poppler/Link.cc b/poppler/Link.cc | ||
1337 | index 8aca0b9..c952887 100644 | ||
1338 | --- a/poppler/Link.cc | ||
1339 | +++ b/poppler/Link.cc | ||
1340 | @@ -35,6 +35,7 @@ | ||
1341 | |||
1342 | #include <cstddef> | ||
1343 | #include <cstring> | ||
1344 | +#include <memory> | ||
1345 | #include "goo/gmem.h" | ||
1346 | #include "goo/GooString.h" | ||
1347 | #include "Error.h" | ||
1348 | @@ -890,20 +891,13 @@ Links::Links(Annots *annots) | ||
1349 | return; | ||
1350 | } | ||
1351 | |||
1352 | - for (Annot *annot : annots->getAnnots()) { | ||
1353 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1354 | |||
1355 | if (annot->getType() != Annot::typeLink) { | ||
1356 | continue; | ||
1357 | } | ||
1358 | - | ||
1359 | - annot->incRefCnt(); | ||
1360 | - links.push_back(static_cast<AnnotLink *>(annot)); | ||
1361 | + links.push_back(std::static_pointer_cast<AnnotLink>(annot)); | ||
1362 | } | ||
1363 | } | ||
1364 | |||
1365 | -Links::~Links() | ||
1366 | -{ | ||
1367 | - for (AnnotLink *link : links) { | ||
1368 | - link->decRefCnt(); | ||
1369 | - } | ||
1370 | -} | ||
1371 | +Links::~Links() = default; | ||
1372 | diff --git a/poppler/Link.h b/poppler/Link.h | ||
1373 | index 204207b..9bd01f0 100644 | ||
1374 | --- a/poppler/Link.h | ||
1375 | +++ b/poppler/Link.h | ||
1376 | @@ -555,10 +555,10 @@ public: | ||
1377 | Links(const Links &) = delete; | ||
1378 | Links &operator=(const Links &) = delete; | ||
1379 | |||
1380 | - const std::vector<AnnotLink *> &getLinks() const { return links; } | ||
1381 | + const std::vector<std::shared_ptr<AnnotLink>> &getLinks() const { return links; } | ||
1382 | |||
1383 | private: | ||
1384 | - std::vector<AnnotLink *> links; | ||
1385 | + std::vector<std::shared_ptr<AnnotLink>> links; | ||
1386 | }; | ||
1387 | |||
1388 | #endif | ||
1389 | diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc | ||
1390 | index f1b9bfc..872841c 100644 | ||
1391 | --- a/poppler/PDFDoc.cc | ||
1392 | +++ b/poppler/PDFDoc.cc | ||
1393 | @@ -2225,7 +2225,7 @@ bool PDFDoc::sign(const std::string &saveFilename, const std::string &certNickna | ||
1394 | field->setImageResource(imageResourceRef); | ||
1395 | |||
1396 | Object refObj(ref); | ||
1397 | - AnnotWidget *signatureAnnot = new AnnotWidget(this, field->getObj(), &refObj, field.get()); | ||
1398 | + auto signatureAnnot = std::make_shared<AnnotWidget>(this, field->getObj(), &refObj, field.get()); | ||
1399 | signatureAnnot->setFlags(signatureAnnot->getFlags() | Annot::flagPrint | Annot::flagLocked | Annot::flagNoRotate); | ||
1400 | Dict dummy(getXRef()); | ||
1401 | auto appearCharacs = std::make_unique<AnnotAppearanceCharacs>(&dummy); | ||
1402 | diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc | ||
1403 | index 23e3dcf..ac03f27 100644 | ||
1404 | --- a/poppler/PSOutputDev.cc | ||
1405 | +++ b/poppler/PSOutputDev.cc | ||
1406 | @@ -1738,7 +1738,7 @@ void PSOutputDev::writeDocSetup(Catalog *catalog, const std::vector<int> &pageLi | ||
1407 | setupResources(resDict); | ||
1408 | } | ||
1409 | annots = page->getAnnots(); | ||
1410 | - for (Annot *annot : annots->getAnnots()) { | ||
1411 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1412 | Object obj1 = annot->getAppearanceResDict(); | ||
1413 | if (obj1.isDict()) { | ||
1414 | setupResources(obj1.getDict()); | ||
1415 | diff --git a/poppler/Page.cc b/poppler/Page.cc | ||
1416 | index 9d5a4ff..234f124 100644 | ||
1417 | --- a/poppler/Page.cc | ||
1418 | +++ b/poppler/Page.cc | ||
1419 | @@ -318,14 +318,7 @@ err1: | ||
1420 | ok = false; | ||
1421 | } | ||
1422 | |||
1423 | -Page::~Page() | ||
1424 | -{ | ||
1425 | - delete attrs; | ||
1426 | - delete annots; | ||
1427 | - for (auto frmField : standaloneFields) { | ||
1428 | - delete frmField; | ||
1429 | - } | ||
1430 | -} | ||
1431 | +Page::~Page() = default; | ||
1432 | |||
1433 | Dict *Page::getResourceDict() | ||
1434 | { | ||
1435 | @@ -364,11 +357,11 @@ void Page::replaceXRef(XRef *xrefA) | ||
1436 | } | ||
1437 | |||
1438 | /* Loads standalone fields into Page, should be called once per page only */ | ||
1439 | -void Page::loadStandaloneFields(Annots *annotations, Form *form) | ||
1440 | +void Page::loadStandaloneFields(Form *form) | ||
1441 | { | ||
1442 | /* Look for standalone annots, identified by being: 1) of type Widget | ||
1443 | * 2) not referenced from the Catalog's Form Field array */ | ||
1444 | - for (Annot *annot : annots->getAnnots()) { | ||
1445 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1446 | |||
1447 | if (annot->getType() != Annot::typeWidget || !annot->getHasRef()) { | ||
1448 | continue; | ||
1449 | @@ -384,7 +377,7 @@ void Page::loadStandaloneFields(Annots *annotations, Form *form) | ||
1450 | |||
1451 | if (field && field->getNumWidgets() == 1) { | ||
1452 | |||
1453 | - static_cast<AnnotWidget *>(annot)->setField(field); | ||
1454 | + std::static_pointer_cast<AnnotWidget>(annot)->setField(field); | ||
1455 | |||
1456 | field->setStandAlone(true); | ||
1457 | FormWidget *formWidget = field->getWidget(0); | ||
1458 | @@ -405,15 +398,15 @@ Annots *Page::getAnnots(XRef *xrefA) | ||
1459 | { | ||
1460 | if (!annots) { | ||
1461 | Object obj = getAnnotsObject(xrefA); | ||
1462 | - annots = new Annots(doc, num, &obj); | ||
1463 | + annots = std::make_unique<Annots>(doc, num, &obj); | ||
1464 | // Load standalone fields once for the page | ||
1465 | - loadStandaloneFields(annots, doc->getCatalog()->getForm()); | ||
1466 | + loadStandaloneFields(doc->getCatalog()->getForm()); | ||
1467 | } | ||
1468 | |||
1469 | - return annots; | ||
1470 | + return annots.get(); | ||
1471 | } | ||
1472 | |||
1473 | -bool Page::addAnnot(Annot *annot) | ||
1474 | +bool Page::addAnnot(const std::shared_ptr<Annot> &annot) | ||
1475 | { | ||
1476 | if (unlikely(xref->getEntry(pageRef.num)->type == xrefEntryFree)) { | ||
1477 | // something very wrong happened if we're here | ||
1478 | @@ -456,14 +449,14 @@ bool Page::addAnnot(Annot *annot) | ||
1479 | // Popup annots are already handled by markup annots, | ||
1480 | // so add to the list only Popup annots without a | ||
1481 | // markup annotation associated. | ||
1482 | - if (annot->getType() != Annot::typePopup || !static_cast<AnnotPopup *>(annot)->hasParent()) { | ||
1483 | + if (annot->getType() != Annot::typePopup || !static_cast<AnnotPopup *>(annot.get())->hasParent()) { | ||
1484 | annots->appendAnnot(annot); | ||
1485 | } | ||
1486 | annot->setPage(num, true); | ||
1487 | |||
1488 | - AnnotMarkup *annotMarkup = dynamic_cast<AnnotMarkup *>(annot); | ||
1489 | + AnnotMarkup *annotMarkup = dynamic_cast<AnnotMarkup *>(annot.get()); | ||
1490 | if (annotMarkup) { | ||
1491 | - AnnotPopup *annotPopup = annotMarkup->getPopup(); | ||
1492 | + std::shared_ptr<AnnotPopup> annotPopup = annotMarkup->getPopup(); | ||
1493 | if (annotPopup) { | ||
1494 | addAnnot(annotPopup); | ||
1495 | } | ||
1496 | @@ -472,7 +465,7 @@ bool Page::addAnnot(Annot *annot) | ||
1497 | return true; | ||
1498 | } | ||
1499 | |||
1500 | -void Page::removeAnnot(Annot *annot) | ||
1501 | +void Page::removeAnnot(const std::shared_ptr<Annot> &annot) | ||
1502 | { | ||
1503 | Ref annotRef = annot->getRef(); | ||
1504 | |||
1505 | @@ -596,8 +589,8 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI, int rotate, bo | ||
1506 | if (globalParams->getPrintCommands()) { | ||
1507 | printf("***** Annotations\n"); | ||
1508 | } | ||
1509 | - for (Annot *annot : annots->getAnnots()) { | ||
1510 | - if ((annotDisplayDecideCbk && (*annotDisplayDecideCbk)(annot, annotDisplayDecideCbkData)) || !annotDisplayDecideCbk) { | ||
1511 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
1512 | + if ((annotDisplayDecideCbk && (*annotDisplayDecideCbk)(annot.get(), annotDisplayDecideCbkData)) || !annotDisplayDecideCbk) { | ||
1513 | annot->draw(gfx, printing); | ||
1514 | } | ||
1515 | } | ||
1516 | @@ -787,8 +780,8 @@ void Page::makeBox(double hDPI, double vDPI, int rotate, bool useMediaBox, bool | ||
1517 | void Page::processLinks(OutputDev *out) | ||
1518 | { | ||
1519 | std::unique_ptr<Links> links = getLinks(); | ||
1520 | - for (AnnotLink *link : links->getLinks()) { | ||
1521 | - out->processLink(link); | ||
1522 | + for (const std::shared_ptr<AnnotLink> &link : links->getLinks()) { | ||
1523 | + out->processLink(link.get()); | ||
1524 | } | ||
1525 | } | ||
1526 | |||
1527 | diff --git a/poppler/Page.h b/poppler/Page.h | ||
1528 | index 3fe86be..56951a2 100644 | ||
1529 | --- a/poppler/Page.h | ||
1530 | +++ b/poppler/Page.h | ||
1531 | @@ -181,9 +181,9 @@ public: | ||
1532 | // Get annotations array. | ||
1533 | Object getAnnotsObject(XRef *xrefA = nullptr) { return annotsObj.fetch(xrefA ? xrefA : xref); } | ||
1534 | // Add a new annotation to the page | ||
1535 | - bool addAnnot(Annot *annot); | ||
1536 | + bool addAnnot(const std::shared_ptr<Annot> &annot); | ||
1537 | // Remove an existing annotation from the page | ||
1538 | - void removeAnnot(Annot *annot); | ||
1539 | + void removeAnnot(const std::shared_ptr<Annot> &annot); | ||
1540 | |||
1541 | // Return a list of links. | ||
1542 | std::unique_ptr<Links> getLinks(); | ||
1543 | @@ -252,7 +252,7 @@ private: | ||
1544 | const Ref pageRef; // page reference | ||
1545 | int num; // page number | ||
1546 | PageAttrs *attrs; // page attributes | ||
1547 | - Annots *annots; // annotations | ||
1548 | + std::unique_ptr<Annots> annots; // annotations | ||
1549 | Object annotsObj; // annotations array | ||
1550 | Object contents; // page contents | ||
1551 | Object thumb; // page thumbnail | ||
1552 | @@ -267,7 +267,7 @@ private: | ||
1553 | // create standalone FormFields to contain those special FormWidgets, as | ||
1554 | // they are 'de facto' being used to implement tooltips. See #34 | ||
1555 | std::vector<FormField *> standaloneFields; | ||
1556 | - void loadStandaloneFields(Annots *annotations, Form *form); | ||
1557 | + void loadStandaloneFields(Form *form); | ||
1558 | }; | ||
1559 | |||
1560 | #endif | ||
1561 | diff --git a/qt5/src/poppler-annotation-private.h b/qt5/src/poppler-annotation-private.h | ||
1562 | index 1f8d756..8970f49 100644 | ||
1563 | --- a/qt5/src/poppler-annotation-private.h | ||
1564 | +++ b/qt5/src/poppler-annotation-private.h | ||
1565 | @@ -57,7 +57,7 @@ public: | ||
1566 | |||
1567 | /* Returns an Annotation of the right subclass whose d_ptr points to | ||
1568 | * this AnnotationPrivate */ | ||
1569 | - virtual Annotation *makeAlias() = 0; | ||
1570 | + virtual std::unique_ptr<Annotation> makeAlias() = 0; | ||
1571 | |||
1572 | /* properties: contents related */ | ||
1573 | QString author; | ||
1574 | @@ -77,18 +77,18 @@ public: | ||
1575 | /* revisions */ | ||
1576 | Annotation::RevScope revisionScope; | ||
1577 | Annotation::RevType revisionType; | ||
1578 | - QList<Annotation *> revisions; | ||
1579 | + std::vector<std::unique_ptr<Annotation>> revisions; | ||
1580 | |||
1581 | /* After this call, the Annotation object will behave like a wrapper for | ||
1582 | * the specified Annot object. All cached values are discarded */ | ||
1583 | - void tieToNativeAnnot(Annot *ann, ::Page *page, DocumentData *doc); | ||
1584 | + void tieToNativeAnnot(std::shared_ptr<Annot> ann, ::Page *page, DocumentData *doc); | ||
1585 | |||
1586 | /* Creates a new Annot object on the specified page, flushes current | ||
1587 | * values to that object and ties this Annotation to that object */ | ||
1588 | - virtual Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) = 0; | ||
1589 | + virtual std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) = 0; | ||
1590 | |||
1591 | /* Inited to 0 (i.e. untied annotation) */ | ||
1592 | - Annot *pdfAnnot; | ||
1593 | + std::shared_ptr<Annot> pdfAnnot; | ||
1594 | ::Page *pdfPage; | ||
1595 | DocumentData *parentDoc; | ||
1596 | |||
1597 | diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc | ||
1598 | index e15523c..f148671 100644 | ||
1599 | --- a/qt5/src/poppler-annotation.cc | ||
1600 | +++ b/qt5/src/poppler-annotation.cc | ||
1601 | @@ -65,6 +65,12 @@ | ||
1602 | * static data set at creation time by findAnnotations | ||
1603 | */ | ||
1604 | |||
1605 | +template<typename T, typename U> | ||
1606 | +static std::unique_ptr<T> static_pointer_cast(std::unique_ptr<U> &&in) | ||
1607 | +{ | ||
1608 | + return std::unique_ptr<T>(static_cast<std::add_pointer_t<T>>(in.release())); | ||
1609 | +} | ||
1610 | + | ||
1611 | namespace Poppler { | ||
1612 | |||
1613 | // BEGIN AnnotationUtils implementation | ||
1614 | @@ -199,36 +205,25 @@ void getRawDataFromQImage(const QImage &qimg, int bitsPerPixel, QByteArray *data | ||
1615 | void AnnotationPrivate::addRevision(Annotation *ann, Annotation::RevScope scope, Annotation::RevType type) | ||
1616 | { | ||
1617 | /* Since ownership stays with the caller, create an alias of ann */ | ||
1618 | - revisions.append(ann->d_ptr->makeAlias()); | ||
1619 | + revisions.push_back(ann->d_ptr->makeAlias()); | ||
1620 | |||
1621 | /* Set revision properties */ | ||
1622 | revisionScope = scope; | ||
1623 | revisionType = type; | ||
1624 | } | ||
1625 | |||
1626 | -AnnotationPrivate::~AnnotationPrivate() | ||
1627 | -{ | ||
1628 | - // Delete all children revisions | ||
1629 | - qDeleteAll(revisions); | ||
1630 | - | ||
1631 | - // Release Annot object | ||
1632 | - if (pdfAnnot) { | ||
1633 | - pdfAnnot->decRefCnt(); | ||
1634 | - } | ||
1635 | -} | ||
1636 | +AnnotationPrivate::~AnnotationPrivate() = default; | ||
1637 | |||
1638 | -void AnnotationPrivate::tieToNativeAnnot(Annot *ann, ::Page *page, Poppler::DocumentData *doc) | ||
1639 | +void AnnotationPrivate::tieToNativeAnnot(std::shared_ptr<Annot> *ann, ::Page *page, Poppler::DocumentData *doc) | ||
1640 | { | ||
1641 | if (pdfAnnot) { | ||
1642 | error(errIO, -1, "Annotation is already tied"); | ||
1643 | return; | ||
1644 | } | ||
1645 | |||
1646 | - pdfAnnot = ann; | ||
1647 | + pdfAnnot = std::move(ann); | ||
1648 | pdfPage = page; | ||
1649 | parentDoc = doc; | ||
1650 | - | ||
1651 | - pdfAnnot->incRefCnt(); | ||
1652 | } | ||
1653 | |||
1654 | /* This method is called when a new annotation is created, after pdfAnnot and | ||
1655 | @@ -237,7 +232,7 @@ void AnnotationPrivate::flushBaseAnnotationProperties() | ||
1656 | { | ||
1657 | Q_ASSERT(pdfPage); | ||
1658 | |||
1659 | - Annotation *q = makeAlias(); // Setters are defined in the public class | ||
1660 | + std::unique_ptr<Annotation> q = makeAlias(); // Setters are defined in the public class | ||
1661 | |||
1662 | // Since pdfAnnot has been set, this calls will write in the Annot object | ||
1663 | q->setAuthor(author); | ||
1664 | @@ -250,13 +245,7 @@ void AnnotationPrivate::flushBaseAnnotationProperties() | ||
1665 | q->setStyle(style); | ||
1666 | q->setPopup(popup); | ||
1667 | |||
1668 | - // Flush revisions | ||
1669 | - foreach (Annotation *r, revisions) { | ||
1670 | - // TODO: Flush revision | ||
1671 | - delete r; // Object is no longer needed | ||
1672 | - } | ||
1673 | - | ||
1674 | - delete q; | ||
1675 | + revisions.clear(); | ||
1676 | |||
1677 | // Clear some members to save memory | ||
1678 | author.clear(); | ||
1679 | @@ -455,14 +444,14 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1680 | |||
1681 | // Create Annotation objects and tie to their native Annot | ||
1682 | QList<Annotation *> res; | ||
1683 | - for (Annot *ann : annots->getAnnots()) { | ||
1684 | + for (const std::shared_ptr<Annot> &ann : annots->getAnnots()) { | ||
1685 | if (!ann) { | ||
1686 | error(errInternal, -1, "Annot is null"); | ||
1687 | continue; | ||
1688 | } | ||
1689 | |||
1690 | // Check parent annotation | ||
1691 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(ann); | ||
1692 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(ann.get()); | ||
1693 | if (!markupann) { | ||
1694 | // Assume it's a root annotation, and skip if user didn't request it | ||
1695 | if (parentID != -1) { | ||
1696 | @@ -536,7 +525,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1697 | continue; | ||
1698 | } | ||
1699 | // parse Link params | ||
1700 | - AnnotLink *linkann = static_cast<AnnotLink *>(ann); | ||
1701 | + AnnotLink *linkann = static_cast<AnnotLink *>(ann.get()); | ||
1702 | LinkAnnotation *l = new LinkAnnotation(); | ||
1703 | annotation = l; | ||
1704 | |||
1705 | @@ -566,7 +555,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1706 | if (!wantFileAttachmentAnnotations) { | ||
1707 | continue; | ||
1708 | } | ||
1709 | - AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann); | ||
1710 | + AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann.get()); | ||
1711 | FileAttachmentAnnotation *f = new FileAttachmentAnnotation(); | ||
1712 | annotation = f; | ||
1713 | // -> fileIcon | ||
1714 | @@ -581,7 +570,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1715 | if (!wantSoundAnnotations) { | ||
1716 | continue; | ||
1717 | } | ||
1718 | - AnnotSound *soundann = static_cast<AnnotSound *>(ann); | ||
1719 | + AnnotSound *soundann = static_cast<AnnotSound *>(ann.get()); | ||
1720 | SoundAnnotation *s = new SoundAnnotation(); | ||
1721 | annotation = s; | ||
1722 | |||
1723 | @@ -596,7 +585,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1724 | if (!wantMovieAnnotations) { | ||
1725 | continue; | ||
1726 | } | ||
1727 | - AnnotMovie *movieann = static_cast<AnnotMovie *>(ann); | ||
1728 | + AnnotMovie *movieann = static_cast<AnnotMovie *>(ann.get()); | ||
1729 | MovieAnnotation *m = new MovieAnnotation(); | ||
1730 | annotation = m; | ||
1731 | |||
1732 | @@ -614,7 +603,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1733 | if (!wantScreenAnnotations) { | ||
1734 | continue; | ||
1735 | } | ||
1736 | - AnnotScreen *screenann = static_cast<AnnotScreen *>(ann); | ||
1737 | + AnnotScreen *screenann = static_cast<AnnotScreen *>(ann.get()); | ||
1738 | // TODO Support other link types than Link::Rendition in ScreenAnnotation | ||
1739 | if (!screenann->getAction() || screenann->getAction()->getKind() != actionRendition) { | ||
1740 | continue; | ||
1741 | @@ -644,7 +633,7 @@ QList<Annotation *> AnnotationPrivate::findAnnotations(::Page *pdfPage, Document | ||
1742 | annotation = new WidgetAnnotation(); | ||
1743 | break; | ||
1744 | case Annot::typeRichMedia: { | ||
1745 | - const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann); | ||
1746 | + const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann.get()); | ||
1747 | |||
1748 | RichMediaAnnotation *richMediaAnnotation = new RichMediaAnnotation; | ||
1749 | |||
1750 | @@ -852,9 +841,9 @@ Link *AnnotationPrivate::additionalAction(Annotation::AdditionalActionType type) | ||
1751 | |||
1752 | std::unique_ptr<::LinkAction> linkAction = nullptr; | ||
1753 | if (pdfAnnot->getType() == Annot::typeScreen) { | ||
1754 | - linkAction = static_cast<AnnotScreen *>(pdfAnnot)->getAdditionalAction(actionType); | ||
1755 | + linkAction = static_cast<AnnotScreen *>(pdfAnnot.get())->getAdditionalAction(actionType); | ||
1756 | } else { | ||
1757 | - linkAction = static_cast<AnnotWidget *>(pdfAnnot)->getAdditionalAction(actionType); | ||
1758 | + linkAction = static_cast<AnnotWidget *>(pdfAnnot.get())->getAdditionalAction(actionType); | ||
1759 | } | ||
1760 | |||
1761 | Link *link = nullptr; | ||
1762 | @@ -875,7 +864,7 @@ void AnnotationPrivate::addAnnotationToPage(::Page *pdfPage, DocumentData *doc, | ||
1763 | |||
1764 | // Unimplemented annotations can't be created by the user because their ctor | ||
1765 | // is private. Therefore, createNativeAnnot will never return 0 | ||
1766 | - Annot *nativeAnnot = ann->d_ptr->createNativeAnnot(pdfPage, doc); | ||
1767 | + std::shared_ptr<Annot> nativeAnnot = ann->d_ptr->createNativeAnnot(pdfPage, doc); | ||
1768 | Q_ASSERT(nativeAnnot); | ||
1769 | |||
1770 | if (ann->d_ptr->annotationAppearance.isStream()) { | ||
1771 | @@ -908,8 +897,8 @@ class TextAnnotationPrivate : public AnnotationPrivate | ||
1772 | { | ||
1773 | public: | ||
1774 | TextAnnotationPrivate(); | ||
1775 | - Annotation *makeAlias() override; | ||
1776 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
1777 | + std::unique_ptr<Annotation> makeAlias() override; | ||
1778 | + std::unique_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
1779 | void setDefaultAppearanceToNative(); | ||
1780 | std::unique_ptr<DefaultAppearance> getDefaultAppearanceFromNative() const; | ||
1781 | |||
1782 | @@ -1419,7 +1408,7 @@ QString Annotation::author() const | ||
1783 | return d->author; | ||
1784 | } | ||
1785 | |||
1786 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
1787 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
1788 | return markupann ? UnicodeParsedString(markupann->getLabel()) : QString(); | ||
1789 | } | ||
1790 | |||
1791 | @@ -1432,7 +1421,7 @@ void Annotation::setAuthor(const QString &author) | ||
1792 | return; | ||
1793 | } | ||
1794 | |||
1795 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
1796 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
1797 | if (markupann) { | ||
1798 | markupann->setLabel(std::unique_ptr<GooString>(QStringToUnicodeGooString(author))); | ||
1799 | } | ||
1800 | @@ -1535,7 +1524,7 @@ QDateTime Annotation::creationDate() const | ||
1801 | return d->creationDate; | ||
1802 | } | ||
1803 | |||
1804 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
1805 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
1806 | |||
1807 | if (markupann && markupann->getDate()) { | ||
1808 | return convertDate(markupann->getDate()->c_str()); | ||
1809 | @@ -1553,7 +1542,7 @@ void Annotation::setCreationDate(const QDateTime &date) | ||
1810 | return; | ||
1811 | } | ||
1812 | |||
1813 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
1814 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
1815 | if (markupann) { | ||
1816 | if (date.isValid()) { | ||
1817 | const time_t t = date.toSecsSinceEpoch(); | ||
1818 | @@ -1686,7 +1675,7 @@ Annotation::Style Annotation::style() const | ||
1819 | Style s; | ||
1820 | s.setColor(convertAnnotColor(d->pdfAnnot->getColor())); | ||
1821 | |||
1822 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
1823 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
1824 | if (markupann) { | ||
1825 | s.setOpacity(markupann->getOpacity()); | ||
1826 | } | ||
1827 | @@ -1713,11 +1702,11 @@ Annotation::Style Annotation::style() const | ||
1828 | AnnotBorderEffect *border_effect; | ||
1829 | switch (d->pdfAnnot->getType()) { | ||
1830 | case Annot::typeFreeText: | ||
1831 | - border_effect = static_cast<AnnotFreeText *>(d->pdfAnnot)->getBorderEffect(); | ||
1832 | + border_effect = static_cast<AnnotFreeText *>(d->pdfAnnot.get())->getBorderEffect(); | ||
1833 | break; | ||
1834 | case Annot::typeSquare: | ||
1835 | case Annot::typeCircle: | ||
1836 | - border_effect = static_cast<AnnotGeometry *>(d->pdfAnnot)->getBorderEffect(); | ||
1837 | + border_effect = static_cast<AnnotGeometry *>(d->pdfAnnot.get())->getBorderEffect(); | ||
1838 | break; | ||
1839 | default: | ||
1840 | border_effect = nullptr; | ||
1841 | @@ -1741,7 +1730,7 @@ void Annotation::setStyle(const Annotation::Style &style) | ||
1842 | |||
1843 | d->pdfAnnot->setColor(convertQColor(style.color())); | ||
1844 | |||
1845 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
1846 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
1847 | if (markupann) { | ||
1848 | markupann->setOpacity(style.opacity()); | ||
1849 | } | ||
1850 | @@ -1765,9 +1754,9 @@ Annotation::Popup Annotation::popup() const | ||
1851 | AnnotPopup *popup = nullptr; | ||
1852 | int flags = -1; // Not initialized | ||
1853 | |||
1854 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
1855 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
1856 | if (markupann) { | ||
1857 | - popup = markupann->getPopup(); | ||
1858 | + popup = markupann->getPopup().get(); | ||
1859 | w.setSummary(UnicodeParsedString(markupann->getSubject())); | ||
1860 | } | ||
1861 | |||
1862 | @@ -1783,7 +1772,7 @@ Annotation::Popup Annotation::popup() const | ||
1863 | } | ||
1864 | |||
1865 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
1866 | - const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot); | ||
1867 | + const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
1868 | |||
1869 | // Text annotations default to same rect as annotation | ||
1870 | if (flags == -1) { | ||
1871 | @@ -1839,7 +1828,7 @@ Annotation::RevScope Annotation::revisionScope() const | ||
1872 | return d->revisionScope; | ||
1873 | } | ||
1874 | |||
1875 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
1876 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
1877 | |||
1878 | if (markupann && markupann->isInReplyTo()) { | ||
1879 | switch (markupann->getReplyTo()) { | ||
1880 | @@ -1861,7 +1850,7 @@ Annotation::RevType Annotation::revisionType() const | ||
1881 | return d->revisionType; | ||
1882 | } | ||
1883 | |||
1884 | - const AnnotText *textann = dynamic_cast<const AnnotText *>(d->pdfAnnot); | ||
1885 | + const AnnotText *textann = dynamic_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
1886 | |||
1887 | if (textann && textann->isInReplyTo()) { | ||
1888 | switch (textann->getState()) { | ||
1889 | @@ -1892,8 +1881,9 @@ QList<Annotation *> Annotation::revisions() const | ||
1890 | if (!d->pdfAnnot) { | ||
1891 | /* Return aliases, whose ownership goes to the caller */ | ||
1892 | QList<Annotation *> res; | ||
1893 | - foreach (Annotation *rev, d->revisions) | ||
1894 | - res.append(rev->d_ptr->makeAlias()); | ||
1895 | + for (const std::unique_ptr<Annotation> &rev : d->revisions) { | ||
1896 | + res.append(rev->d_ptr->makeAlias().release()); | ||
1897 | + } | ||
1898 | return res; | ||
1899 | } | ||
1900 | |||
1901 | @@ -1910,7 +1900,7 @@ std::unique_ptr<AnnotationAppearance> Annotation::annotationAppearance() const | ||
1902 | { | ||
1903 | Q_D(const Annotation); | ||
1904 | |||
1905 | - return std::make_unique<AnnotationAppearance>(new AnnotationAppearancePrivate(d->pdfAnnot)); | ||
1906 | + return std::make_unique<AnnotationAppearance>(new AnnotationAppearancePrivate(d->pdfAnnot.get())); | ||
1907 | } | ||
1908 | |||
1909 | void Annotation::setAnnotationAppearance(const AnnotationAppearance &annotationAppearance) | ||
1910 | @@ -1934,15 +1924,15 @@ void Annotation::setAnnotationAppearance(const AnnotationAppearance &annotationA | ||
1911 | |||
1912 | TextAnnotationPrivate::TextAnnotationPrivate() : AnnotationPrivate(), textType(TextAnnotation::Linked), textIcon(QStringLiteral("Note")), inplaceAlign(0), inplaceIntent(TextAnnotation::Unknown) { } | ||
1913 | |||
1914 | -Annotation *TextAnnotationPrivate::makeAlias() | ||
1915 | +std::unique_ptr<Annotation> TextAnnotationPrivate::makeAlias() | ||
1916 | { | ||
1917 | - return new TextAnnotation(*this); | ||
1918 | + return std::unique_ptr<Annotation>(new TextAnnotation(*this); | ||
1919 | } | ||
1920 | |||
1921 | -Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
1922 | +std::shared_ptr<Annot> *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
1923 | { | ||
1924 | - // Setters are defined in the public class | ||
1925 | - TextAnnotation *q = static_cast<TextAnnotation *>(makeAlias()); | ||
1926 | + // Setters are defined in the public clas | ||
1927 | + std::unique_ptr<TextAnnotation> q = static_pointer_cast<TextAnnotation *>(makeAlias()); | ||
1928 | |||
1929 | // Set page and contents | ||
1930 | pdfPage = destPage; | ||
1931 | @@ -1951,13 +1941,13 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
1932 | // Set pdfAnnot | ||
1933 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
1934 | if (textType == TextAnnotation::Linked) { | ||
1935 | - pdfAnnot = new AnnotText { destPage->getDoc(), &rect }; | ||
1936 | + pdfAnnot = std::make_shared<AnnotText>(destPage->getDoc(), &rect); | ||
1937 | } else { | ||
1938 | const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize; | ||
1939 | if (pointSize < 0) { | ||
1940 | qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0"; | ||
1941 | } | ||
1942 | - pdfAnnot = new AnnotFreeText { destPage->getDoc(), &rect }; | ||
1943 | + pdfAnnot = std::make_shared<AnnotFreeText>(destPage->getDoc(), &rect); | ||
1944 | } | ||
1945 | |||
1946 | // Set properties | ||
1947 | @@ -1967,8 +1957,6 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
1948 | q->setCalloutPoints(inplaceCallout); | ||
1949 | q->setInplaceIntent(inplaceIntent); | ||
1950 | |||
1951 | - delete q; | ||
1952 | - | ||
1953 | inplaceCallout.clear(); // Free up memory | ||
1954 | |||
1955 | setDefaultAppearanceToNative(); | ||
1956 | @@ -1979,7 +1967,7 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
1957 | void TextAnnotationPrivate::setDefaultAppearanceToNative() | ||
1958 | { | ||
1959 | if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) { | ||
1960 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot); | ||
1961 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get()); | ||
1962 | const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize; | ||
1963 | if (pointSize < 0) { | ||
1964 | qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0"; | ||
1965 | @@ -2008,7 +1996,7 @@ void TextAnnotationPrivate::setDefaultAppearanceToNative() | ||
1966 | std::unique_ptr<DefaultAppearance> TextAnnotationPrivate::getDefaultAppearanceFromNative() const | ||
1967 | { | ||
1968 | if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) { | ||
1969 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot); | ||
1970 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get()); | ||
1971 | return ftextann->getDefaultAppearance(); | ||
1972 | } else { | ||
1973 | return {}; | ||
1974 | @@ -2165,7 +2153,7 @@ QString TextAnnotation::textIcon() const | ||
1975 | } | ||
1976 | |||
1977 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
1978 | - const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot); | ||
1979 | + const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
1980 | return QString::fromLatin1(textann->getIcon()->c_str()); | ||
1981 | } | ||
1982 | |||
1983 | @@ -2182,7 +2170,7 @@ void TextAnnotation::setTextIcon(const QString &icon) | ||
1984 | } | ||
1985 | |||
1986 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
1987 | - AnnotText *textann = static_cast<AnnotText *>(d->pdfAnnot); | ||
1988 | + AnnotText *textann = static_cast<AnnotText *>(d->pdfAnnot.get()); | ||
1989 | QByteArray encoded = icon.toLatin1(); | ||
1990 | GooString s(encoded.constData()); | ||
1991 | textann->setIcon(&s); | ||
1992 | @@ -2256,7 +2244,7 @@ int TextAnnotation::inplaceAlign() const | ||
1993 | } | ||
1994 | |||
1995 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
1996 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
1997 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
1998 | return static_cast<int>(ftextann->getQuadding()); | ||
1999 | } | ||
2000 | |||
2001 | @@ -2273,7 +2261,7 @@ void TextAnnotation::setInplaceAlign(int align) | ||
2002 | } | ||
2003 | |||
2004 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
2005 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
2006 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
2007 | ftextann->setQuadding((VariableTextQuadding)align); | ||
2008 | } | ||
2009 | } | ||
2010 | @@ -2300,7 +2288,7 @@ QVector<QPointF> TextAnnotation::calloutPoints() const | ||
2011 | return QVector<QPointF>(); | ||
2012 | } | ||
2013 | |||
2014 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
2015 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
2016 | const AnnotCalloutLine *callout = ftextann->getCalloutLine(); | ||
2017 | |||
2018 | if (!callout) { | ||
2019 | @@ -2332,7 +2320,7 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
2020 | return; | ||
2021 | } | ||
2022 | |||
2023 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
2024 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
2025 | const int count = points.size(); | ||
2026 | |||
2027 | if (count == 0) { | ||
2028 | @@ -2345,7 +2333,7 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
2029 | return; | ||
2030 | } | ||
2031 | |||
2032 | - AnnotCalloutLine *callout; | ||
2033 | + std::unique_ptr<AnnotCalloutLine> callout; | ||
2034 | double x1, y1, x2, y2; | ||
2035 | double MTX[6]; | ||
2036 | d->fillTransformationMTX(MTX); | ||
2037 | @@ -2355,12 +2343,12 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
2038 | if (count == 3) { | ||
2039 | double x3, y3; | ||
2040 | XPDFReader::invTransform(MTX, points[2], x3, y3); | ||
2041 | - callout = new AnnotCalloutMultiLine(x1, y1, x2, y2, x3, y3); | ||
2042 | + callout = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3); | ||
2043 | } else { | ||
2044 | - callout = new AnnotCalloutLine(x1, y1, x2, y2); | ||
2045 | + callout = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2); | ||
2046 | } | ||
2047 | |||
2048 | - ftextann->setCalloutLine(callout); | ||
2049 | + ftextann->setCalloutLine(std::move(callout)); | ||
2050 | delete callout; | ||
2051 | } | ||
2052 | |||
2053 | @@ -2373,7 +2361,7 @@ TextAnnotation::InplaceIntent TextAnnotation::inplaceIntent() const | ||
2054 | } | ||
2055 | |||
2056 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
2057 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
2058 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
2059 | return (TextAnnotation::InplaceIntent)ftextann->getIntent(); | ||
2060 | } | ||
2061 | |||
2062 | @@ -2390,7 +2378,7 @@ void TextAnnotation::setInplaceIntent(TextAnnotation::InplaceIntent intent) | ||
2063 | } | ||
2064 | |||
2065 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
2066 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
2067 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
2068 | ftextann->setIntent((AnnotFreeText::AnnotFreeTextIntent)intent); | ||
2069 | } | ||
2070 | } | ||
2071 | @@ -2400,8 +2388,8 @@ class LineAnnotationPrivate : public AnnotationPrivate | ||
2072 | { | ||
2073 | public: | ||
2074 | LineAnnotationPrivate(); | ||
2075 | - Annotation *makeAlias() override; | ||
2076 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2077 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2078 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2079 | |||
2080 | // data fields (note uses border for rendering style) | ||
2081 | QLinkedList<QPointF> linePoints; | ||
2082 | @@ -2421,15 +2409,15 @@ LineAnnotationPrivate::LineAnnotationPrivate() | ||
2083 | { | ||
2084 | } | ||
2085 | |||
2086 | -Annotation *LineAnnotationPrivate::makeAlias() | ||
2087 | +std::unique_ptr<Annotation> LineAnnotationPrivate::makeAlias() | ||
2088 | { | ||
2089 | - return new LineAnnotation(*this); | ||
2090 | + return std::unique_ptr<LineAnnotation>(new LineAnnotation(*this)); | ||
2091 | } | ||
2092 | |||
2093 | -Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2094 | +std::shared_ptr<Annot> LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2095 | { | ||
2096 | // Setters are defined in the public class | ||
2097 | - LineAnnotation *q = static_cast<LineAnnotation *>(makeAlias()); | ||
2098 | + std::unique_ptr<LineAnnotation> q = static_pointer_cast<LineAnnotation *>(makeAlias()); | ||
2099 | |||
2100 | // Set page and document | ||
2101 | pdfPage = destPage; | ||
2102 | @@ -2438,9 +2426,9 @@ Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
2103 | // Set pdfAnnot | ||
2104 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2105 | if (lineType == LineAnnotation::StraightLine) { | ||
2106 | - pdfAnnot = new AnnotLine(doc->doc, &rect); | ||
2107 | + pdfAnnot = std::make_shared<AnnotLine>(doc->doc, &rect); | ||
2108 | } else { | ||
2109 | - pdfAnnot = new AnnotPolygon(doc->doc, &rect, lineClosed ? Annot::typePolygon : Annot::typePolyLine); | ||
2110 | + pdfAnnot = std::make_shared<AnnotPolygon>(doc->doc, &rect, lineClosed ? Annot::typePolygon : Annot::typePolyLine); | ||
2111 | } | ||
2112 | |||
2113 | // Set properties | ||
2114 | @@ -2454,8 +2442,6 @@ Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
2115 | q->setLineShowCaption(lineShowCaption); | ||
2116 | q->setLineIntent(lineIntent); | ||
2117 | |||
2118 | - delete q; | ||
2119 | - | ||
2120 | linePoints.clear(); // Free up memory | ||
2121 | |||
2122 | return pdfAnnot; | ||
2123 | @@ -2621,14 +2607,14 @@ QLinkedList<QPointF> LineAnnotation::linePoints() const | ||
2124 | |||
2125 | QLinkedList<QPointF> res; | ||
2126 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2127 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2128 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2129 | QPointF p; | ||
2130 | XPDFReader::transform(MTX, lineann->getX1(), lineann->getY1(), p); | ||
2131 | res.append(p); | ||
2132 | XPDFReader::transform(MTX, lineann->getX2(), lineann->getY2(), p); | ||
2133 | res.append(p); | ||
2134 | } else { | ||
2135 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
2136 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
2137 | const AnnotPath *vertices = polyann->getVertices(); | ||
2138 | |||
2139 | for (int i = 0; i < vertices->getCoordsLength(); ++i) { | ||
2140 | @@ -2645,13 +2631,14 @@ void LineAnnotation::setLinePoints(const QLinkedList<QPointF> &points) | ||
2141 | { | ||
2142 | Q_D(LineAnnotation); | ||
2143 | |||
2144 | + if (!d->pdfAnnot) { | ||
2145 | if (!d->pdfAnnot) { | ||
2146 | d->linePoints = points; | ||
2147 | return; | ||
2148 | } | ||
2149 | |||
2150 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2151 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2152 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2153 | if (points.size() != 2) { | ||
2154 | error(errSyntaxError, -1, "Expected two points for a straight line"); | ||
2155 | return; | ||
2156 | @@ -2663,7 +2650,7 @@ void LineAnnotation::setLinePoints(const QLinkedList<QPointF> &points) | ||
2157 | XPDFReader::invTransform(MTX, points.last(), x2, y2); | ||
2158 | lineann->setVertices(x1, y1, x2, y2); | ||
2159 | } else { | ||
2160 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2161 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2162 | AnnotPath *p = d->toAnnotPath(points); | ||
2163 | polyann->setVertices(p); | ||
2164 | delete p; | ||
2165 | @@ -2679,10 +2666,10 @@ LineAnnotation::TermStyle LineAnnotation::lineStartStyle() const | ||
2166 | } | ||
2167 | |||
2168 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2169 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2170 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2171 | return (LineAnnotation::TermStyle)lineann->getStartStyle(); | ||
2172 | } else { | ||
2173 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
2174 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
2175 | return (LineAnnotation::TermStyle)polyann->getStartStyle(); | ||
2176 | } | ||
2177 | } | ||
2178 | @@ -2697,10 +2684,10 @@ void LineAnnotation::setLineStartStyle(LineAnnotation::TermStyle style) | ||
2179 | } | ||
2180 | |||
2181 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2182 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2183 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2184 | lineann->setStartEndStyle((AnnotLineEndingStyle)style, lineann->getEndStyle()); | ||
2185 | } else { | ||
2186 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2187 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2188 | polyann->setStartEndStyle((AnnotLineEndingStyle)style, polyann->getEndStyle()); | ||
2189 | } | ||
2190 | } | ||
2191 | @@ -2714,10 +2701,10 @@ LineAnnotation::TermStyle LineAnnotation::lineEndStyle() const | ||
2192 | } | ||
2193 | |||
2194 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2195 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2196 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2197 | return (LineAnnotation::TermStyle)lineann->getEndStyle(); | ||
2198 | } else { | ||
2199 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
2200 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
2201 | return (LineAnnotation::TermStyle)polyann->getEndStyle(); | ||
2202 | } | ||
2203 | } | ||
2204 | @@ -2732,10 +2719,10 @@ void LineAnnotation::setLineEndStyle(LineAnnotation::TermStyle style) | ||
2205 | } | ||
2206 | |||
2207 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2208 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2209 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2210 | lineann->setStartEndStyle(lineann->getStartStyle(), (AnnotLineEndingStyle)style); | ||
2211 | } else { | ||
2212 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2213 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2214 | polyann->setStartEndStyle(polyann->getStartStyle(), (AnnotLineEndingStyle)style); | ||
2215 | } | ||
2216 | } | ||
2217 | @@ -2761,7 +2748,7 @@ void LineAnnotation::setLineClosed(bool closed) | ||
2218 | } | ||
2219 | |||
2220 | if (d->pdfAnnot->getType() != Annot::typeLine) { | ||
2221 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2222 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2223 | |||
2224 | // Set new subtype and switch intent if necessary | ||
2225 | if (closed) { | ||
2226 | @@ -2789,10 +2776,10 @@ QColor LineAnnotation::lineInnerColor() const | ||
2227 | AnnotColor *c; | ||
2228 | |||
2229 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2230 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2231 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2232 | c = lineann->getInteriorColor(); | ||
2233 | } else { | ||
2234 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
2235 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
2236 | c = polyann->getInteriorColor(); | ||
2237 | } | ||
2238 | |||
2239 | @@ -2811,10 +2798,10 @@ void LineAnnotation::setLineInnerColor(const QColor &color) | ||
2240 | auto c = convertQColor(color); | ||
2241 | |||
2242 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2243 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2244 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2245 | lineann->setInteriorColor(std::move(c)); | ||
2246 | } else { | ||
2247 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2248 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2249 | polyann->setInteriorColor(std::move(c)); | ||
2250 | } | ||
2251 | } | ||
2252 | @@ -2828,7 +2815,7 @@ double LineAnnotation::lineLeadingForwardPoint() const | ||
2253 | } | ||
2254 | |||
2255 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2256 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2257 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2258 | return lineann->getLeaderLineLength(); | ||
2259 | } | ||
2260 | |||
2261 | @@ -2845,7 +2832,7 @@ void LineAnnotation::setLineLeadingForwardPoint(double point) | ||
2262 | } | ||
2263 | |||
2264 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2265 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2266 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2267 | lineann->setLeaderLineLength(point); | ||
2268 | } | ||
2269 | } | ||
2270 | @@ -2859,7 +2846,7 @@ double LineAnnotation::lineLeadingBackPoint() const | ||
2271 | } | ||
2272 | |||
2273 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2274 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2275 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2276 | return lineann->getLeaderLineExtension(); | ||
2277 | } | ||
2278 | |||
2279 | @@ -2876,7 +2863,7 @@ void LineAnnotation::setLineLeadingBackPoint(double point) | ||
2280 | } | ||
2281 | |||
2282 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2283 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2284 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2285 | lineann->setLeaderLineExtension(point); | ||
2286 | } | ||
2287 | } | ||
2288 | @@ -2890,7 +2877,7 @@ bool LineAnnotation::lineShowCaption() const | ||
2289 | } | ||
2290 | |||
2291 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2292 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2293 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2294 | return lineann->getCaption(); | ||
2295 | } | ||
2296 | |||
2297 | @@ -2907,7 +2894,7 @@ void LineAnnotation::setLineShowCaption(bool show) | ||
2298 | } | ||
2299 | |||
2300 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2301 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2302 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2303 | lineann->setCaption(show); | ||
2304 | } | ||
2305 | } | ||
2306 | @@ -2921,10 +2908,10 @@ LineAnnotation::LineIntent LineAnnotation::lineIntent() const | ||
2307 | } | ||
2308 | |||
2309 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2310 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
2311 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
2312 | return (LineAnnotation::LineIntent)(lineann->getIntent() + 1); | ||
2313 | } else { | ||
2314 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
2315 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
2316 | if (polyann->getIntent() == AnnotPolygon::polygonCloud) { | ||
2317 | return LineAnnotation::PolygonCloud; | ||
2318 | } else { // AnnotPolygon::polylineDimension, AnnotPolygon::polygonDimension | ||
2319 | @@ -2947,10 +2934,10 @@ void LineAnnotation::setLineIntent(LineAnnotation::LineIntent intent) | ||
2320 | } | ||
2321 | |||
2322 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
2323 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
2324 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
2325 | lineann->setIntent((AnnotLine::AnnotLineIntent)(intent - 1)); | ||
2326 | } else { | ||
2327 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
2328 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
2329 | if (intent == LineAnnotation::PolygonCloud) { | ||
2330 | polyann->setIntent(AnnotPolygon::polygonCloud); | ||
2331 | } else // LineAnnotation::Dimension | ||
2332 | @@ -2969,8 +2956,8 @@ class GeomAnnotationPrivate : public AnnotationPrivate | ||
2333 | { | ||
2334 | public: | ||
2335 | GeomAnnotationPrivate(); | ||
2336 | - Annotation *makeAlias() override; | ||
2337 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2338 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2339 | + std::unique_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2340 | |||
2341 | // data fields (note uses border for rendering style) | ||
2342 | GeomAnnotation::GeomType geomType; | ||
2343 | @@ -2979,15 +2966,15 @@ public: | ||
2344 | |||
2345 | GeomAnnotationPrivate::GeomAnnotationPrivate() : AnnotationPrivate(), geomType(GeomAnnotation::InscribedSquare) { } | ||
2346 | |||
2347 | -Annotation *GeomAnnotationPrivate::makeAlias() | ||
2348 | +std::unique_ptr<Annotation> GeomAnnotationPrivate::makeAlias() | ||
2349 | { | ||
2350 | - return new GeomAnnotation(*this); | ||
2351 | + return std::unique_ptr<GeomAnnotation>(new GeomAnnotation(*this)); | ||
2352 | } | ||
2353 | |||
2354 | -Annot *GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2355 | +std::shared_ptr<Annot> GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2356 | { | ||
2357 | // Setters are defined in the public class | ||
2358 | - GeomAnnotation *q = static_cast<GeomAnnotation *>(makeAlias()); | ||
2359 | + std::unique_ptr<GeomAnnotation> q = static_pointer_cast<GeomAnnotation *>(makeAlias()); | ||
2360 | |||
2361 | // Set page and document | ||
2362 | pdfPage = destPage; | ||
2363 | @@ -3002,13 +2989,12 @@ Annot *GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
2364 | |||
2365 | // Set pdfAnnot | ||
2366 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2367 | - pdfAnnot = new AnnotGeometry(destPage->getDoc(), &rect, type); | ||
2368 | + pdfAnnot = std::make_shared<AnnotGeometry>(destPage->getDoc(), &rect, type); | ||
2369 | |||
2370 | // Set properties | ||
2371 | flushBaseAnnotationProperties(); | ||
2372 | q->setGeomInnerColor(geomInnerColor); | ||
2373 | |||
2374 | - delete q; | ||
2375 | return pdfAnnot; | ||
2376 | } | ||
2377 | |||
2378 | @@ -3089,7 +3075,7 @@ void GeomAnnotation::setGeomType(GeomAnnotation::GeomType type) | ||
2379 | return; | ||
2380 | } | ||
2381 | |||
2382 | - AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot); | ||
2383 | + AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get()); | ||
2384 | if (type == GeomAnnotation::InscribedSquare) { | ||
2385 | geomann->setType(Annot::typeSquare); | ||
2386 | } else { // GeomAnnotation::InscribedCircle | ||
2387 | @@ -3105,7 +3091,7 @@ QColor GeomAnnotation::geomInnerColor() const | ||
2388 | return d->geomInnerColor; | ||
2389 | } | ||
2390 | |||
2391 | - const AnnotGeometry *geomann = static_cast<const AnnotGeometry *>(d->pdfAnnot); | ||
2392 | + const AnnotGeometry *geomann = static_cast<const AnnotGeometry *>(d->pdfAnnot.get()); | ||
2393 | return convertAnnotColor(geomann->getInteriorColor()); | ||
2394 | } | ||
2395 | |||
2396 | @@ -3118,7 +3104,7 @@ void GeomAnnotation::setGeomInnerColor(const QColor &color) | ||
2397 | return; | ||
2398 | } | ||
2399 | |||
2400 | - AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot); | ||
2401 | + AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get()); | ||
2402 | geomann->setInteriorColor(convertQColor(color)); | ||
2403 | } | ||
2404 | |||
2405 | @@ -3127,8 +3113,8 @@ class HighlightAnnotationPrivate : public AnnotationPrivate | ||
2406 | { | ||
2407 | public: | ||
2408 | HighlightAnnotationPrivate(); | ||
2409 | - Annotation *makeAlias() override; | ||
2410 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2411 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2412 | + std::shared_ptr<Annot> *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2413 | |||
2414 | // data fields | ||
2415 | HighlightAnnotation::HighlightType highlightType; | ||
2416 | @@ -3142,9 +3128,9 @@ public: | ||
2417 | |||
2418 | HighlightAnnotationPrivate::HighlightAnnotationPrivate() : AnnotationPrivate(), highlightType(HighlightAnnotation::Highlight) { } | ||
2419 | |||
2420 | -Annotation *HighlightAnnotationPrivate::makeAlias() | ||
2421 | +std::unique_ptr<Annotation> HighlightAnnotationPrivate::makeAlias() | ||
2422 | { | ||
2423 | - return new HighlightAnnotation(*this); | ||
2424 | + return std::unique_ptr<HighlightAnnotation>(new HighlightAnnotation(*this)); | ||
2425 | } | ||
2426 | |||
2427 | Annot::AnnotSubtype HighlightAnnotationPrivate::toAnnotSubType(HighlightAnnotation::HighlightType type) | ||
2428 | @@ -3217,10 +3203,10 @@ AnnotQuadrilaterals *HighlightAnnotationPrivate::toQuadrilaterals(const QList<Hi | ||
2429 | return new AnnotQuadrilaterals(std::move(ac), count); | ||
2430 | } | ||
2431 | |||
2432 | -Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2433 | +std::shared_ptr<Annot> HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2434 | { | ||
2435 | // Setters are defined in the public class | ||
2436 | - HighlightAnnotation *q = static_cast<HighlightAnnotation *>(makeAlias()); | ||
2437 | + std::unique_ptr<HighlightAnnotation> q = static_pointer_cast<HighlightAnnotation *>(makeAlias()); | ||
2438 | |||
2439 | // Set page and document | ||
2440 | pdfPage = destPage; | ||
2441 | @@ -3228,7 +3214,7 @@ Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentD | ||
2442 | |||
2443 | // Set pdfAnnot | ||
2444 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2445 | - pdfAnnot = new AnnotTextMarkup(destPage->getDoc(), &rect, toAnnotSubType(highlightType)); | ||
2446 | + pdfAnnot = std::make_shared<AnnotTextMarkup>(destPage->getDoc(), &rect, toAnnotSubType(highlightType)); | ||
2447 | |||
2448 | // Set properties | ||
2449 | flushBaseAnnotationProperties(); | ||
2450 | @@ -3236,8 +3222,6 @@ Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentD | ||
2451 | |||
2452 | highlightQuads.clear(); // Free up memory | ||
2453 | |||
2454 | - delete q; | ||
2455 | - | ||
2456 | return pdfAnnot; | ||
2457 | } | ||
2458 | |||
2459 | @@ -3370,7 +3354,7 @@ void HighlightAnnotation::setHighlightType(HighlightAnnotation::HighlightType ty | ||
2460 | return; | ||
2461 | } | ||
2462 | |||
2463 | - AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
2464 | + AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
2465 | hlann->setType(HighlightAnnotationPrivate::toAnnotSubType(type)); | ||
2466 | } | ||
2467 | |||
2468 | @@ -3382,7 +3366,7 @@ QList<HighlightAnnotation::Quad> HighlightAnnotation::highlightQuads() const | ||
2469 | return d->highlightQuads; | ||
2470 | } | ||
2471 | |||
2472 | - const AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
2473 | + const AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
2474 | return d->fromQuadrilaterals(hlann->getQuadrilaterals()); | ||
2475 | } | ||
2476 | |||
2477 | @@ -3395,7 +3379,7 @@ void HighlightAnnotation::setHighlightQuads(const QList<HighlightAnnotation::Qua | ||
2478 | return; | ||
2479 | } | ||
2480 | |||
2481 | - AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
2482 | + AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
2483 | AnnotQuadrilaterals *quadrilaterals = d->toQuadrilaterals(quads); | ||
2484 | hlann->setQuadrilaterals(quadrilaterals); | ||
2485 | delete quadrilaterals; | ||
2486 | @@ -3406,10 +3390,10 @@ class StampAnnotationPrivate : public AnnotationPrivate | ||
2487 | { | ||
2488 | public: | ||
2489 | StampAnnotationPrivate(); | ||
2490 | - Annotation *makeAlias() override; | ||
2491 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2492 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2493 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2494 | |||
2495 | - AnnotStampImageHelper *convertQImageToAnnotStampImageHelper(const QImage &qimg); | ||
2496 | + std::unique_ptr<AnnotStampImageHelper> convertQImageToAnnotStampImageHelper(const QImage &qimg); | ||
2497 | |||
2498 | // data fields | ||
2499 | QString stampIconName; | ||
2500 | @@ -3418,14 +3402,14 @@ public: | ||
2501 | |||
2502 | StampAnnotationPrivate::StampAnnotationPrivate() : AnnotationPrivate(), stampIconName(QStringLiteral("Draft")) { } | ||
2503 | |||
2504 | -Annotation *StampAnnotationPrivate::makeAlias() | ||
2505 | +std::unique_ptr<Annotation> StampAnnotationPrivate::makeAlias() | ||
2506 | { | ||
2507 | - return new StampAnnotation(*this); | ||
2508 | + return std::unique_ptr<StampAnnotation>(new StampAnnotation(*this)); | ||
2509 | } | ||
2510 | |||
2511 | -Annot *StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2512 | +std::shared_ptr<Annot> StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2513 | { | ||
2514 | - StampAnnotation *q = static_cast<StampAnnotation *>(makeAlias()); | ||
2515 | + std::unique_ptr<StampAnnotation> q = static_pointer_cast<StampAnnotation *>(makeAlias()); | ||
2516 | |||
2517 | // Set page and document | ||
2518 | pdfPage = destPage; | ||
2519 | @@ -3433,21 +3417,19 @@ Annot *StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData | ||
2520 | |||
2521 | // Set pdfAnnot | ||
2522 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2523 | - pdfAnnot = new AnnotStamp(destPage->getDoc(), &rect); | ||
2524 | + pdfAnnot = std::make_shared<AnnotStamp>(destPage->getDoc(), &rect); | ||
2525 | |||
2526 | // Set properties | ||
2527 | flushBaseAnnotationProperties(); | ||
2528 | q->setStampIconName(stampIconName); | ||
2529 | q->setStampCustomImage(stampCustomImage); | ||
2530 | |||
2531 | - delete q; | ||
2532 | - | ||
2533 | stampIconName.clear(); // Free up memory | ||
2534 | |||
2535 | return pdfAnnot; | ||
2536 | } | ||
2537 | |||
2538 | -AnnotStampImageHelper *StampAnnotationPrivate::convertQImageToAnnotStampImageHelper(const QImage &qimg) | ||
2539 | +std::unique_ptr<AnnotStampImageHelper> StampAnnotationPrivate::convertQImageToAnnotStampImageHelper(const QImage &qimg) | ||
2540 | { | ||
2541 | QImage convertedQImage = qimg; | ||
2542 | |||
2543 | @@ -3528,13 +3510,13 @@ AnnotStampImageHelper *StampAnnotationPrivate::convertQImageToAnnotStampImageHel | ||
2544 | |||
2545 | getRawDataFromQImage(convertedQImage, convertedQImage.depth(), &data, &sMaskData); | ||
2546 | |||
2547 | - AnnotStampImageHelper *annotImg; | ||
2548 | + std::unique_ptr<AnnotStampImageHelper> annotImg; | ||
2549 | |||
2550 | if (sMaskData.count() > 0) { | ||
2551 | AnnotStampImageHelper sMask(parentDoc->doc, width, height, ColorSpace::DeviceGray, 8, sMaskData.data(), sMaskData.count()); | ||
2552 | - annotImg = new AnnotStampImageHelper(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.count(), sMask.getRef()); | ||
2553 | + annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.count(), sMask.getRef()); | ||
2554 | } else { | ||
2555 | - annotImg = new AnnotStampImageHelper(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.count()); | ||
2556 | + annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.count()); | ||
2557 | } | ||
2558 | |||
2559 | return annotImg; | ||
2560 | @@ -3595,7 +3577,7 @@ QString StampAnnotation::stampIconName() const | ||
2561 | return d->stampIconName; | ||
2562 | } | ||
2563 | |||
2564 | - const AnnotStamp *stampann = static_cast<const AnnotStamp *>(d->pdfAnnot); | ||
2565 | + const AnnotStamp *stampann = static_cast<const AnnotStamp *>(d->pdfAnnot.get()); | ||
2566 | return QString::fromLatin1(stampann->getIcon()->c_str()); | ||
2567 | } | ||
2568 | |||
2569 | @@ -3608,7 +3590,7 @@ void StampAnnotation::setStampIconName(const QString &name) | ||
2570 | return; | ||
2571 | } | ||
2572 | |||
2573 | - AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot); | ||
2574 | + AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get()); | ||
2575 | QByteArray encoded = name.toLatin1(); | ||
2576 | GooString s(encoded.constData()); | ||
2577 | stampann->setIcon(&s); | ||
2578 | @@ -3627,9 +3609,9 @@ void StampAnnotation::setStampCustomImage(const QImage &image) | ||
2579 | return; | ||
2580 | } | ||
2581 | |||
2582 | - AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot); | ||
2583 | - AnnotStampImageHelper *annotCustomImage = d->convertQImageToAnnotStampImageHelper(image); | ||
2584 | - stampann->setCustomImage(annotCustomImage); | ||
2585 | + AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get()); | ||
2586 | + std::unique_ptr<AnnotStampImageHelper> annotCustomImage = d->convertQImageToAnnotStampImageHelper(image); | ||
2587 | + stampann->setCustomImage(std::move(annotCustomImage)); | ||
2588 | } | ||
2589 | |||
2590 | /** InkAnnotation [Annotation] */ | ||
2591 | @@ -3637,8 +3619,8 @@ class InkAnnotationPrivate : public AnnotationPrivate | ||
2592 | { | ||
2593 | public: | ||
2594 | InkAnnotationPrivate(); | ||
2595 | - Annotation *makeAlias() override; | ||
2596 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2597 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2598 | + std::shared_ptr<Annot> *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2599 | |||
2600 | // data fields | ||
2601 | QList<QLinkedList<QPointF>> inkPaths; | ||
2602 | @@ -3649,9 +3631,9 @@ public: | ||
2603 | |||
2604 | InkAnnotationPrivate::InkAnnotationPrivate() : AnnotationPrivate() { } | ||
2605 | |||
2606 | -Annotation *InkAnnotationPrivate::makeAlias() | ||
2607 | +std::unique_ptr<Annotation> *InkAnnotationPrivate::makeAlias() | ||
2608 | { | ||
2609 | - return new InkAnnotation(*this); | ||
2610 | + return std::unique_ptr<InkAnnotation>(new InkAnnotation(*this)); | ||
2611 | } | ||
2612 | |||
2613 | // Note: Caller is required to delete array elements and the array itself after use | ||
2614 | @@ -3665,10 +3647,10 @@ AnnotPath **InkAnnotationPrivate::toAnnotPaths(const QList<QLinkedList<QPointF>> | ||
2615 | return res; | ||
2616 | } | ||
2617 | |||
2618 | -Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2619 | +std::shared_ptr<Annot> *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2620 | { | ||
2621 | // Setters are defined in the public class | ||
2622 | - InkAnnotation *q = static_cast<InkAnnotation *>(makeAlias()); | ||
2623 | + std::shared_ptr<InkAnnotation> q = static_pointer_cast<InkAnnotation *>(makeAlias()); | ||
2624 | |||
2625 | // Set page and document | ||
2626 | pdfPage = destPage; | ||
2627 | @@ -3676,7 +3658,7 @@ Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *d | ||
2628 | |||
2629 | // Set pdfAnnot | ||
2630 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2631 | - pdfAnnot = new AnnotInk(destPage->getDoc(), &rect); | ||
2632 | + pdfAnnot = std::make_shared<AnnotInk>(destPage->getDoc(), &rect); | ||
2633 | |||
2634 | // Set properties | ||
2635 | flushBaseAnnotationProperties(); | ||
2636 | @@ -3684,8 +3666,6 @@ Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *d | ||
2637 | |||
2638 | inkPaths.clear(); // Free up memory | ||
2639 | |||
2640 | - delete q; | ||
2641 | - | ||
2642 | return pdfAnnot; | ||
2643 | } | ||
2644 | |||
2645 | @@ -3787,7 +3767,7 @@ QList<QLinkedList<QPointF>> InkAnnotation::inkPaths() const | ||
2646 | return d->inkPaths; | ||
2647 | } | ||
2648 | |||
2649 | - const AnnotInk *inkann = static_cast<const AnnotInk *>(d->pdfAnnot); | ||
2650 | + const AnnotInk *inkann = static_cast<const AnnotInk *>(d->pdfAnnot.get()); | ||
2651 | |||
2652 | const AnnotPath *const *paths = inkann->getInkList(); | ||
2653 | if (!paths || !inkann->getInkListLength()) { | ||
2654 | @@ -3825,7 +3805,7 @@ void InkAnnotation::setInkPaths(const QList<QLinkedList<QPointF>> &paths) | ||
2655 | return; | ||
2656 | } | ||
2657 | |||
2658 | - AnnotInk *inkann = static_cast<AnnotInk *>(d->pdfAnnot); | ||
2659 | + AnnotInk *inkann = static_cast<AnnotInk *>(d->pdfAnnot.get()); | ||
2660 | AnnotPath **annotpaths = d->toAnnotPaths(paths); | ||
2661 | const int pathsNumber = paths.size(); | ||
2662 | inkann->setInkList(annotpaths, pathsNumber); | ||
2663 | @@ -3842,8 +3822,8 @@ class LinkAnnotationPrivate : public AnnotationPrivate | ||
2664 | public: | ||
2665 | LinkAnnotationPrivate(); | ||
2666 | ~LinkAnnotationPrivate() override; | ||
2667 | - Annotation *makeAlias() override; | ||
2668 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2669 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2670 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2671 | |||
2672 | // data fields | ||
2673 | Link *linkDestination; | ||
2674 | @@ -3858,12 +3838,12 @@ LinkAnnotationPrivate::~LinkAnnotationPrivate() | ||
2675 | delete linkDestination; | ||
2676 | } | ||
2677 | |||
2678 | -Annotation *LinkAnnotationPrivate::makeAlias() | ||
2679 | +std::unique_ptr<Annotation> LinkAnnotationPrivate::makeAlias() | ||
2680 | { | ||
2681 | - return new LinkAnnotation(*this); | ||
2682 | + return std::unique_ptr<LinkAnnotation>(new LinkAnnotation(*this)); | ||
2683 | } | ||
2684 | |||
2685 | -Annot *LinkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2686 | +std::shared_ptr<Annot> LinkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2687 | { | ||
2688 | return nullptr; // Not implemented | ||
2689 | } | ||
2690 | @@ -4144,8 +4124,8 @@ class CaretAnnotationPrivate : public AnnotationPrivate | ||
2691 | { | ||
2692 | public: | ||
2693 | CaretAnnotationPrivate(); | ||
2694 | - Annotation *makeAlias() override; | ||
2695 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2696 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2697 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2698 | |||
2699 | // data fields | ||
2700 | CaretAnnotation::CaretSymbol symbol; | ||
2701 | @@ -4174,15 +4154,15 @@ static CaretAnnotation::CaretSymbol caretSymbolFromString(const QString &symbol) | ||
2702 | |||
2703 | CaretAnnotationPrivate::CaretAnnotationPrivate() : AnnotationPrivate(), symbol(CaretAnnotation::None) { } | ||
2704 | |||
2705 | -Annotation *CaretAnnotationPrivate::makeAlias() | ||
2706 | +std::unique_ptr<Annotation> CaretAnnotationPrivate::makeAlias() | ||
2707 | { | ||
2708 | - return new CaretAnnotation(*this); | ||
2709 | + return std::unique_ptr<CaretAnnotation>(new CaretAnnotation(*this)); | ||
2710 | } | ||
2711 | |||
2712 | -Annot *CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2713 | +std::shared_ptr<Annot> CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2714 | { | ||
2715 | // Setters are defined in the public class | ||
2716 | - CaretAnnotation *q = static_cast<CaretAnnotation *>(makeAlias()); | ||
2717 | + std::unique_ptr<CaretAnnotation> q = static_pointer_cast<CaretAnnotation *>(makeAlias()); | ||
2718 | |||
2719 | // Set page and document | ||
2720 | pdfPage = destPage; | ||
2721 | @@ -4190,13 +4170,12 @@ Annot *CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData | ||
2722 | |||
2723 | // Set pdfAnnot | ||
2724 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
2725 | - pdfAnnot = new AnnotCaret(destPage->getDoc(), &rect); | ||
2726 | + pdfAnnot = std::make_shared<AnnotCaret>(destPage->getDoc(), &rect); | ||
2727 | |||
2728 | // Set properties | ||
2729 | flushBaseAnnotationProperties(); | ||
2730 | q->setCaretSymbol(symbol); | ||
2731 | |||
2732 | - delete q; | ||
2733 | return pdfAnnot; | ||
2734 | } | ||
2735 | |||
2736 | @@ -4255,7 +4234,7 @@ CaretAnnotation::CaretSymbol CaretAnnotation::caretSymbol() const | ||
2737 | return d->symbol; | ||
2738 | } | ||
2739 | |||
2740 | - const AnnotCaret *caretann = static_cast<const AnnotCaret *>(d->pdfAnnot); | ||
2741 | + const AnnotCaret *caretann = static_cast<const AnnotCaret *>(d->pdfAnnot.get()); | ||
2742 | return (CaretAnnotation::CaretSymbol)caretann->getSymbol(); | ||
2743 | } | ||
2744 | |||
2745 | @@ -4268,7 +4247,7 @@ void CaretAnnotation::setCaretSymbol(CaretAnnotation::CaretSymbol symbol) | ||
2746 | return; | ||
2747 | } | ||
2748 | |||
2749 | - AnnotCaret *caretann = static_cast<AnnotCaret *>(d->pdfAnnot); | ||
2750 | + AnnotCaret *caretann = static_cast<AnnotCaret *>(d->pdfAnnot.get()); | ||
2751 | caretann->setSymbol((AnnotCaret::AnnotCaretSymbol)symbol); | ||
2752 | } | ||
2753 | |||
2754 | @@ -4278,8 +4257,8 @@ class FileAttachmentAnnotationPrivate : public AnnotationPrivate | ||
2755 | public: | ||
2756 | FileAttachmentAnnotationPrivate(); | ||
2757 | ~FileAttachmentAnnotationPrivate() override; | ||
2758 | - Annotation *makeAlias() override; | ||
2759 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2760 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2761 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2762 | |||
2763 | // data fields | ||
2764 | QString icon; | ||
2765 | @@ -4293,12 +4272,12 @@ FileAttachmentAnnotationPrivate::~FileAttachmentAnnotationPrivate() | ||
2766 | delete embfile; | ||
2767 | } | ||
2768 | |||
2769 | -Annotation *FileAttachmentAnnotationPrivate::makeAlias() | ||
2770 | +std::unique_ptr<Annotation> FileAttachmentAnnotationPrivate::makeAlias() | ||
2771 | { | ||
2772 | - return new FileAttachmentAnnotation(*this); | ||
2773 | + return std::unique_ptr<FileAttachmentAnnotation>(new FileAttachmentAnnotation(*this)); | ||
2774 | } | ||
2775 | |||
2776 | -Annot *FileAttachmentAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2777 | +std::shared_ptr<Annot> *FileAttachmentAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2778 | { | ||
2779 | return nullptr; // Not implemented | ||
2780 | } | ||
2781 | @@ -4370,8 +4349,8 @@ class SoundAnnotationPrivate : public AnnotationPrivate | ||
2782 | public: | ||
2783 | SoundAnnotationPrivate(); | ||
2784 | ~SoundAnnotationPrivate() override; | ||
2785 | - Annotation *makeAlias() override; | ||
2786 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2787 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2788 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2789 | |||
2790 | // data fields | ||
2791 | QString icon; | ||
2792 | @@ -4385,12 +4364,12 @@ SoundAnnotationPrivate::~SoundAnnotationPrivate() | ||
2793 | delete sound; | ||
2794 | } | ||
2795 | |||
2796 | -Annotation *SoundAnnotationPrivate::makeAlias() | ||
2797 | +std::unique_ptr<Annotation> SoundAnnotationPrivate::makeAlias() | ||
2798 | { | ||
2799 | - return new SoundAnnotation(*this); | ||
2800 | + return std::unique_ptr<SoundAnnotation>(new SoundAnnotation(*this)); | ||
2801 | } | ||
2802 | |||
2803 | -Annot *SoundAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2804 | +std::shared_ptr<Annot> SoundAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2805 | { | ||
2806 | return nullptr; // Not implemented | ||
2807 | } | ||
2808 | @@ -4462,8 +4441,8 @@ class MovieAnnotationPrivate : public AnnotationPrivate | ||
2809 | public: | ||
2810 | MovieAnnotationPrivate(); | ||
2811 | ~MovieAnnotationPrivate() override; | ||
2812 | - Annotation *makeAlias() override; | ||
2813 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2814 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2815 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2816 | |||
2817 | // data fields | ||
2818 | MovieObject *movie; | ||
2819 | @@ -4477,12 +4456,12 @@ MovieAnnotationPrivate::~MovieAnnotationPrivate() | ||
2820 | delete movie; | ||
2821 | } | ||
2822 | |||
2823 | -Annotation *MovieAnnotationPrivate::makeAlias() | ||
2824 | +std::unique_ptr<Annotation> MovieAnnotationPrivate::makeAlias() | ||
2825 | { | ||
2826 | - return new MovieAnnotation(*this); | ||
2827 | + return std::unique_ptr<Annotation>(new MovieAnnotation(*this)); | ||
2828 | } | ||
2829 | |||
2830 | -Annot *MovieAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2831 | +std::shared_ptr<Annot> MovieAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2832 | { | ||
2833 | return nullptr; // Not implemented | ||
2834 | } | ||
2835 | @@ -4554,8 +4533,8 @@ class ScreenAnnotationPrivate : public AnnotationPrivate | ||
2836 | public: | ||
2837 | ScreenAnnotationPrivate(); | ||
2838 | ~ScreenAnnotationPrivate() override; | ||
2839 | - Annotation *makeAlias() override; | ||
2840 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2841 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2842 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2843 | |||
2844 | // data fields | ||
2845 | LinkRendition *action; | ||
2846 | @@ -4571,12 +4550,12 @@ ScreenAnnotationPrivate::~ScreenAnnotationPrivate() | ||
2847 | |||
2848 | ScreenAnnotation::ScreenAnnotation(ScreenAnnotationPrivate &dd) : Annotation(dd) { } | ||
2849 | |||
2850 | -Annotation *ScreenAnnotationPrivate::makeAlias() | ||
2851 | +std::unique_ptr<Annotation> ScreenAnnotationPrivate::makeAlias() | ||
2852 | { | ||
2853 | - return new ScreenAnnotation(*this); | ||
2854 | + return std::unique_ptr<ScreenAnnotation>(new ScreenAnnotation(*this)); | ||
2855 | } | ||
2856 | |||
2857 | -Annot *ScreenAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2858 | +std::shared_ptr<Annot> ScreenAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2859 | { | ||
2860 | return nullptr; // Not implemented | ||
2861 | } | ||
2862 | @@ -4634,16 +4613,16 @@ Link *ScreenAnnotation::additionalAction(AdditionalActionType type) const | ||
2863 | class WidgetAnnotationPrivate : public AnnotationPrivate | ||
2864 | { | ||
2865 | public: | ||
2866 | - Annotation *makeAlias() override; | ||
2867 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2868 | + std::unique_ptr<Annotation> makeAlias() override; | ||
2869 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
2870 | }; | ||
2871 | |||
2872 | -Annotation *WidgetAnnotationPrivate::makeAlias() | ||
2873 | +std::unique_ptr<Annotation> WidgetAnnotationPrivate::makeAlias() | ||
2874 | { | ||
2875 | - return new WidgetAnnotation(*this); | ||
2876 | + return std::unique_ptr<WidgetAnnotation>(new WidgetAnnotation(*this)); | ||
2877 | } | ||
2878 | |||
2879 | -Annot *WidgetAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2880 | +std::shared_ptr<Annot> WidgetAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
2881 | { | ||
2882 | return nullptr; // Not implemented | ||
2883 | } | ||
2884 | @@ -4967,9 +4946,9 @@ public: | ||
2885 | |||
2886 | ~RichMediaAnnotationPrivate() override; | ||
2887 | |||
2888 | - Annotation *makeAlias() override { return new RichMediaAnnotation(*this); } | ||
2889 | + std::unique_ptr<Annotation> makeAlias() override { return std::unique_ptr<RichMediaAnnotation>(new RichMediaAnnotation(*this)); } | ||
2890 | |||
2891 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override | ||
2892 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override | ||
2893 | { | ||
2894 | Q_UNUSED(destPage); | ||
2895 | Q_UNUSED(doc); | ||
2896 | diff --git a/qt5/src/poppler-form.cc b/qt5/src/poppler-form.cc | ||
2897 | index dfdcd39..760a891 100644 | ||
2898 | --- a/qt5/src/poppler-form.cc | ||
2899 | +++ b/qt5/src/poppler-form.cc | ||
2900 | @@ -269,7 +269,7 @@ Link *FormField::additionalAction(AdditionalActionType type) const | ||
2901 | |||
2902 | Link *FormField::additionalAction(Annotation::AdditionalActionType type) const | ||
2903 | { | ||
2904 | - ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation(); | ||
2905 | + std::shared_ptr<AnnotWidget> w = m_formData->fm->getWidgetAnnotation(); | ||
2906 | if (!w) { | ||
2907 | return nullptr; | ||
2908 | } | ||
2909 | @@ -350,7 +350,7 @@ void FormFieldButton::setIcon(const FormFieldIcon &icon) | ||
2910 | |||
2911 | FormWidgetButton *fwb = static_cast<FormWidgetButton *>(m_formData->fm); | ||
2912 | if (fwb->getButtonType() == formButtonPush) { | ||
2913 | - ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation(); | ||
2914 | + ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation().get(); | ||
2915 | FormFieldIconData *data = FormFieldIconData::getData(icon); | ||
2916 | if (data->icon != nullptr) { | ||
2917 | w->setNewAppearance(data->icon->lookup("AP")); | ||
2918 | diff --git a/qt6/src/poppler-annotation-private.h b/qt6/src/poppler-annotation-private.h | ||
2919 | index 35e2676..11cda48 100644 | ||
2920 | --- a/qt6/src/poppler-annotation-private.h | ||
2921 | +++ b/qt6/src/poppler-annotation-private.h | ||
2922 | @@ -59,7 +59,7 @@ public: | ||
2923 | |||
2924 | /* Returns an Annotation of the right subclass whose d_ptr points to | ||
2925 | * this AnnotationPrivate */ | ||
2926 | - virtual Annotation *makeAlias() = 0; | ||
2927 | + virtual std::unique_ptr<Annotation> makeAlias() = 0; | ||
2928 | |||
2929 | /* properties: contents related */ | ||
2930 | QString author; | ||
2931 | @@ -79,18 +79,18 @@ public: | ||
2932 | /* revisions */ | ||
2933 | Annotation::RevScope revisionScope; | ||
2934 | Annotation::RevType revisionType; | ||
2935 | - QList<Annotation *> revisions; | ||
2936 | + std::vector<std::unique_ptr<Annotation>> revisions; | ||
2937 | |||
2938 | /* After this call, the Annotation object will behave like a wrapper for | ||
2939 | * the specified Annot object. All cached values are discarded */ | ||
2940 | - void tieToNativeAnnot(Annot *ann, ::Page *page, DocumentData *doc); | ||
2941 | + void tieToNativeAnnot(std::shared_ptr<Annot> ann, ::Page *page, DocumentData *doc); | ||
2942 | |||
2943 | /* Creates a new Annot object on the specified page, flushes current | ||
2944 | * values to that object and ties this Annotation to that object */ | ||
2945 | - virtual Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) = 0; | ||
2946 | + virtual std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) = 0; | ||
2947 | |||
2948 | /* Inited to 0 (i.e. untied annotation) */ | ||
2949 | - Annot *pdfAnnot; | ||
2950 | + std::shared_ptr<Annot> pdfAnnot; | ||
2951 | ::Page *pdfPage; | ||
2952 | DocumentData *parentDoc; | ||
2953 | |||
2954 | diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc | ||
2955 | index 1a3c813..c1fcdb6 100644 | ||
2956 | --- a/qt6/src/poppler-annotation.cc | ||
2957 | +++ b/qt6/src/poppler-annotation.cc | ||
2958 | @@ -57,6 +57,12 @@ | ||
2959 | #include <Link.h> | ||
2960 | #include <DateInfo.h> | ||
2961 | |||
2962 | +template<typename T, typename U> | ||
2963 | +static std::unique_ptr<T> static_pointer_cast(std::unique_ptr<U> &&in) | ||
2964 | +{ | ||
2965 | + return std::unique_ptr<T>(static_cast<std::add_pointer_t<T>>(in.release())); | ||
2966 | +} | ||
2967 | + | ||
2968 | /* Almost all getters directly query the underlying poppler annotation, with | ||
2969 | * the exceptions of link, file attachment, sound, movie and screen annotations, | ||
2970 | * Whose data retrieval logic has not been moved yet. Their getters return | ||
2971 | @@ -129,36 +135,25 @@ void getRawDataFromQImage(const QImage &qimg, int bitsPerPixel, QByteArray *data | ||
2972 | void AnnotationPrivate::addRevision(Annotation *ann, Annotation::RevScope scope, Annotation::RevType type) | ||
2973 | { | ||
2974 | /* Since ownership stays with the caller, create an alias of ann */ | ||
2975 | - revisions.append(ann->d_ptr->makeAlias()); | ||
2976 | + revisions.push_back(ann->d_ptr->makeAlias()); | ||
2977 | |||
2978 | /* Set revision properties */ | ||
2979 | revisionScope = scope; | ||
2980 | revisionType = type; | ||
2981 | } | ||
2982 | |||
2983 | -AnnotationPrivate::~AnnotationPrivate() | ||
2984 | -{ | ||
2985 | - // Delete all children revisions | ||
2986 | - qDeleteAll(revisions); | ||
2987 | - | ||
2988 | - // Release Annot object | ||
2989 | - if (pdfAnnot) { | ||
2990 | - pdfAnnot->decRefCnt(); | ||
2991 | - } | ||
2992 | -} | ||
2993 | +AnnotationPrivate::~AnnotationPrivate() = default; | ||
2994 | |||
2995 | -void AnnotationPrivate::tieToNativeAnnot(Annot *ann, ::Page *page, Poppler::DocumentData *doc) | ||
2996 | +void AnnotationPrivate::tieToNativeAnnot(std::shared_ptr<Annot> ann, ::Page *page, Poppler::DocumentData *doc) | ||
2997 | { | ||
2998 | if (pdfAnnot) { | ||
2999 | error(errIO, -1, "Annotation is already tied"); | ||
3000 | return; | ||
3001 | } | ||
3002 | |||
3003 | - pdfAnnot = ann; | ||
3004 | + pdfAnnot = std::move(ann); | ||
3005 | pdfPage = page; | ||
3006 | parentDoc = doc; | ||
3007 | - | ||
3008 | - pdfAnnot->incRefCnt(); | ||
3009 | } | ||
3010 | |||
3011 | /* This method is called when a new annotation is created, after pdfAnnot and | ||
3012 | @@ -167,7 +162,7 @@ void AnnotationPrivate::flushBaseAnnotationProperties() | ||
3013 | { | ||
3014 | Q_ASSERT(pdfPage); | ||
3015 | |||
3016 | - Annotation *q = makeAlias(); // Setters are defined in the public class | ||
3017 | + std::unique_ptr<Annotation> q = makeAlias(); // Setters are defined in the public class | ||
3018 | |||
3019 | // Since pdfAnnot has been set, this calls will write in the Annot object | ||
3020 | q->setAuthor(author); | ||
3021 | @@ -180,14 +175,6 @@ void AnnotationPrivate::flushBaseAnnotationProperties() | ||
3022 | q->setStyle(style); | ||
3023 | q->setPopup(popup); | ||
3024 | |||
3025 | - // Flush revisions | ||
3026 | - foreach (Annotation *r, revisions) { | ||
3027 | - // TODO: Flush revision | ||
3028 | - delete r; // Object is no longer needed | ||
3029 | - } | ||
3030 | - | ||
3031 | - delete q; | ||
3032 | - | ||
3033 | // Clear some members to save memory | ||
3034 | author.clear(); | ||
3035 | contents.clear(); | ||
3036 | @@ -377,14 +364,14 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3037 | |||
3038 | // Create Annotation objects and tie to their native Annot | ||
3039 | std::vector<std::unique_ptr<Annotation>> res; | ||
3040 | - for (Annot *ann : annots->getAnnots()) { | ||
3041 | + for (const std::shared_ptr<Annot> &ann : annots->getAnnots()) { | ||
3042 | if (!ann) { | ||
3043 | error(errInternal, -1, "Annot is null"); | ||
3044 | continue; | ||
3045 | } | ||
3046 | |||
3047 | // Check parent annotation | ||
3048 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(ann); | ||
3049 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(ann.get()); | ||
3050 | if (!markupann) { | ||
3051 | // Assume it's a root annotation, and skip if user didn't request it | ||
3052 | if (parentID != -1) { | ||
3053 | @@ -458,7 +445,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3054 | continue; | ||
3055 | } | ||
3056 | // parse Link params | ||
3057 | - AnnotLink *linkann = static_cast<AnnotLink *>(ann); | ||
3058 | + AnnotLink *linkann = static_cast<AnnotLink *>(ann.get()); | ||
3059 | LinkAnnotation *l = new LinkAnnotation(); | ||
3060 | |||
3061 | // -> hlMode | ||
3062 | @@ -488,7 +475,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3063 | if (!wantFileAttachmentAnnotations) { | ||
3064 | continue; | ||
3065 | } | ||
3066 | - AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann); | ||
3067 | + AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann.get()); | ||
3068 | FileAttachmentAnnotation *f = new FileAttachmentAnnotation(); | ||
3069 | // -> fileIcon | ||
3070 | f->setFileIconName(QString::fromLatin1(attachann->getName()->c_str())); | ||
3071 | @@ -503,7 +490,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3072 | if (!wantSoundAnnotations) { | ||
3073 | continue; | ||
3074 | } | ||
3075 | - AnnotSound *soundann = static_cast<AnnotSound *>(ann); | ||
3076 | + AnnotSound *soundann = static_cast<AnnotSound *>(ann.get()); | ||
3077 | SoundAnnotation *s = new SoundAnnotation(); | ||
3078 | |||
3079 | // -> soundIcon | ||
3080 | @@ -518,7 +505,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3081 | if (!wantMovieAnnotations) { | ||
3082 | continue; | ||
3083 | } | ||
3084 | - AnnotMovie *movieann = static_cast<AnnotMovie *>(ann); | ||
3085 | + AnnotMovie *movieann = static_cast<AnnotMovie *>(ann.get()); | ||
3086 | MovieAnnotation *m = new MovieAnnotation(); | ||
3087 | |||
3088 | // -> movie | ||
3089 | @@ -536,7 +523,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3090 | if (!wantScreenAnnotations) { | ||
3091 | continue; | ||
3092 | } | ||
3093 | - AnnotScreen *screenann = static_cast<AnnotScreen *>(ann); | ||
3094 | + AnnotScreen *screenann = static_cast<AnnotScreen *>(ann.get()); | ||
3095 | // TODO Support other link types than Link::Rendition in ScreenAnnotation | ||
3096 | if (!screenann->getAction() || screenann->getAction()->getKind() != actionRendition) { | ||
3097 | continue; | ||
3098 | @@ -566,7 +553,7 @@ std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Pa | ||
3099 | annotation.reset(new WidgetAnnotation()); | ||
3100 | break; | ||
3101 | case Annot::typeRichMedia: { | ||
3102 | - const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann); | ||
3103 | + const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann.get()); | ||
3104 | |||
3105 | RichMediaAnnotation *richMediaAnnotation = new RichMediaAnnotation; | ||
3106 | |||
3107 | @@ -774,9 +761,9 @@ std::unique_ptr<Link> AnnotationPrivate::additionalAction(Annotation::Additional | ||
3108 | |||
3109 | std::unique_ptr<::LinkAction> linkAction; | ||
3110 | if (pdfAnnot->getType() == Annot::typeScreen) { | ||
3111 | - linkAction = static_cast<AnnotScreen *>(pdfAnnot)->getAdditionalAction(actionType); | ||
3112 | + linkAction = static_cast<AnnotScreen *>(pdfAnnot.get())->getAdditionalAction(actionType); | ||
3113 | } else { | ||
3114 | - linkAction = static_cast<AnnotWidget *>(pdfAnnot)->getAdditionalAction(actionType); | ||
3115 | + linkAction = static_cast<AnnotWidget *>(pdfAnnot.get())->getAdditionalAction(actionType); | ||
3116 | } | ||
3117 | |||
3118 | if (linkAction) { | ||
3119 | @@ -795,7 +782,7 @@ void AnnotationPrivate::addAnnotationToPage(::Page *pdfPage, DocumentData *doc, | ||
3120 | |||
3121 | // Unimplemented annotations can't be created by the user because their ctor | ||
3122 | // is private. Therefore, createNativeAnnot will never return 0 | ||
3123 | - Annot *nativeAnnot = ann->d_ptr->createNativeAnnot(pdfPage, doc); | ||
3124 | + std::shared_ptr<Annot> nativeAnnot = ann->d_ptr->createNativeAnnot(pdfPage, doc); | ||
3125 | Q_ASSERT(nativeAnnot); | ||
3126 | |||
3127 | if (ann->d_ptr->annotationAppearance.isStream()) { | ||
3128 | @@ -828,8 +815,8 @@ class TextAnnotationPrivate : public AnnotationPrivate | ||
3129 | { | ||
3130 | public: | ||
3131 | TextAnnotationPrivate(); | ||
3132 | - Annotation *makeAlias() override; | ||
3133 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3134 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3135 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3136 | void setDefaultAppearanceToNative(); | ||
3137 | std::unique_ptr<DefaultAppearance> getDefaultAppearanceFromNative() const; | ||
3138 | |||
3139 | @@ -1057,7 +1044,7 @@ QString Annotation::author() const | ||
3140 | return d->author; | ||
3141 | } | ||
3142 | |||
3143 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
3144 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
3145 | return markupann ? UnicodeParsedString(markupann->getLabel()) : QString(); | ||
3146 | } | ||
3147 | |||
3148 | @@ -1070,7 +1057,7 @@ void Annotation::setAuthor(const QString &author) | ||
3149 | return; | ||
3150 | } | ||
3151 | |||
3152 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
3153 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
3154 | if (markupann) { | ||
3155 | markupann->setLabel(std::unique_ptr<GooString>(QStringToUnicodeGooString(author))); | ||
3156 | } | ||
3157 | @@ -1173,7 +1160,7 @@ QDateTime Annotation::creationDate() const | ||
3158 | return d->creationDate; | ||
3159 | } | ||
3160 | |||
3161 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
3162 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
3163 | |||
3164 | if (markupann && markupann->getDate()) { | ||
3165 | return convertDate(markupann->getDate()->c_str()); | ||
3166 | @@ -1191,7 +1178,7 @@ void Annotation::setCreationDate(const QDateTime &date) | ||
3167 | return; | ||
3168 | } | ||
3169 | |||
3170 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
3171 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
3172 | if (markupann) { | ||
3173 | if (date.isValid()) { | ||
3174 | const time_t t = date.toSecsSinceEpoch(); | ||
3175 | @@ -1325,7 +1312,7 @@ Annotation::Style Annotation::style() const | ||
3176 | Style s; | ||
3177 | s.setColor(convertAnnotColor(d->pdfAnnot->getColor())); | ||
3178 | |||
3179 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
3180 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
3181 | if (markupann) { | ||
3182 | s.setOpacity(markupann->getOpacity()); | ||
3183 | } | ||
3184 | @@ -1348,11 +1335,11 @@ Annotation::Style Annotation::style() const | ||
3185 | AnnotBorderEffect *border_effect; | ||
3186 | switch (d->pdfAnnot->getType()) { | ||
3187 | case Annot::typeFreeText: | ||
3188 | - border_effect = static_cast<AnnotFreeText *>(d->pdfAnnot)->getBorderEffect(); | ||
3189 | + border_effect = static_cast<AnnotFreeText *>(d->pdfAnnot.get())->getBorderEffect(); | ||
3190 | break; | ||
3191 | case Annot::typeSquare: | ||
3192 | case Annot::typeCircle: | ||
3193 | - border_effect = static_cast<AnnotGeometry *>(d->pdfAnnot)->getBorderEffect(); | ||
3194 | + border_effect = static_cast<AnnotGeometry *>(d->pdfAnnot.get())->getBorderEffect(); | ||
3195 | break; | ||
3196 | default: | ||
3197 | border_effect = nullptr; | ||
3198 | @@ -1376,7 +1363,7 @@ void Annotation::setStyle(const Annotation::Style &style) | ||
3199 | |||
3200 | d->pdfAnnot->setColor(convertQColor(style.color())); | ||
3201 | |||
3202 | - AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); | ||
3203 | + AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get()); | ||
3204 | if (markupann) { | ||
3205 | markupann->setOpacity(style.opacity()); | ||
3206 | } | ||
3207 | @@ -1397,10 +1384,10 @@ Annotation::Popup Annotation::popup() const | ||
3208 | } | ||
3209 | |||
3210 | Popup w; | ||
3211 | - AnnotPopup *popup = nullptr; | ||
3212 | + std::shared_ptr<AnnotPopup> popup = nullptr; | ||
3213 | int flags = -1; // Not initialized | ||
3214 | |||
3215 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
3216 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
3217 | if (markupann) { | ||
3218 | popup = markupann->getPopup(); | ||
3219 | w.setSummary(UnicodeParsedString(markupann->getSubject())); | ||
3220 | @@ -1418,7 +1405,7 @@ Annotation::Popup Annotation::popup() const | ||
3221 | } | ||
3222 | |||
3223 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
3224 | - const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot); | ||
3225 | + const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
3226 | |||
3227 | // Text annotations default to same rect as annotation | ||
3228 | if (flags == -1) { | ||
3229 | @@ -1474,7 +1461,7 @@ Annotation::RevScope Annotation::revisionScope() const | ||
3230 | return d->revisionScope; | ||
3231 | } | ||
3232 | |||
3233 | - const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot); | ||
3234 | + const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get()); | ||
3235 | |||
3236 | if (markupann && markupann->isInReplyTo()) { | ||
3237 | switch (markupann->getReplyTo()) { | ||
3238 | @@ -1496,7 +1483,7 @@ Annotation::RevType Annotation::revisionType() const | ||
3239 | return d->revisionType; | ||
3240 | } | ||
3241 | |||
3242 | - const AnnotText *textann = dynamic_cast<const AnnotText *>(d->pdfAnnot); | ||
3243 | + const AnnotText *textann = dynamic_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
3244 | |||
3245 | if (textann && textann->isInReplyTo()) { | ||
3246 | switch (textann->getState()) { | ||
3247 | @@ -1527,8 +1514,10 @@ std::vector<std::unique_ptr<Annotation>> Annotation::revisions() const | ||
3248 | if (!d->pdfAnnot) { | ||
3249 | /* Return aliases, whose ownership goes to the caller */ | ||
3250 | std::vector<std::unique_ptr<Annotation>> res; | ||
3251 | - foreach (Annotation *rev, d->revisions) | ||
3252 | - res.push_back(std::unique_ptr<Annotation>(rev->d_ptr->makeAlias())); | ||
3253 | + res.reserve(d->revisions.size()); | ||
3254 | + for (const std::unique_ptr<Annotation> &rev : d->revisions) { | ||
3255 | + res.push_back(rev->d_ptr->makeAlias()); | ||
3256 | + } | ||
3257 | return res; | ||
3258 | } | ||
3259 | |||
3260 | @@ -1545,7 +1534,7 @@ std::unique_ptr<AnnotationAppearance> Annotation::annotationAppearance() const | ||
3261 | { | ||
3262 | Q_D(const Annotation); | ||
3263 | |||
3264 | - return std::make_unique<AnnotationAppearance>(new AnnotationAppearancePrivate(d->pdfAnnot)); | ||
3265 | + return std::make_unique<AnnotationAppearance>(new AnnotationAppearancePrivate(d->pdfAnnot.get())); | ||
3266 | } | ||
3267 | |||
3268 | void Annotation::setAnnotationAppearance(const AnnotationAppearance &annotationAppearance) | ||
3269 | @@ -1568,15 +1557,15 @@ void Annotation::setAnnotationAppearance(const AnnotationAppearance &annotationA | ||
3270 | /** TextAnnotation [Annotation] */ | ||
3271 | TextAnnotationPrivate::TextAnnotationPrivate() : AnnotationPrivate(), textType(TextAnnotation::Linked), textIcon(QStringLiteral("Note")), inplaceAlign(TextAnnotation::InplaceAlignLeft), inplaceIntent(TextAnnotation::Unknown) { } | ||
3272 | |||
3273 | -Annotation *TextAnnotationPrivate::makeAlias() | ||
3274 | +std::unique_ptr<Annotation> TextAnnotationPrivate::makeAlias() | ||
3275 | { | ||
3276 | - return new TextAnnotation(*this); | ||
3277 | + return std::unique_ptr<Annotation>(new TextAnnotation(*this)); | ||
3278 | } | ||
3279 | |||
3280 | -Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3281 | +std::shared_ptr<Annot> TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3282 | { | ||
3283 | // Setters are defined in the public class | ||
3284 | - TextAnnotation *q = static_cast<TextAnnotation *>(makeAlias()); | ||
3285 | + std::unique_ptr<TextAnnotation> q = static_pointer_cast<TextAnnotation>(makeAlias()); | ||
3286 | |||
3287 | // Set page and contents | ||
3288 | pdfPage = destPage; | ||
3289 | @@ -1585,13 +1574,13 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3290 | // Set pdfAnnot | ||
3291 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3292 | if (textType == TextAnnotation::Linked) { | ||
3293 | - pdfAnnot = new AnnotText { destPage->getDoc(), &rect }; | ||
3294 | + pdfAnnot = std::make_shared<AnnotText>(destPage->getDoc(), &rect); | ||
3295 | } else { | ||
3296 | const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize; | ||
3297 | if (pointSize < 0) { | ||
3298 | qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0"; | ||
3299 | } | ||
3300 | - pdfAnnot = new AnnotFreeText { destPage->getDoc(), &rect }; | ||
3301 | + pdfAnnot = std::make_shared<AnnotFreeText>(destPage->getDoc(), &rect); | ||
3302 | } | ||
3303 | |||
3304 | // Set properties | ||
3305 | @@ -1601,8 +1590,6 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3306 | q->setCalloutPoints(inplaceCallout); | ||
3307 | q->setInplaceIntent(inplaceIntent); | ||
3308 | |||
3309 | - delete q; | ||
3310 | - | ||
3311 | inplaceCallout.clear(); // Free up memory | ||
3312 | |||
3313 | setDefaultAppearanceToNative(); | ||
3314 | @@ -1613,7 +1600,7 @@ Annot *TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3315 | void TextAnnotationPrivate::setDefaultAppearanceToNative() | ||
3316 | { | ||
3317 | if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) { | ||
3318 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot); | ||
3319 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get()); | ||
3320 | const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize; | ||
3321 | if (pointSize < 0) { | ||
3322 | qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0"; | ||
3323 | @@ -1642,7 +1629,7 @@ void TextAnnotationPrivate::setDefaultAppearanceToNative() | ||
3324 | std::unique_ptr<DefaultAppearance> TextAnnotationPrivate::getDefaultAppearanceFromNative() const | ||
3325 | { | ||
3326 | if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) { | ||
3327 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot); | ||
3328 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get()); | ||
3329 | return ftextann->getDefaultAppearance(); | ||
3330 | } else { | ||
3331 | return {}; | ||
3332 | @@ -1696,7 +1683,7 @@ QString TextAnnotation::textIcon() const | ||
3333 | } | ||
3334 | |||
3335 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
3336 | - const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot); | ||
3337 | + const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get()); | ||
3338 | return QString::fromLatin1(textann->getIcon()->c_str()); | ||
3339 | } | ||
3340 | |||
3341 | @@ -1713,7 +1700,7 @@ void TextAnnotation::setTextIcon(const QString &icon) | ||
3342 | } | ||
3343 | |||
3344 | if (d->pdfAnnot->getType() == Annot::typeText) { | ||
3345 | - AnnotText *textann = static_cast<AnnotText *>(d->pdfAnnot); | ||
3346 | + AnnotText *textann = static_cast<AnnotText *>(d->pdfAnnot.get()); | ||
3347 | QByteArray encoded = icon.toLatin1(); | ||
3348 | GooString s(encoded.constData()); | ||
3349 | textann->setIcon(&s); | ||
3350 | @@ -1787,7 +1774,7 @@ TextAnnotation::InplaceAlignPosition TextAnnotation::inplaceAlign() const | ||
3351 | } | ||
3352 | |||
3353 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
3354 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
3355 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
3356 | switch (ftextann->getQuadding()) { | ||
3357 | case VariableTextQuadding::leftJustified: | ||
3358 | return InplaceAlignLeft; | ||
3359 | @@ -1824,7 +1811,7 @@ void TextAnnotation::setInplaceAlign(InplaceAlignPosition align) | ||
3360 | } | ||
3361 | |||
3362 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
3363 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
3364 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
3365 | ftextann->setQuadding(alignToQuadding(align)); | ||
3366 | } | ||
3367 | } | ||
3368 | @@ -1851,7 +1838,7 @@ QVector<QPointF> TextAnnotation::calloutPoints() const | ||
3369 | return QVector<QPointF>(); | ||
3370 | } | ||
3371 | |||
3372 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
3373 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
3374 | const AnnotCalloutLine *callout = ftextann->getCalloutLine(); | ||
3375 | |||
3376 | if (!callout) { | ||
3377 | @@ -1883,7 +1870,7 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
3378 | return; | ||
3379 | } | ||
3380 | |||
3381 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
3382 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
3383 | const int count = points.size(); | ||
3384 | |||
3385 | if (count == 0) { | ||
3386 | @@ -1896,7 +1883,7 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
3387 | return; | ||
3388 | } | ||
3389 | |||
3390 | - AnnotCalloutLine *callout; | ||
3391 | + std::unique_ptr<AnnotCalloutLine> *callout; | ||
3392 | double x1, y1, x2, y2; | ||
3393 | double MTX[6]; | ||
3394 | d->fillTransformationMTX(MTX); | ||
3395 | @@ -1906,13 +1893,12 @@ void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points) | ||
3396 | if (count == 3) { | ||
3397 | double x3, y3; | ||
3398 | XPDFReader::invTransform(MTX, points[2], x3, y3); | ||
3399 | - callout = new AnnotCalloutMultiLine(x1, y1, x2, y2, x3, y3); | ||
3400 | + callout = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3); | ||
3401 | } else { | ||
3402 | - callout = new AnnotCalloutLine(x1, y1, x2, y2); | ||
3403 | + callout = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2); | ||
3404 | } | ||
3405 | |||
3406 | - ftextann->setCalloutLine(callout); | ||
3407 | - delete callout; | ||
3408 | + ftextann->setCalloutLine(std::move(callout)); | ||
3409 | } | ||
3410 | |||
3411 | TextAnnotation::InplaceIntent TextAnnotation::inplaceIntent() const | ||
3412 | @@ -1924,7 +1910,7 @@ TextAnnotation::InplaceIntent TextAnnotation::inplaceIntent() const | ||
3413 | } | ||
3414 | |||
3415 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
3416 | - const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot); | ||
3417 | + const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get()); | ||
3418 | return (TextAnnotation::InplaceIntent)ftextann->getIntent(); | ||
3419 | } | ||
3420 | |||
3421 | @@ -1941,7 +1927,7 @@ void TextAnnotation::setInplaceIntent(TextAnnotation::InplaceIntent intent) | ||
3422 | } | ||
3423 | |||
3424 | if (d->pdfAnnot->getType() == Annot::typeFreeText) { | ||
3425 | - AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot); | ||
3426 | + AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get()); | ||
3427 | ftextann->setIntent((AnnotFreeText::AnnotFreeTextIntent)intent); | ||
3428 | } | ||
3429 | } | ||
3430 | @@ -1951,8 +1937,8 @@ class LineAnnotationPrivate : public AnnotationPrivate | ||
3431 | { | ||
3432 | public: | ||
3433 | LineAnnotationPrivate(); | ||
3434 | - Annotation *makeAlias() override; | ||
3435 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3436 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3437 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3438 | |||
3439 | // data fields (note uses border for rendering style) | ||
3440 | QVector<QPointF> linePoints; | ||
3441 | @@ -1972,15 +1958,15 @@ LineAnnotationPrivate::LineAnnotationPrivate() | ||
3442 | { | ||
3443 | } | ||
3444 | |||
3445 | -Annotation *LineAnnotationPrivate::makeAlias() | ||
3446 | +std::unique_ptr<Annotation> LineAnnotationPrivate::makeAlias() | ||
3447 | { | ||
3448 | - return new LineAnnotation(*this); | ||
3449 | + return std::unique_ptr<Annotation>(new LineAnnotation(*this)); | ||
3450 | } | ||
3451 | |||
3452 | -Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3453 | +std::shared_ptr<Annot> LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3454 | { | ||
3455 | // Setters are defined in the public class | ||
3456 | - LineAnnotation *q = static_cast<LineAnnotation *>(makeAlias()); | ||
3457 | + std::unique_ptr<LineAnnotation> q = static_pointer_cast<LineAnnotation *>(makeAlias()); | ||
3458 | |||
3459 | // Set page and document | ||
3460 | pdfPage = destPage; | ||
3461 | @@ -1989,9 +1975,9 @@ Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3462 | // Set pdfAnnot | ||
3463 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3464 | if (lineType == LineAnnotation::StraightLine) { | ||
3465 | - pdfAnnot = new AnnotLine(doc->doc, &rect); | ||
3466 | + pdfAnnot = std::make_shared<AnnotLine>(doc->doc, &rect); | ||
3467 | } else { | ||
3468 | - pdfAnnot = new AnnotPolygon(doc->doc, &rect, lineClosed ? Annot::typePolygon : Annot::typePolyLine); | ||
3469 | + pdfAnnot = std::make_shared<AnnotPolygon>(doc->doc, &rect, lineClosed ? Annot::typePolygon : Annot::typePolyLine); | ||
3470 | } | ||
3471 | |||
3472 | // Set properties | ||
3473 | @@ -2005,8 +1991,6 @@ Annot *LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3474 | q->setLineShowCaption(lineShowCaption); | ||
3475 | q->setLineIntent(lineIntent); | ||
3476 | |||
3477 | - delete q; | ||
3478 | - | ||
3479 | linePoints.clear(); // Free up memory | ||
3480 | |||
3481 | return pdfAnnot; | ||
3482 | @@ -2063,14 +2047,14 @@ QVector<QPointF> LineAnnotation::linePoints() const | ||
3483 | |||
3484 | QVector<QPointF> res; | ||
3485 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3486 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3487 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3488 | QPointF p; | ||
3489 | XPDFReader::transform(MTX, lineann->getX1(), lineann->getY1(), p); | ||
3490 | res.append(p); | ||
3491 | XPDFReader::transform(MTX, lineann->getX2(), lineann->getY2(), p); | ||
3492 | res.append(p); | ||
3493 | } else { | ||
3494 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
3495 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
3496 | const AnnotPath *vertices = polyann->getVertices(); | ||
3497 | |||
3498 | for (int i = 0; i < vertices->getCoordsLength(); ++i) { | ||
3499 | @@ -2093,7 +2077,7 @@ void LineAnnotation::setLinePoints(const QVector<QPointF> &points) | ||
3500 | } | ||
3501 | |||
3502 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3503 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3504 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3505 | if (points.size() != 2) { | ||
3506 | error(errSyntaxError, -1, "Expected two points for a straight line"); | ||
3507 | return; | ||
3508 | @@ -2105,7 +2089,7 @@ void LineAnnotation::setLinePoints(const QVector<QPointF> &points) | ||
3509 | XPDFReader::invTransform(MTX, points.last(), x2, y2); | ||
3510 | lineann->setVertices(x1, y1, x2, y2); | ||
3511 | } else { | ||
3512 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3513 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3514 | AnnotPath *p = d->toAnnotPath(points); | ||
3515 | polyann->setVertices(p); | ||
3516 | delete p; | ||
3517 | @@ -2121,10 +2105,10 @@ LineAnnotation::TermStyle LineAnnotation::lineStartStyle() const | ||
3518 | } | ||
3519 | |||
3520 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3521 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3522 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3523 | return (LineAnnotation::TermStyle)lineann->getStartStyle(); | ||
3524 | } else { | ||
3525 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
3526 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
3527 | return (LineAnnotation::TermStyle)polyann->getStartStyle(); | ||
3528 | } | ||
3529 | } | ||
3530 | @@ -2139,10 +2123,10 @@ void LineAnnotation::setLineStartStyle(LineAnnotation::TermStyle style) | ||
3531 | } | ||
3532 | |||
3533 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3534 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3535 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3536 | lineann->setStartEndStyle((AnnotLineEndingStyle)style, lineann->getEndStyle()); | ||
3537 | } else { | ||
3538 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3539 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3540 | polyann->setStartEndStyle((AnnotLineEndingStyle)style, polyann->getEndStyle()); | ||
3541 | } | ||
3542 | } | ||
3543 | @@ -2156,10 +2140,10 @@ LineAnnotation::TermStyle LineAnnotation::lineEndStyle() const | ||
3544 | } | ||
3545 | |||
3546 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3547 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3548 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3549 | return (LineAnnotation::TermStyle)lineann->getEndStyle(); | ||
3550 | } else { | ||
3551 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
3552 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
3553 | return (LineAnnotation::TermStyle)polyann->getEndStyle(); | ||
3554 | } | ||
3555 | } | ||
3556 | @@ -2174,10 +2158,10 @@ void LineAnnotation::setLineEndStyle(LineAnnotation::TermStyle style) | ||
3557 | } | ||
3558 | |||
3559 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3560 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3561 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3562 | lineann->setStartEndStyle(lineann->getStartStyle(), (AnnotLineEndingStyle)style); | ||
3563 | } else { | ||
3564 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3565 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3566 | polyann->setStartEndStyle(polyann->getStartStyle(), (AnnotLineEndingStyle)style); | ||
3567 | } | ||
3568 | } | ||
3569 | @@ -2203,7 +2187,7 @@ void LineAnnotation::setLineClosed(bool closed) | ||
3570 | } | ||
3571 | |||
3572 | if (d->pdfAnnot->getType() != Annot::typeLine) { | ||
3573 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3574 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3575 | |||
3576 | // Set new subtype and switch intent if necessary | ||
3577 | if (closed) { | ||
3578 | @@ -2231,10 +2215,10 @@ QColor LineAnnotation::lineInnerColor() const | ||
3579 | AnnotColor *c; | ||
3580 | |||
3581 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3582 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3583 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3584 | c = lineann->getInteriorColor(); | ||
3585 | } else { | ||
3586 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
3587 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
3588 | c = polyann->getInteriorColor(); | ||
3589 | } | ||
3590 | |||
3591 | @@ -2253,10 +2237,10 @@ void LineAnnotation::setLineInnerColor(const QColor &color) | ||
3592 | auto c = convertQColor(color); | ||
3593 | |||
3594 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3595 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3596 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3597 | lineann->setInteriorColor(std::move(c)); | ||
3598 | } else { | ||
3599 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3600 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3601 | polyann->setInteriorColor(std::move(c)); | ||
3602 | } | ||
3603 | } | ||
3604 | @@ -2270,7 +2254,7 @@ double LineAnnotation::lineLeadingForwardPoint() const | ||
3605 | } | ||
3606 | |||
3607 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3608 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3609 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3610 | return lineann->getLeaderLineLength(); | ||
3611 | } | ||
3612 | |||
3613 | @@ -2287,7 +2271,7 @@ void LineAnnotation::setLineLeadingForwardPoint(double point) | ||
3614 | } | ||
3615 | |||
3616 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3617 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3618 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3619 | lineann->setLeaderLineLength(point); | ||
3620 | } | ||
3621 | } | ||
3622 | @@ -2301,7 +2285,7 @@ double LineAnnotation::lineLeadingBackPoint() const | ||
3623 | } | ||
3624 | |||
3625 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3626 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3627 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3628 | return lineann->getLeaderLineExtension(); | ||
3629 | } | ||
3630 | |||
3631 | @@ -2318,7 +2302,7 @@ void LineAnnotation::setLineLeadingBackPoint(double point) | ||
3632 | } | ||
3633 | |||
3634 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3635 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3636 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3637 | lineann->setLeaderLineExtension(point); | ||
3638 | } | ||
3639 | } | ||
3640 | @@ -2332,7 +2316,7 @@ bool LineAnnotation::lineShowCaption() const | ||
3641 | } | ||
3642 | |||
3643 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3644 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3645 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3646 | return lineann->getCaption(); | ||
3647 | } | ||
3648 | |||
3649 | @@ -2349,7 +2333,7 @@ void LineAnnotation::setLineShowCaption(bool show) | ||
3650 | } | ||
3651 | |||
3652 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3653 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3654 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3655 | lineann->setCaption(show); | ||
3656 | } | ||
3657 | } | ||
3658 | @@ -2363,10 +2347,10 @@ LineAnnotation::LineIntent LineAnnotation::lineIntent() const | ||
3659 | } | ||
3660 | |||
3661 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3662 | - const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot); | ||
3663 | + const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get()); | ||
3664 | return (LineAnnotation::LineIntent)(lineann->getIntent() + 1); | ||
3665 | } else { | ||
3666 | - const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot); | ||
3667 | + const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get()); | ||
3668 | if (polyann->getIntent() == AnnotPolygon::polygonCloud) { | ||
3669 | return LineAnnotation::PolygonCloud; | ||
3670 | } else { // AnnotPolygon::polylineDimension, AnnotPolygon::polygonDimension | ||
3671 | @@ -2389,10 +2373,10 @@ void LineAnnotation::setLineIntent(LineAnnotation::LineIntent intent) | ||
3672 | } | ||
3673 | |||
3674 | if (d->pdfAnnot->getType() == Annot::typeLine) { | ||
3675 | - AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot); | ||
3676 | + AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get()); | ||
3677 | lineann->setIntent((AnnotLine::AnnotLineIntent)(intent - 1)); | ||
3678 | } else { | ||
3679 | - AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot); | ||
3680 | + AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get()); | ||
3681 | if (intent == LineAnnotation::PolygonCloud) { | ||
3682 | polyann->setIntent(AnnotPolygon::polygonCloud); | ||
3683 | } else // LineAnnotation::Dimension | ||
3684 | @@ -2411,8 +2395,8 @@ class GeomAnnotationPrivate : public AnnotationPrivate | ||
3685 | { | ||
3686 | public: | ||
3687 | GeomAnnotationPrivate(); | ||
3688 | - Annotation *makeAlias() override; | ||
3689 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3690 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3691 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3692 | |||
3693 | // data fields (note uses border for rendering style) | ||
3694 | GeomAnnotation::GeomType geomType; | ||
3695 | @@ -2421,15 +2405,15 @@ public: | ||
3696 | |||
3697 | GeomAnnotationPrivate::GeomAnnotationPrivate() : AnnotationPrivate(), geomType(GeomAnnotation::InscribedSquare) { } | ||
3698 | |||
3699 | -Annotation *GeomAnnotationPrivate::makeAlias() | ||
3700 | +std::unique_ptr<Annotation> GeomAnnotationPrivate::makeAlias() | ||
3701 | { | ||
3702 | - return new GeomAnnotation(*this); | ||
3703 | + return std::unique_ptr<Annotation>(new GeomAnnotation(*this)); | ||
3704 | } | ||
3705 | |||
3706 | -Annot *GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3707 | +std::shared_ptr<Annot> GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3708 | { | ||
3709 | // Setters are defined in the public class | ||
3710 | - GeomAnnotation *q = static_cast<GeomAnnotation *>(makeAlias()); | ||
3711 | + std::unique_ptr<GeomAnnotation> q = static_pointer_cast<GeomAnnotation *>(makeAlias()); | ||
3712 | |||
3713 | // Set page and document | ||
3714 | pdfPage = destPage; | ||
3715 | @@ -2444,13 +2428,12 @@ Annot *GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData * | ||
3716 | |||
3717 | // Set pdfAnnot | ||
3718 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3719 | - pdfAnnot = new AnnotGeometry(destPage->getDoc(), &rect, type); | ||
3720 | + pdfAnnot = std::make_shared<AnnotGeometry>(destPage->getDoc(), &rect, type); | ||
3721 | |||
3722 | // Set properties | ||
3723 | flushBaseAnnotationProperties(); | ||
3724 | q->setGeomInnerColor(geomInnerColor); | ||
3725 | |||
3726 | - delete q; | ||
3727 | return pdfAnnot; | ||
3728 | } | ||
3729 | |||
3730 | @@ -2489,7 +2472,7 @@ void GeomAnnotation::setGeomType(GeomAnnotation::GeomType type) | ||
3731 | return; | ||
3732 | } | ||
3733 | |||
3734 | - AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot); | ||
3735 | + AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get()); | ||
3736 | if (type == GeomAnnotation::InscribedSquare) { | ||
3737 | geomann->setType(Annot::typeSquare); | ||
3738 | } else { // GeomAnnotation::InscribedCircle | ||
3739 | @@ -2505,7 +2488,7 @@ QColor GeomAnnotation::geomInnerColor() const | ||
3740 | return d->geomInnerColor; | ||
3741 | } | ||
3742 | |||
3743 | - const AnnotGeometry *geomann = static_cast<const AnnotGeometry *>(d->pdfAnnot); | ||
3744 | + const AnnotGeometry *geomann = static_cast<const AnnotGeometry *>(d->pdfAnnot.get()); | ||
3745 | return convertAnnotColor(geomann->getInteriorColor()); | ||
3746 | } | ||
3747 | |||
3748 | @@ -2518,7 +2501,7 @@ void GeomAnnotation::setGeomInnerColor(const QColor &color) | ||
3749 | return; | ||
3750 | } | ||
3751 | |||
3752 | - AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot); | ||
3753 | + AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get()); | ||
3754 | geomann->setInteriorColor(convertQColor(color)); | ||
3755 | } | ||
3756 | |||
3757 | @@ -2527,8 +2510,8 @@ class HighlightAnnotationPrivate : public AnnotationPrivate | ||
3758 | { | ||
3759 | public: | ||
3760 | HighlightAnnotationPrivate(); | ||
3761 | - Annotation *makeAlias() override; | ||
3762 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3763 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3764 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3765 | |||
3766 | // data fields | ||
3767 | HighlightAnnotation::HighlightType highlightType; | ||
3768 | @@ -2542,9 +2525,9 @@ public: | ||
3769 | |||
3770 | HighlightAnnotationPrivate::HighlightAnnotationPrivate() : AnnotationPrivate(), highlightType(HighlightAnnotation::Highlight) { } | ||
3771 | |||
3772 | -Annotation *HighlightAnnotationPrivate::makeAlias() | ||
3773 | +std::unique_ptr<Annotation> HighlightAnnotationPrivate::makeAlias() | ||
3774 | { | ||
3775 | - return new HighlightAnnotation(*this); | ||
3776 | + return std::unique_ptr<Annotation>(new HighlightAnnotation(*this)); | ||
3777 | } | ||
3778 | |||
3779 | Annot::AnnotSubtype HighlightAnnotationPrivate::toAnnotSubType(HighlightAnnotation::HighlightType type) | ||
3780 | @@ -2617,10 +2600,10 @@ AnnotQuadrilaterals *HighlightAnnotationPrivate::toQuadrilaterals(const QList<Hi | ||
3781 | return new AnnotQuadrilaterals(std::move(ac), count); | ||
3782 | } | ||
3783 | |||
3784 | -Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3785 | +std::shared_ptr<Annot> HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3786 | { | ||
3787 | // Setters are defined in the public class | ||
3788 | - HighlightAnnotation *q = static_cast<HighlightAnnotation *>(makeAlias()); | ||
3789 | + std::unique_ptr<HighlightAnnotation> q = static_pointer_cast<HighlightAnnotation *>(makeAlias()); | ||
3790 | |||
3791 | // Set page and document | ||
3792 | pdfPage = destPage; | ||
3793 | @@ -2628,7 +2611,7 @@ Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentD | ||
3794 | |||
3795 | // Set pdfAnnot | ||
3796 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3797 | - pdfAnnot = new AnnotTextMarkup(destPage->getDoc(), &rect, toAnnotSubType(highlightType)); | ||
3798 | + pdfAnnot = std::make_shared<AnnotTextMarkup>(destPage->getDoc(), &rect, toAnnotSubType(highlightType)); | ||
3799 | |||
3800 | // Set properties | ||
3801 | flushBaseAnnotationProperties(); | ||
3802 | @@ -2636,8 +2619,6 @@ Annot *HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentD | ||
3803 | |||
3804 | highlightQuads.clear(); // Free up memory | ||
3805 | |||
3806 | - delete q; | ||
3807 | - | ||
3808 | return pdfAnnot; | ||
3809 | } | ||
3810 | |||
3811 | @@ -2682,7 +2663,7 @@ void HighlightAnnotation::setHighlightType(HighlightAnnotation::HighlightType ty | ||
3812 | return; | ||
3813 | } | ||
3814 | |||
3815 | - AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
3816 | + AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
3817 | hlann->setType(HighlightAnnotationPrivate::toAnnotSubType(type)); | ||
3818 | } | ||
3819 | |||
3820 | @@ -2694,7 +2675,7 @@ QList<HighlightAnnotation::Quad> HighlightAnnotation::highlightQuads() const | ||
3821 | return d->highlightQuads; | ||
3822 | } | ||
3823 | |||
3824 | - const AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
3825 | + const AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
3826 | return d->fromQuadrilaterals(hlann->getQuadrilaterals()); | ||
3827 | } | ||
3828 | |||
3829 | @@ -2707,7 +2688,7 @@ void HighlightAnnotation::setHighlightQuads(const QList<HighlightAnnotation::Qua | ||
3830 | return; | ||
3831 | } | ||
3832 | |||
3833 | - AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot); | ||
3834 | + AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get()); | ||
3835 | AnnotQuadrilaterals *quadrilaterals = d->toQuadrilaterals(quads); | ||
3836 | hlann->setQuadrilaterals(quadrilaterals); | ||
3837 | delete quadrilaterals; | ||
3838 | @@ -2718,10 +2699,10 @@ class StampAnnotationPrivate : public AnnotationPrivate | ||
3839 | { | ||
3840 | public: | ||
3841 | StampAnnotationPrivate(); | ||
3842 | - Annotation *makeAlias() override; | ||
3843 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3844 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3845 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3846 | |||
3847 | - AnnotStampImageHelper *convertQImageToAnnotStampImageHelper(const QImage &qimg); | ||
3848 | + std::unique_ptr<AnnotStampImageHelper> convertQImageToAnnotStampImageHelper(const QImage &qimg); | ||
3849 | |||
3850 | // data fields | ||
3851 | QString stampIconName; | ||
3852 | @@ -2730,14 +2711,14 @@ public: | ||
3853 | |||
3854 | StampAnnotationPrivate::StampAnnotationPrivate() : AnnotationPrivate(), stampIconName(QStringLiteral("Draft")) { } | ||
3855 | |||
3856 | -Annotation *StampAnnotationPrivate::makeAlias() | ||
3857 | +std::unique_ptr<Annotation> StampAnnotationPrivate::makeAlias() | ||
3858 | { | ||
3859 | - return new StampAnnotation(*this); | ||
3860 | + return std::unique_ptr<Annotation>(new StampAnnotation(*this)); | ||
3861 | } | ||
3862 | |||
3863 | -Annot *StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3864 | +std::shared_ptr<Annot> StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3865 | { | ||
3866 | - StampAnnotation *q = static_cast<StampAnnotation *>(makeAlias()); | ||
3867 | + std::shared_ptr<StampAnnotation> q = static_pointer_cast<StampAnnotation *>(makeAlias()); | ||
3868 | |||
3869 | // Set page and document | ||
3870 | pdfPage = destPage; | ||
3871 | @@ -2745,21 +2726,19 @@ Annot *StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData | ||
3872 | |||
3873 | // Set pdfAnnot | ||
3874 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3875 | - pdfAnnot = new AnnotStamp(destPage->getDoc(), &rect); | ||
3876 | + pdfAnnot = std::make_shared<AnnotStamp>(destPage->getDoc(), &rect); | ||
3877 | |||
3878 | // Set properties | ||
3879 | flushBaseAnnotationProperties(); | ||
3880 | q->setStampIconName(stampIconName); | ||
3881 | q->setStampCustomImage(stampCustomImage); | ||
3882 | |||
3883 | - delete q; | ||
3884 | - | ||
3885 | stampIconName.clear(); // Free up memory | ||
3886 | |||
3887 | return pdfAnnot; | ||
3888 | } | ||
3889 | |||
3890 | -AnnotStampImageHelper *StampAnnotationPrivate::convertQImageToAnnotStampImageHelper(const QImage &qimg) | ||
3891 | +std::unique_ptr<AnnotStampImageHelper> *StampAnnotationPrivate::convertQImageToAnnotStampImageHelper(const QImage &qimg) | ||
3892 | { | ||
3893 | QImage convertedQImage = qimg; | ||
3894 | |||
3895 | @@ -2838,13 +2817,13 @@ AnnotStampImageHelper *StampAnnotationPrivate::convertQImageToAnnotStampImageHel | ||
3896 | |||
3897 | getRawDataFromQImage(convertedQImage, convertedQImage.depth(), &data, &sMaskData); | ||
3898 | |||
3899 | - AnnotStampImageHelper *annotImg; | ||
3900 | + std::unique_ptr<AnnotStampImageHelper> annotImg; | ||
3901 | |||
3902 | if (sMaskData.size() > 0) { | ||
3903 | AnnotStampImageHelper sMask(parentDoc->doc, width, height, ColorSpace::DeviceGray, 8, sMaskData.data(), sMaskData.size()); | ||
3904 | - annotImg = new AnnotStampImageHelper(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size(), sMask.getRef()); | ||
3905 | + annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size(), sMask.getRef()); | ||
3906 | } else { | ||
3907 | - annotImg = new AnnotStampImageHelper(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size()); | ||
3908 | + annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size()); | ||
3909 | } | ||
3910 | |||
3911 | return annotImg; | ||
3912 | @@ -2869,7 +2848,7 @@ QString StampAnnotation::stampIconName() const | ||
3913 | return d->stampIconName; | ||
3914 | } | ||
3915 | |||
3916 | - const AnnotStamp *stampann = static_cast<const AnnotStamp *>(d->pdfAnnot); | ||
3917 | + const AnnotStamp *stampann = static_cast<const AnnotStamp *>(d->pdfAnnot.get()); | ||
3918 | return QString::fromLatin1(stampann->getIcon()->c_str()); | ||
3919 | } | ||
3920 | |||
3921 | @@ -2882,7 +2861,7 @@ void StampAnnotation::setStampIconName(const QString &name) | ||
3922 | return; | ||
3923 | } | ||
3924 | |||
3925 | - AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot); | ||
3926 | + AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get()); | ||
3927 | QByteArray encoded = name.toLatin1(); | ||
3928 | GooString s(encoded.constData()); | ||
3929 | stampann->setIcon(&s); | ||
3930 | @@ -2901,9 +2880,9 @@ void StampAnnotation::setStampCustomImage(const QImage &image) | ||
3931 | return; | ||
3932 | } | ||
3933 | |||
3934 | - AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot); | ||
3935 | - AnnotStampImageHelper *annotCustomImage = d->convertQImageToAnnotStampImageHelper(image); | ||
3936 | - stampann->setCustomImage(annotCustomImage); | ||
3937 | + AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get()); | ||
3938 | + std::unique_ptr<AnnotStampImageHelper> annotCustomImage = d->convertQImageToAnnotStampImageHelper(image); | ||
3939 | + stampann->setCustomImage(std::move(annotCustomImage)); | ||
3940 | } | ||
3941 | |||
3942 | /** InkAnnotation [Annotation] */ | ||
3943 | @@ -2911,8 +2890,8 @@ class InkAnnotationPrivate : public AnnotationPrivate | ||
3944 | { | ||
3945 | public: | ||
3946 | InkAnnotationPrivate(); | ||
3947 | - Annotation *makeAlias() override; | ||
3948 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3949 | + std::unique_ptr<Annotation> makeAlias() override; | ||
3950 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
3951 | |||
3952 | // data fields | ||
3953 | QList<QVector<QPointF>> inkPaths; | ||
3954 | @@ -2923,9 +2902,9 @@ public: | ||
3955 | |||
3956 | InkAnnotationPrivate::InkAnnotationPrivate() : AnnotationPrivate() { } | ||
3957 | |||
3958 | -Annotation *InkAnnotationPrivate::makeAlias() | ||
3959 | +std::unique_ptr<Annotation> *InkAnnotationPrivate::makeAlias() | ||
3960 | { | ||
3961 | - return new InkAnnotation(*this); | ||
3962 | + return std::unique_ptr<Annotation>(new InkAnnotation(*this)); | ||
3963 | } | ||
3964 | |||
3965 | // Note: Caller is required to delete array elements and the array itself after use | ||
3966 | @@ -2939,10 +2918,10 @@ AnnotPath **InkAnnotationPrivate::toAnnotPaths(const QList<QVector<QPointF>> &pa | ||
3967 | return res; | ||
3968 | } | ||
3969 | |||
3970 | -Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3971 | +std::shared_ptr<Annot> InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
3972 | { | ||
3973 | // Setters are defined in the public class | ||
3974 | - InkAnnotation *q = static_cast<InkAnnotation *>(makeAlias()); | ||
3975 | + std::unique_ptr<InkAnnotation> q = static_pointer_cast<InkAnnotation *>(makeAlias()); | ||
3976 | |||
3977 | // Set page and document | ||
3978 | pdfPage = destPage; | ||
3979 | @@ -2950,7 +2929,7 @@ Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *d | ||
3980 | |||
3981 | // Set pdfAnnot | ||
3982 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
3983 | - pdfAnnot = new AnnotInk(destPage->getDoc(), &rect); | ||
3984 | + pdfAnnot = std::make_shared<AnnotInk>(destPage->getDoc(), &rect); | ||
3985 | |||
3986 | // Set properties | ||
3987 | flushBaseAnnotationProperties(); | ||
3988 | @@ -2958,8 +2937,6 @@ Annot *InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *d | ||
3989 | |||
3990 | inkPaths.clear(); // Free up memory | ||
3991 | |||
3992 | - delete q; | ||
3993 | - | ||
3994 | return pdfAnnot; | ||
3995 | } | ||
3996 | |||
3997 | @@ -2982,7 +2959,7 @@ QList<QVector<QPointF>> InkAnnotation::inkPaths() const | ||
3998 | return d->inkPaths; | ||
3999 | } | ||
4000 | |||
4001 | - const AnnotInk *inkann = static_cast<const AnnotInk *>(d->pdfAnnot); | ||
4002 | + const AnnotInk *inkann = static_cast<const AnnotInk *>(d->pdfAnnot.get()); | ||
4003 | |||
4004 | const AnnotPath *const *paths = inkann->getInkList(); | ||
4005 | if (!paths || !inkann->getInkListLength()) { | ||
4006 | @@ -3020,7 +2997,7 @@ void InkAnnotation::setInkPaths(const QList<QVector<QPointF>> &paths) | ||
4007 | return; | ||
4008 | } | ||
4009 | |||
4010 | - AnnotInk *inkann = static_cast<AnnotInk *>(d->pdfAnnot); | ||
4011 | + AnnotInk *inkann = static_cast<AnnotInk *>(d->pdfAnnot.get()); | ||
4012 | AnnotPath **annotpaths = d->toAnnotPaths(paths); | ||
4013 | const int pathsNumber = paths.size(); | ||
4014 | inkann->setInkList(annotpaths, pathsNumber); | ||
4015 | @@ -3037,8 +3014,8 @@ class LinkAnnotationPrivate : public AnnotationPrivate | ||
4016 | public: | ||
4017 | LinkAnnotationPrivate(); | ||
4018 | ~LinkAnnotationPrivate() override; | ||
4019 | - Annotation *makeAlias() override; | ||
4020 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4021 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4022 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4023 | |||
4024 | // data fields | ||
4025 | std::unique_ptr<Link> linkDestination; | ||
4026 | @@ -3050,12 +3027,12 @@ LinkAnnotationPrivate::LinkAnnotationPrivate() : AnnotationPrivate(), linkHLMode | ||
4027 | |||
4028 | LinkAnnotationPrivate::~LinkAnnotationPrivate() { } | ||
4029 | |||
4030 | -Annotation *LinkAnnotationPrivate::makeAlias() | ||
4031 | +std::unique_ptr<Annotation> LinkAnnotationPrivate::makeAlias() | ||
4032 | { | ||
4033 | - return new LinkAnnotation(*this); | ||
4034 | + return std::unique_ptr<Annotation>(new LinkAnnotation(*this)); | ||
4035 | } | ||
4036 | |||
4037 | -Annot *LinkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4038 | +std::unique_ptr<Annot> *LinkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4039 | { | ||
4040 | return nullptr; // Not implemented | ||
4041 | } | ||
4042 | @@ -3076,7 +3053,6 @@ Link *LinkAnnotation::linkDestination() const | ||
4043 | Q_D(const LinkAnnotation); | ||
4044 | return d->linkDestination.get(); | ||
4045 | } | ||
4046 | - | ||
4047 | void LinkAnnotation::setLinkDestination(std::unique_ptr<Link> &&link) | ||
4048 | { | ||
4049 | Q_D(LinkAnnotation); | ||
4050 | @@ -3120,8 +3096,8 @@ class CaretAnnotationPrivate : public AnnotationPrivate | ||
4051 | { | ||
4052 | public: | ||
4053 | CaretAnnotationPrivate(); | ||
4054 | - Annotation *makeAlias() override; | ||
4055 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4056 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4057 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4058 | |||
4059 | // data fields | ||
4060 | CaretAnnotation::CaretSymbol symbol; | ||
4061 | @@ -3129,15 +3105,15 @@ public: | ||
4062 | |||
4063 | CaretAnnotationPrivate::CaretAnnotationPrivate() : AnnotationPrivate(), symbol(CaretAnnotation::None) { } | ||
4064 | |||
4065 | -Annotation *CaretAnnotationPrivate::makeAlias() | ||
4066 | +std::unique_ptr<Annotation> CaretAnnotationPrivate::makeAlias() | ||
4067 | { | ||
4068 | - return new CaretAnnotation(*this); | ||
4069 | + return std::unique_ptr<Annotation>(new CaretAnnotation(*this)); | ||
4070 | } | ||
4071 | |||
4072 | -Annot *CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4073 | +std::shared_ptr<Annot> CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4074 | { | ||
4075 | // Setters are defined in the public class | ||
4076 | - CaretAnnotation *q = static_cast<CaretAnnotation *>(makeAlias()); | ||
4077 | + std::unique_ptr<CaretAnnotation> q = static_pointer_cast<CaretAnnotation *>(makeAlias()); | ||
4078 | |||
4079 | // Set page and document | ||
4080 | pdfPage = destPage; | ||
4081 | @@ -3145,13 +3121,12 @@ Annot *CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData | ||
4082 | |||
4083 | // Set pdfAnnot | ||
4084 | PDFRectangle rect = boundaryToPdfRectangle(boundary, flags); | ||
4085 | - pdfAnnot = new AnnotCaret(destPage->getDoc(), &rect); | ||
4086 | + pdfAnnot = std::make_shared<AnnotCaret>(destPage->getDoc(), &rect); | ||
4087 | |||
4088 | // Set properties | ||
4089 | flushBaseAnnotationProperties(); | ||
4090 | q->setCaretSymbol(symbol); | ||
4091 | |||
4092 | - delete q; | ||
4093 | return pdfAnnot; | ||
4094 | } | ||
4095 | |||
4096 | @@ -3174,7 +3149,7 @@ CaretAnnotation::CaretSymbol CaretAnnotation::caretSymbol() const | ||
4097 | return d->symbol; | ||
4098 | } | ||
4099 | |||
4100 | - const AnnotCaret *caretann = static_cast<const AnnotCaret *>(d->pdfAnnot); | ||
4101 | + const AnnotCaret *caretann = static_cast<const AnnotCaret *>(d->pdfAnnot.get()); | ||
4102 | return (CaretAnnotation::CaretSymbol)caretann->getSymbol(); | ||
4103 | } | ||
4104 | |||
4105 | @@ -3187,7 +3162,7 @@ void CaretAnnotation::setCaretSymbol(CaretAnnotation::CaretSymbol symbol) | ||
4106 | return; | ||
4107 | } | ||
4108 | |||
4109 | - AnnotCaret *caretann = static_cast<AnnotCaret *>(d->pdfAnnot); | ||
4110 | + AnnotCaret *caretann = static_cast<AnnotCaret *>(d->pdfAnnot.get()); | ||
4111 | caretann->setSymbol((AnnotCaret::AnnotCaretSymbol)symbol); | ||
4112 | } | ||
4113 | |||
4114 | @@ -3197,8 +3172,8 @@ class FileAttachmentAnnotationPrivate : public AnnotationPrivate | ||
4115 | public: | ||
4116 | FileAttachmentAnnotationPrivate(); | ||
4117 | ~FileAttachmentAnnotationPrivate() override; | ||
4118 | - Annotation *makeAlias() override; | ||
4119 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4120 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4121 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4122 | |||
4123 | // data fields | ||
4124 | QString icon; | ||
4125 | @@ -3212,12 +3187,12 @@ FileAttachmentAnnotationPrivate::~FileAttachmentAnnotationPrivate() | ||
4126 | delete embfile; | ||
4127 | } | ||
4128 | |||
4129 | -Annotation *FileAttachmentAnnotationPrivate::makeAlias() | ||
4130 | +std::unique_ptr<Annotation> FileAttachmentAnnotationPrivate::makeAlias() | ||
4131 | { | ||
4132 | - return new FileAttachmentAnnotation(*this); | ||
4133 | + return std::unique_ptr<Annotation>(new FileAttachmentAnnotation(*this)); | ||
4134 | } | ||
4135 | |||
4136 | -Annot *FileAttachmentAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4137 | +std::shared_ptr<Annot> *FileAttachmentAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4138 | { | ||
4139 | return nullptr; // Not implemented | ||
4140 | } | ||
4141 | @@ -3263,8 +3238,8 @@ class SoundAnnotationPrivate : public AnnotationPrivate | ||
4142 | public: | ||
4143 | SoundAnnotationPrivate(); | ||
4144 | ~SoundAnnotationPrivate() override; | ||
4145 | - Annotation *makeAlias() override; | ||
4146 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4147 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4148 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4149 | |||
4150 | // data fields | ||
4151 | QString icon; | ||
4152 | @@ -3278,12 +3253,12 @@ SoundAnnotationPrivate::~SoundAnnotationPrivate() | ||
4153 | delete sound; | ||
4154 | } | ||
4155 | |||
4156 | -Annotation *SoundAnnotationPrivate::makeAlias() | ||
4157 | +std::unique_ptr<Annotation> SoundAnnotationPrivate::makeAlias() | ||
4158 | { | ||
4159 | - return new SoundAnnotation(*this); | ||
4160 | + return std::unique_ptr<Annotation>(new SoundAnnotation(*this)); | ||
4161 | } | ||
4162 | |||
4163 | -Annot *SoundAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4164 | +std::shared_ptr<Annot> SoundAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4165 | { | ||
4166 | return nullptr; // Not implemented | ||
4167 | } | ||
4168 | @@ -3329,8 +3304,8 @@ class MovieAnnotationPrivate : public AnnotationPrivate | ||
4169 | public: | ||
4170 | MovieAnnotationPrivate(); | ||
4171 | ~MovieAnnotationPrivate() override; | ||
4172 | - Annotation *makeAlias() override; | ||
4173 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4174 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4175 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4176 | |||
4177 | // data fields | ||
4178 | MovieObject *movie; | ||
4179 | @@ -3344,12 +3319,12 @@ MovieAnnotationPrivate::~MovieAnnotationPrivate() | ||
4180 | delete movie; | ||
4181 | } | ||
4182 | |||
4183 | -Annotation *MovieAnnotationPrivate::makeAlias() | ||
4184 | +std::unique_ptr<Annotation> MovieAnnotationPrivate::makeAlias() | ||
4185 | { | ||
4186 | - return new MovieAnnotation(*this); | ||
4187 | + return std::unique_ptr<Annotation>(new MovieAnnotation(*this)); | ||
4188 | } | ||
4189 | |||
4190 | -Annot *MovieAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4191 | +std::shared_ptr<Annot> MovieAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4192 | { | ||
4193 | return nullptr; // Not implemented | ||
4194 | } | ||
4195 | @@ -3395,8 +3370,8 @@ class ScreenAnnotationPrivate : public AnnotationPrivate | ||
4196 | public: | ||
4197 | ScreenAnnotationPrivate(); | ||
4198 | ~ScreenAnnotationPrivate() override; | ||
4199 | - Annotation *makeAlias() override; | ||
4200 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4201 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4202 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4203 | |||
4204 | // data fields | ||
4205 | LinkRendition *action; | ||
4206 | @@ -3412,12 +3387,12 @@ ScreenAnnotationPrivate::~ScreenAnnotationPrivate() | ||
4207 | |||
4208 | ScreenAnnotation::ScreenAnnotation(ScreenAnnotationPrivate &dd) : Annotation(dd) { } | ||
4209 | |||
4210 | -Annotation *ScreenAnnotationPrivate::makeAlias() | ||
4211 | +std::unique_ptr<Annotation> ScreenAnnotationPrivate::makeAlias() | ||
4212 | { | ||
4213 | - return new ScreenAnnotation(*this); | ||
4214 | + return std::unique_ptr<Annotation>(new ScreenAnnotation(*this)); | ||
4215 | } | ||
4216 | |||
4217 | -Annot *ScreenAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4218 | +std::shared_ptr<Annot> ScreenAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4219 | { | ||
4220 | return nullptr; // Not implemented | ||
4221 | } | ||
4222 | @@ -3465,16 +3440,16 @@ std::unique_ptr<Link> ScreenAnnotation::additionalAction(AdditionalActionType ty | ||
4223 | class WidgetAnnotationPrivate : public AnnotationPrivate | ||
4224 | { | ||
4225 | public: | ||
4226 | - Annotation *makeAlias() override; | ||
4227 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4228 | + std::unique_ptr<Annotation> makeAlias() override; | ||
4229 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override; | ||
4230 | }; | ||
4231 | |||
4232 | -Annotation *WidgetAnnotationPrivate::makeAlias() | ||
4233 | +std::unique_ptr<Annotation> WidgetAnnotationPrivate::makeAlias() | ||
4234 | { | ||
4235 | - return new WidgetAnnotation(*this); | ||
4236 | + return std::unique_ptr<Annotation>(new WidgetAnnotation(*this)); | ||
4237 | } | ||
4238 | |||
4239 | -Annot *WidgetAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4240 | +std::shared_ptr<Annot> WidgetAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc) | ||
4241 | { | ||
4242 | return nullptr; // Not implemented | ||
4243 | } | ||
4244 | @@ -3788,9 +3763,9 @@ public: | ||
4245 | |||
4246 | ~RichMediaAnnotationPrivate() override; | ||
4247 | |||
4248 | - Annotation *makeAlias() override { return new RichMediaAnnotation(*this); } | ||
4249 | + std::unique_ptr<Annotation> makeAlias() override { return std::unique_ptr<Annotation>(new RichMediaAnnotation(*this)); } | ||
4250 | |||
4251 | - Annot *createNativeAnnot(::Page *destPage, DocumentData *doc) override | ||
4252 | + std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override | ||
4253 | { | ||
4254 | Q_UNUSED(destPage); | ||
4255 | Q_UNUSED(doc); | ||
4256 | diff --git a/qt6/src/poppler-form.cc b/qt6/src/poppler-form.cc | ||
4257 | index b415c08..74ba075 100644 | ||
4258 | --- a/qt6/src/poppler-form.cc | ||
4259 | +++ b/qt6/src/poppler-form.cc | ||
4260 | @@ -269,7 +269,7 @@ std::unique_ptr<Link> FormField::additionalAction(AdditionalActionType type) con | ||
4261 | |||
4262 | std::unique_ptr<Link> FormField::additionalAction(Annotation::AdditionalActionType type) const | ||
4263 | { | ||
4264 | - ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation(); | ||
4265 | + ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation().get(); | ||
4266 | if (!w) { | ||
4267 | return {}; | ||
4268 | } | ||
4269 | @@ -350,7 +350,7 @@ void FormFieldButton::setIcon(const FormFieldIcon &icon) | ||
4270 | |||
4271 | FormWidgetButton *fwb = static_cast<FormWidgetButton *>(m_formData->fm); | ||
4272 | if (fwb->getButtonType() == formButtonPush) { | ||
4273 | - ::AnnotWidget *w = m_formData->fm->getWidgetAnnotation(); | ||
4274 | + std::shared_ptr<::AnnotWidget> w = m_formData->fm->getWidgetAnnotation(); | ||
4275 | FormFieldIconData *data = FormFieldIconData::getData(icon); | ||
4276 | if (data->icon != nullptr) { | ||
4277 | w->setNewAppearance(data->icon->lookup("AP")); | ||
4278 | diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc | ||
4279 | index b45a5ff..ec51a24 100644 | ||
4280 | --- a/utils/HtmlOutputDev.cc | ||
4281 | +++ b/utils/HtmlOutputDev.cc | ||
4282 | @@ -1252,8 +1252,8 @@ void HtmlOutputDev::startPage(int pageNumA, GfxState *state, XRef *xref) | ||
4283 | void HtmlOutputDev::endPage() | ||
4284 | { | ||
4285 | std::unique_ptr<Links> linksList = docPage->getLinks(); | ||
4286 | - for (AnnotLink *link : linksList->getLinks()) { | ||
4287 | - doProcessLink(link); | ||
4288 | + for (const std::shared_ptr<AnnotLink> &link : linksList->getLinks()) { | ||
4289 | + doProcessLink(link.get()); | ||
4290 | } | ||
4291 | |||
4292 | pages->conv(); | ||
4293 | diff --git a/utils/pdfdetach.cc b/utils/pdfdetach.cc | ||
4294 | index 247c2c1..cbb4f30 100644 | ||
4295 | --- a/utils/pdfdetach.cc | ||
4296 | +++ b/utils/pdfdetach.cc | ||
4297 | @@ -150,11 +150,11 @@ int main(int argc, char *argv[]) | ||
4298 | break; | ||
4299 | } | ||
4300 | |||
4301 | - for (Annot *annot : annots->getAnnots()) { | ||
4302 | + for (const std::shared_ptr<Annot> &annot : annots->getAnnots()) { | ||
4303 | if (annot->getType() != Annot::typeFileAttachment) { | ||
4304 | continue; | ||
4305 | } | ||
4306 | - embeddedFiles.push_back(std::make_unique<FileSpec>(static_cast<AnnotFileAttachment *>(annot)->getFile())); | ||
4307 | + embeddedFiles.push_back(std::make_unique<FileSpec>(static_cast<AnnotFileAttachment *>(annot.get())->getFile())); | ||
4308 | } | ||
4309 | } | ||
4310 | |||
4311 | diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc | ||
4312 | index 5f96b41..7b3896e 100644 | ||
4313 | --- a/utils/pdfinfo.cc | ||
4314 | +++ b/utils/pdfinfo.cc | ||
4315 | @@ -415,7 +415,7 @@ static void printUrlList(PDFDoc *doc) | ||
4316 | Page *page = doc->getPage(pg); | ||
4317 | if (page) { | ||
4318 | std::unique_ptr<Links> links = page->getLinks(); | ||
4319 | - for (AnnotLink *annot : links->getLinks()) { | ||
4320 | + for (const std::shared_ptr<AnnotLink> &annot : links->getLinks()) { | ||
4321 | LinkAction *action = annot->getAction(); | ||
4322 | if (action->getKind() == actionURI) { | ||
4323 | LinkURI *linkUri = dynamic_cast<LinkURI *>(action); | ||
4324 | -- | ||
4325 | 2.40.0 | ||
diff --git a/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0002.patch b/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0002.patch new file mode 100644 index 0000000000..d8668699c1 --- /dev/null +++ b/meta-oe/recipes-support/poppler/poppler/CVE-2025-52886-0002.patch | |||
@@ -0,0 +1,58 @@ | |||
1 | From ac36affcc8486de38e8905a8d6547a3464ff46e5 Mon Sep 17 00:00:00 2001 | ||
2 | From: Sune Vuorela <sune@vuorela.dk> | ||
3 | Date: Tue, 3 Jun 2025 00:35:19 +0200 | ||
4 | Subject: [PATCH] Limit ammount of annots per document/page | ||
5 | |||
6 | CVE: CVE-2025-52886 | ||
7 | Upstream-Status: Backport [https://gitlab.freedesktop.org/poppler/poppler/-/commit/ac36affcc8486de38e8905a8d6547a3464ff46e5 | ||
8 | |||
9 | Signed-off-by: Yogita Urade <yogita.urade@windriver.com> | ||
10 | --- | ||
11 | poppler/Annot.cc | 4 ++++ | ||
12 | poppler/Page.cc | 16 ++++++++++++++++ | ||
13 | 2 files changed, 20 insertions(+) | ||
14 | |||
15 | diff --git a/poppler/Annot.cc b/poppler/Annot.cc | ||
16 | index b98df5d..3e9dfac 100644 | ||
17 | --- a/poppler/Annot.cc | ||
18 | +++ b/poppler/Annot.cc | ||
19 | @@ -7450,6 +7450,10 @@ Annots::Annots(PDFDoc *docA, int page, Object *annotsObj) | ||
20 | const Object &obj2 = annotsObj->arrayGetNF(i); | ||
21 | std::shared_ptr<Annot> annot = createAnnot(std::move(obj1), &obj2); | ||
22 | if (annot) { | ||
23 | + if (annot.use_count() > 100000) { | ||
24 | + error(errSyntaxError, -1, "Annotations likely malformed. Too many references. Stopping processing annots on page {0:d}", page); | ||
25 | + break; | ||
26 | + } | ||
27 | if (annot->isOk()) { | ||
28 | annot->setPage(page, false); // Don't change /P | ||
29 | appendAnnot(annot); | ||
30 | diff --git a/poppler/Page.cc b/poppler/Page.cc | ||
31 | index 234f124..858b128 100644 | ||
32 | --- a/poppler/Page.cc | ||
33 | +++ b/poppler/Page.cc | ||
34 | @@ -288,6 +288,22 @@ Page::Page(PDFDoc *docA, int numA, Object &&pageDict, Ref pageRefA, PageAttrs *a | ||
35 | goto err2; | ||
36 | } | ||
37 | |||
38 | + if (annotsObj.isArray() && annotsObj.arrayGetLength() > 10000) { | ||
39 | + error(errSyntaxError, -1, "Page annotations object (page {0:d}) is likely malformed. Too big: ({1:d})", num, annotsObj.arrayGetLength()); | ||
40 | + goto err2; | ||
41 | + } | ||
42 | + if (annotsObj.isRef()) { | ||
43 | + auto resolvedObj = getAnnotsObject(); | ||
44 | + if (resolvedObj.isArray() && resolvedObj.arrayGetLength() > 10000) { | ||
45 | + error(errSyntaxError, -1, "Page annotations object (page {0:d}) is likely malformed. Too big: ({1:d})", num, resolvedObj.arrayGetLength()); | ||
46 | + goto err2; | ||
47 | + } | ||
48 | + if (!resolvedObj.isArray() && !resolvedObj.isNull()) { | ||
49 | + error(errSyntaxError, -1, "Page annotations object (page {0:d}) is wrong type ({1:s})", num, resolvedObj.getTypeName()); | ||
50 | + goto err2; | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | // contents | ||
55 | contents = pageObj.dictLookupNF("Contents").copy(); | ||
56 | if (!(contents.isRef() || contents.isArray() || contents.isNull())) { | ||
57 | -- | ||
58 | 2.40.0 | ||
diff --git a/meta-oe/recipes-support/poppler/poppler_23.04.0.bb b/meta-oe/recipes-support/poppler/poppler_23.04.0.bb index a8ab19064d..81574177e0 100644 --- a/meta-oe/recipes-support/poppler/poppler_23.04.0.bb +++ b/meta-oe/recipes-support/poppler/poppler_23.04.0.bb | |||
@@ -16,6 +16,8 @@ SRC_URI = "http://poppler.freedesktop.org/${BP}.tar.xz \ | |||
16 | file://CVE-2025-32365.patch \ | 16 | file://CVE-2025-32365.patch \ |
17 | file://CVE-2025-43903-0001.patch \ | 17 | file://CVE-2025-43903-0001.patch \ |
18 | file://CVE-2025-43903-0002.patch \ | 18 | file://CVE-2025-43903-0002.patch \ |
19 | file://CVE-2025-52886-0001.patch \ | ||
20 | file://CVE-2025-52886-0002.patch \ | ||
19 | " | 21 | " |
20 | SRC_URI[sha256sum] = "b6d893dc7dcd4138b9e9df59a13c59695e50e80dc5c2cacee0674670693951a1" | 22 | SRC_URI[sha256sum] = "b6d893dc7dcd4138b9e9df59a13c59695e50e80dc5c2cacee0674670693951a1" |
21 | 23 | ||