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