include/vcl/pdfread.hxx | 16 ++++++++++++++-- sd/source/filter/pdf/sdpdffilter.cxx | 26 ++++++++++++++++++++++++-- vcl/source/filter/ipdf/pdfread.cxx | 31 ++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 5 deletions(-)
New commits: commit 3870dd43e94c440a5094a57c47d3b7565658d73c Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Jun 18 13:30:38 2020 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Sun Jun 21 13:32:08 2020 +0200 sd: support adding PDF text / pop-up annotations as comments Change-Id: I3e072f011089864f3349a470a32412cc33bcc022 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96758 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/include/vcl/pdfread.hxx b/include/vcl/pdfread.hxx index a65d230279b9..d79115f40249 100644 --- a/include/vcl/pdfread.hxx +++ b/include/vcl/pdfread.hxx @@ -14,6 +14,7 @@ #include <tools/gen.hxx> #include <tools/stream.hxx> #include <vcl/graph.hxx> +#include <basegfx/range/b2drectangle.hxx> namespace com::sun::star::uno { @@ -31,16 +32,27 @@ VCL_DLLPUBLIC size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vecto /// Imports a PDF stream into rGraphic as VectorGraphicData. VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic); +struct PDFGraphicAnnotation +{ + OUString maAuthor; + OUString maText; + // In HMM + basegfx::B2DRectangle maRectangle; +}; + struct PDFGraphicResult { Graphic maGraphic; - // Size in HMM Size maSize; - PDFGraphicResult(Graphic const& rGraphic, Size const& rSize) + std::vector<PDFGraphicAnnotation> maAnnotations; + + PDFGraphicResult(Graphic const& rGraphic, Size const& rSize, + std::vector<PDFGraphicAnnotation> const& aAnnotations) : maGraphic(rGraphic) , maSize(rSize) + , maAnnotations(aAnnotations) { } }; diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx index 2b09bc9e828e..da989974bc87 100644 --- a/sd/source/filter/pdf/sdpdffilter.cxx +++ b/sd/source/filter/pdf/sdpdffilter.cxx @@ -29,6 +29,11 @@ #include <vcl/graph.hxx> #include <vcl/pdfread.hxx> +#include <com/sun/star/office/XAnnotation.hpp> +#include <com/sun/star/text/XText.hpp> + +using namespace css; + SdPdfFilter::SdPdfFilter(SfxMedium& rMedium, sd::DrawDocShell& rDocShell) : SdFilter(rMedium, rDocShell) { @@ -65,11 +70,28 @@ bool SdPdfFilter::Import() // Make the page size match the rendered image. pPage->SetSize(aSizeHMM); - Point aPosition(0, 0); SdrGrafObj* pSdrGrafObj = new SdrGrafObj(pPage->getSdrModelFromSdrPage(), rGraphic, - tools::Rectangle(aPosition, aSizeHMM)); + tools::Rectangle(Point(), aSizeHMM)); pPage->InsertObject(pSdrGrafObj); + + for (auto const& rPDFAnnotation : rPDFGraphicResult.maAnnotations) + { + uno::Reference<office::XAnnotation> xAnnotation; + pPage->createAnnotation(xAnnotation); + + xAnnotation->setAuthor(rPDFAnnotation.maAuthor); + + uno::Reference<text::XText> xText(xAnnotation->getTextRange()); + xText->setString(rPDFAnnotation.maText); + // position is in mm not 100thmm + geometry::RealPoint2D aUnoPosition(rPDFAnnotation.maRectangle.getMinX() / 100.0, + rPDFAnnotation.maRectangle.getMinY() / 100.00); + geometry::RealSize2D aUnoSize(rPDFAnnotation.maRectangle.getWidth() / 100.0, + rPDFAnnotation.maRectangle.getHeight() / 100.00); + xAnnotation->setPosition(aUnoPosition); + xAnnotation->setSize(aUnoSize); + } } return true; diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index 9845c6c387c4..b5e63937bf00 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -278,7 +278,36 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<PDFGraphicResult>& rG Graphic aGraphic(aVectorGraphicDataPtr); aGraphic.SetGfxLink(pGfxLink); - rGraphics.emplace_back(std::move(aGraphic), Size(nPageWidth, nPageHeight)); + auto pPage = pPdfDocument->openPage(nPageIndex); + + std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations; + for (int nAnnotation = 0; nAnnotation < pPage->getAnnotationCount(); nAnnotation++) + { + auto pAnnotation = pPage->getAnnotation(nAnnotation); + if (pAnnotation && pAnnotation->getSubType() == 1 /*FPDF_ANNOT_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())); + + PDFGraphicAnnotation aPDFGraphicAnnotation; + aPDFGraphicAnnotation.maRectangle = rRectangleHMM; + aPDFGraphicAnnotation.maAuthor = sAuthor; + aPDFGraphicAnnotation.maText = sText; + aPDFGraphicAnnotations.push_back(aPDFGraphicAnnotation); + } + } + + rGraphics.emplace_back(std::move(aGraphic), Size(nPageWidth, nPageHeight), + aPDFGraphicAnnotations); } return rGraphics.size(); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
