desktop/source/lib/init.cxx | 34 +++++++++++++++------------ include/vcl/filter/PDFiumLibrary.hxx | 21 +++++++++++++++++ svx/source/inc/svdpdf.hxx | 6 +++- svx/source/svdraw/svdpdf.cxx | 43 ++++++++++++++--------------------- vcl/source/pdf/PDFiumLibrary.cxx | 33 ++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 42 deletions(-)
New commits: commit 32609b2a79790a7029bdc646f65b84a740afaba2 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Jul 6 14:57:29 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Aug 1 08:30:39 2020 +0200 lok: set to export PDF bookmarks by default when save-as a PDF Change-Id: Ieb182b9a0d1f18a29a83ce369881578c06e217ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98211 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 224160656d549b5b1891edd1b3cee251b754e69b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99880 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index c010fcbfb2c7..eb9c42bf816d 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -58,6 +58,7 @@ #include <comphelper/propertysequence.hxx> #include <comphelper/scopeguard.hxx> #include <comphelper/threadpool.hxx> +#include <comphelper/sequenceashashmap.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -2136,6 +2137,15 @@ void setLanguageAndLocale(OUString const & aLangISO) aLocalOptions.Commit(); } +void setFormatSpecificFilterData(OUString const & sFormat, comphelper::SequenceAsHashMap & rFilterDataMap) +{ + if (sFormat == "pdf") + { + // always export bookmarks, which is needed for annotations + rFilterDataMap["ExportBookmarks"] <<= true; + } +} + } // anonymous namespace // Wonder global state ... @@ -2567,25 +2577,19 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha aFilterOptions = comphelper::string::convertCommaSeparated(aFilteredOptionSeq); aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions; - if(!watermarkText.isEmpty() || bFullSheetPreview) - { - uno::Sequence< beans::PropertyValue > aFilterData( static_cast<int>(bFullSheetPreview) + static_cast<int>(!watermarkText.isEmpty()) ); + comphelper::SequenceAsHashMap aFilterDataMap; - if (!watermarkText.isEmpty()) - { - aFilterData[ 0 ].Name = "TiledWatermark"; - aFilterData[ 0 ].Value <<= watermarkText; - } + setFormatSpecificFilterData(sFormat, aFilterDataMap); - if (bFullSheetPreview) - { - int nOptIndex = static_cast<int>(!watermarkText.isEmpty()); + if (!watermarkText.isEmpty()) + aFilterDataMap["TiledWatermark"] <<= watermarkText; - aFilterData[ nOptIndex ].Name = "SinglePageSheets"; - aFilterData[ nOptIndex ].Value <<= true; - } + if (bFullSheetPreview) + aFilterDataMap["SinglePageSheets"] <<= true; - aSaveMediaDescriptor["FilterData"] <<= aFilterData; + if (!aFilterDataMap.empty()) + { + aSaveMediaDescriptor["FilterData"] <<= aFilterDataMap.getAsConstPropertyValueList(); } // add interaction handler too commit 7cbb10598d6b1a0f5e0d612eb6ffc1df28d086e4 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Jul 6 14:08:23 2020 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Aug 1 08:30:27 2020 +0200 pdf: add PDFiumPathSegment to the wrapper & use in ImpSdrPdfImport A PageObject of type FPDF_PAGEOBJ_PATH can have a path segment, that is common in vector graphic objects. The path segment is wrapped into PDFiumPathSegment which can be used to handle the path and path properties. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98210 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit bc8016b81c2c609711c26af1f85da327cf30a4ff) Change-Id: I990d51ba90fa356a6eca137eb4b71947858289aa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99879 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index f7dcc4b2c99e..43176f584420 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -73,6 +73,24 @@ public: class PDFiumTextPage; +class VCL_DLLPUBLIC PDFiumPathSegment final +{ +private: + FPDF_PATHSEGMENT mpPathSegment; + + PDFiumPathSegment(const PDFiumPathSegment&) = delete; + PDFiumPathSegment& operator=(const PDFiumPathSegment&) = delete; + +public: + PDFiumPathSegment(FPDF_PATHSEGMENT pPathSegment); + ~PDFiumPathSegment(); + + FPDF_PATHSEGMENT getPointer() { return mpPathSegment; } + basegfx::B2DPoint getPoint(); + bool isClosed(); + int getType(); +}; + class VCL_DLLPUBLIC PDFiumPageObject final { private: @@ -100,6 +118,9 @@ public: int getTextRenderMode(); Color getFillColor(); Color getStrokeColor(); + // Path + int getPathSegmentCount(); + std::unique_ptr<PDFiumPathSegment> getPathSegment(int index); }; class VCL_DLLPUBLIC PDFiumTextPage final diff --git a/svx/source/inc/svdpdf.hxx b/svx/source/inc/svdpdf.hxx index b1ad9d69ad12..09105acd0376 100644 --- a/svx/source/inc/svdpdf.hxx +++ b/svx/source/inc/svdpdf.hxx @@ -118,8 +118,10 @@ class SVXCORE_DLLPUBLIC ImpSdrPdfImport final void ImportForm(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage, int nPageObjectIndex); - void ImportImage(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); - void ImportPath(FPDF_PAGEOBJECT pPageObject, int nPageObjectIndex); + void ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, + int nPageObjectIndex); + void ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, + int nPageObjectIndex); void ImportText(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, std::unique_ptr<vcl::pdf::PDFiumTextPage> const& pTextPage, int nPageObjectIndex); diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index ff4029a00b54..62bebbf4ce3b 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -697,10 +697,10 @@ void ImpSdrPdfImport::ImportPdfObject( ImportText(pPageObject, pTextPage, nPageObjectIndex); break; case FPDF_PAGEOBJ_PATH: - ImportPath(pPageObject->getPointer(), nPageObjectIndex); + ImportPath(pPageObject, nPageObjectIndex); break; case FPDF_PAGEOBJ_IMAGE: - ImportImage(pPageObject->getPointer(), nPageObjectIndex); + ImportImage(pPageObject, nPageObjectIndex); break; case FPDF_PAGEOBJ_SHADING: SAL_WARN("sd.filter", "Got page object SHADING: " << nPageObjectIndex); @@ -893,10 +893,11 @@ void ImpSdrPdfImport::MapScaling() mnMapScalingOfs = nCount; } -void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/) +void ImpSdrPdfImport::ImportImage(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, + int /*nPageObjectIndex*/) { std::unique_ptr<std::remove_pointer<FPDF_BITMAP>::type, FPDFBitmapDeleter> bitmap( - FPDFImageObj_GetBitmap(pPageObject)); + FPDFImageObj_GetBitmap(pPageObject->getPointer())); if (!bitmap) { SAL_WARN("sd.filter", "Failed to get IMAGE"); @@ -939,7 +940,7 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObject float bottom; float right; float top; - if (!FPDFPageObj_GetBounds(pPageObject, &left, &bottom, &right, &top)) + if (!FPDFPageObj_GetBounds(pPageObject->getPointer(), &left, &bottom, &right, &top)) { SAL_WARN("sd.filter", "FAILED to get image bounds"); } @@ -956,34 +957,26 @@ void ImpSdrPdfImport::ImportImage(FPDF_PAGEOBJECT pPageObject, int /*nPageObject InsertObj(pGraf); } -void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectIndex*/) +void ImpSdrPdfImport::ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> const& pPageObject, + int /*nPageObjectIndex*/) { - double a, b, c, d, e, f; - FPDFPath_GetMatrix(pPageObject, &a, &b, &c, &d, &e, &f); - auto aPathMatrix = basegfx::B2DHomMatrix::abcdef(a, b, c, d, e, f); + auto aPathMatrix = pPageObject->getMatrix(); aPathMatrix *= maCurrentMatrix; basegfx::B2DPolyPolygon aPolyPoly; basegfx::B2DPolygon aPoly; std::vector<basegfx::B2DPoint> aBezier; - const int nSegments = FPDFPath_CountSegments(pPageObject); + const int nSegments = pPageObject->getPathSegmentCount(); for (int nSegmentIndex = 0; nSegmentIndex < nSegments; ++nSegmentIndex) { - FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(pPageObject, nSegmentIndex); + auto pPathSegment = pPageObject->getPathSegment(nSegmentIndex); if (pPathSegment != nullptr) { - float fx, fy; - if (!FPDFPathSegment_GetPoint(pPathSegment, &fx, &fy)) - { - SAL_WARN("sd.filter", "Failed to get PDF path segment point"); - continue; - } - - basegfx::B2DPoint aB2DPoint(fx, fy); + basegfx::B2DPoint aB2DPoint = pPathSegment->getPoint(); aB2DPoint *= aPathMatrix; - const bool bClose = FPDFPathSegment_GetClose(pPathSegment); + const bool bClose = pPathSegment->isClosed(); if (bClose) aPoly.setClosed(bClose); // TODO: Review @@ -991,7 +984,7 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI aB2DPoint.setX(aPoint.X()); aB2DPoint.setY(aPoint.Y()); - const int nSegmentType = FPDFPathSegment_GetType(pPathSegment); + const int nSegmentType = pPathSegment->getType(); switch (nSegmentType) { case FPDF_SEGMENT_LINETO: @@ -1043,13 +1036,13 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI aPolyPoly.transform(aTransform); float fWidth = 1; - FPDFPageObj_GetStrokeWidth(pPageObject, &fWidth); + FPDFPageObj_GetStrokeWidth(pPageObject->getPointer(), &fWidth); const double dWidth = 0.5 * fabs(sqrt2(aPathMatrix.a(), aPathMatrix.c()) * fWidth); mnLineWidth = convertPointToMm100(dWidth); int nFillMode = FPDF_FILLMODE_ALTERNATE; FPDF_BOOL bStroke = 1; // Assume we have to draw, unless told otherwise. - if (FPDFPath_GetDrawMode(pPageObject, &nFillMode, &bStroke)) + if (FPDFPath_GetDrawMode(pPageObject->getPointer(), &nFillMode, &bStroke)) { if (nFillMode == FPDF_FILLMODE_ALTERNATE) mpVD->SetDrawMode(DrawModeFlags::Default); @@ -1063,12 +1056,12 @@ void ImpSdrPdfImport::ImportPath(FPDF_PAGEOBJECT pPageObject, int /*nPageObjectI unsigned int nG; unsigned int nB; unsigned int nA; - FPDFPageObj_GetFillColor(pPageObject, &nR, &nG, &nB, &nA); + FPDFPageObj_GetFillColor(pPageObject->getPointer(), &nR, &nG, &nB, &nA); mpVD->SetFillColor(Color(nR, nG, nB)); if (bStroke) { - FPDFPageObj_GetStrokeColor(pPageObject, &nR, &nG, &nB, &nA); + FPDFPageObj_GetStrokeColor(pPageObject->getPointer(), &nR, &nG, &nB, &nA); mpVD->SetLineColor(Color(nR, nG, nB)); } else diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index e86b7565dd1b..caf1bd27eefb 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -315,6 +315,39 @@ Color PDFiumPageObject::getStrokeColor() return aColor; } +int PDFiumPageObject::getPathSegmentCount() { return FPDFPath_CountSegments(mpPageObject); } + +std::unique_ptr<PDFiumPathSegment> PDFiumPageObject::getPathSegment(int index) +{ + std::unique_ptr<PDFiumPathSegment> pPDFiumPathSegment; + FPDF_PATHSEGMENT pPathSegment = FPDFPath_GetPathSegment(mpPageObject, index); + if (pPathSegment) + { + pPDFiumPathSegment = std::make_unique<PDFiumPathSegment>(pPathSegment); + } + return pPDFiumPathSegment; +} + +PDFiumPathSegment::PDFiumPathSegment(FPDF_PATHSEGMENT pPathSegment) + : mpPathSegment(pPathSegment) +{ +} + +PDFiumPathSegment::~PDFiumPathSegment() {} + +basegfx::B2DPoint PDFiumPathSegment::getPoint() +{ + basegfx::B2DPoint aPoint; + float fx, fy; + if (FPDFPathSegment_GetPoint(mpPathSegment, &fx, &fy)) + aPoint = basegfx::B2DPoint(fx, fy); + return aPoint; +} + +bool PDFiumPathSegment::isClosed() { return FPDFPathSegment_GetClose(mpPathSegment); } + +int PDFiumPathSegment::getType() { return FPDFPathSegment_GetType(mpPathSegment); } + PDFiumAnnotation::PDFiumAnnotation(FPDF_ANNOTATION pAnnotation) : mpAnnotation(pAnnotation) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits