diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-10-03 11:02:34 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-10-04 08:40:01 +0200 |
commit | b68761f4a5cd22b48c3214c8be919cb4c84da241 (patch) | |
tree | d4939210d51101e560ec3d830f1ada3922e6d8dc /vcl | |
parent | 9f9dec0679da48e49af09d8fa609955bca6db67b (diff) |
pdfium: Support for InkStrokes and Vertices
This extends PDFium with getting InkStrokes and Vertices for
annotations, which wasn't implemented before, and adds support to
PDFium wrapper in LibreOffice.
Change-Id: I570d53038a59ab830fcd5639583c75cf8adda86c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103885
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/PDFiumLibraryTest.cxx | 6 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 40 |
2 files changed, 46 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/PDFiumLibraryTest.cxx b/vcl/qa/cppunit/PDFiumLibraryTest.cxx index 547c59872216..3fc4ba86a6c3 100644 --- a/vcl/qa/cppunit/PDFiumLibraryTest.cxx +++ b/vcl/qa/cppunit/PDFiumLibraryTest.cxx @@ -334,6 +334,10 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes() CPPUNIT_ASSERT_EQUAL(0, pAnnotation->getObjectCount()); OUString aContentsString = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); CPPUNIT_ASSERT_EQUAL(OUString("Freehand Text"), aContentsString); + CPPUNIT_ASSERT_EQUAL(size_t(1), pAnnotation->getInkStrokes().size()); + auto const& aInkStrokes = pAnnotation->getInkStrokes(); + auto const& aPoints = aInkStrokes[0]; + CPPUNIT_ASSERT_EQUAL(size_t(74), aPoints.size()); } { @@ -353,6 +357,8 @@ void PDFiumLibraryTest::testAnnotationsDifferentTypes() CPPUNIT_ASSERT_EQUAL(true, pAnnotation->hasKey("Vertices")); OUString aContentsString = pAnnotation->getString(vcl::pdf::constDictionaryKeyContents); CPPUNIT_ASSERT_EQUAL(OUString("Polygon Text"), aContentsString); + auto const& aVertices = pAnnotation->getVertices(); + CPPUNIT_ASSERT_EQUAL(size_t(3), aVertices.size()); } { diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 136a40786112..dc31eb4fb952 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -465,6 +465,46 @@ OUString PDFiumAnnotation::getString(OString const& rKey) return rString; } +std::vector<std::vector<basegfx::B2DPoint>> PDFiumAnnotation::getInkStrokes() +{ + std::vector<std::vector<basegfx::B2DPoint>> aB2DPointList; + int nInkStrokes = FPDFAnnot_GetInkStrokeCount(mpAnnotation); + for (int i = 0; i < nInkStrokes; i++) + { + std::vector<basegfx::B2DPoint> aB2DPoints; + int nPoints = FPDFAnnot_GetInkStrokePointCount(mpAnnotation, i); + if (nPoints) + { + std::vector<FS_POINTF> aPoints(nPoints); + if (FPDFAnnot_GetInkStrokePoints(mpAnnotation, i, aPoints.data())) + { + for (auto const& rPoint : aPoints) + { + aB2DPoints.emplace_back(rPoint.x, rPoint.y); + } + aB2DPointList.push_back(aB2DPoints); + } + } + } + return aB2DPointList; +} + +std::vector<basegfx::B2DPoint> PDFiumAnnotation::getVertices() +{ + std::vector<basegfx::B2DPoint> aB2DPoints; + int nPoints = FPDFAnnot_GetVerticesCount(mpAnnotation); + if (nPoints) + { + std::vector<FS_POINTF> aPoints(nPoints); + if (FPDFAnnot_GetVertices(mpAnnotation, aPoints.data())) + { + for (auto const& rPoint : aPoints) + aB2DPoints.emplace_back(rPoint.x, rPoint.y); + } + } + return aB2DPoints; +} + std::unique_ptr<PDFiumAnnotation> PDFiumAnnotation::getLinked(OString const& rKey) { std::unique_ptr<PDFiumAnnotation> pPDFiumAnnotation; |