Debian Codegraph @

qt5/src/poppler-document.cc

raw
1 /* poppler-document.cc: qt interface to poppler
2 * Copyright (C) 2005, Net Integration Technologies, Inc.
3 * Copyright (C) 2005, 2008, Brad Hards <[email protected]>
4 * Copyright (C) 2005-2010, 2012, 2013, 2015, 2017-2022, 2024, 2025, Albert Astals Cid <[email protected]>
5 * Copyright (C) 2006-2010, Pino Toscano <[email protected]>
6 * Copyright (C) 2010, 2011 Hib Eris <[email protected]>
7 * Copyright (C) 2012 Koji Otani <[email protected]>
8 * Copyright (C) 2012, 2013 Thomas Freitag <[email protected]>
9 * Copyright (C) 2012 Fabio D'Urso <[email protected]>
10 * Copyright (C) 2014, 2018, 2020 Adam Reichold <[email protected]>
11 * Copyright (C) 2015 William Bader <[email protected]>
12 * Copyright (C) 2016 Jakub Alba <[email protected]>
13 * Copyright (C) 2017, 2021 Adrian Johnson <[email protected]>
14 * Copyright (C) 2017 Suzuki Toshiya <[email protected]>
15 * Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich
16 * Copyright (C) 2019-2021 Oliver Sander <[email protected]>
17 * Copyright (C) 2019 Alexander Volkov <[email protected]>
18 * Copyright (C) 2020 Philipp Knechtges <[email protected]>
19 * Copyright (C) 2020 Katarina Behrens <[email protected]>
20 * Copyright (C) 2020 Thorsten Behrens <[email protected]>
21 * Copyright (C) 2021 Mahmoud Khalil <[email protected]>
22 * Copyright (C) 2021 Hubert Figuiere <[email protected]>
23 * Copyright (C) 2024 Pratham Gandhi <[email protected]>
24 * Copyright (C) 2024 Stefan Brüns <[email protected]>
25 * Copyright (C) 2025 g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
26 * Copyright (C) 2025 Arnav V <[email protected]>
27 *
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2, or (at your option)
31 * any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
41 */
42
43 #include "poppler-qt5.h"
44
45 #include <config.h>
46 #include <poppler-config.h>
47 #include <ErrorCodes.h>
48 #include <GlobalParams.h>
49 #include <Outline.h>
50 #include <PDFDoc.h>
51 #include <Stream.h>
52 #include <Catalog.h>
53 #include <ViewerPreferences.h>
54 #include <DateInfo.h>
55 #include <GfxState.h>
56
57 #include <QtCore/QDebug>
58 #include <QtCore/QFile>
59 #include <QtCore/QByteArray>
60 #include <QTimeZone>
61
62 #include "poppler-form.h"
63 #include "poppler-private.h"
64 #include "poppler-link-private.h"
65 #include "poppler-page-private.h"
66 #include "poppler-outline-private.h"
67
68 #if USE_CMS
69 # include <lcms2.h>
70 #endif
71
72 namespace Poppler {
73
74 Document *Document::load(const QString &filePath, const QByteArray &ownerPassword, const QByteArray &userPassword)
75 {
76 DocumentData *doc = new DocumentData(filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
77 return DocumentData::checkDocument(doc);
78 }
79
80 Document *Document::load(QIODevice *device, const QByteArray &ownerPassword, const QByteArray &userPassword)
81 {
82 DocumentData *doc = new DocumentData(device, GooString(ownerPassword.data()), GooString(userPassword.data()));
83 return DocumentData::checkDocument(doc);
84 }
85
86 Document *Document::loadFromData(const QByteArray &fileContents, const QByteArray &ownerPassword, const QByteArray &userPassword)
87 {
88 // create stream
89 DocumentData *doc = new DocumentData(fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
90 return DocumentData::checkDocument(doc);
91 }
92
93 Document *DocumentData::checkDocument(DocumentData *doc)
94 {
95 Document *pdoc;
96 if (doc->doc->isOk() || doc->doc->getErrorCode() == errEncrypted) {
97 pdoc = new Document(doc);
98 if (doc->doc->getErrorCode() == errEncrypted) {
99 pdoc->m_doc->locked = true;
100 } else {
101 pdoc->m_doc->locked = false;
102 pdoc->m_doc->fillMembers();
103 }
104 return pdoc;
105 } else {
106 delete doc;
107 }
108 return nullptr;
109 }
110
111 Document::Document(DocumentData *dataA)
112 {
113 m_doc = dataA;
114 }
115
116 Document::~Document()
117 {
118 delete m_doc;
119 }
120
121 Page *Document::page(int index) const
122 {
123 Page *page = new Page(m_doc, index);
124 if (page->m_page->page == nullptr) {
125 delete page;
126 return nullptr;
127 }
128
129 return page;
130 }
131
132 bool Document::isLocked() const
133 {
134 return m_doc->locked;
135 }
136
137 bool Document::unlock(const QByteArray &ownerPassword, const QByteArray &userPassword)
138 {
139 if (m_doc->locked) {
140 /* racier then it needs to be */
141 DocumentData *doc2;
142 if (!m_doc->fileContents.isEmpty()) {
143 doc2 = new DocumentData(m_doc->fileContents, GooString(ownerPassword.data()), GooString(userPassword.data()));
144 } else if (m_doc->m_device) {
145 doc2 = new DocumentData(m_doc->m_device, GooString(ownerPassword.data()), GooString(userPassword.data()));
146 } else {
147 doc2 = new DocumentData(m_doc->m_filePath, GooString(ownerPassword.data()), GooString(userPassword.data()));
148 }
149 if (!doc2->doc->isOk()) {
150 delete doc2;
151 } else {
152 delete m_doc;
153 m_doc = doc2;
154 m_doc->locked = false;
155 m_doc->fillMembers();
156 }
157 }
158 return m_doc->locked;
159 }
160
161 Document::PageMode Document::pageMode() const
162 {
163 switch (m_doc->doc->getCatalog()->getPageMode()) {
164 case Catalog::pageModeNone:
165 return UseNone;
166 case Catalog::pageModeOutlines:
167 return UseOutlines;
168 case Catalog::pageModeThumbs:
169 return UseThumbs;
170 case Catalog::pageModeFullScreen:
171 return FullScreen;
172 case Catalog::pageModeOC:
173 return UseOC;
174 case Catalog::pageModeAttach:
175 return UseAttach;
176 default:
177 return UseNone;
178 }
179 }
180
181 Document::PageLayout Document::pageLayout() const
182 {
183 switch (m_doc->doc->getCatalog()->getPageLayout()) {
184 case Catalog::pageLayoutNone:
185 return NoLayout;
186 case Catalog::pageLayoutSinglePage:
187 return SinglePage;
188 case Catalog::pageLayoutOneColumn:
189 return OneColumn;
190 case Catalog::pageLayoutTwoColumnLeft:
191 return TwoColumnLeft;
192 case Catalog::pageLayoutTwoColumnRight:
193 return TwoColumnRight;
194 case Catalog::pageLayoutTwoPageLeft:
195 return TwoPageLeft;
196 case Catalog::pageLayoutTwoPageRight:
197 return TwoPageRight;
198 default:
199 return NoLayout;
200 }
201 }
202
203 Qt::LayoutDirection Document::textDirection() const
204 {
205 if (!m_doc->doc->getCatalog()->getViewerPreferences()) {
206 return Qt::LayoutDirectionAuto;
207 }
208
209 switch (m_doc->doc->getCatalog()->getViewerPreferences()->getDirection()) {
210 case ViewerPreferences::directionL2R:
211 return Qt::LeftToRight;
212 case ViewerPreferences::directionR2L:
213 return Qt::RightToLeft;
214 default:
215 return Qt::LayoutDirectionAuto;
216 }
217 }
218
219 int Document::numPages() const
220 {
221 return m_doc->doc->getNumPages();
222 }
223
224 QList<FontInfo> Document::fonts() const
225 {
226 QList<FontInfo> ourList;
227 FontIterator it(0, m_doc);
228 while (it.hasNext()) {
229 ourList += it.next();
230 }
231 return ourList;
232 }
233
234 QList<EmbeddedFile *> Document::embeddedFiles() const
235 {
236 return m_doc->m_embeddedFiles;
237 }
238
239 FontIterator *Document::newFontIterator(int startPage) const
240 {
241 return new FontIterator(startPage, m_doc);
242 }
243
244 QByteArray Document::fontData(const FontInfo &fi) const
245 {
246 QByteArray result;
247 if (fi.isEmbedded()) {
248 XRef *xref = m_doc->doc->getXRef()->copy();
249
250 Object refObj(fi.m_data->embRef);
251 Object strObj = refObj.fetch(xref);
252 if (strObj.isStream() && strObj.streamRewind()) {
253 int c;
254 while ((c = strObj.streamGetChar()) != EOF) {
255 result.append((char)c);
256 }
257 strObj.streamClose();
258 }
259 delete xref;
260 }
261 return result;
262 }
263
264 QString Document::info(const QString &type) const
265 {
266 if (m_doc->locked) {
267 return QString();
268 }
269
270 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoStringEntry(type.toLatin1().constData()));
271 return UnicodeParsedString(goo.get());
272 }
273
274 bool Document::setInfo(const QString &key, const QString &val)
275 {
276 if (m_doc->locked) {
277 return false;
278 }
279
280 std::unique_ptr<GooString> goo = QStringToUnicodeGooString(val);
281 m_doc->doc->setDocInfoStringEntry(key.toLatin1().constData(), std::move(goo));
282 return true;
283 }
284
285 QString Document::title() const
286 {
287 if (m_doc->locked) {
288 return QString();
289 }
290
291 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoTitle());
292 return UnicodeParsedString(goo.get());
293 }
294
295 bool Document::setTitle(const QString &val)
296 {
297 if (m_doc->locked) {
298 return false;
299 }
300
301 m_doc->doc->setDocInfoTitle(QStringToUnicodeGooString(val));
302 return true;
303 }
304
305 QString Document::author() const
306 {
307 if (m_doc->locked) {
308 return QString();
309 }
310
311 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoAuthor());
312 return UnicodeParsedString(goo.get());
313 }
314
315 bool Document::setAuthor(const QString &val)
316 {
317 if (m_doc->locked) {
318 return false;
319 }
320
321 m_doc->doc->setDocInfoAuthor(QStringToUnicodeGooString(val));
322 return true;
323 }
324
325 QString Document::subject() const
326 {
327 if (m_doc->locked) {
328 return QString();
329 }
330
331 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoSubject());
332 return UnicodeParsedString(goo.get());
333 }
334
335 bool Document::setSubject(const QString &val)
336 {
337 if (m_doc->locked) {
338 return false;
339 }
340
341 m_doc->doc->setDocInfoSubject(QStringToUnicodeGooString(val));
342 return true;
343 }
344
345 QString Document::keywords() const
346 {
347 if (m_doc->locked) {
348 return QString();
349 }
350
351 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoKeywords());
352 return UnicodeParsedString(goo.get());
353 }
354
355 bool Document::setKeywords(const QString &val)
356 {
357 if (m_doc->locked) {
358 return false;
359 }
360
361 m_doc->doc->setDocInfoKeywords(QStringToUnicodeGooString(val));
362 return true;
363 }
364
365 QString Document::creator() const
366 {
367 if (m_doc->locked) {
368 return QString();
369 }
370
371 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoCreator());
372 return UnicodeParsedString(goo.get());
373 }
374
375 bool Document::setCreator(const QString &val)
376 {
377 if (m_doc->locked) {
378 return false;
379 }
380
381 m_doc->doc->setDocInfoCreator(QStringToUnicodeGooString(val));
382 return true;
383 }
384
385 QString Document::producer() const
386 {
387 if (m_doc->locked) {
388 return QString();
389 }
390
391 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoProducer());
392 return UnicodeParsedString(goo.get());
393 }
394
395 bool Document::setProducer(const QString &val)
396 {
397 if (m_doc->locked) {
398 return false;
399 }
400
401 m_doc->doc->setDocInfoProducer(QStringToUnicodeGooString(val));
402 return true;
403 }
404
405 bool Document::removeInfo()
406 {
407 if (m_doc->locked) {
408 return false;
409 }
410
411 m_doc->doc->removeDocInfo();
412 return true;
413 }
414
415 QStringList Document::infoKeys() const
416 {
417 QStringList keys;
418
419 if (m_doc->locked) {
420 return QStringList();
421 }
422
423 QScopedPointer<XRef> xref(m_doc->doc->getXRef()->copy());
424 if (!xref) {
425 return QStringList();
426 }
427 Object info = xref->getDocInfo();
428 if (!info.isDict()) {
429 return QStringList();
430 }
431
432 Dict *infoDict = info.getDict();
433 // somehow iterate over keys in infoDict
434 keys.reserve(infoDict->getLength());
435 for (int i = 0; i < infoDict->getLength(); ++i) {
436 keys.append(QString::fromLatin1(infoDict->getKey(i)));
437 }
438
439 return keys;
440 }
441
442 QDateTime Document::date(const QString &type) const
443 {
444 if (m_doc->locked) {
445 return QDateTime();
446 }
447
448 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoStringEntry(type.toLatin1().constData()));
449 QString str = UnicodeParsedString(goo.get());
450 return Poppler::convertDate(str.toLatin1().constData());
451 }
452
453 bool Document::setDate(const QString &key, const QDateTime &val)
454 {
455 if (m_doc->locked) {
456 return false;
457 }
458
459 m_doc->doc->setDocInfoStringEntry(key.toLatin1().constData(), QDateTimeToUnicodeGooString(val));
460 return true;
461 }
462
463 QDateTime Document::creationDate() const
464 {
465 if (m_doc->locked) {
466 return QDateTime();
467 }
468
469 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoCreatDate());
470 QString str = UnicodeParsedString(goo.get());
471 return Poppler::convertDate(str.toLatin1().constData());
472 }
473
474 bool Document::setCreationDate(const QDateTime &val)
475 {
476 if (m_doc->locked) {
477 return false;
478 }
479
480 m_doc->doc->setDocInfoCreatDate(QDateTimeToUnicodeGooString(val));
481 return true;
482 }
483
484 QDateTime Document::modificationDate() const
485 {
486 if (m_doc->locked) {
487 return QDateTime();
488 }
489
490 std::unique_ptr<GooString> goo(m_doc->doc->getDocInfoModDate());
491 QString str = UnicodeParsedString(goo.get());
492 return Poppler::convertDate(str.toLatin1().constData());
493 }
494
495 bool Document::setModificationDate(const QDateTime &val)
496 {
497 if (m_doc->locked) {
498 return false;
499 }
500
501 m_doc->doc->setDocInfoModDate(QDateTimeToUnicodeGooString(val));
502 return true;
503 }
504
505 bool Document::isEncrypted() const
506 {
507 return m_doc->doc->isEncrypted();
508 }
509
510 bool Document::isLinearized() const
511 {
512 return m_doc->doc->isLinearized();
513 }
514
515 bool Document::okToPrint() const
516 {
517 return m_doc->doc->okToPrint();
518 }
519
520 bool Document::okToPrintHighRes() const
521 {
522 return m_doc->doc->okToPrintHighRes();
523 }
524
525 bool Document::okToChange() const
526 {
527 return m_doc->doc->okToChange();
528 }
529
530 bool Document::okToCopy() const
531 {
532 return m_doc->doc->okToCopy();
533 }
534
535 bool Document::okToAddNotes() const
536 {
537 return m_doc->doc->okToAddNotes();
538 }
539
540 bool Document::okToFillForm() const
541 {
542 return m_doc->doc->okToFillForm();
543 }
544
545 bool Document::okToCreateFormFields() const
546 {
547 return (okToFillForm() && okToChange());
548 }
549
550 bool Document::okToExtractForAccessibility() const
551 {
552 return m_doc->doc->okToAccessibility();
553 }
554
555 bool Document::okToAssemble() const
556 {
557 return m_doc->doc->okToAssemble();
558 }
559
560 void Document::getPdfVersion(int *major, int *minor) const
561 {
562 if (major) {
563 *major = m_doc->doc->getPDFMajorVersion();
564 }
565 if (minor) {
566 *minor = m_doc->doc->getPDFMinorVersion();
567 }
568 }
569
570 Document::PdfVersion Document::getPdfVersion() const
571 {
572 return PdfVersion { m_doc->doc->getPDFMajorVersion(), m_doc->doc->getPDFMinorVersion() };
573 }
574
575 Page *Document::page(const QString &label) const
576 {
577 const GooString label_g(label.toLatin1().data());
578 int index;
579
580 if (!m_doc->doc->getCatalog()->labelToIndex(label_g, &index)) {
581 const std::unique_ptr<GooString> label_ug(QStringToUnicodeGooString(label));
582 if (!m_doc->doc->getCatalog()->labelToIndex(*label_ug, &index)) {
583 return nullptr;
584 }
585 }
586
587 return page(index);
588 }
589
590 bool Document::hasEmbeddedFiles() const
591 {
592 return (!(0 == m_doc->doc->getCatalog()->numEmbeddedFiles()));
593 }
594
595 QDomDocument *Document::toc() const
596 {
597 Outline *outline = m_doc->doc->getOutline();
598 if (!outline) {
599 return nullptr;
600 }
601
602 const std::vector<::OutlineItem *> *items = outline->getItems();
603 if (!items || items->empty()) {
604 return nullptr;
605 }
606
607 QDomDocument *toc = new QDomDocument();
608 m_doc->addTocChildren(toc, toc, items);
609
610 return toc;
611 }
612
613 QVector<OutlineItem> Document::outline() const
614 {
615 QVector<OutlineItem> result;
616
617 if (::Outline *outline = m_doc->doc->getOutline()) {
618 if (const std::vector<::OutlineItem *> *items = outline->getItems()) {
619 for (void *item : *items) {
620 result.push_back(OutlineItem { new OutlineItemData { static_cast<::OutlineItem *>(item), m_doc } });
621 }
622 }
623 }
624
625 return result;
626 }
627
628 LinkDestination *Document::linkDestination(const QString &name)
629 {
630 const std::unique_ptr<GooString> namedDest = QStringToGooString(name);
631 LinkDestinationData ldd(nullptr, namedDest.get(), m_doc, false);
632 LinkDestination *ld = new LinkDestination(ldd);
633 return ld;
634 }
635
636 void Document::setPaperColor(const QColor &color)
637 {
638 m_doc->setPaperColor(color);
639 }
640
641 void Document::setColorDisplayProfile(void *outputProfileA)
642 {
643 #if USE_CMS
644 if (m_doc->m_sRGBProfile && m_doc->m_sRGBProfile.get() == outputProfileA) {
645 // Catch the special case that the user passes the sRGB profile
646 m_doc->m_displayProfile = m_doc->m_sRGBProfile;
647 return;
648 }
649 if (m_doc->m_displayProfile && m_doc->m_displayProfile.get() == outputProfileA) {
650 // Catch the special case that the user passes the display profile
651 return;
652 }
653 m_doc->m_displayProfile = make_GfxLCMSProfilePtr(outputProfileA);
654 #else
655 Q_UNUSED(outputProfileA);
656 #endif
657 }
658
659 void Document::setColorDisplayProfileName(const QString &name)
660 {
661 #if USE_CMS
662 void *rawprofile = cmsOpenProfileFromFile(name.toLocal8Bit().constData(), "r");
663 m_doc->m_displayProfile = make_GfxLCMSProfilePtr(rawprofile);
664 #else
665 Q_UNUSED(name);
666 #endif
667 }
668
669 void *Document::colorRgbProfile() const
670 {
671 #if USE_CMS
672 if (!m_doc->m_sRGBProfile) {
673 m_doc->m_sRGBProfile = make_GfxLCMSProfilePtr(cmsCreate_sRGBProfile());
674 }
675 return m_doc->m_sRGBProfile.get();
676 #else
677 return nullptr;
678 #endif
679 }
680
681 void *Document::colorDisplayProfile() const
682 {
683 #if USE_CMS
684 return m_doc->m_displayProfile.get();
685 #else
686 return nullptr;
687 #endif
688 }
689
690 QColor Document::paperColor() const
691 {
692 return m_doc->paperColor;
693 }
694
695 void Document::setRenderBackend(Document::RenderBackend backend)
696 {
697 // no need to delete the outputdev as for the moment we always create a splash one
698 // as the QPainter one does not allow "precaching" due to it's signature
699 // delete m_doc->m_outputDev;
700 // m_doc->m_outputDev = NULL;
701 m_doc->m_backend = backend;
702 }
703
704 Document::RenderBackend Document::renderBackend() const
705 {
706 return m_doc->m_backend;
707 }
708
709 QSet<Document::RenderBackend> Document::availableRenderBackends()
710 {
711 QSet<Document::RenderBackend> ret;
712 ret << Document::SplashBackend;
713 ret << Document::QPainterBackend;
714 ret << Document::ArthurBackend; // For backward compatibility
715 return ret;
716 }
717
718 void Document::setRenderHint(Document::RenderHint hint, bool on)
719 {
720 const bool touchesOverprinting = hint & Document::OverprintPreview;
721
722 int hintForOperation = hint;
723 if (touchesOverprinting && !isOverprintPreviewAvailable()) {
724 hintForOperation = hintForOperation & ~(int)Document::OverprintPreview;
725 }
726
727 if (on) {
728 m_doc->m_hints |= hintForOperation;
729 } else {
730 m_doc->m_hints &= ~hintForOperation;
731 }
732 }
733
734 Document::RenderHints Document::renderHints() const
735 {
736 return Document::RenderHints(m_doc->m_hints);
737 }
738
739 PSConverter *Document::psConverter() const
740 {
741 return new PSConverter(m_doc);
742 }
743
744 PDFConverter *Document::pdfConverter() const
745 {
746 return new PDFConverter(m_doc);
747 }
748
749 QString Document::metadata() const
750 {
751 QString result;
752 Catalog *catalog = m_doc->doc->getCatalog();
753 if (catalog && catalog->isOk()) {
754 std::unique_ptr<GooString> s = catalog->readMetadata();
755 if (s) {
756 result = UnicodeParsedString(s.get());
757 }
758 }
759 return result;
760 }
761
762 bool Document::hasOptionalContent() const
763 {
764 return (m_doc->doc->getOptContentConfig() && m_doc->doc->getOptContentConfig()->hasOCGs());
765 }
766
767 OptContentModel *Document::optionalContentModel()
768 {
769 if (m_doc->m_optContentModel.isNull()) {
770 m_doc->m_optContentModel = new OptContentModel(m_doc->doc->getOptContentConfig(), nullptr);
771 }
772 return (OptContentModel *)m_doc->m_optContentModel;
773 }
774
775 Link *Document::additionalAction(DocumentAdditionalActionsType type) const
776 {
777 Catalog::DocumentAdditionalActionsType actionType;
778 switch (type) {
779 case CloseDocument:
780 actionType = Catalog::actionCloseDocument;
781 break;
782 case SaveDocumentStart:
783 actionType = Catalog::actionSaveDocumentStart;
784 break;
785 case SaveDocumentFinish:
786 actionType = Catalog::actionSaveDocumentFinish;
787 break;
788 case PrintDocumentStart:
789 actionType = Catalog::actionPrintDocumentStart;
790 break;
791 case PrintDocumentFinish:
792 actionType = Catalog::actionPrintDocumentFinish;
793 break;
794 default:
795 return {};
796 }
797
798 Link *action = nullptr;
799 if (std::unique_ptr<::LinkAction> act = m_doc->doc->getCatalog()->getAdditionalAction(actionType)) {
800 action = PageData::convertLinkActionToLink(act.get(), m_doc, QRectF());
801 }
802
803 return action;
804 }
805
806 void Document::applyResetFormsLink(const LinkResetForm &link)
807 {
808 const LinkResetFormPrivate *lrfp = link.d_func();
809 Catalog *catalog = m_doc->doc->getCatalog();
810 if (catalog && catalog->isOk()) {
811 Form *form = catalog->getForm();
812 if (form) {
813 std::vector<std::string> stdStringFields;
814 const QStringList fields = lrfp->m_fields;
815 stdStringFields.reserve(fields.size());
816 for (const auto &field : fields) {
817 stdStringFields.emplace_back(field.toStdString());
818 }
819 form->reset(stdStringFields, lrfp->m_exclude);
820 }
821 }
822 }
823
824 QStringList Document::scripts() const
825 {
826 Catalog *catalog = m_doc->doc->getCatalog();
827 const int numScripts = catalog->numJS();
828 QStringList scripts;
829 for (int i = 0; i < numScripts; ++i) {
830 std::string s = catalog->getJS(i);
831 if (!s.empty()) {
832 scripts.append(UnicodeParsedString(s));
833 }
834 }
835 return scripts;
836 }
837
838 bool Document::getPdfId(QByteArray *permanentId, QByteArray *updateId) const
839 {
840 GooString gooPermanentId;
841 GooString gooUpdateId;
842
843 if (!m_doc->doc->getID(permanentId ? &gooPermanentId : nullptr, updateId ? &gooUpdateId : nullptr)) {
844 return false;
845 }
846
847 if (permanentId) {
848 *permanentId = gooPermanentId.c_str();
849 }
850 if (updateId) {
851 *updateId = gooUpdateId.c_str();
852 }
853
854 return true;
855 }
856
857 Document::FormType Document::formType() const
858 {
859 switch (m_doc->doc->getCatalog()->getFormType()) {
860 case Catalog::NoForm:
861 return Document::NoForm;
862 case Catalog::AcroForm:
863 return Document::AcroForm;
864 case Catalog::XfaForm:
865 return Document::XfaForm;
866 }
867
868 return Document::NoForm; // make gcc happy
869 }
870
871 QVector<int> Document::formCalculateOrder() const
872 {
873 Form *form = m_doc->doc->getCatalog()->getForm();
874 if (!form) {
875 return {};
876 }
877
878 QVector<int> result;
879 const std::vector<Ref> &calculateOrder = form->getCalculateOrder();
880 for (Ref r : calculateOrder) {
881 FormWidget *w = form->findWidgetByRef(r);
882 if (w) {
883 result << w->getID();
884 }
885 }
886
887 return result;
888 }
889
890 QVector<FormFieldSignature *> Document::signatures() const
891 {
892 QVector<FormFieldSignature *> result;
893
894 const std::vector<::FormFieldSignature *> pSignatures = m_doc->doc->getSignatureFields();
895
896 for (::FormFieldSignature *pSignature : pSignatures) {
897 ::FormWidget *fw = pSignature->getCreateWidget();
898 ::Page *p = m_doc->doc->getPage(fw->getWidgetAnnotation()->getPageNum());
899 result.append(new FormFieldSignature(m_doc, p, static_cast<FormWidgetSignature *>(fw)));
900 }
901
902 return result;
903 }
904
905 bool Document::xrefWasReconstructed() const
906 {
907 return m_doc->xrefReconstructed;
908 }
909
910 void Document::setXRefReconstructedCallback(const std::function<void()> &callback)
911 {
912 m_doc->xrefReconstructedCallback = callback;
913 }
914
915 QDateTime convertDate(const char *dateString)
916 {
917 int year, mon, day, hour, min, sec, tzHours, tzMins;
918 char tz;
919
920 GooString date(dateString);
921 if (parseDateString(&date, &year, &mon, &day, &hour, &min, &sec, &tz, &tzHours, &tzMins)) {
922 QDate d(year, mon, day);
923 QTime t(hour, min, sec);
924 if (d.isValid() && t.isValid()) {
925 int tzSecs = 0;
926 if (tz) {
927 // then we have some form of timezone
928 if ('Z' == tz) {
929 // We are already at UTC
930 } else if ('+' == tz) {
931 // local time is ahead of UTC
932 tzSecs = (tzHours * 3600) + (tzMins * 60);
933 } else if ('-' == tz) {
934 // local time is behind UTC
935 tzSecs = (tzHours * -3600) + (tzMins * -60);
936 } else {
937 qWarning("unexpected tz val");
938 }
939 }
940 return QDateTime(d, t, QTimeZone(tzSecs));
941 }
942 }
943 return QDateTime();
944 }
945
946 QDateTime convertDate(char *dateString)
947 {
948 return convertDate((const char *)dateString);
949 }
950
951 bool isCmsAvailable()
952 {
953 #if USE_CMS
954 return true;
955 #else
956 return false;
957 #endif
958 }
959
960 bool isOverprintPreviewAvailable()
961 {
962 return true;
963 }
964
965 }