include/vcl/filter/PDFiumLibrary.hxx | 3 ++- include/vcl/pdf/PDFSegmentType.hxx | 25 +++++++++++++++++++++++++ svx/source/svdraw/svdpdf.cxx | 15 ++++++++------- vcl/qa/cppunit/pdfexport/pdfexport.cxx | 10 +++++----- vcl/source/pdf/PDFiumLibrary.cxx | 14 +++++++++++++- 5 files changed, 53 insertions(+), 14 deletions(-)
New commits: commit 0e072c8225e747267eeb915ac88b33b7201df210 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Dec 1 21:02:54 2020 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Dec 2 09:07:51 2020 +0100 pdfium: introduce an enum class for path segment types Towards not including fpdf_edit.h in PDFiumLibrary client code. Change-Id: Iffdd11b0613399f31a3ed383c22b7a91059b83de Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107011 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 1fe0dd8d988a..497ef3e2d47e 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -31,6 +31,7 @@ #include <vcl/Scanline.hxx> #include <vcl/pdf/PDFAnnotationSubType.hxx> #include <vcl/pdf/PDFPageObjectType.hxx> +#include <vcl/pdf/PDFSegmentType.hxx> #include <fpdf_doc.h> @@ -135,7 +136,7 @@ public: FPDF_PATHSEGMENT getPointer() const { return mpPathSegment; } basegfx::B2DPoint getPoint() const; bool isClosed() const; - int getType() const; + PDFSegmentType getType() const; }; class VCL_DLLPUBLIC PDFiumPageObject final diff --git a/include/vcl/pdf/PDFSegmentType.hxx b/include/vcl/pdf/PDFSegmentType.hxx new file mode 100644 index 000000000000..98f74482e6f3 --- /dev/null +++ b/include/vcl/pdf/PDFSegmentType.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#pragma once + +namespace vcl::pdf +{ +enum class PDFSegmentType +{ + Unknown = -1, + Lineto = 0, + Bezierto = 1, + Moveto = 2, +}; + +} // namespace vcl::pdf + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/svdraw/svdpdf.cxx b/svx/source/svdraw/svdpdf.cxx index db83863b001a..47ea46c62801 100644 --- a/svx/source/svdraw/svdpdf.cxx +++ b/svx/source/svdraw/svdpdf.cxx @@ -964,14 +964,14 @@ void ImpSdrPdfImport::ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> con aB2DPoint.setX(aPoint.X()); aB2DPoint.setY(aPoint.Y()); - const int nSegmentType = pPathSegment->getType(); - switch (nSegmentType) + const vcl::pdf::PDFSegmentType eSegmentType = pPathSegment->getType(); + switch (eSegmentType) { - case FPDF_SEGMENT_LINETO: + case vcl::pdf::PDFSegmentType::Lineto: aPoly.append(aB2DPoint); break; - case FPDF_SEGMENT_BEZIERTO: + case vcl::pdf::PDFSegmentType::Bezierto: aBezier.emplace_back(aB2DPoint.getX(), aB2DPoint.getY()); if (aBezier.size() == 3) { @@ -980,7 +980,7 @@ void ImpSdrPdfImport::ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> con } break; - case FPDF_SEGMENT_MOVETO: + case vcl::pdf::PDFSegmentType::Moveto: // New Poly. if (aPoly.count() > 0) { @@ -991,9 +991,10 @@ void ImpSdrPdfImport::ImportPath(std::unique_ptr<vcl::pdf::PDFiumPageObject> con aPoly.append(aB2DPoint); break; - case FPDF_SEGMENT_UNKNOWN: + case vcl::pdf::PDFSegmentType::Unknown: default: - SAL_WARN("sd.filter", "Unknown path segment type in PDF: " << nSegmentType); + SAL_WARN("sd.filter", "Unknown path segment type in PDF: " + << static_cast<int>(eSegmentType)); break; } } diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 136c54aec41e..eaf905986928 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -861,35 +861,35 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf108963) CPPUNIT_ASSERT_EQUAL(5, nSegments); std::unique_ptr<vcl::pdf::PDFiumPathSegment> pSegment = pPdfPageObject->getPathSegment(0); - CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_MOVETO, pSegment->getType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Moveto, pSegment->getType()); basegfx::B2DPoint aPoint = pSegment->getPoint(); CPPUNIT_ASSERT_EQUAL(245395, static_cast<int>(round(aPoint.getX() * 1000))); CPPUNIT_ASSERT_EQUAL(244261, static_cast<int>(round(aPoint.getY() * 1000))); CPPUNIT_ASSERT(!pSegment->isClosed()); pSegment = pPdfPageObject->getPathSegment(1); - CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, pSegment->getType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType()); aPoint = pSegment->getPoint(); CPPUNIT_ASSERT_EQUAL(275102, static_cast<int>(round(aPoint.getX() * 1000))); CPPUNIT_ASSERT_EQUAL(267618, static_cast<int>(round(aPoint.getY() * 1000))); CPPUNIT_ASSERT(!pSegment->isClosed()); pSegment = pPdfPageObject->getPathSegment(2); - CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, pSegment->getType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType()); aPoint = pSegment->getPoint(); CPPUNIT_ASSERT_EQUAL(287518, static_cast<int>(round(aPoint.getX() * 1000))); CPPUNIT_ASSERT_EQUAL(251829, static_cast<int>(round(aPoint.getY() * 1000))); CPPUNIT_ASSERT(!pSegment->isClosed()); pSegment = pPdfPageObject->getPathSegment(3); - CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, pSegment->getType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType()); aPoint = pSegment->getPoint(); CPPUNIT_ASSERT_EQUAL(257839, static_cast<int>(round(aPoint.getX() * 1000))); CPPUNIT_ASSERT_EQUAL(228472, static_cast<int>(round(aPoint.getY() * 1000))); CPPUNIT_ASSERT(!pSegment->isClosed()); pSegment = pPdfPageObject->getPathSegment(4); - CPPUNIT_ASSERT_EQUAL(FPDF_SEGMENT_LINETO, pSegment->getType()); + CPPUNIT_ASSERT_EQUAL(vcl::pdf::PDFSegmentType::Lineto, pSegment->getType()); aPoint = pSegment->getPoint(); CPPUNIT_ASSERT_EQUAL(245395, static_cast<int>(round(aPoint.getX() * 1000))); CPPUNIT_ASSERT_EQUAL(244261, static_cast<int>(round(aPoint.getY() * 1000))); diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 5c308d3e772b..0952c9a5d3e8 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -42,6 +42,15 @@ static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Shading) == FPDF_PAG static_assert(static_cast<int>(vcl::pdf::PDFPageObjectType::Form) == FPDF_PAGEOBJ_FORM, "PDFPageObjectType::Form value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Unknown) == FPDF_SEGMENT_UNKNOWN, + "PDFSegmentType::Unknown value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Lineto) == FPDF_SEGMENT_LINETO, + "PDFSegmentType::Lineto value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Bezierto) == FPDF_SEGMENT_BEZIERTO, + "PDFSegmentType::Bezierto value mismatch"); +static_assert(static_cast<int>(vcl::pdf::PDFSegmentType::Moveto) == FPDF_SEGMENT_MOVETO, + "PDFSegmentType::Moveto value mismatch"); + namespace { /// Callback class to be used with FPDF_SaveWithVersion(). @@ -604,7 +613,10 @@ basegfx::B2DPoint PDFiumPathSegment::getPoint() const bool PDFiumPathSegment::isClosed() const { return FPDFPathSegment_GetClose(mpPathSegment); } -int PDFiumPathSegment::getType() const { return FPDFPathSegment_GetType(mpPathSegment); } +PDFSegmentType PDFiumPathSegment::getType() const +{ + return static_cast<PDFSegmentType>(FPDFPathSegment_GetType(mpPathSegment)); +} PDFiumBitmap::PDFiumBitmap(FPDF_BITMAP pBitmap) : mpBitmap(pBitmap) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits