vcl/source/filter/ipdf/pdfread.cxx | 97 ++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 43 deletions(-)
New commits: commit 6d275917944c274a22620c2c19880eb8e94f2558 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Sep 2 17:04:27 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sun Sep 6 14:01:07 2020 +0200 extract PDF import for annotations to a separate function Change-Id: Ibaabaee5e1e6416f1ac518ff846b13e6c3f29cad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102091 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 01ab6d3625cd..190644d91d31 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -226,6 +226,58 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic) return true; } +namespace +{ +std::vector<PDFGraphicAnnotation> findAnnotations(std::unique_ptr<vcl::pdf::PDFiumPage>& pPage, + basegfx::B2DSize aPageSize) +{ + std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations; + for (int nAnnotation = 0; nAnnotation < pPage->getAnnotationCount(); nAnnotation++) + { + auto pAnnotation = pPage->getAnnotation(nAnnotation); + if (pAnnotation) + { + auto eSubtype = pAnnotation->getSubType(); + + if (eSubtype == vcl::pdf::PDFAnnotationSubType::Text + && pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)) + { + OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); + OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); + auto pPopupAnnotation = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); + + basegfx::B2DRectangle rRectangle = pAnnotation->getRectangle(); + basegfx::B2DRectangle rRectangleHMM( + convertPointToMm100(rRectangle.getMinX()), + convertPointToMm100(aPageSize.getY() - rRectangle.getMinY()), + convertPointToMm100(rRectangle.getMaxX()), + convertPointToMm100(aPageSize.getY() - rRectangle.getMaxY())); + + OUString sDateTimeString + = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); + OUString sISO8601String = vcl::pdf::convertPdfDateToISO8601(sDateTimeString); + + css::util::DateTime aDateTime; + if (!sISO8601String.isEmpty()) + { + utl::ISO8601parseDateTime(sISO8601String, aDateTime); + } + + PDFGraphicAnnotation aPDFGraphicAnnotation; + aPDFGraphicAnnotation.maRectangle = rRectangleHMM; + aPDFGraphicAnnotation.maAuthor = sAuthor; + aPDFGraphicAnnotation.maText = sText; + aPDFGraphicAnnotation.maDateTime = aDateTime; + aPDFGraphicAnnotation.meSubType = eSubtype; + aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); + } + } + } + return aPDFGraphicAnnotations; +} + +} // end anonymous namespace + size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rGraphics) { #if HAVE_FEATURE_PDFIUM @@ -282,49 +334,8 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG auto pPage = pPdfDocument->openPage(nPageIndex); - std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations; - for (int nAnnotation = 0; nAnnotation < pPage->getAnnotationCount(); nAnnotation++) - { - auto pAnnotation = pPage->getAnnotation(nAnnotation); - if (pAnnotation) - { - auto eSubtype = pAnnotation->getSubType(); - - if (eSubtype == vcl::pdf::PDFAnnotationSubType::Text - && pAnnotation->hasKey(vcl::pdf::constDictionaryKeyPopup)) - { - OUString sAuthor = pAnnotation->getString(vcl::pdf::constDictionaryKeyTitle); - OUString sText = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); - auto pPopupAnnotation - = pAnnotation->getLinked(vcl::pdf::constDictionaryKeyPopup); - - basegfx::B2DRectangle rRectangle = pAnnotation->getRectangle(); - basegfx::B2DRectangle rRectangleHMM( - convertPointToMm100(rRectangle.getMinX()), - convertPointToMm100(aPageSize.getY() - rRectangle.getMinY()), - convertPointToMm100(rRectangle.getMaxX()), - convertPointToMm100(aPageSize.getY() - rRectangle.getMaxY())); - - OUString sDateTimeString - = pAnnotation->getString(vcl::pdf::constDictionaryKeyModificationDate); - OUString sISO8601String = vcl::pdf::convertPdfDateToISO8601(sDateTimeString); - - css::util::DateTime aDateTime; - if (!sISO8601String.isEmpty()) - { - utl::ISO8601parseDateTime(sISO8601String, aDateTime); - } - - PDFGraphicAnnotation aPDFGraphicAnnotation; - aPDFGraphicAnnotation.maRectangle = rRectangleHMM; - aPDFGraphicAnnotation.maAuthor = sAuthor; - aPDFGraphicAnnotation.maText = sText; - aPDFGraphicAnnotation.maDateTime = aDateTime; - aPDFGraphicAnnotation.meSubType = eSubtype; - aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); - } - } - } + std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations + = findAnnotations(pPage, aPageSize); rGraphics.emplace_back(std::move(aGraphic), Size(nPageWidth, nPageHeight), aPDFGraphicAnnotations); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits