Debian Codegraph @

qt6/src/poppler-annotation.cc

raw
1 /* poppler-annotation.cc: qt interface to poppler
2 * Copyright (C) 2006, 2009, 2012-2015, 2018-2022, 2024, 2025 Albert Astals Cid <[email protected]>
3 * Copyright (C) 2006, 2008, 2010 Pino Toscano <[email protected]>
4 * Copyright (C) 2012, Guillermo A. Amaral B. <[email protected]>
5 * Copyright (C) 2012-2014 Fabio D'Urso <[email protected]>
6 * Copyright (C) 2012, 2015, Tobias Koenig <[email protected]>
7 * Copyright (C) 2018 Adam Reichold <[email protected]>
8 * Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich
9 * Copyright (C) 2018 Intevation GmbH <[email protected]>
10 * Copyright (C) 2018 Dileep Sankhla <[email protected]>
11 * Copyright (C) 2018, 2019 Tobias Deiminger <[email protected]>
12 * Copyright (C) 2018 Carlos Garcia Campos <[email protected]>
13 * Copyright (C) 2020-2022 Oliver Sander <[email protected]>
14 * Copyright (C) 2020 Katarina Behrens <[email protected]>
15 * Copyright (C) 2020 Thorsten Behrens <[email protected]>
16 * Copyright (C) 2020, 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by Technische Universität Dresden
17 * Copyright (C) 2021 Mahmoud Ahmed Khalil <[email protected]>
18 * Copyright (C) 2024, 2025 g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
19 * Adapting code from
20 * Copyright (C) 2004 by Enrico Ros <[email protected]>
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2, or (at your option)
25 * any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
35 */
36
37 // qt/kde includes
38 #include <QtCore/QtAlgorithms>
39 #include <QtGui/QColor>
40 #include <QtGui/QTransform>
41 #include <QImage>
42
43 // local includes
44 #include "CryptoSignBackend.h"
45 #include "poppler-annotation.h"
46 #include "poppler-link.h"
47 #include "poppler-qt6.h"
48 #include "poppler-annotation-helper.h"
49 #include "poppler-annotation-private.h"
50 #include "poppler-page-private.h"
51 #include "poppler-private.h"
52 #include "poppler-form.h"
53
54 // poppler includes
55 #include <Page.h>
56 #include <Annot.h>
57 #include <Gfx.h>
58 #include <Error.h>
59 #include <FileSpec.h>
60 #include <Link.h>
61 #include <DateInfo.h>
62
63 template<typename T, typename U>
64 static std::unique_ptr<T> static_pointer_cast(std::unique_ptr<U> &&in)
65 {
66 return std::unique_ptr<T>(static_cast<std::add_pointer_t<T>>(in.release()));
67 }
68
69 /* Almost all getters directly query the underlying poppler annotation, with
70 * the exceptions of link, file attachment, sound, movie and screen annotations,
71 * Whose data retrieval logic has not been moved yet. Their getters return
72 * static data set at creation time by findAnnotations
73 */
74
75 namespace Poppler {
76
77 // BEGIN AnnotationAppearancePrivate implementation
78 AnnotationAppearancePrivate::AnnotationAppearancePrivate(Annot *annot)
79 {
80 if (annot) {
81 appearance = annot->getAppearance();
82 } else {
83 appearance.setToNull();
84 }
85 }
86 // END AnnotationAppearancePrivate implementation
87
88 // BEGIN AnnotationAppearance implementation
89 AnnotationAppearance::AnnotationAppearance(AnnotationAppearancePrivate *annotationAppearancePrivate) : d(annotationAppearancePrivate) { }
90
91 AnnotationAppearance::~AnnotationAppearance()
92 {
93 delete d;
94 }
95 // END AnnotationAppearance implementation
96
97 // BEGIN Annotation implementation
98 AnnotationPrivate::AnnotationPrivate() : revisionScope(Annotation::Root), revisionType(Annotation::None), pdfAnnot(nullptr), pdfPage(nullptr), parentDoc(nullptr) { }
99
100 void getRawDataFromQImage(const QImage &qimg, int bitsPerPixel, QByteArray *data, QByteArray *sMaskData)
101 {
102 const int height = qimg.height();
103 const int width = qimg.width();
104
105 switch (bitsPerPixel) {
106 case 1:
107 for (int line = 0; line < height; line++) {
108 const char *lineData = reinterpret_cast<const char *>(qimg.scanLine(line));
109 for (int offset = 0; offset < (width + 7) / 8; offset++) {
110 data->append(lineData[offset]);
111 }
112 }
113 break;
114 case 8:
115 case 24:
116 data->append((const char *)qimg.bits(), static_cast<int>(qimg.sizeInBytes()));
117 break;
118 case 32:
119 for (int line = 0; line < height; line++) {
120 const QRgb *lineData = reinterpret_cast<const QRgb *>(qimg.scanLine(line));
121 for (int offset = 0; offset < width; offset++) {
122 char a = (char)qAlpha(lineData[offset]);
123 char r = (char)qRed(lineData[offset]);
124 char g = (char)qGreen(lineData[offset]);
125 char b = (char)qBlue(lineData[offset]);
126
127 data->append(r);
128 data->append(g);
129 data->append(b);
130
131 sMaskData->append(a);
132 }
133 }
134 break;
135 }
136 }
137
138 void AnnotationPrivate::addRevision(Annotation *ann, Annotation::RevScope scope, Annotation::RevType type)
139 {
140 /* Since ownership stays with the caller, create an alias of ann */
141 revisions.push_back(ann->d_ptr->makeAlias());
142
143 /* Set revision properties */
144 revisionScope = scope;
145 revisionType = type;
146 }
147
148 AnnotationPrivate::~AnnotationPrivate() = default;
149
150 void AnnotationPrivate::tieToNativeAnnot(std::shared_ptr<Annot> ann, ::Page *page, Poppler::DocumentData *doc)
151 {
152 if (pdfAnnot) {
153 error(errIO, -1, "Annotation is already tied");
154 return;
155 }
156
157 pdfAnnot = std::move(ann);
158 pdfPage = page;
159 parentDoc = doc;
160 }
161
162 /* This method is called when a new annotation is created, after pdfAnnot and
163 * pdfPage have been set */
164 void AnnotationPrivate::flushBaseAnnotationProperties()
165 {
166 Q_ASSERT(pdfPage);
167
168 std::unique_ptr<Annotation> q = makeAlias(); // Setters are defined in the public class
169
170 // Since pdfAnnot has been set, this calls will write in the Annot object
171 q->setAuthor(author);
172 q->setContents(contents);
173 q->setUniqueName(uniqueName);
174 q->setModificationDate(modDate);
175 q->setCreationDate(creationDate);
176 q->setFlags(flags);
177 // q->setBoundary(boundary); -- already set by subclass-specific code
178 q->setStyle(style);
179 q->setPopup(popup);
180
181 // Clear some members to save memory
182 author.clear();
183 contents.clear();
184 uniqueName.clear();
185 revisions.clear();
186 }
187
188 // Returns matrix to convert from user space coords (oriented according to the
189 // specified rotation) to normalized coords
190 static void fillNormalizationMTX(::Page *pdfPage, double MTX[6], int pageRotation)
191 {
192 Q_ASSERT(pdfPage);
193
194 // build a normalized transform matrix for this page at 100% scale
195 GfxState *gfxState = new GfxState(72.0, 72.0, pdfPage->getCropBox(), pageRotation, true);
196 const double *gfxCTM = gfxState->getCTM();
197
198 double w = pdfPage->getCropWidth();
199 double h = pdfPage->getCropHeight();
200
201 // Swap width and height if the page is rotated landscape or seascape
202 if (pageRotation == 90 || pageRotation == 270) {
203 double t = w;
204 w = h;
205 h = t;
206 }
207
208 for (int i = 0; i < 6; i += 2) {
209 MTX[i] = gfxCTM[i] / w;
210 MTX[i + 1] = gfxCTM[i + 1] / h;
211 }
212 delete gfxState;
213 }
214
215 // Returns matrix to convert from user space coords (i.e. those that are stored
216 // in the PDF file) to normalized coords (i.e. those that we expose to clients).
217 // This method also applies a rotation around the top-left corner if the
218 // FixedRotation flag is set.
219 void AnnotationPrivate::fillTransformationMTX(double MTX[6]) const
220 {
221 Q_ASSERT(pdfPage);
222 Q_ASSERT(pdfAnnot);
223
224 const int pageRotate = pdfPage->getRotate();
225
226 if (pageRotate == 0 || (pdfAnnot->getFlags() & Annot::flagNoRotate) == 0) {
227 // Use the normalization matrix for this page's rotation
228 fillNormalizationMTX(pdfPage, MTX, pageRotate);
229 } else {
230 // Clients expect coordinates relative to this page's rotation, but
231 // FixedRotation annotations internally use unrotated coordinates:
232 // construct matrix to both normalize and rotate coordinates using the
233 // top-left corner as rotation pivot
234
235 double MTXnorm[6];
236 fillNormalizationMTX(pdfPage, MTXnorm, pageRotate);
237
238 QTransform transform(MTXnorm[0], MTXnorm[1], MTXnorm[2], MTXnorm[3], MTXnorm[4], MTXnorm[5]);
239 transform.translate(+pdfAnnot->getXMin(), +pdfAnnot->getYMax());
240 transform.rotate(pageRotate);
241 transform.translate(-pdfAnnot->getXMin(), -pdfAnnot->getYMax());
242
243 MTX[0] = transform.m11();
244 MTX[1] = transform.m12();
245 MTX[2] = transform.m21();
246 MTX[3] = transform.m22();
247 MTX[4] = transform.dx();
248 MTX[5] = transform.dy();
249 }
250 }
251
252 QRectF AnnotationPrivate::fromPdfRectangle(const PDFRectangle &r) const
253 {
254 double swp, MTX[6];
255 fillTransformationMTX(MTX);
256
257 QPointF p1, p2;
258 XPDFReader::transform(MTX, r.x1, r.y1, p1);
259 XPDFReader::transform(MTX, r.x2, r.y2, p2);
260
261 double tl_x = p1.x();
262 double tl_y = p1.y();
263 double br_x = p2.x();
264 double br_y = p2.y();
265
266 if (tl_x > br_x) {
267 swp = tl_x;
268 tl_x = br_x;
269 br_x = swp;
270 }
271
272 if (tl_y > br_y) {
273 swp = tl_y;
274 tl_y = br_y;
275 br_y = swp;
276 }
277
278 return QRectF(QPointF(tl_x, tl_y), QPointF(br_x, br_y));
279 }
280
281 // This function converts a boundary QRectF in normalized coords to a
282 // PDFRectangle in user coords. If the FixedRotation flag is set, this function
283 // also applies a rotation around the top-left corner: it's the inverse of
284 // the transformation produced by fillTransformationMTX, but we can't use
285 // fillTransformationMTX here because it relies on the native annotation
286 // object's boundary rect to be already set up.
287 PDFRectangle boundaryToPdfRectangle(::Page *pdfPage, const QRectF &r, int rFlags)
288 {
289 Q_ASSERT(pdfPage);
290
291 const int pageRotate = pdfPage->getRotate();
292
293 double MTX[6];
294 fillNormalizationMTX(pdfPage, MTX, pageRotate);
295
296 double tl_x, tl_y, br_x, br_y, swp;
297 XPDFReader::invTransform(MTX, r.topLeft(), tl_x, tl_y);
298 XPDFReader::invTransform(MTX, r.bottomRight(), br_x, br_y);
299
300 if (tl_x > br_x) {
301 swp = tl_x;
302 tl_x = br_x;
303 br_x = swp;
304 }
305
306 if (tl_y > br_y) {
307 swp = tl_y;
308 tl_y = br_y;
309 br_y = swp;
310 }
311
312 const int rotationFixUp = (rFlags & Annotation::FixedRotation) ? pageRotate : 0;
313 const double width = br_x - tl_x;
314 const double height = br_y - tl_y;
315
316 if (rotationFixUp == 0) {
317 return PDFRectangle(tl_x, tl_y, br_x, br_y);
318 } else if (rotationFixUp == 90) {
319 return PDFRectangle(tl_x, tl_y - width, tl_x + height, tl_y);
320 } else if (rotationFixUp == 180) {
321 return PDFRectangle(br_x, tl_y - height, br_x + width, tl_y);
322 } else { // rotationFixUp == 270
323 return PDFRectangle(br_x, br_y - width, br_x + height, br_y);
324 }
325 }
326
327 PDFRectangle AnnotationPrivate::boundaryToPdfRectangle(const QRectF &r, int rFlags) const
328 {
329 return Poppler::boundaryToPdfRectangle(pdfPage, r, rFlags);
330 }
331
332 std::unique_ptr<AnnotPath> AnnotationPrivate::toAnnotPath(const QVector<QPointF> &list) const
333 {
334 const int count = list.size();
335 std::vector<AnnotCoord> ac;
336 ac.reserve(count);
337
338 double MTX[6];
339 fillTransformationMTX(MTX);
340
341 Q_FOREACH (const QPointF &p, list) {
342 double x, y;
343 XPDFReader::invTransform(MTX, p, x, y);
344 ac.emplace_back(x, y);
345 }
346
347 return std::make_unique<AnnotPath>(std::move(ac));
348 }
349
350 std::vector<std::unique_ptr<Annotation>> AnnotationPrivate::findAnnotations(::Page *pdfPage, DocumentData *doc, const QSet<Annotation::SubType> &subtypes, int parentID)
351 {
352 Annots *annots = pdfPage->getAnnots();
353
354 const bool wantTextAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AText);
355 const bool wantLineAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::ALine);
356 const bool wantGeomAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AGeom);
357 const bool wantHighlightAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AHighlight);
358 const bool wantStampAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AStamp);
359 const bool wantInkAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AInk);
360 const bool wantLinkAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::ALink);
361 const bool wantCaretAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::ACaret);
362 const bool wantFileAttachmentAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AFileAttachment);
363 const bool wantSoundAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::ASound);
364 const bool wantMovieAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AMovie);
365 const bool wantScreenAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AScreen);
366 const bool wantWidgetAnnotations = subtypes.isEmpty() || subtypes.contains(Annotation::AWidget);
367
368 // Create Annotation objects and tie to their native Annot
369 std::vector<std::unique_ptr<Annotation>> res;
370 for (const std::shared_ptr<Annot> &ann : annots->getAnnots()) {
371 if (!ann) {
372 error(errInternal, -1, "Annot is null");
373 continue;
374 }
375
376 // Check parent annotation
377 AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(ann.get());
378 if (!markupann) {
379 // Assume it's a root annotation, and skip if user didn't request it
380 if (parentID != -1) {
381 continue;
382 }
383 } else if (markupann->getInReplyToID() != parentID) {
384 continue;
385 }
386
387 /* Create Annotation of the right subclass */
388 std::unique_ptr<Annotation> annotation;
389 Annot::AnnotSubtype subType = ann->getType();
390
391 switch (subType) {
392 case Annot::typeText:
393 if (!wantTextAnnotations) {
394 continue;
395 }
396 annotation = std::make_unique<TextAnnotation>(TextAnnotation::Linked);
397 break;
398 case Annot::typeFreeText:
399 if (!wantTextAnnotations) {
400 continue;
401 }
402 annotation = std::make_unique<TextAnnotation>(TextAnnotation::InPlace);
403 break;
404 case Annot::typeLine:
405 if (!wantLineAnnotations) {
406 continue;
407 }
408 annotation = std::make_unique<LineAnnotation>(LineAnnotation::StraightLine);
409 break;
410 case Annot::typePolygon:
411 case Annot::typePolyLine:
412 if (!wantLineAnnotations) {
413 continue;
414 }
415 annotation = std::make_unique<LineAnnotation>(LineAnnotation::Polyline);
416 break;
417 case Annot::typeSquare:
418 case Annot::typeCircle:
419 if (!wantGeomAnnotations) {
420 continue;
421 }
422 annotation = std::make_unique<GeomAnnotation>();
423 break;
424 case Annot::typeHighlight:
425 case Annot::typeUnderline:
426 case Annot::typeSquiggly:
427 case Annot::typeStrikeOut:
428 if (!wantHighlightAnnotations) {
429 continue;
430 }
431 annotation = std::make_unique<HighlightAnnotation>();
432 break;
433 case Annot::typeStamp:
434 if (!wantStampAnnotations) {
435 continue;
436 }
437 annotation = std::make_unique<StampAnnotation>();
438 break;
439 case Annot::typeInk:
440 if (!wantInkAnnotations) {
441 continue;
442 }
443 annotation = std::make_unique<InkAnnotation>();
444 break;
445 case Annot::typeLink: /* TODO: Move logic to getters */
446 {
447 if (!wantLinkAnnotations) {
448 continue;
449 }
450 // parse Link params
451 AnnotLink *linkann = static_cast<AnnotLink *>(ann.get());
452 LinkAnnotation *l = new LinkAnnotation();
453
454 // -> hlMode
455 l->setLinkHighlightMode((LinkAnnotation::HighlightMode)linkann->getLinkEffect());
456
457 // -> link region
458 // TODO
459
460 // reading link action
461 if (linkann->getAction()) {
462 std::unique_ptr<Link> popplerLink = PageData::convertLinkActionToLink(linkann->getAction(), doc, QRectF());
463 if (popplerLink) {
464 l->setLinkDestination(std::move(popplerLink));
465 }
466 }
467 annotation.reset(l);
468 break;
469 }
470 case Annot::typeCaret:
471 if (!wantCaretAnnotations) {
472 continue;
473 }
474 annotation = std::make_unique<CaretAnnotation>();
475 break;
476 case Annot::typeFileAttachment: /* TODO: Move logic to getters */
477 {
478 if (!wantFileAttachmentAnnotations) {
479 continue;
480 }
481 AnnotFileAttachment *attachann = static_cast<AnnotFileAttachment *>(ann.get());
482 FileAttachmentAnnotation *f = new FileAttachmentAnnotation();
483 // -> fileIcon
484 f->setFileIconName(QString::fromLatin1(attachann->getName()->c_str()));
485 // -> embeddedFile
486 auto filespec = std::make_unique<FileSpec>(attachann->getFile());
487 f->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(filespec))));
488 annotation.reset(f);
489 break;
490 }
491 case Annot::typeSound: /* TODO: Move logic to getters */
492 {
493 if (!wantSoundAnnotations) {
494 continue;
495 }
496 AnnotSound *soundann = static_cast<AnnotSound *>(ann.get());
497 SoundAnnotation *s = new SoundAnnotation();
498
499 // -> soundIcon
500 s->setSoundIconName(QString::fromLatin1(soundann->getName()->c_str()));
501 // -> sound
502 s->setSound(new SoundObject(soundann->getSound()));
503 annotation.reset(s);
504 break;
505 }
506 case Annot::typeMovie: /* TODO: Move logic to getters */
507 {
508 if (!wantMovieAnnotations) {
509 continue;
510 }
511 AnnotMovie *movieann = static_cast<AnnotMovie *>(ann.get());
512 MovieAnnotation *m = new MovieAnnotation();
513
514 // -> movie
515 MovieObject *movie = new MovieObject(movieann);
516 m->setMovie(movie);
517 // -> movieTitle
518 const GooString *movietitle = movieann->getTitle();
519 if (movietitle) {
520 m->setMovieTitle(QString::fromLatin1(movietitle->c_str()));
521 }
522 annotation.reset(m);
523 break;
524 }
525 case Annot::typeScreen: {
526 if (!wantScreenAnnotations) {
527 continue;
528 }
529 AnnotScreen *screenann = static_cast<AnnotScreen *>(ann.get());
530 // TODO Support other link types than Link::Rendition in ScreenAnnotation
531 if (!screenann->getAction() || screenann->getAction()->getKind() != actionRendition) {
532 continue;
533 }
534 ScreenAnnotation *s = new ScreenAnnotation();
535
536 // -> screen
537 std::unique_ptr<Link> popplerLink = PageData::convertLinkActionToLink(screenann->getAction(), doc, QRectF());
538 s->setAction(static_cast<Poppler::LinkRendition *>(popplerLink.release()));
539
540 // -> screenTitle
541 const GooString *screentitle = screenann->getTitle();
542 if (screentitle) {
543 s->setScreenTitle(UnicodeParsedString(screentitle));
544 }
545 annotation.reset(s);
546 break;
547 }
548 case Annot::typePopup:
549 continue; // popups are parsed by Annotation's window() getter
550 case Annot::typeUnknown:
551 continue; // special case for ignoring unknown annotations
552 case Annot::typeWidget:
553 if (!wantWidgetAnnotations) {
554 continue;
555 }
556 annotation.reset(new WidgetAnnotation());
557 break;
558 case Annot::typeRichMedia: {
559 const AnnotRichMedia *annotRichMedia = static_cast<AnnotRichMedia *>(ann.get());
560
561 RichMediaAnnotation *richMediaAnnotation = new RichMediaAnnotation;
562
563 const AnnotRichMedia::Settings *annotSettings = annotRichMedia->getSettings();
564 if (annotSettings) {
565 RichMediaAnnotation::Settings *settings = new RichMediaAnnotation::Settings;
566
567 if (annotSettings->getActivation()) {
568 RichMediaAnnotation::Activation *activation = new RichMediaAnnotation::Activation;
569
570 switch (annotSettings->getActivation()->getCondition()) {
571 case AnnotRichMedia::Activation::conditionPageOpened:
572 activation->setCondition(RichMediaAnnotation::Activation::PageOpened);
573 break;
574 case AnnotRichMedia::Activation::conditionPageVisible:
575 activation->setCondition(RichMediaAnnotation::Activation::PageVisible);
576 break;
577 case AnnotRichMedia::Activation::conditionUserAction:
578 activation->setCondition(RichMediaAnnotation::Activation::UserAction);
579 break;
580 }
581
582 settings->setActivation(activation);
583 }
584
585 if (annotSettings->getDeactivation()) {
586 RichMediaAnnotation::Deactivation *deactivation = new RichMediaAnnotation::Deactivation;
587
588 switch (annotSettings->getDeactivation()->getCondition()) {
589 case AnnotRichMedia::Deactivation::conditionPageClosed:
590 deactivation->setCondition(RichMediaAnnotation::Deactivation::PageClosed);
591 break;
592 case AnnotRichMedia::Deactivation::conditionPageInvisible:
593 deactivation->setCondition(RichMediaAnnotation::Deactivation::PageInvisible);
594 break;
595 case AnnotRichMedia::Deactivation::conditionUserAction:
596 deactivation->setCondition(RichMediaAnnotation::Deactivation::UserAction);
597 break;
598 }
599
600 settings->setDeactivation(deactivation);
601 }
602
603 richMediaAnnotation->setSettings(settings);
604 }
605
606 const AnnotRichMedia::Content *annotContent = annotRichMedia->getContent();
607 if (annotContent) {
608 RichMediaAnnotation::Content *content = new RichMediaAnnotation::Content;
609
610 const std::vector<std::unique_ptr<AnnotRichMedia::Configuration>> &annotConfigurations = annotContent->getConfigurations();
611 QList<RichMediaAnnotation::Configuration *> configurations;
612
613 for (const std::unique_ptr<AnnotRichMedia::Configuration> &annotConfiguration : annotConfigurations) {
614 if (!annotConfiguration) {
615 continue;
616 }
617
618 RichMediaAnnotation::Configuration *configuration = new RichMediaAnnotation::Configuration;
619
620 if (annotConfiguration->getName()) {
621 configuration->setName(UnicodeParsedString(annotConfiguration->getName()));
622 }
623
624 switch (annotConfiguration->getType()) {
625 case AnnotRichMedia::Configuration::type3D:
626 configuration->setType(RichMediaAnnotation::Configuration::Type3D);
627 break;
628 case AnnotRichMedia::Configuration::typeFlash:
629 configuration->setType(RichMediaAnnotation::Configuration::TypeFlash);
630 break;
631 case AnnotRichMedia::Configuration::typeSound:
632 configuration->setType(RichMediaAnnotation::Configuration::TypeSound);
633 break;
634 case AnnotRichMedia::Configuration::typeVideo:
635 configuration->setType(RichMediaAnnotation::Configuration::TypeVideo);
636 break;
637 }
638
639 const std::vector<std::unique_ptr<AnnotRichMedia::Instance>> &annotInstances = annotConfiguration->getInstances();
640 QList<RichMediaAnnotation::Instance *> instances;
641
642 for (const std::unique_ptr<AnnotRichMedia::Instance> &annotInstance : annotInstances) {
643 if (!annotInstance) {
644 continue;
645 }
646
647 RichMediaAnnotation::Instance *instance = new RichMediaAnnotation::Instance;
648
649 switch (annotInstance->getType()) {
650 case AnnotRichMedia::Instance::type3D:
651 instance->setType(RichMediaAnnotation::Instance::Type3D);
652 break;
653 case AnnotRichMedia::Instance::typeFlash:
654 instance->setType(RichMediaAnnotation::Instance::TypeFlash);
655 break;
656 case AnnotRichMedia::Instance::typeSound:
657 instance->setType(RichMediaAnnotation::Instance::TypeSound);
658 break;
659 case AnnotRichMedia::Instance::typeVideo:
660 instance->setType(RichMediaAnnotation::Instance::TypeVideo);
661 break;
662 }
663
664 const AnnotRichMedia::Params *annotParams = annotInstance->getParams();
665 if (annotParams) {
666 RichMediaAnnotation::Params *params = new RichMediaAnnotation::Params;
667
668 if (annotParams->getFlashVars()) {
669 params->setFlashVars(UnicodeParsedString(annotParams->getFlashVars()));
670 }
671
672 instance->setParams(params);
673 }
674
675 instances.append(instance);
676 }
677
678 configuration->setInstances(instances);
679
680 configurations.append(configuration);
681 }
682
683 content->setConfigurations(configurations);
684
685 const std::vector<std::unique_ptr<AnnotRichMedia::Asset>> &annotAssets = annotContent->getAssets();
686 QList<RichMediaAnnotation::Asset *> assets;
687
688 for (const std::unique_ptr<AnnotRichMedia::Asset> &annotAsset : annotAssets) {
689 if (!annotAsset) {
690 continue;
691 }
692
693 RichMediaAnnotation::Asset *asset = new RichMediaAnnotation::Asset;
694
695 if (annotAsset->getName()) {
696 asset->setName(UnicodeParsedString(annotAsset->getName()));
697 }
698
699 auto fileSpec = std::make_unique<FileSpec>(annotAsset->getFileSpec());
700 asset->setEmbeddedFile(new EmbeddedFile(*new EmbeddedFileData(std::move(fileSpec))));
701
702 assets.append(asset);
703 }
704
705 content->setAssets(assets);
706
707 richMediaAnnotation->setContent(content);
708 }
709
710 annotation.reset(richMediaAnnotation);
711
712 break;
713 }
714 default: {
715 #define CASE_FOR_TYPE(thetype) \
716 case Annot::type##thetype: \
717 error(errUnimplemented, -1, "Annotation " #thetype " not supported"); \
718 break;
719 switch (subType) {
720 CASE_FOR_TYPE(PrinterMark)
721 CASE_FOR_TYPE(TrapNet)
722 CASE_FOR_TYPE(Watermark)
723 CASE_FOR_TYPE(3D)
724 default:
725 error(errUnimplemented, -1, "Annotation {0:d} not supported", subType);
726 }
727 continue;
728 #undef CASE_FOR_TYPE
729 }
730 }
731
732 annotation->d_ptr->tieToNativeAnnot(ann, pdfPage, doc);
733 res.push_back(std::move(annotation));
734 }
735
736 return res;
737 }
738
739 Ref AnnotationPrivate::pdfObjectReference() const
740 {
741 if (pdfAnnot == nullptr) {
742 return Ref::INVALID();
743 }
744
745 return pdfAnnot->getRef();
746 }
747
748 std::unique_ptr<Link> AnnotationPrivate::additionalAction(Annotation::AdditionalActionType type) const
749 {
750 if (pdfAnnot->getType() != Annot::typeScreen && pdfAnnot->getType() != Annot::typeWidget) {
751 return {};
752 }
753
754 const Annot::AdditionalActionsType actionType = toPopplerAdditionalActionType(type);
755
756 std::unique_ptr<::LinkAction> linkAction;
757 if (pdfAnnot->getType() == Annot::typeScreen) {
758 linkAction = static_cast<AnnotScreen *>(pdfAnnot.get())->getAdditionalAction(actionType);
759 } else {
760 linkAction = static_cast<AnnotWidget *>(pdfAnnot.get())->getAdditionalAction(actionType);
761 }
762
763 if (linkAction) {
764 return PageData::convertLinkActionToLink(linkAction.get(), parentDoc, QRectF());
765 }
766
767 return {};
768 }
769
770 void AnnotationPrivate::addAnnotationToPage(::Page *pdfPage, DocumentData *doc, const Annotation *ann)
771 {
772 if (ann->d_ptr->pdfAnnot != nullptr) {
773 error(errIO, -1, "Annotation is already tied");
774 return;
775 }
776
777 // Unimplemented annotations can't be created by the user because their ctor
778 // is private. Therefore, createNativeAnnot will never return 0
779 std::shared_ptr<Annot> nativeAnnot = ann->d_ptr->createNativeAnnot(pdfPage, doc);
780 Q_ASSERT(nativeAnnot);
781
782 if (ann->d_ptr->annotationAppearance.isStream()) {
783 nativeAnnot->setNewAppearance(ann->d_ptr->annotationAppearance.copy());
784 }
785
786 pdfPage->addAnnot(nativeAnnot);
787 }
788
789 void AnnotationPrivate::removeAnnotationFromPage(::Page *pdfPage, const Annotation *ann)
790 {
791 if (ann->d_ptr->pdfAnnot == nullptr) {
792 error(errIO, -1, "Annotation is not tied");
793 return;
794 }
795
796 if (ann->d_ptr->pdfPage != pdfPage) {
797 error(errIO, -1, "Annotation doesn't belong to the specified page");
798 return;
799 }
800
801 // Remove annotation
802 pdfPage->removeAnnot(ann->d_ptr->pdfAnnot);
803
804 // Destroy object
805 delete ann;
806 }
807
808 class TextAnnotationPrivate : public AnnotationPrivate
809 {
810 public:
811 TextAnnotationPrivate();
812 std::unique_ptr<Annotation> makeAlias() override;
813 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
814 void setDefaultAppearanceToNative();
815 std::unique_ptr<DefaultAppearance> getDefaultAppearanceFromNative() const;
816
817 // data fields
818 TextAnnotation::TextType textType;
819 QString textIcon;
820 std::optional<QFont> textFont;
821 QColor textColor = Qt::black;
822 TextAnnotation::InplaceAlignPosition inplaceAlign;
823 QVector<QPointF> inplaceCallout;
824 TextAnnotation::InplaceIntent inplaceIntent;
825 };
826
827 class Annotation::Style::Private : public QSharedData
828 {
829 public:
830 Private() : opacity(1.0), width(1.0), lineStyle(Solid), xCorners(0.0), yCorners(0.0), lineEffect(NoEffect), effectIntensity(1.0)
831 {
832 dashArray.resize(1);
833 dashArray[0] = 3;
834 }
835
836 QColor color;
837 double opacity;
838 double width;
839 Annotation::LineStyle lineStyle;
840 double xCorners;
841 double yCorners;
842 QVector<double> dashArray;
843 Annotation::LineEffect lineEffect;
844 double effectIntensity;
845 };
846
847 Annotation::Style::Style() : d(new Private) { }
848
849 Annotation::Style::Style(const Style &other) = default;
850
851 Annotation::Style &Annotation::Style::operator=(const Style &other)
852 {
853 if (this != &other) {
854 d = other.d;
855 }
856
857 return *this;
858 }
859
860 Annotation::Style::~Style() = default;
861
862 QColor Annotation::Style::color() const
863 {
864 return d->color;
865 }
866
867 void Annotation::Style::setColor(const QColor &color)
868 {
869 d->color = color;
870 }
871
872 double Annotation::Style::opacity() const
873 {
874 return d->opacity;
875 }
876
877 void Annotation::Style::setOpacity(double opacity)
878 {
879 d->opacity = opacity;
880 }
881
882 double Annotation::Style::width() const
883 {
884 return d->width;
885 }
886
887 void Annotation::Style::setWidth(double width)
888 {
889 d->width = width;
890 }
891
892 Annotation::LineStyle Annotation::Style::lineStyle() const
893 {
894 return d->lineStyle;
895 }
896
897 void Annotation::Style::setLineStyle(Annotation::LineStyle style)
898 {
899 d->lineStyle = style;
900 }
901
902 double Annotation::Style::xCorners() const
903 {
904 return d->xCorners;
905 }
906
907 void Annotation::Style::setXCorners(double radius)
908 {
909 d->xCorners = radius;
910 }
911
912 double Annotation::Style::yCorners() const
913 {
914 return d->yCorners;
915 }
916
917 void Annotation::Style::setYCorners(double radius)
918 {
919 d->yCorners = radius;
920 }
921
922 const QVector<double> &Annotation::Style::dashArray() const
923 {
924 return d->dashArray;
925 }
926
927 void Annotation::Style::setDashArray(const QVector<double> &array)
928 {
929 d->dashArray = array;
930 }
931
932 Annotation::LineEffect Annotation::Style::lineEffect() const
933 {
934 return d->lineEffect;
935 }
936
937 void Annotation::Style::setLineEffect(Annotation::LineEffect effect)
938 {
939 d->lineEffect = effect;
940 }
941
942 double Annotation::Style::effectIntensity() const
943 {
944 return d->effectIntensity;
945 }
946
947 void Annotation::Style::setEffectIntensity(double intens)
948 {
949 d->effectIntensity = intens;
950 }
951
952 class Annotation::Popup::Private : public QSharedData
953 {
954 public:
955 Private() : flags(-1) { }
956
957 int flags;
958 QRectF geometry;
959 QString title;
960 QString summary;
961 QString text;
962 };
963
964 Annotation::Popup::Popup() : d(new Private) { }
965
966 Annotation::Popup::Popup(const Popup &other) = default;
967
968 Annotation::Popup &Annotation::Popup::operator=(const Popup &other)
969 {
970 if (this != &other) {
971 d = other.d;
972 }
973
974 return *this;
975 }
976
977 Annotation::Popup::~Popup() = default;
978
979 int Annotation::Popup::flags() const
980 {
981 return d->flags;
982 }
983
984 void Annotation::Popup::setFlags(int flags)
985 {
986 d->flags = flags;
987 }
988
989 QRectF Annotation::Popup::geometry() const
990 {
991 return d->geometry;
992 }
993
994 void Annotation::Popup::setGeometry(const QRectF &geom)
995 {
996 d->geometry = geom;
997 }
998
999 QString Annotation::Popup::title() const
1000 {
1001 return d->title;
1002 }
1003
1004 void Annotation::Popup::setTitle(const QString &title)
1005 {
1006 d->title = title;
1007 }
1008
1009 QString Annotation::Popup::summary() const
1010 {
1011 return d->summary;
1012 }
1013
1014 void Annotation::Popup::setSummary(const QString &summary)
1015 {
1016 d->summary = summary;
1017 }
1018
1019 QString Annotation::Popup::text() const
1020 {
1021 return d->text;
1022 }
1023
1024 void Annotation::Popup::setText(const QString &text)
1025 {
1026 d->text = text;
1027 }
1028
1029 Annotation::Annotation(AnnotationPrivate &dd) : d_ptr(&dd) { }
1030
1031 Annotation::~Annotation() = default;
1032
1033 QString Annotation::author() const
1034 {
1035 Q_D(const Annotation);
1036
1037 if (!d->pdfAnnot) {
1038 return d->author;
1039 }
1040
1041 const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get());
1042 return markupann ? UnicodeParsedString(markupann->getLabel()) : QString();
1043 }
1044
1045 void Annotation::setAuthor(const QString &author)
1046 {
1047 Q_D(Annotation);
1048
1049 if (!d->pdfAnnot) {
1050 d->author = author;
1051 return;
1052 }
1053
1054 AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get());
1055 if (markupann) {
1056 markupann->setLabel(std::unique_ptr<GooString>(QStringToUnicodeGooString(author)));
1057 }
1058 }
1059
1060 QString Annotation::contents() const
1061 {
1062 Q_D(const Annotation);
1063
1064 if (!d->pdfAnnot) {
1065 return d->contents;
1066 }
1067
1068 return UnicodeParsedString(d->pdfAnnot->getContents());
1069 }
1070
1071 void Annotation::setContents(const QString &contents)
1072 {
1073 Q_D(Annotation);
1074
1075 if (!d->pdfAnnot) {
1076 d->contents = contents;
1077 return;
1078 }
1079
1080 d->pdfAnnot->setContents(std::unique_ptr<GooString>(QStringToUnicodeGooString(contents)));
1081
1082 TextAnnotationPrivate *textAnnotD = dynamic_cast<TextAnnotationPrivate *>(d);
1083 if (textAnnotD) {
1084 textAnnotD->setDefaultAppearanceToNative();
1085 }
1086 }
1087
1088 QString Annotation::uniqueName() const
1089 {
1090 Q_D(const Annotation);
1091
1092 if (!d->pdfAnnot) {
1093 return d->uniqueName;
1094 }
1095
1096 return UnicodeParsedString(d->pdfAnnot->getName());
1097 }
1098
1099 void Annotation::setUniqueName(const QString &uniqueName)
1100 {
1101 Q_D(Annotation);
1102
1103 if (!d->pdfAnnot) {
1104 d->uniqueName = uniqueName;
1105 return;
1106 }
1107
1108 GooString s(uniqueName.toStdString());
1109 d->pdfAnnot->setName(&s);
1110 }
1111
1112 QDateTime Annotation::modificationDate() const
1113 {
1114 Q_D(const Annotation);
1115
1116 if (!d->pdfAnnot) {
1117 return d->modDate;
1118 }
1119
1120 if (d->pdfAnnot->getModified()) {
1121 return convertDate(d->pdfAnnot->getModified()->c_str());
1122 } else {
1123 return QDateTime();
1124 }
1125 }
1126
1127 void Annotation::setModificationDate(const QDateTime &date)
1128 {
1129 Q_D(Annotation);
1130
1131 if (!d->pdfAnnot) {
1132 d->modDate = date;
1133 return;
1134 }
1135
1136 if (d->pdfAnnot) {
1137 if (date.isValid()) {
1138 const time_t t = date.toSecsSinceEpoch();
1139 std::unique_ptr<GooString> s = timeToDateString(&t);
1140 d->pdfAnnot->setModified(std::move(s));
1141 } else {
1142 d->pdfAnnot->setModified(nullptr);
1143 }
1144 }
1145 }
1146
1147 QDateTime Annotation::creationDate() const
1148 {
1149 Q_D(const Annotation);
1150
1151 if (!d->pdfAnnot) {
1152 return d->creationDate;
1153 }
1154
1155 const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get());
1156
1157 if (markupann && markupann->getDate()) {
1158 return convertDate(markupann->getDate()->c_str());
1159 }
1160
1161 return modificationDate();
1162 }
1163
1164 void Annotation::setCreationDate(const QDateTime &date)
1165 {
1166 Q_D(Annotation);
1167
1168 if (!d->pdfAnnot) {
1169 d->creationDate = date;
1170 return;
1171 }
1172
1173 AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get());
1174 if (markupann) {
1175 if (date.isValid()) {
1176 const time_t t = date.toSecsSinceEpoch();
1177 std::unique_ptr<GooString> s = timeToDateString(&t);
1178 markupann->setDate(std::move(s));
1179 } else {
1180 markupann->setDate(nullptr);
1181 }
1182 }
1183 }
1184
1185 static Annotation::Flags fromPdfFlags(int flags)
1186 {
1187 Annotation::Flags qtflags;
1188
1189 if (flags & Annot::flagHidden) {
1190 qtflags |= Annotation::Hidden;
1191 }
1192 if (flags & Annot::flagNoZoom) {
1193 qtflags |= Annotation::FixedSize;
1194 }
1195 if (flags & Annot::flagNoRotate) {
1196 qtflags |= Annotation::FixedRotation;
1197 }
1198 if (!(flags & Annot::flagPrint)) {
1199 qtflags |= Annotation::DenyPrint;
1200 }
1201 if (flags & Annot::flagReadOnly) {
1202 qtflags |= Annotation::DenyWrite;
1203 qtflags |= Annotation::DenyDelete;
1204 }
1205 if (flags & Annot::flagLocked) {
1206 qtflags |= Annotation::DenyDelete;
1207 }
1208 if (flags & Annot::flagToggleNoView) {
1209 qtflags |= Annotation::ToggleHidingOnMouse;
1210 }
1211
1212 return qtflags;
1213 }
1214
1215 static int toPdfFlags(Annotation::Flags qtflags)
1216 {
1217 int flags = 0;
1218
1219 if (qtflags & Annotation::Hidden) {
1220 flags |= Annot::flagHidden;
1221 }
1222 if (qtflags & Annotation::FixedSize) {
1223 flags |= Annot::flagNoZoom;
1224 }
1225 if (qtflags & Annotation::FixedRotation) {
1226 flags |= Annot::flagNoRotate;
1227 }
1228 if (!(qtflags & Annotation::DenyPrint)) {
1229 flags |= Annot::flagPrint;
1230 }
1231 if (qtflags & Annotation::DenyWrite) {
1232 flags |= Annot::flagReadOnly;
1233 }
1234 if (qtflags & Annotation::DenyDelete) {
1235 flags |= Annot::flagLocked;
1236 }
1237 if (qtflags & Annotation::ToggleHidingOnMouse) {
1238 flags |= Annot::flagToggleNoView;
1239 }
1240
1241 return flags;
1242 }
1243
1244 Annotation::Flags Annotation::flags() const
1245 {
1246 Q_D(const Annotation);
1247
1248 if (!d->pdfAnnot) {
1249 return d->flags;
1250 }
1251
1252 return fromPdfFlags(d->pdfAnnot->getFlags());
1253 }
1254
1255 void Annotation::setFlags(Annotation::Flags flags)
1256 {
1257 Q_D(Annotation);
1258
1259 if (!d->pdfAnnot) {
1260 d->flags = flags;
1261 return;
1262 }
1263
1264 d->pdfAnnot->setFlags(toPdfFlags(flags));
1265 }
1266
1267 QRectF Annotation::boundary() const
1268 {
1269 Q_D(const Annotation);
1270
1271 if (!d->pdfAnnot) {
1272 return d->boundary;
1273 }
1274
1275 const PDFRectangle &rect = d->pdfAnnot->getRect();
1276 return d->fromPdfRectangle(rect);
1277 }
1278
1279 void Annotation::setBoundary(const QRectF &boundary)
1280 {
1281 Q_D(Annotation);
1282
1283 if (!d->pdfAnnot) {
1284 d->boundary = boundary;
1285 return;
1286 }
1287
1288 const PDFRectangle rect = d->boundaryToPdfRectangle(boundary, flags());
1289 if (rect == d->pdfAnnot->getRect()) {
1290 return;
1291 }
1292 d->pdfAnnot->setRect(rect);
1293 }
1294
1295 Annotation::Style Annotation::style() const
1296 {
1297 Q_D(const Annotation);
1298
1299 if (!d->pdfAnnot) {
1300 return d->style;
1301 }
1302
1303 Style s;
1304 s.setColor(convertAnnotColor(d->pdfAnnot->getColor()));
1305
1306 const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get());
1307 if (markupann) {
1308 s.setOpacity(markupann->getOpacity());
1309 }
1310
1311 const AnnotBorder *border = d->pdfAnnot->getBorder();
1312 if (border) {
1313 if (border->getType() == AnnotBorder::typeArray) {
1314 const AnnotBorderArray *border_array = static_cast<const AnnotBorderArray *>(border);
1315 s.setXCorners(border_array->getHorizontalCorner());
1316 s.setYCorners(border_array->getVerticalCorner());
1317 }
1318
1319 s.setWidth(border->getWidth());
1320 s.setLineStyle((Annotation::LineStyle)(1 << border->getStyle()));
1321
1322 const std::vector<double> &dashArray = border->getDash();
1323 s.setDashArray(QVector<double>(dashArray.begin(), dashArray.end()));
1324 }
1325
1326 AnnotBorderEffect *border_effect;
1327 switch (d->pdfAnnot->getType()) {
1328 case Annot::typeFreeText:
1329 border_effect = static_cast<AnnotFreeText *>(d->pdfAnnot.get())->getBorderEffect();
1330 break;
1331 case Annot::typeSquare:
1332 case Annot::typeCircle:
1333 border_effect = static_cast<AnnotGeometry *>(d->pdfAnnot.get())->getBorderEffect();
1334 break;
1335 default:
1336 border_effect = nullptr;
1337 }
1338 if (border_effect) {
1339 s.setLineEffect((Annotation::LineEffect)border_effect->getEffectType());
1340 s.setEffectIntensity(border_effect->getIntensity());
1341 }
1342
1343 return s;
1344 }
1345
1346 void Annotation::setStyle(const Annotation::Style &style)
1347 {
1348 Q_D(Annotation);
1349
1350 if (!d->pdfAnnot) {
1351 d->style = style;
1352 return;
1353 }
1354
1355 d->pdfAnnot->setColor(convertQColor(style.color()));
1356
1357 AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot.get());
1358 if (markupann) {
1359 markupann->setOpacity(style.opacity());
1360 }
1361
1362 auto border = std::make_unique<AnnotBorderArray>();
1363 border->setWidth(style.width());
1364 border->setHorizontalCorner(style.xCorners());
1365 border->setVerticalCorner(style.yCorners());
1366 d->pdfAnnot->setBorder(std::move(border));
1367 }
1368
1369 Annotation::Popup Annotation::popup() const
1370 {
1371 Q_D(const Annotation);
1372
1373 if (!d->pdfAnnot) {
1374 return d->popup;
1375 }
1376
1377 Popup w;
1378 std::shared_ptr<AnnotPopup> popup = nullptr;
1379 int flags = -1; // Not initialized
1380
1381 const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get());
1382 if (markupann) {
1383 popup = markupann->getPopup();
1384 w.setSummary(UnicodeParsedString(markupann->getSubject()));
1385 }
1386
1387 if (popup) {
1388 flags = fromPdfFlags(popup->getFlags()) & (Annotation::Hidden | Annotation::FixedSize | Annotation::FixedRotation);
1389
1390 if (!popup->getOpen()) {
1391 flags |= Annotation::Hidden;
1392 }
1393
1394 const PDFRectangle &rect = popup->getRect();
1395 w.setGeometry(d->fromPdfRectangle(rect));
1396 }
1397
1398 if (d->pdfAnnot->getType() == Annot::typeText) {
1399 const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get());
1400
1401 // Text annotations default to same rect as annotation
1402 if (flags == -1) {
1403 flags = 0;
1404 w.setGeometry(boundary());
1405 }
1406
1407 // If text is not 'opened', force window hiding. if the window
1408 // was parsed from popup, the flag should already be set
1409 if (!textann->getOpen() && flags != -1) {
1410 flags |= Annotation::Hidden;
1411 }
1412 }
1413
1414 w.setFlags(flags);
1415
1416 return w;
1417 }
1418
1419 void Annotation::setPopup(const Annotation::Popup &popup)
1420 {
1421 Q_D(Annotation);
1422
1423 if (!d->pdfAnnot) {
1424 d->popup = popup;
1425 return;
1426 }
1427
1428 #if 0 /* TODO: Remove old popup and add AnnotPopup to page */
1429 AnnotMarkup *markupann = dynamic_cast<AnnotMarkup*>(d->pdfAnnot);
1430 if (!markupann)
1431 return;
1432
1433 // Create a new AnnotPopup and assign it to pdfAnnot
1434 PDFRectangle rect = d->toPdfRectangle( popup.geometry() );
1435 AnnotPopup * p = new AnnotPopup( d->pdfPage->getDoc(), &rect );
1436 p->setOpen( !(popup.flags() & Annotation::Hidden) );
1437 if (!popup.summary().isEmpty())
1438 {
1439 GooString *s = QStringToUnicodeGooString(popup.summary());
1440 markupann->setLabel(s);
1441 delete s;
1442 }
1443 markupann->setPopup(p);
1444 #endif
1445 }
1446
1447 Annotation::RevScope Annotation::revisionScope() const
1448 {
1449 Q_D(const Annotation);
1450
1451 if (!d->pdfAnnot) {
1452 return d->revisionScope;
1453 }
1454
1455 const AnnotMarkup *markupann = dynamic_cast<const AnnotMarkup *>(d->pdfAnnot.get());
1456
1457 if (markupann && markupann->isInReplyTo()) {
1458 switch (markupann->getReplyTo()) {
1459 case AnnotMarkup::replyTypeR:
1460 return Annotation::Reply;
1461 case AnnotMarkup::replyTypeGroup:
1462 return Annotation::Group;
1463 }
1464 }
1465
1466 return Annotation::Root; // It's not a revision
1467 }
1468
1469 Annotation::RevType Annotation::revisionType() const
1470 {
1471 Q_D(const Annotation);
1472
1473 if (!d->pdfAnnot) {
1474 return d->revisionType;
1475 }
1476
1477 const AnnotText *textann = dynamic_cast<const AnnotText *>(d->pdfAnnot.get());
1478
1479 if (textann && textann->isInReplyTo()) {
1480 switch (textann->getState()) {
1481 case AnnotText::stateMarked:
1482 return Annotation::Marked;
1483 case AnnotText::stateUnmarked:
1484 return Annotation::Unmarked;
1485 case AnnotText::stateAccepted:
1486 return Annotation::Accepted;
1487 case AnnotText::stateRejected:
1488 return Annotation::Rejected;
1489 case AnnotText::stateCancelled:
1490 return Annotation::Cancelled;
1491 case AnnotText::stateCompleted:
1492 return Annotation::Completed;
1493 default:
1494 break;
1495 }
1496 }
1497
1498 return Annotation::None;
1499 }
1500
1501 std::vector<std::unique_ptr<Annotation>> Annotation::revisions() const
1502 {
1503 Q_D(const Annotation);
1504
1505 if (!d->pdfAnnot) {
1506 /* Return aliases, whose ownership goes to the caller */
1507 std::vector<std::unique_ptr<Annotation>> res;
1508 res.reserve(d->revisions.size());
1509 for (const std::unique_ptr<Annotation> &rev : d->revisions) {
1510 res.push_back(rev->d_ptr->makeAlias());
1511 }
1512 return res;
1513 }
1514
1515 /* If the annotation doesn't live in a object on its own (eg bug51361), it
1516 * has no ref, therefore it can't have revisions */
1517 if (!d->pdfAnnot->getHasRef()) {
1518 return std::vector<std::unique_ptr<Annotation>>();
1519 }
1520
1521 return AnnotationPrivate::findAnnotations(d->pdfPage, d->parentDoc, QSet<Annotation::SubType>(), d->pdfAnnot->getId());
1522 }
1523
1524 std::unique_ptr<AnnotationAppearance> Annotation::annotationAppearance() const
1525 {
1526 Q_D(const Annotation);
1527
1528 return std::make_unique<AnnotationAppearance>(new AnnotationAppearancePrivate(d->pdfAnnot.get()));
1529 }
1530
1531 void Annotation::setAnnotationAppearance(const AnnotationAppearance &annotationAppearance)
1532 {
1533 Q_D(Annotation);
1534
1535 if (!d->pdfAnnot) {
1536 d->annotationAppearance = annotationAppearance.d->appearance.copy();
1537 return;
1538 }
1539
1540 // Moving the appearance object using std::move would result
1541 // in the object being completed moved from the AnnotationAppearancePrivate
1542 // class. So, we'll not be able to retrieve the stamp's original AP stream
1543 d->pdfAnnot->setNewAppearance(annotationAppearance.d->appearance.copy());
1544 }
1545
1546 // END Annotation implementation
1547
1548 /** TextAnnotation [Annotation] */
1549 TextAnnotationPrivate::TextAnnotationPrivate() : textType(TextAnnotation::Linked), textIcon(QStringLiteral("Note")), inplaceAlign(TextAnnotation::InplaceAlignLeft), inplaceIntent(TextAnnotation::Unknown) { }
1550
1551 std::unique_ptr<Annotation> TextAnnotationPrivate::makeAlias()
1552 {
1553 return std::unique_ptr<Annotation>(new TextAnnotation(*this));
1554 }
1555
1556 std::shared_ptr<Annot> TextAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
1557 {
1558 // Setters are defined in the public class
1559 std::unique_ptr<TextAnnotation> q = static_pointer_cast<TextAnnotation>(makeAlias());
1560
1561 // Set page and contents
1562 pdfPage = destPage;
1563 parentDoc = doc;
1564
1565 // Set pdfAnnot
1566 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
1567 if (textType == TextAnnotation::Linked) {
1568 pdfAnnot = std::make_shared<AnnotText>(destPage->getDoc(), &rect);
1569 } else {
1570 const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
1571 if (pointSize < 0) {
1572 qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
1573 }
1574 pdfAnnot = std::make_shared<AnnotFreeText>(destPage->getDoc(), &rect);
1575 }
1576
1577 // Set properties
1578 flushBaseAnnotationProperties();
1579 q->setTextIcon(textIcon);
1580 q->setInplaceAlign(inplaceAlign);
1581 q->setCalloutPoints(inplaceCallout);
1582 q->setInplaceIntent(inplaceIntent);
1583
1584 inplaceCallout.clear(); // Free up memory
1585
1586 setDefaultAppearanceToNative();
1587
1588 return pdfAnnot;
1589 }
1590
1591 void TextAnnotationPrivate::setDefaultAppearanceToNative()
1592 {
1593 if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) {
1594 AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get());
1595 const double pointSize = textFont ? textFont->pointSizeF() : AnnotFreeText::undefinedFontPtSize;
1596 if (pointSize < 0) {
1597 qWarning() << "TextAnnotationPrivate::createNativeAnnot: font pointSize < 0";
1598 }
1599 std::string fontName = "Invalid_font";
1600 if (textFont) {
1601 Form *form = pdfPage->getDoc()->getCatalog()->getCreateForm();
1602 if (form) {
1603 fontName = form->findFontInDefaultResources(textFont->family().toStdString(), textFont->styleName().toStdString());
1604 if (fontName.empty()) {
1605 fontName = form->addFontToDefaultResources(textFont->family().toStdString(), textFont->styleName().toStdString()).fontName;
1606 }
1607
1608 if (!fontName.empty()) {
1609 form->ensureFontsForAllCharacters(pdfAnnot->getContents(), fontName);
1610 } else {
1611 fontName = "Invalid_font";
1612 }
1613 }
1614 }
1615 DefaultAppearance da { { objName, fontName.c_str() }, pointSize, convertQColor(textColor) };
1616 ftextann->setDefaultAppearance(da);
1617 }
1618 }
1619
1620 std::unique_ptr<DefaultAppearance> TextAnnotationPrivate::getDefaultAppearanceFromNative() const
1621 {
1622 if (pdfAnnot && pdfAnnot->getType() == Annot::typeFreeText) {
1623 AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(pdfAnnot.get());
1624 return ftextann->getDefaultAppearance();
1625 } else {
1626 return {};
1627 }
1628 }
1629
1630 TextAnnotation::TextAnnotation(TextAnnotation::TextType type) : Annotation(*new TextAnnotationPrivate())
1631 {
1632 setTextType(type);
1633 }
1634
1635 TextAnnotation::TextAnnotation(TextAnnotationPrivate &dd) : Annotation(dd) { }
1636
1637 TextAnnotation::~TextAnnotation() = default;
1638
1639 Annotation::SubType TextAnnotation::subType() const
1640 {
1641 return AText;
1642 }
1643
1644 TextAnnotation::TextType TextAnnotation::textType() const
1645 {
1646 Q_D(const TextAnnotation);
1647
1648 if (!d->pdfAnnot) {
1649 return d->textType;
1650 }
1651
1652 return d->pdfAnnot->getType() == Annot::typeText ? TextAnnotation::Linked : TextAnnotation::InPlace;
1653 }
1654
1655 void TextAnnotation::setTextType(TextAnnotation::TextType type)
1656 {
1657 Q_D(TextAnnotation);
1658
1659 if (!d->pdfAnnot) {
1660 d->textType = type;
1661 return;
1662 }
1663
1664 // Type cannot be changed if annotation is already tied
1665 qWarning() << "You can't change the type of a TextAnnotation that is already in a page";
1666 }
1667
1668 QString TextAnnotation::textIcon() const
1669 {
1670 Q_D(const TextAnnotation);
1671
1672 if (!d->pdfAnnot) {
1673 return d->textIcon;
1674 }
1675
1676 if (d->pdfAnnot->getType() == Annot::typeText) {
1677 const AnnotText *textann = static_cast<const AnnotText *>(d->pdfAnnot.get());
1678 return QString::fromStdString(textann->getIcon());
1679 }
1680
1681 return QString();
1682 }
1683
1684 void TextAnnotation::setTextIcon(const QString &icon)
1685 {
1686 Q_D(TextAnnotation);
1687
1688 if (!d->pdfAnnot) {
1689 d->textIcon = icon;
1690 return;
1691 }
1692
1693 if (d->pdfAnnot->getType() == Annot::typeText) {
1694 AnnotText *textann = static_cast<AnnotText *>(d->pdfAnnot.get());
1695 textann->setIcon(icon.toStdString());
1696 }
1697 }
1698
1699 QFont TextAnnotation::textFont() const
1700 {
1701 Q_D(const TextAnnotation);
1702
1703 if (d->textFont) {
1704 return *d->textFont;
1705 }
1706
1707 double fontSize { AnnotFreeText::undefinedFontPtSize };
1708 if (d->pdfAnnot->getType() == Annot::typeFreeText) {
1709 std::unique_ptr<DefaultAppearance> da { d->getDefaultAppearanceFromNative() };
1710 if (da && da->getFontPtSize() > 0) {
1711 fontSize = da->getFontPtSize();
1712 }
1713 }
1714
1715 QFont font;
1716 font.setPointSizeF(fontSize);
1717 return font;
1718 }
1719
1720 void TextAnnotation::setTextFont(const QFont &font)
1721 {
1722 Q_D(TextAnnotation);
1723 if (font == d->textFont) {
1724 return;
1725 }
1726 d->textFont = font;
1727
1728 d->setDefaultAppearanceToNative();
1729 }
1730
1731 QColor TextAnnotation::textColor() const
1732 {
1733 Q_D(const TextAnnotation);
1734
1735 if (!d->pdfAnnot) {
1736 return d->textColor;
1737 }
1738
1739 if (std::unique_ptr<DefaultAppearance> da { d->getDefaultAppearanceFromNative() }) {
1740 return convertAnnotColor(da->getFontColor());
1741 }
1742
1743 return {};
1744 }
1745
1746 void TextAnnotation::setTextColor(const QColor &color)
1747 {
1748 Q_D(TextAnnotation);
1749 if (color == d->textColor) {
1750 return;
1751 }
1752 d->textColor = color;
1753
1754 d->setDefaultAppearanceToNative();
1755 }
1756
1757 TextAnnotation::InplaceAlignPosition TextAnnotation::inplaceAlign() const
1758 {
1759 Q_D(const TextAnnotation);
1760
1761 if (!d->pdfAnnot) {
1762 return d->inplaceAlign;
1763 }
1764
1765 if (d->pdfAnnot->getType() == Annot::typeFreeText) {
1766 const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get());
1767 switch (ftextann->getQuadding()) {
1768 case VariableTextQuadding::leftJustified:
1769 return InplaceAlignLeft;
1770 case VariableTextQuadding::centered:
1771 return InplaceAlignCenter;
1772 case VariableTextQuadding::rightJustified:
1773 return InplaceAlignRight;
1774 }
1775 }
1776
1777 return InplaceAlignLeft;
1778 }
1779
1780 static VariableTextQuadding alignToQuadding(TextAnnotation::InplaceAlignPosition align)
1781 {
1782 switch (align) {
1783 case TextAnnotation::InplaceAlignLeft:
1784 return VariableTextQuadding::leftJustified;
1785 case TextAnnotation::InplaceAlignCenter:
1786 return VariableTextQuadding::centered;
1787 case TextAnnotation::InplaceAlignRight:
1788 return VariableTextQuadding::rightJustified;
1789 }
1790 return VariableTextQuadding::leftJustified;
1791 }
1792
1793 void TextAnnotation::setInplaceAlign(InplaceAlignPosition align)
1794 {
1795 Q_D(TextAnnotation);
1796
1797 if (!d->pdfAnnot) {
1798 d->inplaceAlign = align;
1799 return;
1800 }
1801
1802 if (d->pdfAnnot->getType() == Annot::typeFreeText) {
1803 AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get());
1804 ftextann->setQuadding(alignToQuadding(align));
1805 }
1806 }
1807
1808 QPointF TextAnnotation::calloutPoint(int id) const
1809 {
1810 const QVector<QPointF> points = calloutPoints();
1811 if (id < 0 || id >= points.size()) {
1812 return QPointF();
1813 } else {
1814 return points[id];
1815 }
1816 }
1817
1818 QVector<QPointF> TextAnnotation::calloutPoints() const
1819 {
1820 Q_D(const TextAnnotation);
1821
1822 if (!d->pdfAnnot) {
1823 return d->inplaceCallout;
1824 }
1825
1826 if (d->pdfAnnot->getType() == Annot::typeText) {
1827 return QVector<QPointF>();
1828 }
1829
1830 const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get());
1831 const AnnotCalloutLine *callout = ftextann->getCalloutLine();
1832
1833 if (!callout) {
1834 return QVector<QPointF>();
1835 }
1836
1837 double MTX[6];
1838 d->fillTransformationMTX(MTX);
1839
1840 const AnnotCalloutMultiLine *callout_v6 = dynamic_cast<const AnnotCalloutMultiLine *>(callout);
1841 QVector<QPointF> res(callout_v6 ? 3 : 2);
1842 XPDFReader::transform(MTX, callout->getX1(), callout->getY1(), res[0]);
1843 XPDFReader::transform(MTX, callout->getX2(), callout->getY2(), res[1]);
1844 if (callout_v6) {
1845 XPDFReader::transform(MTX, callout_v6->getX3(), callout_v6->getY3(), res[2]);
1846 }
1847 return res;
1848 }
1849
1850 void TextAnnotation::setCalloutPoints(const QVector<QPointF> &points)
1851 {
1852 Q_D(TextAnnotation);
1853 if (!d->pdfAnnot) {
1854 d->inplaceCallout = points;
1855 return;
1856 }
1857
1858 if (d->pdfAnnot->getType() != Annot::typeFreeText) {
1859 return;
1860 }
1861
1862 AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get());
1863 const int count = points.size();
1864
1865 if (count == 0) {
1866 ftextann->setCalloutLine(nullptr);
1867 return;
1868 }
1869
1870 if (count != 2 && count != 3) {
1871 error(errSyntaxError, -1, "Expected zero, two or three points for callout");
1872 return;
1873 }
1874
1875 std::unique_ptr<AnnotCalloutLine> callout;
1876 double x1, y1, x2, y2;
1877 double MTX[6];
1878 d->fillTransformationMTX(MTX);
1879
1880 XPDFReader::invTransform(MTX, points[0], x1, y1);
1881 XPDFReader::invTransform(MTX, points[1], x2, y2);
1882 if (count == 3) {
1883 double x3, y3;
1884 XPDFReader::invTransform(MTX, points[2], x3, y3);
1885 callout = std::make_unique<AnnotCalloutMultiLine>(x1, y1, x2, y2, x3, y3);
1886 } else {
1887 callout = std::make_unique<AnnotCalloutLine>(x1, y1, x2, y2);
1888 }
1889
1890 ftextann->setCalloutLine(std::move(callout));
1891 }
1892
1893 TextAnnotation::InplaceIntent TextAnnotation::inplaceIntent() const
1894 {
1895 Q_D(const TextAnnotation);
1896
1897 if (!d->pdfAnnot) {
1898 return d->inplaceIntent;
1899 }
1900
1901 if (d->pdfAnnot->getType() == Annot::typeFreeText) {
1902 const AnnotFreeText *ftextann = static_cast<const AnnotFreeText *>(d->pdfAnnot.get());
1903 return (TextAnnotation::InplaceIntent)ftextann->getIntent();
1904 }
1905
1906 return TextAnnotation::Unknown;
1907 }
1908
1909 void TextAnnotation::setInplaceIntent(TextAnnotation::InplaceIntent intent)
1910 {
1911 Q_D(TextAnnotation);
1912
1913 if (!d->pdfAnnot) {
1914 d->inplaceIntent = intent;
1915 return;
1916 }
1917
1918 if (d->pdfAnnot->getType() == Annot::typeFreeText) {
1919 AnnotFreeText *ftextann = static_cast<AnnotFreeText *>(d->pdfAnnot.get());
1920 ftextann->setIntent((AnnotFreeText::AnnotFreeTextIntent)intent);
1921 }
1922 }
1923
1924 /** LineAnnotation [Annotation] */
1925 class LineAnnotationPrivate : public AnnotationPrivate
1926 {
1927 public:
1928 LineAnnotationPrivate();
1929 std::unique_ptr<Annotation> makeAlias() override;
1930 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
1931
1932 // data fields (note uses border for rendering style)
1933 QVector<QPointF> linePoints;
1934 LineAnnotation::TermStyle lineStartStyle;
1935 LineAnnotation::TermStyle lineEndStyle;
1936 bool lineClosed : 1; // (if true draw close shape)
1937 bool lineShowCaption : 1;
1938 LineAnnotation::LineType lineType;
1939 QColor lineInnerColor;
1940 double lineLeadingFwdPt;
1941 double lineLeadingBackPt;
1942 LineAnnotation::LineIntent lineIntent;
1943 };
1944
1945 LineAnnotationPrivate::LineAnnotationPrivate()
1946 : lineStartStyle(LineAnnotation::None), lineEndStyle(LineAnnotation::None), lineClosed(false), lineShowCaption(false), lineLeadingFwdPt(0), lineLeadingBackPt(0), lineIntent(LineAnnotation::Unknown)
1947 {
1948 }
1949
1950 std::unique_ptr<Annotation> LineAnnotationPrivate::makeAlias()
1951 {
1952 return std::unique_ptr<Annotation>(new LineAnnotation(*this));
1953 }
1954
1955 std::shared_ptr<Annot> LineAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
1956 {
1957 // Setters are defined in the public class
1958 std::unique_ptr<LineAnnotation> q = static_pointer_cast<LineAnnotation>(makeAlias());
1959
1960 // Set page and document
1961 pdfPage = destPage;
1962 parentDoc = doc;
1963
1964 // Set pdfAnnot
1965 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
1966 if (lineType == LineAnnotation::StraightLine) {
1967 pdfAnnot = std::make_shared<AnnotLine>(doc->doc, &rect);
1968 } else {
1969 pdfAnnot = std::make_shared<AnnotPolygon>(doc->doc, &rect, lineClosed ? Annot::typePolygon : Annot::typePolyLine);
1970 }
1971
1972 // Set properties
1973 flushBaseAnnotationProperties();
1974 q->setLinePoints(linePoints);
1975 q->setLineStartStyle(lineStartStyle);
1976 q->setLineEndStyle(lineEndStyle);
1977 q->setLineInnerColor(lineInnerColor);
1978 q->setLineLeadingForwardPoint(lineLeadingFwdPt);
1979 q->setLineLeadingBackPoint(lineLeadingBackPt);
1980 q->setLineShowCaption(lineShowCaption);
1981 q->setLineIntent(lineIntent);
1982
1983 linePoints.clear(); // Free up memory
1984
1985 return pdfAnnot;
1986 }
1987
1988 LineAnnotation::LineAnnotation(LineAnnotation::LineType type) : Annotation(*new LineAnnotationPrivate())
1989 {
1990 setLineType(type);
1991 }
1992
1993 LineAnnotation::LineAnnotation(LineAnnotationPrivate &dd) : Annotation(dd) { }
1994
1995 LineAnnotation::~LineAnnotation() = default;
1996
1997 Annotation::SubType LineAnnotation::subType() const
1998 {
1999 return ALine;
2000 }
2001
2002 LineAnnotation::LineType LineAnnotation::lineType() const
2003 {
2004 Q_D(const LineAnnotation);
2005
2006 if (!d->pdfAnnot) {
2007 return d->lineType;
2008 }
2009
2010 return (d->pdfAnnot->getType() == Annot::typeLine) ? LineAnnotation::StraightLine : LineAnnotation::Polyline;
2011 }
2012
2013 void LineAnnotation::setLineType(LineAnnotation::LineType type)
2014 {
2015 Q_D(LineAnnotation);
2016
2017 if (!d->pdfAnnot) {
2018 d->lineType = type;
2019 return;
2020 }
2021
2022 // Type cannot be changed if annotation is already tied
2023 qWarning() << "You can't change the type of a LineAnnotation that is already in a page";
2024 }
2025
2026 QVector<QPointF> LineAnnotation::linePoints() const
2027 {
2028 Q_D(const LineAnnotation);
2029
2030 if (!d->pdfAnnot) {
2031 return d->linePoints;
2032 }
2033
2034 double MTX[6];
2035 d->fillTransformationMTX(MTX);
2036
2037 QVector<QPointF> res;
2038 if (d->pdfAnnot->getType() == Annot::typeLine) {
2039 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2040 QPointF p;
2041 XPDFReader::transform(MTX, lineann->getX1(), lineann->getY1(), p);
2042 res.append(p);
2043 XPDFReader::transform(MTX, lineann->getX2(), lineann->getY2(), p);
2044 res.append(p);
2045 } else {
2046 const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get());
2047 const AnnotPath *vertices = polyann->getVertices();
2048
2049 for (int i = 0; i < vertices->getCoordsLength(); ++i) {
2050 QPointF p;
2051 XPDFReader::transform(MTX, vertices->getX(i), vertices->getY(i), p);
2052 res.append(p);
2053 }
2054 }
2055
2056 return res;
2057 }
2058
2059 void LineAnnotation::setLinePoints(const QVector<QPointF> &points)
2060 {
2061 Q_D(LineAnnotation);
2062
2063 if (!d->pdfAnnot) {
2064 d->linePoints = points;
2065 return;
2066 }
2067
2068 if (d->pdfAnnot->getType() == Annot::typeLine) {
2069 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2070 if (points.size() != 2) {
2071 error(errSyntaxError, -1, "Expected two points for a straight line");
2072 return;
2073 }
2074 double x1, y1, x2, y2;
2075 double MTX[6];
2076 d->fillTransformationMTX(MTX);
2077 XPDFReader::invTransform(MTX, points.first(), x1, y1);
2078 XPDFReader::invTransform(MTX, points.last(), x2, y2);
2079 lineann->setVertices(x1, y1, x2, y2);
2080 } else {
2081 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2082 const std::unique_ptr<AnnotPath> p = d->toAnnotPath(points);
2083 polyann->setVertices(*p);
2084 }
2085 }
2086
2087 LineAnnotation::TermStyle LineAnnotation::lineStartStyle() const
2088 {
2089 Q_D(const LineAnnotation);
2090
2091 if (!d->pdfAnnot) {
2092 return d->lineStartStyle;
2093 }
2094
2095 if (d->pdfAnnot->getType() == Annot::typeLine) {
2096 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2097 return (LineAnnotation::TermStyle)lineann->getStartStyle();
2098 } else {
2099 const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get());
2100 return (LineAnnotation::TermStyle)polyann->getStartStyle();
2101 }
2102 }
2103
2104 void LineAnnotation::setLineStartStyle(LineAnnotation::TermStyle style)
2105 {
2106 Q_D(LineAnnotation);
2107
2108 if (!d->pdfAnnot) {
2109 d->lineStartStyle = style;
2110 return;
2111 }
2112
2113 if (d->pdfAnnot->getType() == Annot::typeLine) {
2114 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2115 lineann->setStartEndStyle((AnnotLineEndingStyle)style, lineann->getEndStyle());
2116 } else {
2117 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2118 polyann->setStartEndStyle((AnnotLineEndingStyle)style, polyann->getEndStyle());
2119 }
2120 }
2121
2122 LineAnnotation::TermStyle LineAnnotation::lineEndStyle() const
2123 {
2124 Q_D(const LineAnnotation);
2125
2126 if (!d->pdfAnnot) {
2127 return d->lineEndStyle;
2128 }
2129
2130 if (d->pdfAnnot->getType() == Annot::typeLine) {
2131 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2132 return (LineAnnotation::TermStyle)lineann->getEndStyle();
2133 } else {
2134 const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get());
2135 return (LineAnnotation::TermStyle)polyann->getEndStyle();
2136 }
2137 }
2138
2139 void LineAnnotation::setLineEndStyle(LineAnnotation::TermStyle style)
2140 {
2141 Q_D(LineAnnotation);
2142
2143 if (!d->pdfAnnot) {
2144 d->lineEndStyle = style;
2145 return;
2146 }
2147
2148 if (d->pdfAnnot->getType() == Annot::typeLine) {
2149 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2150 lineann->setStartEndStyle(lineann->getStartStyle(), (AnnotLineEndingStyle)style);
2151 } else {
2152 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2153 polyann->setStartEndStyle(polyann->getStartStyle(), (AnnotLineEndingStyle)style);
2154 }
2155 }
2156
2157 bool LineAnnotation::isLineClosed() const
2158 {
2159 Q_D(const LineAnnotation);
2160
2161 if (!d->pdfAnnot) {
2162 return d->lineClosed;
2163 }
2164
2165 return d->pdfAnnot->getType() == Annot::typePolygon;
2166 }
2167
2168 void LineAnnotation::setLineClosed(bool closed)
2169 {
2170 Q_D(LineAnnotation);
2171
2172 if (!d->pdfAnnot) {
2173 d->lineClosed = closed;
2174 return;
2175 }
2176
2177 if (d->pdfAnnot->getType() != Annot::typeLine) {
2178 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2179
2180 // Set new subtype and switch intent if necessary
2181 if (closed) {
2182 polyann->setType(Annot::typePolygon);
2183 if (polyann->getIntent() == AnnotPolygon::polylineDimension) {
2184 polyann->setIntent(AnnotPolygon::polygonDimension);
2185 }
2186 } else {
2187 polyann->setType(Annot::typePolyLine);
2188 if (polyann->getIntent() == AnnotPolygon::polygonDimension) {
2189 polyann->setIntent(AnnotPolygon::polylineDimension);
2190 }
2191 }
2192 }
2193 }
2194
2195 QColor LineAnnotation::lineInnerColor() const
2196 {
2197 Q_D(const LineAnnotation);
2198
2199 if (!d->pdfAnnot) {
2200 return d->lineInnerColor;
2201 }
2202
2203 AnnotColor *c;
2204
2205 if (d->pdfAnnot->getType() == Annot::typeLine) {
2206 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2207 c = lineann->getInteriorColor();
2208 } else {
2209 const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get());
2210 c = polyann->getInteriorColor();
2211 }
2212
2213 return convertAnnotColor(c);
2214 }
2215
2216 void LineAnnotation::setLineInnerColor(const QColor &color)
2217 {
2218 Q_D(LineAnnotation);
2219
2220 if (!d->pdfAnnot) {
2221 d->lineInnerColor = color;
2222 return;
2223 }
2224
2225 auto c = convertQColor(color);
2226
2227 if (d->pdfAnnot->getType() == Annot::typeLine) {
2228 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2229 lineann->setInteriorColor(std::move(c));
2230 } else {
2231 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2232 polyann->setInteriorColor(std::move(c));
2233 }
2234 }
2235
2236 double LineAnnotation::lineLeadingForwardPoint() const
2237 {
2238 Q_D(const LineAnnotation);
2239
2240 if (!d->pdfAnnot) {
2241 return d->lineLeadingFwdPt;
2242 }
2243
2244 if (d->pdfAnnot->getType() == Annot::typeLine) {
2245 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2246 return lineann->getLeaderLineLength();
2247 }
2248
2249 return 0;
2250 }
2251
2252 void LineAnnotation::setLineLeadingForwardPoint(double point)
2253 {
2254 Q_D(LineAnnotation);
2255
2256 if (!d->pdfAnnot) {
2257 d->lineLeadingFwdPt = point;
2258 return;
2259 }
2260
2261 if (d->pdfAnnot->getType() == Annot::typeLine) {
2262 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2263 lineann->setLeaderLineLength(point);
2264 }
2265 }
2266
2267 double LineAnnotation::lineLeadingBackPoint() const
2268 {
2269 Q_D(const LineAnnotation);
2270
2271 if (!d->pdfAnnot) {
2272 return d->lineLeadingBackPt;
2273 }
2274
2275 if (d->pdfAnnot->getType() == Annot::typeLine) {
2276 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2277 return lineann->getLeaderLineExtension();
2278 }
2279
2280 return 0;
2281 }
2282
2283 void LineAnnotation::setLineLeadingBackPoint(double point)
2284 {
2285 Q_D(LineAnnotation);
2286
2287 if (!d->pdfAnnot) {
2288 d->lineLeadingBackPt = point;
2289 return;
2290 }
2291
2292 if (d->pdfAnnot->getType() == Annot::typeLine) {
2293 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2294 lineann->setLeaderLineExtension(point);
2295 }
2296 }
2297
2298 bool LineAnnotation::lineShowCaption() const
2299 {
2300 Q_D(const LineAnnotation);
2301
2302 if (!d->pdfAnnot) {
2303 return d->lineShowCaption;
2304 }
2305
2306 if (d->pdfAnnot->getType() == Annot::typeLine) {
2307 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2308 return lineann->getCaption();
2309 }
2310
2311 return false;
2312 }
2313
2314 void LineAnnotation::setLineShowCaption(bool show)
2315 {
2316 Q_D(LineAnnotation);
2317
2318 if (!d->pdfAnnot) {
2319 d->lineShowCaption = show;
2320 return;
2321 }
2322
2323 if (d->pdfAnnot->getType() == Annot::typeLine) {
2324 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2325 lineann->setCaption(show);
2326 }
2327 }
2328
2329 LineAnnotation::LineIntent LineAnnotation::lineIntent() const
2330 {
2331 Q_D(const LineAnnotation);
2332
2333 if (!d->pdfAnnot) {
2334 return d->lineIntent;
2335 }
2336
2337 if (d->pdfAnnot->getType() == Annot::typeLine) {
2338 const AnnotLine *lineann = static_cast<const AnnotLine *>(d->pdfAnnot.get());
2339 return (LineAnnotation::LineIntent)(lineann->getIntent() + 1);
2340 } else {
2341 const AnnotPolygon *polyann = static_cast<const AnnotPolygon *>(d->pdfAnnot.get());
2342 if (polyann->getIntent() == AnnotPolygon::polygonCloud) {
2343 return LineAnnotation::PolygonCloud;
2344 } else { // AnnotPolygon::polylineDimension, AnnotPolygon::polygonDimension
2345 return LineAnnotation::Dimension;
2346 }
2347 }
2348 }
2349
2350 void LineAnnotation::setLineIntent(LineAnnotation::LineIntent intent)
2351 {
2352 Q_D(LineAnnotation);
2353
2354 if (!d->pdfAnnot) {
2355 d->lineIntent = intent;
2356 return;
2357 }
2358
2359 if (intent == LineAnnotation::Unknown) {
2360 return; // Do not set (actually, it should clear the property)
2361 }
2362
2363 if (d->pdfAnnot->getType() == Annot::typeLine) {
2364 AnnotLine *lineann = static_cast<AnnotLine *>(d->pdfAnnot.get());
2365 lineann->setIntent((AnnotLine::AnnotLineIntent)(intent - 1));
2366 } else {
2367 AnnotPolygon *polyann = static_cast<AnnotPolygon *>(d->pdfAnnot.get());
2368 if (intent == LineAnnotation::PolygonCloud) {
2369 polyann->setIntent(AnnotPolygon::polygonCloud);
2370 } else // LineAnnotation::Dimension
2371 {
2372 if (d->pdfAnnot->getType() == Annot::typePolygon) {
2373 polyann->setIntent(AnnotPolygon::polygonDimension);
2374 } else { // Annot::typePolyLine
2375 polyann->setIntent(AnnotPolygon::polylineDimension);
2376 }
2377 }
2378 }
2379 }
2380
2381 /** GeomAnnotation [Annotation] */
2382 class GeomAnnotationPrivate : public AnnotationPrivate
2383 {
2384 public:
2385 GeomAnnotationPrivate();
2386 std::unique_ptr<Annotation> makeAlias() override;
2387 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
2388
2389 // data fields (note uses border for rendering style)
2390 GeomAnnotation::GeomType geomType;
2391 QColor geomInnerColor;
2392 };
2393
2394 GeomAnnotationPrivate::GeomAnnotationPrivate() : geomType(GeomAnnotation::InscribedSquare) { }
2395
2396 std::unique_ptr<Annotation> GeomAnnotationPrivate::makeAlias()
2397 {
2398 return std::unique_ptr<Annotation>(new GeomAnnotation(*this));
2399 }
2400
2401 std::shared_ptr<Annot> GeomAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
2402 {
2403 // Setters are defined in the public class
2404 std::unique_ptr<GeomAnnotation> q = static_pointer_cast<GeomAnnotation>(makeAlias());
2405
2406 // Set page and document
2407 pdfPage = destPage;
2408 parentDoc = doc;
2409
2410 Annot::AnnotSubtype type;
2411 if (geomType == GeomAnnotation::InscribedSquare) {
2412 type = Annot::typeSquare;
2413 } else { // GeomAnnotation::InscribedCircle
2414 type = Annot::typeCircle;
2415 }
2416
2417 // Set pdfAnnot
2418 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
2419 pdfAnnot = std::make_shared<AnnotGeometry>(destPage->getDoc(), &rect, type);
2420
2421 // Set properties
2422 flushBaseAnnotationProperties();
2423 q->setGeomInnerColor(geomInnerColor);
2424
2425 return pdfAnnot;
2426 }
2427
2428 GeomAnnotation::GeomAnnotation() : Annotation(*new GeomAnnotationPrivate()) { }
2429
2430 GeomAnnotation::GeomAnnotation(GeomAnnotationPrivate &dd) : Annotation(dd) { }
2431
2432 GeomAnnotation::~GeomAnnotation() = default;
2433
2434 Annotation::SubType GeomAnnotation::subType() const
2435 {
2436 return AGeom;
2437 }
2438
2439 GeomAnnotation::GeomType GeomAnnotation::geomType() const
2440 {
2441 Q_D(const GeomAnnotation);
2442
2443 if (!d->pdfAnnot) {
2444 return d->geomType;
2445 }
2446
2447 if (d->pdfAnnot->getType() == Annot::typeSquare) {
2448 return GeomAnnotation::InscribedSquare;
2449 } else { // Annot::typeCircle
2450 return GeomAnnotation::InscribedCircle;
2451 }
2452 }
2453
2454 void GeomAnnotation::setGeomType(GeomAnnotation::GeomType type)
2455 {
2456 Q_D(GeomAnnotation);
2457
2458 if (!d->pdfAnnot) {
2459 d->geomType = type;
2460 return;
2461 }
2462
2463 AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get());
2464 if (type == GeomAnnotation::InscribedSquare) {
2465 geomann->setType(Annot::typeSquare);
2466 } else { // GeomAnnotation::InscribedCircle
2467 geomann->setType(Annot::typeCircle);
2468 }
2469 }
2470
2471 QColor GeomAnnotation::geomInnerColor() const
2472 {
2473 Q_D(const GeomAnnotation);
2474
2475 if (!d->pdfAnnot) {
2476 return d->geomInnerColor;
2477 }
2478
2479 const AnnotGeometry *geomann = static_cast<const AnnotGeometry *>(d->pdfAnnot.get());
2480 return convertAnnotColor(geomann->getInteriorColor());
2481 }
2482
2483 void GeomAnnotation::setGeomInnerColor(const QColor &color)
2484 {
2485 Q_D(GeomAnnotation);
2486
2487 if (!d->pdfAnnot) {
2488 d->geomInnerColor = color;
2489 return;
2490 }
2491
2492 AnnotGeometry *geomann = static_cast<AnnotGeometry *>(d->pdfAnnot.get());
2493 geomann->setInteriorColor(convertQColor(color));
2494 }
2495
2496 /** HighlightAnnotation [Annotation] */
2497 class HighlightAnnotationPrivate : public AnnotationPrivate
2498 {
2499 public:
2500 HighlightAnnotationPrivate();
2501 std::unique_ptr<Annotation> makeAlias() override;
2502 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
2503
2504 // data fields
2505 HighlightAnnotation::HighlightType highlightType;
2506 QList<HighlightAnnotation::Quad> highlightQuads; // not empty
2507
2508 // helpers
2509 static Annot::AnnotSubtype toAnnotSubType(HighlightAnnotation::HighlightType type);
2510 QList<HighlightAnnotation::Quad> fromQuadrilaterals(AnnotQuadrilaterals *quads) const;
2511 AnnotQuadrilaterals *toQuadrilaterals(const QList<HighlightAnnotation::Quad> &quads) const;
2512 };
2513
2514 HighlightAnnotationPrivate::HighlightAnnotationPrivate() : highlightType(HighlightAnnotation::Highlight) { }
2515
2516 std::unique_ptr<Annotation> HighlightAnnotationPrivate::makeAlias()
2517 {
2518 return std::unique_ptr<Annotation>(new HighlightAnnotation(*this));
2519 }
2520
2521 Annot::AnnotSubtype HighlightAnnotationPrivate::toAnnotSubType(HighlightAnnotation::HighlightType type)
2522 {
2523 switch (type) {
2524 default: // HighlightAnnotation::Highlight:
2525 return Annot::typeHighlight;
2526 case HighlightAnnotation::Underline:
2527 return Annot::typeUnderline;
2528 case HighlightAnnotation::Squiggly:
2529 return Annot::typeSquiggly;
2530 case HighlightAnnotation::StrikeOut:
2531 return Annot::typeStrikeOut;
2532 }
2533 }
2534
2535 QList<HighlightAnnotation::Quad> HighlightAnnotationPrivate::fromQuadrilaterals(AnnotQuadrilaterals *hlquads) const
2536 {
2537 QList<HighlightAnnotation::Quad> quads;
2538
2539 if (!hlquads || !hlquads->getQuadrilateralsLength()) {
2540 return quads;
2541 }
2542 const int quadsCount = hlquads->getQuadrilateralsLength();
2543
2544 double MTX[6];
2545 fillTransformationMTX(MTX);
2546
2547 quads.reserve(quadsCount);
2548 for (int q = 0; q < quadsCount; ++q) {
2549 HighlightAnnotation::Quad quad;
2550 XPDFReader::transform(MTX, hlquads->getX1(q), hlquads->getY1(q), quad.points[0]);
2551 XPDFReader::transform(MTX, hlquads->getX2(q), hlquads->getY2(q), quad.points[1]);
2552 XPDFReader::transform(MTX, hlquads->getX3(q), hlquads->getY3(q), quad.points[2]);
2553 XPDFReader::transform(MTX, hlquads->getX4(q), hlquads->getY4(q), quad.points[3]);
2554 // ### PDF1.6 specs says that point are in ccw order, but in fact
2555 // points 3 and 4 are swapped in every PDF around!
2556 QPointF tmpPoint = quad.points[2];
2557 quad.points[2] = quad.points[3];
2558 quad.points[3] = tmpPoint;
2559 // initialize other properties and append quad
2560 quad.capStart = true; // unlinked quads are always capped
2561 quad.capEnd = true; // unlinked quads are always capped
2562 quad.feather = 0.1; // default feather
2563 quads.append(quad);
2564 }
2565
2566 return quads;
2567 }
2568
2569 AnnotQuadrilaterals *HighlightAnnotationPrivate::toQuadrilaterals(const QList<HighlightAnnotation::Quad> &quads) const
2570 {
2571 const int count = quads.size();
2572 auto ac = std::make_unique<AnnotQuadrilaterals::AnnotQuadrilateral[]>(count);
2573
2574 double MTX[6];
2575 fillTransformationMTX(MTX);
2576
2577 int pos = 0;
2578 Q_FOREACH (const HighlightAnnotation::Quad &q, quads) {
2579 double x1, y1, x2, y2, x3, y3, x4, y4;
2580 XPDFReader::invTransform(MTX, q.points[0], x1, y1);
2581 XPDFReader::invTransform(MTX, q.points[1], x2, y2);
2582 // Swap points 3 and 4 (see HighlightAnnotationPrivate::fromQuadrilaterals)
2583 XPDFReader::invTransform(MTX, q.points[3], x3, y3);
2584 XPDFReader::invTransform(MTX, q.points[2], x4, y4);
2585 ac[pos++] = AnnotQuadrilaterals::AnnotQuadrilateral(x1, y1, x2, y2, x3, y3, x4, y4);
2586 }
2587
2588 return new AnnotQuadrilaterals(std::move(ac), count);
2589 }
2590
2591 std::shared_ptr<Annot> HighlightAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
2592 {
2593 // Setters are defined in the public class
2594 std::unique_ptr<HighlightAnnotation> q = static_pointer_cast<HighlightAnnotation>(makeAlias());
2595
2596 // Set page and document
2597 pdfPage = destPage;
2598 parentDoc = doc;
2599
2600 // Set pdfAnnot
2601 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
2602 pdfAnnot = std::make_shared<AnnotTextMarkup>(destPage->getDoc(), &rect, toAnnotSubType(highlightType));
2603
2604 // Set properties
2605 flushBaseAnnotationProperties();
2606 q->setHighlightQuads(highlightQuads);
2607
2608 highlightQuads.clear(); // Free up memory
2609
2610 return pdfAnnot;
2611 }
2612
2613 HighlightAnnotation::HighlightAnnotation() : Annotation(*new HighlightAnnotationPrivate()) { }
2614
2615 HighlightAnnotation::HighlightAnnotation(HighlightAnnotationPrivate &dd) : Annotation(dd) { }
2616
2617 HighlightAnnotation::~HighlightAnnotation() = default;
2618
2619 Annotation::SubType HighlightAnnotation::subType() const
2620 {
2621 return AHighlight;
2622 }
2623
2624 HighlightAnnotation::HighlightType HighlightAnnotation::highlightType() const
2625 {
2626 Q_D(const HighlightAnnotation);
2627
2628 if (!d->pdfAnnot) {
2629 return d->highlightType;
2630 }
2631
2632 Annot::AnnotSubtype subType = d->pdfAnnot->getType();
2633
2634 if (subType == Annot::typeHighlight) {
2635 return HighlightAnnotation::Highlight;
2636 } else if (subType == Annot::typeUnderline) {
2637 return HighlightAnnotation::Underline;
2638 } else if (subType == Annot::typeSquiggly) {
2639 return HighlightAnnotation::Squiggly;
2640 } else { // Annot::typeStrikeOut
2641 return HighlightAnnotation::StrikeOut;
2642 }
2643 }
2644
2645 void HighlightAnnotation::setHighlightType(HighlightAnnotation::HighlightType type)
2646 {
2647 Q_D(HighlightAnnotation);
2648
2649 if (!d->pdfAnnot) {
2650 d->highlightType = type;
2651 return;
2652 }
2653
2654 AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get());
2655 hlann->setType(HighlightAnnotationPrivate::toAnnotSubType(type));
2656 }
2657
2658 QList<HighlightAnnotation::Quad> HighlightAnnotation::highlightQuads() const
2659 {
2660 Q_D(const HighlightAnnotation);
2661
2662 if (!d->pdfAnnot) {
2663 return d->highlightQuads;
2664 }
2665
2666 const AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get());
2667 return d->fromQuadrilaterals(hlann->getQuadrilaterals());
2668 }
2669
2670 void HighlightAnnotation::setHighlightQuads(const QList<HighlightAnnotation::Quad> &quads)
2671 {
2672 Q_D(HighlightAnnotation);
2673
2674 if (!d->pdfAnnot) {
2675 d->highlightQuads = quads;
2676 return;
2677 }
2678
2679 AnnotTextMarkup *hlann = static_cast<AnnotTextMarkup *>(d->pdfAnnot.get());
2680 AnnotQuadrilaterals *quadrilaterals = d->toQuadrilaterals(quads);
2681 hlann->setQuadrilaterals(*quadrilaterals);
2682 delete quadrilaterals;
2683 }
2684
2685 /** StampAnnotation [Annotation] */
2686 class StampAnnotationPrivate : public AnnotationPrivate
2687 {
2688 public:
2689 StampAnnotationPrivate();
2690 std::unique_ptr<Annotation> makeAlias() override;
2691 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
2692
2693 std::unique_ptr<AnnotStampImageHelper> convertQImageToAnnotStampImageHelper(const QImage &qimg);
2694
2695 // data fields
2696 QString stampIconName;
2697 QImage stampCustomImage;
2698 };
2699
2700 StampAnnotationPrivate::StampAnnotationPrivate() : stampIconName(QStringLiteral("Draft")) { }
2701
2702 std::unique_ptr<Annotation> StampAnnotationPrivate::makeAlias()
2703 {
2704 return std::unique_ptr<Annotation>(new StampAnnotation(*this));
2705 }
2706
2707 std::shared_ptr<Annot> StampAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
2708 {
2709 std::unique_ptr<StampAnnotation> q = static_pointer_cast<StampAnnotation>(makeAlias());
2710
2711 // Set page and document
2712 pdfPage = destPage;
2713 parentDoc = doc;
2714
2715 // Set pdfAnnot
2716 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
2717 pdfAnnot = std::make_shared<AnnotStamp>(destPage->getDoc(), &rect);
2718
2719 // Set properties
2720 flushBaseAnnotationProperties();
2721 q->setStampIconName(stampIconName);
2722 q->setStampCustomImage(stampCustomImage);
2723
2724 stampIconName.clear(); // Free up memory
2725
2726 return pdfAnnot;
2727 }
2728
2729 std::unique_ptr<AnnotStampImageHelper> StampAnnotationPrivate::convertQImageToAnnotStampImageHelper(const QImage &qimg)
2730 {
2731 QImage convertedQImage = qimg;
2732
2733 QByteArray data;
2734 QByteArray sMaskData;
2735 const int width = convertedQImage.width();
2736 const int height = convertedQImage.height();
2737 int bitsPerComponent = 1;
2738 ColorSpace colorSpace = ColorSpace::DeviceGray;
2739
2740 switch (convertedQImage.format()) {
2741 case QImage::Format_MonoLSB:
2742 if (!convertedQImage.allGray()) {
2743 convertedQImage = convertedQImage.convertToFormat(QImage::Format_RGB888);
2744
2745 colorSpace = ColorSpace::DeviceRGB;
2746 bitsPerComponent = 8;
2747 } else {
2748 convertedQImage = convertedQImage.convertToFormat(QImage::Format_Mono);
2749 }
2750 break;
2751 case QImage::Format_Mono:
2752 if (!convertedQImage.allGray()) {
2753 convertedQImage = convertedQImage.convertToFormat(QImage::Format_RGB888);
2754
2755 colorSpace = ColorSpace::DeviceRGB;
2756 bitsPerComponent = 8;
2757 }
2758 break;
2759 case QImage::Format_RGB32:
2760 case QImage::Format_ARGB32_Premultiplied:
2761 case QImage::Format_ARGB8565_Premultiplied:
2762 case QImage::Format_ARGB6666_Premultiplied:
2763 case QImage::Format_ARGB8555_Premultiplied:
2764 case QImage::Format_ARGB4444_Premultiplied:
2765 case QImage::Format_Alpha8:
2766 convertedQImage = convertedQImage.convertToFormat(QImage::Format_ARGB32);
2767 colorSpace = ColorSpace::DeviceRGB;
2768 bitsPerComponent = 8;
2769 break;
2770 case QImage::Format_RGBA8888:
2771 case QImage::Format_RGBA8888_Premultiplied:
2772 case QImage::Format_RGBX8888:
2773 case QImage::Format_ARGB32:
2774 colorSpace = ColorSpace::DeviceRGB;
2775 bitsPerComponent = 8;
2776 break;
2777 case QImage::Format_Grayscale8:
2778 bitsPerComponent = 8;
2779 break;
2780 case QImage::Format_Grayscale16:
2781 convertedQImage = convertedQImage.convertToFormat(QImage::Format_Grayscale8);
2782
2783 colorSpace = ColorSpace::DeviceGray;
2784 bitsPerComponent = 8;
2785 break;
2786 case QImage::Format_RGB16:
2787 case QImage::Format_RGB666:
2788 case QImage::Format_RGB555:
2789 case QImage::Format_RGB444:
2790 convertedQImage = convertedQImage.convertToFormat(QImage::Format_RGB888);
2791 colorSpace = ColorSpace::DeviceRGB;
2792 bitsPerComponent = 8;
2793 break;
2794 case QImage::Format_RGB888:
2795 colorSpace = ColorSpace::DeviceRGB;
2796 bitsPerComponent = 8;
2797 break;
2798 default:
2799 convertedQImage = convertedQImage.convertToFormat(QImage::Format_ARGB32);
2800
2801 colorSpace = ColorSpace::DeviceRGB;
2802 bitsPerComponent = 8;
2803 break;
2804 }
2805
2806 getRawDataFromQImage(convertedQImage, convertedQImage.depth(), &data, &sMaskData);
2807
2808 std::unique_ptr<AnnotStampImageHelper> annotImg;
2809
2810 if (sMaskData.size() > 0) {
2811 AnnotStampImageHelper sMask(parentDoc->doc, width, height, ColorSpace::DeviceGray, 8, sMaskData.data(), sMaskData.size());
2812 annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size(), sMask.getRef());
2813 } else {
2814 annotImg = std::make_unique<AnnotStampImageHelper>(parentDoc->doc, width, height, colorSpace, bitsPerComponent, data.data(), data.size());
2815 }
2816
2817 return annotImg;
2818 }
2819
2820 StampAnnotation::StampAnnotation() : Annotation(*new StampAnnotationPrivate()) { }
2821
2822 StampAnnotation::StampAnnotation(StampAnnotationPrivate &dd) : Annotation(dd) { }
2823
2824 StampAnnotation::~StampAnnotation() = default;
2825
2826 Annotation::SubType StampAnnotation::subType() const
2827 {
2828 return AStamp;
2829 }
2830
2831 QString StampAnnotation::stampIconName() const
2832 {
2833 Q_D(const StampAnnotation);
2834
2835 if (!d->pdfAnnot) {
2836 return d->stampIconName;
2837 }
2838
2839 const AnnotStamp *stampann = static_cast<const AnnotStamp *>(d->pdfAnnot.get());
2840 return QString::fromStdString(stampann->getIcon());
2841 }
2842
2843 void StampAnnotation::setStampIconName(const QString &name)
2844 {
2845 Q_D(StampAnnotation);
2846
2847 if (!d->pdfAnnot) {
2848 d->stampIconName = name;
2849 return;
2850 }
2851
2852 AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get());
2853 stampann->setIcon(name.toStdString());
2854 }
2855
2856 void StampAnnotation::setStampCustomImage(const QImage &image)
2857 {
2858 if (image.isNull()) {
2859 return;
2860 }
2861
2862 Q_D(StampAnnotation);
2863
2864 if (!d->pdfAnnot) {
2865 d->stampCustomImage = QImage(image);
2866 return;
2867 }
2868
2869 AnnotStamp *stampann = static_cast<AnnotStamp *>(d->pdfAnnot.get());
2870 std::unique_ptr<AnnotStampImageHelper> annotCustomImage = d->convertQImageToAnnotStampImageHelper(image);
2871 stampann->setCustomImage(std::move(annotCustomImage));
2872 }
2873
2874 /** SignatureAnnotation [Annotation] */
2875 class SignatureAnnotationPrivate : public AnnotationPrivate
2876 {
2877 public:
2878 SignatureAnnotationPrivate();
2879 std::unique_ptr<Annotation> makeAlias() override;
2880 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
2881
2882 // data fields
2883 QString text;
2884 QString leftText;
2885 double fontSize = 10.0;
2886 double leftFontSize = 20.0;
2887 QColor fontColor = Qt::red;
2888 QColor borderColor = Qt::red;
2889 double borderWidth = 1.5;
2890 QColor backgroundColor = QColor(240, 240, 240);
2891 QString imagePath;
2892 QString fieldPartialName;
2893 ErrorString lastSigningErrorDetails;
2894 std::unique_ptr<::FormFieldSignature> field = nullptr;
2895 };
2896
2897 SignatureAnnotationPrivate::SignatureAnnotationPrivate() = default;
2898
2899 std::unique_ptr<Annotation> SignatureAnnotationPrivate::makeAlias()
2900 {
2901 return std::unique_ptr<Annotation>(new SignatureAnnotation(*this));
2902 }
2903
2904 std::shared_ptr<Annot> SignatureAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
2905 {
2906 std::unique_ptr<SignatureAnnotation> q = static_pointer_cast<SignatureAnnotation>(makeAlias());
2907
2908 // Set page and document
2909 pdfPage = destPage;
2910 parentDoc = doc;
2911
2912 // Set pdfAnnot
2913 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
2914
2915 std::unique_ptr<GooString> gSignatureText = std::unique_ptr<GooString>(QStringToUnicodeGooString(text));
2916 std::unique_ptr<GooString> gSignatureLeftText = std::unique_ptr<GooString>(QStringToUnicodeGooString(leftText));
2917
2918 std::variant<PDFDoc::SignatureData, CryptoSign::SigningErrorMessage> result =
2919 destPage->getDoc()->createSignature(destPage, QStringToGooString(fieldPartialName), rect, *gSignatureText, *gSignatureLeftText, fontSize, leftFontSize, convertQColor(fontColor), borderWidth, convertQColor(borderColor),
2920 convertQColor(backgroundColor), imagePath.toStdString());
2921
2922 if (std::holds_alternative<CryptoSign::SigningErrorMessage>(result)) {
2923 error(errInternal, -1, "Failed creating signature data, will crash shortly: {0:s}", std::get<CryptoSign::SigningErrorMessage>(result).message.text.c_str());
2924 return nullptr;
2925 }
2926
2927 auto sig = std::get_if<PDFDoc::SignatureData>(&result);
2928
2929 sig->formWidget->updateWidgetAppearance();
2930 field = std::move(sig->field);
2931
2932 // Set properties
2933 flushBaseAnnotationProperties();
2934
2935 pdfAnnot = sig->annotWidget;
2936
2937 return pdfAnnot;
2938 }
2939
2940 SignatureAnnotation::SignatureAnnotation() : Annotation(*new SignatureAnnotationPrivate()) { }
2941
2942 SignatureAnnotation::SignatureAnnotation(SignatureAnnotationPrivate &dd) : Annotation(dd) { }
2943
2944 SignatureAnnotation::~SignatureAnnotation() = default;
2945
2946 Annotation::SubType SignatureAnnotation::subType() const
2947 {
2948 return AWidget;
2949 }
2950
2951 void SignatureAnnotation::setText(const QString &text)
2952 {
2953 Q_D(SignatureAnnotation);
2954 d->text = text;
2955 }
2956
2957 void SignatureAnnotation::setLeftText(const QString &text)
2958 {
2959 Q_D(SignatureAnnotation);
2960 d->leftText = text;
2961 }
2962
2963 double SignatureAnnotation::fontSize() const
2964 {
2965 Q_D(const SignatureAnnotation);
2966 return d->fontSize;
2967 }
2968
2969 void SignatureAnnotation::setFontSize(double fontSize)
2970 {
2971 Q_D(SignatureAnnotation);
2972 d->fontSize = fontSize;
2973 }
2974
2975 double SignatureAnnotation::leftFontSize() const
2976 {
2977 Q_D(const SignatureAnnotation);
2978 return d->leftFontSize;
2979 }
2980
2981 void SignatureAnnotation::setLeftFontSize(double fontSize)
2982 {
2983 Q_D(SignatureAnnotation);
2984 d->leftFontSize = fontSize;
2985 }
2986
2987 QColor SignatureAnnotation::fontColor() const
2988 {
2989 Q_D(const SignatureAnnotation);
2990 return d->fontColor;
2991 }
2992
2993 void SignatureAnnotation::setFontColor(const QColor &color)
2994 {
2995 Q_D(SignatureAnnotation);
2996 d->fontColor = color;
2997 }
2998
2999 QColor SignatureAnnotation::borderColor() const
3000 {
3001 Q_D(const SignatureAnnotation);
3002 return d->borderColor;
3003 }
3004
3005 void SignatureAnnotation::setBorderColor(const QColor &color)
3006 {
3007 Q_D(SignatureAnnotation);
3008 d->borderColor = color;
3009 }
3010
3011 QColor SignatureAnnotation::backgroundColor() const
3012 {
3013 Q_D(const SignatureAnnotation);
3014 return d->backgroundColor;
3015 }
3016
3017 double SignatureAnnotation::borderWidth() const
3018 {
3019 Q_D(const SignatureAnnotation);
3020 return d->borderWidth;
3021 }
3022
3023 void SignatureAnnotation::setBorderWidth(double width)
3024 {
3025 Q_D(SignatureAnnotation);
3026 d->borderWidth = width;
3027 }
3028
3029 void SignatureAnnotation::setBackgroundColor(const QColor &color)
3030 {
3031 Q_D(SignatureAnnotation);
3032 d->backgroundColor = color;
3033 }
3034
3035 QString SignatureAnnotation::imagePath() const
3036 {
3037 Q_D(const SignatureAnnotation);
3038 return d->imagePath;
3039 }
3040
3041 void SignatureAnnotation::setImagePath(const QString &imagePath)
3042 {
3043 Q_D(SignatureAnnotation);
3044 d->imagePath = imagePath;
3045 }
3046
3047 QString SignatureAnnotation::fieldPartialName() const
3048 {
3049 Q_D(const SignatureAnnotation);
3050 return d->fieldPartialName;
3051 }
3052
3053 void SignatureAnnotation::setFieldPartialName(const QString &fieldPartialName)
3054 {
3055 Q_D(SignatureAnnotation);
3056 d->fieldPartialName = fieldPartialName;
3057 }
3058
3059 SignatureAnnotation::SigningResult SignatureAnnotation::sign(const QString &outputFileName, const PDFConverter::NewSignatureData &data)
3060 {
3061 Q_D(SignatureAnnotation);
3062 auto formField = std::make_unique<FormFieldSignature>(d->parentDoc, d->pdfPage, static_cast<::FormWidgetSignature *>(d->field->getCreateWidget()));
3063
3064 const auto result = formField->sign(outputFileName, data);
3065 d->lastSigningErrorDetails = formField->lastSigningErrorDetails();
3066
3067 switch (result) {
3068 case FormFieldSignature::SigningSuccess:
3069 return SigningSuccess;
3070 case FormFieldSignature::FieldAlreadySigned:
3071 return FieldAlreadySigned;
3072 case FormFieldSignature::GenericSigningError:
3073 return GenericSigningError;
3074 case FormFieldSignature::InternalError:
3075 return InternalError;
3076 case FormFieldSignature::KeyMissing:
3077 return KeyMissing;
3078 case FormFieldSignature::WriteFailed:
3079 return WriteFailed;
3080 case FormFieldSignature::UserCancelled:
3081 return UserCancelled;
3082 case FormFieldSignature::BadPassphrase:
3083 return BadPassphrase;
3084 }
3085 return GenericSigningError;
3086 }
3087
3088 Poppler::ErrorString SignatureAnnotation::lastSigningErrorDetails() const
3089 {
3090 Q_D(const SignatureAnnotation);
3091 return d->lastSigningErrorDetails;
3092 }
3093
3094 /** InkAnnotation [Annotation] */
3095 class InkAnnotationPrivate : public AnnotationPrivate
3096 {
3097 public:
3098 InkAnnotationPrivate();
3099 std::unique_ptr<Annotation> makeAlias() override;
3100 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3101
3102 // data fields
3103 QList<QVector<QPointF>> inkPaths;
3104
3105 // helper
3106 std::vector<std::unique_ptr<AnnotPath>> toAnnotPaths(const QList<QVector<QPointF>> &paths);
3107 };
3108
3109 InkAnnotationPrivate::InkAnnotationPrivate() = default;
3110
3111 std::unique_ptr<Annotation> InkAnnotationPrivate::makeAlias()
3112 {
3113 return std::unique_ptr<Annotation>(new InkAnnotation(*this));
3114 }
3115
3116 // Note: Caller is required to delete array elements and the array itself after use
3117 std::vector<std::unique_ptr<AnnotPath>> InkAnnotationPrivate::toAnnotPaths(const QList<QVector<QPointF>> &paths)
3118 {
3119 std::vector<std::unique_ptr<AnnotPath>> res;
3120 res.reserve(paths.size());
3121 for (const auto &path : paths) {
3122 res.push_back(toAnnotPath(path));
3123 }
3124 return res;
3125 }
3126
3127 std::shared_ptr<Annot> InkAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
3128 {
3129 // Setters are defined in the public class
3130 std::unique_ptr<InkAnnotation> q = static_pointer_cast<InkAnnotation>(makeAlias());
3131
3132 // Set page and document
3133 pdfPage = destPage;
3134 parentDoc = doc;
3135
3136 // Set pdfAnnot
3137 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
3138 pdfAnnot = std::make_shared<AnnotInk>(destPage->getDoc(), &rect);
3139
3140 // Set properties
3141 flushBaseAnnotationProperties();
3142 q->setInkPaths(inkPaths);
3143
3144 inkPaths.clear(); // Free up memory
3145
3146 return pdfAnnot;
3147 }
3148
3149 InkAnnotation::InkAnnotation() : Annotation(*new InkAnnotationPrivate()) { }
3150
3151 InkAnnotation::InkAnnotation(InkAnnotationPrivate &dd) : Annotation(dd) { }
3152
3153 InkAnnotation::~InkAnnotation() = default;
3154
3155 Annotation::SubType InkAnnotation::subType() const
3156 {
3157 return AInk;
3158 }
3159
3160 QList<QVector<QPointF>> InkAnnotation::inkPaths() const
3161 {
3162 Q_D(const InkAnnotation);
3163
3164 if (!d->pdfAnnot) {
3165 return d->inkPaths;
3166 }
3167
3168 const AnnotInk *inkann = static_cast<const AnnotInk *>(d->pdfAnnot.get());
3169
3170 const std::vector<std::unique_ptr<AnnotPath>> &paths = inkann->getInkList();
3171 if (paths.empty()) {
3172 return {};
3173 }
3174
3175 double MTX[6];
3176 d->fillTransformationMTX(MTX);
3177
3178 QList<QVector<QPointF>> inkPaths;
3179 inkPaths.reserve(paths.size());
3180 for (const auto &path : paths) {
3181 // transform each path in a list of normalized points ..
3182 QVector<QPointF> localList;
3183 const int pointsNumber = path ? path->getCoordsLength() : 0;
3184 for (int n = 0; n < pointsNumber; ++n) {
3185 QPointF point;
3186 XPDFReader::transform(MTX, path->getX(n), path->getY(n), point);
3187 localList.append(point);
3188 }
3189 // ..and add it to the annotation
3190 inkPaths.append(localList);
3191 }
3192 inkPaths.shrink_to_fit();
3193 return inkPaths;
3194 }
3195
3196 void InkAnnotation::setInkPaths(const QList<QVector<QPointF>> &paths)
3197 {
3198 Q_D(InkAnnotation);
3199
3200 if (!d->pdfAnnot) {
3201 d->inkPaths = paths;
3202 return;
3203 }
3204
3205 AnnotInk *inkann = static_cast<AnnotInk *>(d->pdfAnnot.get());
3206 const std::vector<std::unique_ptr<AnnotPath>> annotpaths = d->toAnnotPaths(paths);
3207 inkann->setInkList(annotpaths);
3208 }
3209
3210 /** LinkAnnotation [Annotation] */
3211 class LinkAnnotationPrivate : public AnnotationPrivate
3212 {
3213 public:
3214 LinkAnnotationPrivate();
3215 ~LinkAnnotationPrivate() override;
3216 std::unique_ptr<Annotation> makeAlias() override;
3217 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3218
3219 // data fields
3220 std::unique_ptr<Link> linkDestination;
3221 LinkAnnotation::HighlightMode linkHLMode;
3222 QPointF linkRegion[4];
3223 };
3224
3225 LinkAnnotationPrivate::LinkAnnotationPrivate() : linkHLMode(LinkAnnotation::Invert) { }
3226
3227 LinkAnnotationPrivate::~LinkAnnotationPrivate() = default;
3228
3229 std::unique_ptr<Annotation> LinkAnnotationPrivate::makeAlias()
3230 {
3231 return std::unique_ptr<Annotation>(new LinkAnnotation(*this));
3232 }
3233
3234 std::shared_ptr<Annot> LinkAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3235 {
3236 return nullptr; // Not implemented
3237 }
3238
3239 LinkAnnotation::LinkAnnotation() : Annotation(*new LinkAnnotationPrivate()) { }
3240
3241 LinkAnnotation::LinkAnnotation(LinkAnnotationPrivate &dd) : Annotation(dd) { }
3242
3243 LinkAnnotation::~LinkAnnotation() = default;
3244
3245 Annotation::SubType LinkAnnotation::subType() const
3246 {
3247 return ALink;
3248 }
3249
3250 Link *LinkAnnotation::linkDestination() const
3251 {
3252 Q_D(const LinkAnnotation);
3253 return d->linkDestination.get();
3254 }
3255
3256 void LinkAnnotation::setLinkDestination(std::unique_ptr<Link> &&link)
3257 {
3258 Q_D(LinkAnnotation);
3259 d->linkDestination = std::move(link);
3260 }
3261
3262 LinkAnnotation::HighlightMode LinkAnnotation::linkHighlightMode() const
3263 {
3264 Q_D(const LinkAnnotation);
3265 return d->linkHLMode;
3266 }
3267
3268 void LinkAnnotation::setLinkHighlightMode(LinkAnnotation::HighlightMode mode)
3269 {
3270 Q_D(LinkAnnotation);
3271 d->linkHLMode = mode;
3272 }
3273
3274 QPointF LinkAnnotation::linkRegionPoint(int id) const
3275 {
3276 if (id < 0 || id >= 4) {
3277 return QPointF();
3278 }
3279
3280 Q_D(const LinkAnnotation);
3281 return d->linkRegion[id];
3282 }
3283
3284 void LinkAnnotation::setLinkRegionPoint(int id, const QPointF point)
3285 {
3286 if (id < 0 || id >= 4) {
3287 return;
3288 }
3289
3290 Q_D(LinkAnnotation);
3291 d->linkRegion[id] = point;
3292 }
3293
3294 /** CaretAnnotation [Annotation] */
3295 class CaretAnnotationPrivate : public AnnotationPrivate
3296 {
3297 public:
3298 CaretAnnotationPrivate();
3299 std::unique_ptr<Annotation> makeAlias() override;
3300 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3301
3302 // data fields
3303 CaretAnnotation::CaretSymbol symbol;
3304 };
3305
3306 CaretAnnotationPrivate::CaretAnnotationPrivate() : symbol(CaretAnnotation::None) { }
3307
3308 std::unique_ptr<Annotation> CaretAnnotationPrivate::makeAlias()
3309 {
3310 return std::unique_ptr<Annotation>(new CaretAnnotation(*this));
3311 }
3312
3313 std::shared_ptr<Annot> CaretAnnotationPrivate::createNativeAnnot(::Page *destPage, DocumentData *doc)
3314 {
3315 // Setters are defined in the public class
3316 std::unique_ptr<CaretAnnotation> q = static_pointer_cast<CaretAnnotation>(makeAlias());
3317
3318 // Set page and document
3319 pdfPage = destPage;
3320 parentDoc = doc;
3321
3322 // Set pdfAnnot
3323 PDFRectangle rect = boundaryToPdfRectangle(boundary, flags);
3324 pdfAnnot = std::make_shared<AnnotCaret>(destPage->getDoc(), &rect);
3325
3326 // Set properties
3327 flushBaseAnnotationProperties();
3328 q->setCaretSymbol(symbol);
3329
3330 return pdfAnnot;
3331 }
3332
3333 CaretAnnotation::CaretAnnotation() : Annotation(*new CaretAnnotationPrivate()) { }
3334
3335 CaretAnnotation::CaretAnnotation(CaretAnnotationPrivate &dd) : Annotation(dd) { }
3336
3337 CaretAnnotation::~CaretAnnotation() = default;
3338
3339 Annotation::SubType CaretAnnotation::subType() const
3340 {
3341 return ACaret;
3342 }
3343
3344 CaretAnnotation::CaretSymbol CaretAnnotation::caretSymbol() const
3345 {
3346 Q_D(const CaretAnnotation);
3347
3348 if (!d->pdfAnnot) {
3349 return d->symbol;
3350 }
3351
3352 const AnnotCaret *caretann = static_cast<const AnnotCaret *>(d->pdfAnnot.get());
3353 return (CaretAnnotation::CaretSymbol)caretann->getSymbol();
3354 }
3355
3356 void CaretAnnotation::setCaretSymbol(CaretAnnotation::CaretSymbol symbol)
3357 {
3358 Q_D(CaretAnnotation);
3359
3360 if (!d->pdfAnnot) {
3361 d->symbol = symbol;
3362 return;
3363 }
3364
3365 AnnotCaret *caretann = static_cast<AnnotCaret *>(d->pdfAnnot.get());
3366 caretann->setSymbol((AnnotCaret::AnnotCaretSymbol)symbol);
3367 }
3368
3369 /** FileAttachmentAnnotation [Annotation] */
3370 class FileAttachmentAnnotationPrivate : public AnnotationPrivate
3371 {
3372 public:
3373 FileAttachmentAnnotationPrivate();
3374 ~FileAttachmentAnnotationPrivate() override;
3375 std::unique_ptr<Annotation> makeAlias() override;
3376 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3377
3378 // data fields
3379 QString icon;
3380 EmbeddedFile *embfile;
3381 };
3382
3383 FileAttachmentAnnotationPrivate::FileAttachmentAnnotationPrivate() : icon(QStringLiteral("PushPin")), embfile(nullptr) { }
3384
3385 FileAttachmentAnnotationPrivate::~FileAttachmentAnnotationPrivate()
3386 {
3387 delete embfile;
3388 }
3389
3390 std::unique_ptr<Annotation> FileAttachmentAnnotationPrivate::makeAlias()
3391 {
3392 return std::unique_ptr<Annotation>(new FileAttachmentAnnotation(*this));
3393 }
3394
3395 std::shared_ptr<Annot> FileAttachmentAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3396 {
3397 return nullptr; // Not implemented
3398 }
3399
3400 FileAttachmentAnnotation::FileAttachmentAnnotation() : Annotation(*new FileAttachmentAnnotationPrivate()) { }
3401
3402 FileAttachmentAnnotation::FileAttachmentAnnotation(FileAttachmentAnnotationPrivate &dd) : Annotation(dd) { }
3403
3404 FileAttachmentAnnotation::~FileAttachmentAnnotation() = default;
3405
3406 Annotation::SubType FileAttachmentAnnotation::subType() const
3407 {
3408 return AFileAttachment;
3409 }
3410
3411 QString FileAttachmentAnnotation::fileIconName() const
3412 {
3413 Q_D(const FileAttachmentAnnotation);
3414 return d->icon;
3415 }
3416
3417 void FileAttachmentAnnotation::setFileIconName(const QString &icon)
3418 {
3419 Q_D(FileAttachmentAnnotation);
3420 d->icon = icon;
3421 }
3422
3423 EmbeddedFile *FileAttachmentAnnotation::embeddedFile() const
3424 {
3425 Q_D(const FileAttachmentAnnotation);
3426 return d->embfile;
3427 }
3428
3429 void FileAttachmentAnnotation::setEmbeddedFile(EmbeddedFile *ef)
3430 {
3431 Q_D(FileAttachmentAnnotation);
3432 d->embfile = ef;
3433 }
3434
3435 /** SoundAnnotation [Annotation] */
3436 class SoundAnnotationPrivate : public AnnotationPrivate
3437 {
3438 public:
3439 SoundAnnotationPrivate();
3440 ~SoundAnnotationPrivate() override;
3441 std::unique_ptr<Annotation> makeAlias() override;
3442 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3443
3444 // data fields
3445 QString icon;
3446 SoundObject *sound;
3447 };
3448
3449 SoundAnnotationPrivate::SoundAnnotationPrivate() : icon(QStringLiteral("Speaker")), sound(nullptr) { }
3450
3451 SoundAnnotationPrivate::~SoundAnnotationPrivate()
3452 {
3453 delete sound;
3454 }
3455
3456 std::unique_ptr<Annotation> SoundAnnotationPrivate::makeAlias()
3457 {
3458 return std::unique_ptr<Annotation>(new SoundAnnotation(*this));
3459 }
3460
3461 std::shared_ptr<Annot> SoundAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3462 {
3463 return nullptr; // Not implemented
3464 }
3465
3466 SoundAnnotation::SoundAnnotation() : Annotation(*new SoundAnnotationPrivate()) { }
3467
3468 SoundAnnotation::SoundAnnotation(SoundAnnotationPrivate &dd) : Annotation(dd) { }
3469
3470 SoundAnnotation::~SoundAnnotation() = default;
3471
3472 Annotation::SubType SoundAnnotation::subType() const
3473 {
3474 return ASound;
3475 }
3476
3477 QString SoundAnnotation::soundIconName() const
3478 {
3479 Q_D(const SoundAnnotation);
3480 return d->icon;
3481 }
3482
3483 void SoundAnnotation::setSoundIconName(const QString &icon)
3484 {
3485 Q_D(SoundAnnotation);
3486 d->icon = icon;
3487 }
3488
3489 SoundObject *SoundAnnotation::sound() const
3490 {
3491 Q_D(const SoundAnnotation);
3492 return d->sound;
3493 }
3494
3495 void SoundAnnotation::setSound(SoundObject *s)
3496 {
3497 Q_D(SoundAnnotation);
3498 d->sound = s;
3499 }
3500
3501 /** MovieAnnotation [Annotation] */
3502 class MovieAnnotationPrivate : public AnnotationPrivate
3503 {
3504 public:
3505 MovieAnnotationPrivate();
3506 ~MovieAnnotationPrivate() override;
3507 std::unique_ptr<Annotation> makeAlias() override;
3508 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3509
3510 // data fields
3511 MovieObject *movie;
3512 QString title;
3513 };
3514
3515 MovieAnnotationPrivate::MovieAnnotationPrivate() : movie(nullptr) { }
3516
3517 MovieAnnotationPrivate::~MovieAnnotationPrivate()
3518 {
3519 delete movie;
3520 }
3521
3522 std::unique_ptr<Annotation> MovieAnnotationPrivate::makeAlias()
3523 {
3524 return std::unique_ptr<Annotation>(new MovieAnnotation(*this));
3525 }
3526
3527 std::shared_ptr<Annot> MovieAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3528 {
3529 return nullptr; // Not implemented
3530 }
3531
3532 MovieAnnotation::MovieAnnotation() : Annotation(*new MovieAnnotationPrivate()) { }
3533
3534 MovieAnnotation::MovieAnnotation(MovieAnnotationPrivate &dd) : Annotation(dd) { }
3535
3536 MovieAnnotation::~MovieAnnotation() = default;
3537
3538 Annotation::SubType MovieAnnotation::subType() const
3539 {
3540 return AMovie;
3541 }
3542
3543 MovieObject *MovieAnnotation::movie() const
3544 {
3545 Q_D(const MovieAnnotation);
3546 return d->movie;
3547 }
3548
3549 void MovieAnnotation::setMovie(MovieObject *movie)
3550 {
3551 Q_D(MovieAnnotation);
3552 d->movie = movie;
3553 }
3554
3555 QString MovieAnnotation::movieTitle() const
3556 {
3557 Q_D(const MovieAnnotation);
3558 return d->title;
3559 }
3560
3561 void MovieAnnotation::setMovieTitle(const QString &title)
3562 {
3563 Q_D(MovieAnnotation);
3564 d->title = title;
3565 }
3566
3567 /** ScreenAnnotation [Annotation] */
3568 class ScreenAnnotationPrivate : public AnnotationPrivate
3569 {
3570 public:
3571 ScreenAnnotationPrivate();
3572 ~ScreenAnnotationPrivate() override;
3573 std::unique_ptr<Annotation> makeAlias() override;
3574 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3575
3576 // data fields
3577 LinkRendition *action;
3578 QString title;
3579 };
3580
3581 ScreenAnnotationPrivate::ScreenAnnotationPrivate() : action(nullptr) { }
3582
3583 ScreenAnnotationPrivate::~ScreenAnnotationPrivate()
3584 {
3585 delete action;
3586 }
3587
3588 ScreenAnnotation::ScreenAnnotation(ScreenAnnotationPrivate &dd) : Annotation(dd) { }
3589
3590 std::unique_ptr<Annotation> ScreenAnnotationPrivate::makeAlias()
3591 {
3592 return std::unique_ptr<Annotation>(new ScreenAnnotation(*this));
3593 }
3594
3595 std::shared_ptr<Annot> ScreenAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3596 {
3597 return nullptr; // Not implemented
3598 }
3599
3600 ScreenAnnotation::ScreenAnnotation() : Annotation(*new ScreenAnnotationPrivate()) { }
3601
3602 ScreenAnnotation::~ScreenAnnotation() = default;
3603
3604 Annotation::SubType ScreenAnnotation::subType() const
3605 {
3606 return AScreen;
3607 }
3608
3609 LinkRendition *ScreenAnnotation::action() const
3610 {
3611 Q_D(const ScreenAnnotation);
3612 return d->action;
3613 }
3614
3615 void ScreenAnnotation::setAction(LinkRendition *action)
3616 {
3617 Q_D(ScreenAnnotation);
3618 d->action = action;
3619 }
3620
3621 QString ScreenAnnotation::screenTitle() const
3622 {
3623 Q_D(const ScreenAnnotation);
3624 return d->title;
3625 }
3626
3627 void ScreenAnnotation::setScreenTitle(const QString &title)
3628 {
3629 Q_D(ScreenAnnotation);
3630 d->title = title;
3631 }
3632
3633 std::unique_ptr<Link> ScreenAnnotation::additionalAction(AdditionalActionType type) const
3634 {
3635 Q_D(const ScreenAnnotation);
3636 return d->additionalAction(type);
3637 }
3638
3639 /** WidgetAnnotation [Annotation] */
3640 class WidgetAnnotationPrivate : public AnnotationPrivate
3641 {
3642 public:
3643 std::unique_ptr<Annotation> makeAlias() override;
3644 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override;
3645 };
3646
3647 std::unique_ptr<Annotation> WidgetAnnotationPrivate::makeAlias()
3648 {
3649 return std::unique_ptr<Annotation>(new WidgetAnnotation(*this));
3650 }
3651
3652 std::shared_ptr<Annot> WidgetAnnotationPrivate::createNativeAnnot(::Page * /*destPage*/, DocumentData * /*doc*/)
3653 {
3654 return nullptr; // Not implemented
3655 }
3656
3657 WidgetAnnotation::WidgetAnnotation(WidgetAnnotationPrivate &dd) : Annotation(dd) { }
3658
3659 WidgetAnnotation::WidgetAnnotation() : Annotation(*new WidgetAnnotationPrivate()) { }
3660
3661 WidgetAnnotation::~WidgetAnnotation() = default;
3662
3663 Annotation::SubType WidgetAnnotation::subType() const
3664 {
3665 return AWidget;
3666 }
3667
3668 std::unique_ptr<Link> WidgetAnnotation::additionalAction(AdditionalActionType type) const
3669 {
3670 Q_D(const WidgetAnnotation);
3671 return d->additionalAction(type);
3672 }
3673
3674 /** RichMediaAnnotation [Annotation] */
3675 class RichMediaAnnotation::Params::Private
3676 {
3677 public:
3678 Private() = default;
3679
3680 QString flashVars;
3681 };
3682
3683 RichMediaAnnotation::Params::Params() : d(new Private) { }
3684
3685 RichMediaAnnotation::Params::~Params() = default;
3686
3687 void RichMediaAnnotation::Params::setFlashVars(const QString &flashVars)
3688 {
3689 d->flashVars = flashVars;
3690 }
3691
3692 QString RichMediaAnnotation::Params::flashVars() const
3693 {
3694 return d->flashVars;
3695 }
3696
3697 class RichMediaAnnotation::Instance::Private
3698 {
3699 public:
3700 Private() : params(nullptr) { }
3701
3702 ~Private() { delete params; }
3703
3704 Private(const Private &) = delete;
3705 Private &operator=(const Private &) = delete;
3706
3707 RichMediaAnnotation::Instance::Type type;
3708 RichMediaAnnotation::Params *params;
3709 };
3710
3711 RichMediaAnnotation::Instance::Instance() : d(new Private) { }
3712
3713 RichMediaAnnotation::Instance::~Instance() = default;
3714
3715 void RichMediaAnnotation::Instance::setType(Type type)
3716 {
3717 d->type = type;
3718 }
3719
3720 RichMediaAnnotation::Instance::Type RichMediaAnnotation::Instance::type() const
3721 {
3722 return d->type;
3723 }
3724
3725 void RichMediaAnnotation::Instance::setParams(RichMediaAnnotation::Params *params)
3726 {
3727 delete d->params;
3728 d->params = params;
3729 }
3730
3731 RichMediaAnnotation::Params *RichMediaAnnotation::Instance::params() const
3732 {
3733 return d->params;
3734 }
3735
3736 class RichMediaAnnotation::Configuration::Private
3737 {
3738 public:
3739 Private() = default;
3740 ~Private()
3741 {
3742 qDeleteAll(instances);
3743 instances.clear();
3744 }
3745
3746 Private(const Private &) = delete;
3747 Private &operator=(const Private &) = delete;
3748
3749 RichMediaAnnotation::Configuration::Type type;
3750 QString name;
3751 QList<RichMediaAnnotation::Instance *> instances;
3752 };
3753
3754 RichMediaAnnotation::Configuration::Configuration() : d(new Private) { }
3755
3756 RichMediaAnnotation::Configuration::~Configuration() = default;
3757
3758 void RichMediaAnnotation::Configuration::setType(Type type)
3759 {
3760 d->type = type;
3761 }
3762
3763 RichMediaAnnotation::Configuration::Type RichMediaAnnotation::Configuration::type() const
3764 {
3765 return d->type;
3766 }
3767
3768 void RichMediaAnnotation::Configuration::setName(const QString &name)
3769 {
3770 d->name = name;
3771 }
3772
3773 QString RichMediaAnnotation::Configuration::name() const
3774 {
3775 return d->name;
3776 }
3777
3778 void RichMediaAnnotation::Configuration::setInstances(const QList<RichMediaAnnotation::Instance *> &instances)
3779 {
3780 qDeleteAll(d->instances);
3781 d->instances.clear();
3782
3783 d->instances = instances;
3784 }
3785
3786 QList<RichMediaAnnotation::Instance *> RichMediaAnnotation::Configuration::instances() const
3787 {
3788 return d->instances;
3789 }
3790
3791 class RichMediaAnnotation::Asset::Private
3792 {
3793 public:
3794 Private() : embeddedFile(nullptr) { }
3795
3796 ~Private() { delete embeddedFile; }
3797
3798 Private(const Private &) = delete;
3799 Private &operator=(const Private &) = delete;
3800
3801 QString name;
3802 EmbeddedFile *embeddedFile;
3803 };
3804
3805 RichMediaAnnotation::Asset::Asset() : d(new Private) { }
3806
3807 RichMediaAnnotation::Asset::~Asset() = default;
3808
3809 void RichMediaAnnotation::Asset::setName(const QString &name)
3810 {
3811 d->name = name;
3812 }
3813
3814 QString RichMediaAnnotation::Asset::name() const
3815 {
3816 return d->name;
3817 }
3818
3819 void RichMediaAnnotation::Asset::setEmbeddedFile(EmbeddedFile *embeddedFile)
3820 {
3821 delete d->embeddedFile;
3822 d->embeddedFile = embeddedFile;
3823 }
3824
3825 EmbeddedFile *RichMediaAnnotation::Asset::embeddedFile() const
3826 {
3827 return d->embeddedFile;
3828 }
3829
3830 class RichMediaAnnotation::Content::Private
3831 {
3832 public:
3833 Private() = default;
3834 ~Private()
3835 {
3836 qDeleteAll(configurations);
3837 configurations.clear();
3838
3839 qDeleteAll(assets);
3840 assets.clear();
3841 }
3842
3843 Private(const Private &) = delete;
3844 Private &operator=(const Private &) = delete;
3845
3846 QList<RichMediaAnnotation::Configuration *> configurations;
3847 QList<RichMediaAnnotation::Asset *> assets;
3848 };
3849
3850 RichMediaAnnotation::Content::Content() : d(new Private) { }
3851
3852 RichMediaAnnotation::Content::~Content() = default;
3853
3854 void RichMediaAnnotation::Content::setConfigurations(const QList<RichMediaAnnotation::Configuration *> &configurations)
3855 {
3856 qDeleteAll(d->configurations);
3857 d->configurations.clear();
3858
3859 d->configurations = configurations;
3860 }
3861
3862 QList<RichMediaAnnotation::Configuration *> RichMediaAnnotation::Content::configurations() const
3863 {
3864 return d->configurations;
3865 }
3866
3867 void RichMediaAnnotation::Content::setAssets(const QList<RichMediaAnnotation::Asset *> &assets)
3868 {
3869 qDeleteAll(d->assets);
3870 d->assets.clear();
3871
3872 d->assets = assets;
3873 }
3874
3875 QList<RichMediaAnnotation::Asset *> RichMediaAnnotation::Content::assets() const
3876 {
3877 return d->assets;
3878 }
3879
3880 class RichMediaAnnotation::Activation::Private
3881 {
3882 public:
3883 Private() : condition(RichMediaAnnotation::Activation::UserAction) { }
3884
3885 RichMediaAnnotation::Activation::Condition condition;
3886 };
3887
3888 RichMediaAnnotation::Activation::Activation() : d(new Private) { }
3889
3890 RichMediaAnnotation::Activation::~Activation() = default;
3891
3892 void RichMediaAnnotation::Activation::setCondition(Condition condition)
3893 {
3894 d->condition = condition;
3895 }
3896
3897 RichMediaAnnotation::Activation::Condition RichMediaAnnotation::Activation::condition() const
3898 {
3899 return d->condition;
3900 }
3901
3902 class RichMediaAnnotation::Deactivation::Private : public QSharedData
3903 {
3904 public:
3905 Private() : condition(RichMediaAnnotation::Deactivation::UserAction) { }
3906
3907 RichMediaAnnotation::Deactivation::Condition condition;
3908 };
3909
3910 RichMediaAnnotation::Deactivation::Deactivation() : d(new Private) { }
3911
3912 RichMediaAnnotation::Deactivation::~Deactivation() = default;
3913
3914 void RichMediaAnnotation::Deactivation::setCondition(Condition condition)
3915 {
3916 d->condition = condition;
3917 }
3918
3919 RichMediaAnnotation::Deactivation::Condition RichMediaAnnotation::Deactivation::condition() const
3920 {
3921 return d->condition;
3922 }
3923
3924 class RichMediaAnnotation::Settings::Private : public QSharedData
3925 {
3926 public:
3927 Private() : activation(nullptr), deactivation(nullptr) { }
3928
3929 RichMediaAnnotation::Activation *activation;
3930 RichMediaAnnotation::Deactivation *deactivation;
3931 };
3932
3933 RichMediaAnnotation::Settings::Settings() : d(new Private) { }
3934
3935 RichMediaAnnotation::Settings::~Settings() = default;
3936
3937 void RichMediaAnnotation::Settings::setActivation(RichMediaAnnotation::Activation *activation)
3938 {
3939 delete d->activation;
3940 d->activation = activation;
3941 }
3942
3943 RichMediaAnnotation::Activation *RichMediaAnnotation::Settings::activation() const
3944 {
3945 return d->activation;
3946 }
3947
3948 void RichMediaAnnotation::Settings::setDeactivation(RichMediaAnnotation::Deactivation *deactivation)
3949 {
3950 delete d->deactivation;
3951 d->deactivation = deactivation;
3952 }
3953
3954 RichMediaAnnotation::Deactivation *RichMediaAnnotation::Settings::deactivation() const
3955 {
3956 return d->deactivation;
3957 }
3958
3959 class RichMediaAnnotationPrivate : public AnnotationPrivate
3960 {
3961 public:
3962 RichMediaAnnotationPrivate() : settings(nullptr), content(nullptr) { }
3963
3964 ~RichMediaAnnotationPrivate() override;
3965
3966 std::unique_ptr<Annotation> makeAlias() override { return std::unique_ptr<Annotation>(new RichMediaAnnotation(*this)); }
3967
3968 std::shared_ptr<Annot> createNativeAnnot(::Page *destPage, DocumentData *doc) override
3969 {
3970 Q_UNUSED(destPage);
3971 Q_UNUSED(doc);
3972
3973 return nullptr;
3974 }
3975
3976 RichMediaAnnotation::Settings *settings;
3977 RichMediaAnnotation::Content *content;
3978 };
3979
3980 RichMediaAnnotationPrivate::~RichMediaAnnotationPrivate()
3981 {
3982 delete settings;
3983 delete content;
3984 }
3985
3986 RichMediaAnnotation::RichMediaAnnotation() : Annotation(*new RichMediaAnnotationPrivate()) { }
3987
3988 RichMediaAnnotation::RichMediaAnnotation(RichMediaAnnotationPrivate &dd) : Annotation(dd) { }
3989
3990 RichMediaAnnotation::~RichMediaAnnotation() = default;
3991
3992 Annotation::SubType RichMediaAnnotation::subType() const
3993 {
3994 return ARichMedia;
3995 }
3996
3997 void RichMediaAnnotation::setSettings(RichMediaAnnotation::Settings *settings)
3998 {
3999 Q_D(RichMediaAnnotation);
4000
4001 delete d->settings;
4002 d->settings = settings;
4003 }
4004
4005 RichMediaAnnotation::Settings *RichMediaAnnotation::settings() const
4006 {
4007 Q_D(const RichMediaAnnotation);
4008
4009 return d->settings;
4010 }
4011
4012 void RichMediaAnnotation::setContent(RichMediaAnnotation::Content *content)
4013 {
4014 Q_D(RichMediaAnnotation);
4015
4016 delete d->content;
4017 d->content = content;
4018 }
4019
4020 RichMediaAnnotation::Content *RichMediaAnnotation::content() const
4021 {
4022 Q_D(const RichMediaAnnotation);
4023
4024 return d->content;
4025 }
4026
4027 // BEGIN utility annotation functions
4028 QColor convertAnnotColor(const AnnotColor *color)
4029 {
4030 if (!color) {
4031 return QColor();
4032 }
4033
4034 QColor newcolor;
4035 const std::array<double, 4> &color_data = color->getValues();
4036 switch (color->getSpace()) {
4037 case AnnotColor::colorTransparent: // = 0,
4038 newcolor = Qt::transparent;
4039 break;
4040 case AnnotColor::colorGray: // = 1,
4041 newcolor.setRgbF(color_data[0], color_data[0], color_data[0]);
4042 break;
4043 case AnnotColor::colorRGB: // = 3,
4044 newcolor.setRgbF(color_data[0], color_data[1], color_data[2]);
4045 break;
4046 case AnnotColor::colorCMYK: // = 4
4047 newcolor.setCmykF(color_data[0], color_data[1], color_data[2], color_data[3]);
4048 break;
4049 }
4050 return newcolor;
4051 }
4052
4053 std::unique_ptr<AnnotColor> convertQColor(const QColor &c)
4054 {
4055 if (c.alpha() == 0) {
4056 return {}; // Transparent
4057 }
4058
4059 switch (c.spec()) {
4060 case QColor::Rgb:
4061 case QColor::Hsl:
4062 case QColor::Hsv:
4063 return std::make_unique<AnnotColor>(c.redF(), c.greenF(), c.blueF());
4064 case QColor::Cmyk:
4065 return std::make_unique<AnnotColor>(c.cyanF(), c.magentaF(), c.yellowF(), c.blackF());
4066 case QColor::Invalid:
4067 default:
4068 return {};
4069 }
4070 }
4071 // END utility annotation functions
4072
4073 }