diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-02-11 09:09:10 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-02-11 10:20:50 +0100 |
commit | ab882c0506c886eb32d8de0d2441de94920598bc (patch) | |
tree | ebcbfb39bbbe4fac2076b0bd0a1cd025e79a37ee | |
parent | ef0be13a2aff3fe42a99c0c92a7c39e23c864bfe (diff) |
pdfium: add a FPDFText_GetCharBox() wrapper
Which was the last public use of PDFiumTextPage::getPointer().
Change-Id: If3339f09ba38a3f10b19fe85cded718c913eb067
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110750
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | include/vcl/filter/PDFiumLibrary.hxx | 3 | ||||
-rw-r--r-- | vcl/source/graphic/VectorGraphicSearch.cxx | 16 | ||||
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 21 |
3 files changed, 27 insertions, 13 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx index 20480f1e1e26..5908f01e4ab0 100644 --- a/include/vcl/filter/PDFiumLibrary.hxx +++ b/include/vcl/filter/PDFiumLibrary.hxx @@ -179,6 +179,9 @@ public: unsigned int getUnicode(int index); std::unique_ptr<PDFiumSearchHandle> findStart(const OUString& rFindWhat, PDFFindFlags nFlags, sal_Int32 nStartIndex); + + /// Returned rect is no longer upside down and is in mm100. + basegfx::B2DRectangle getCharBox(int nIndex, double fPageHeight); }; class VCL_DLLPUBLIC PDFiumPage final diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx index aabfd220f651..09839c3524ef 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -169,20 +169,10 @@ public: for (int nCount = 0; nCount < nSize; nCount++) { - double left = 0.0; - double right = 0.0; - double bottom = 0.0; - double top = 0.0; - - if (FPDFText_GetCharBox(mpTextPage->getPointer(), nIndex + nCount, &left, &right, - &bottom, &top)) + basegfx::B2DRectangle aRectangle = mpTextPage->getCharBox(nIndex + nCount, fPageHeight); + if (!aRectangle.isEmpty()) { - left = convertPointToMm100(left); - right = convertPointToMm100(right); - top = fPageHeight - convertPointToMm100(top); - bottom = fPageHeight - convertPointToMm100(bottom); - - aRectangles.emplace_back(left, bottom, right, top); + aRectangles.push_back(aRectangle); } } diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 278fb284901d..c14a73ddd469 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -24,6 +24,7 @@ #include <osl/endian.h> #include <vcl/bitmap.hxx> #include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> #include <bitmap/BitmapWriteAccess.hxx> @@ -1120,6 +1121,26 @@ PDFiumTextPage::~PDFiumTextPage() int PDFiumTextPage::countChars() { return FPDFText_CountChars(mpTextPage); } +basegfx::B2DRectangle PDFiumTextPage::getCharBox(int nIndex, double fPageHeight) +{ + double left = 0.0; + double right = 0.0; + double bottom = 0.0; + double top = 0.0; + + if (FPDFText_GetCharBox(mpTextPage, nIndex, &left, &right, &bottom, &top)) + { + left = convertPointToMm100(left); + right = convertPointToMm100(right); + top = fPageHeight - convertPointToMm100(top); + bottom = fPageHeight - convertPointToMm100(bottom); + + return basegfx::B2DRectangle(left, bottom, right, top); + } + + return basegfx::B2DRectangle(); +} + unsigned int PDFiumTextPage::getUnicode(int index) { return FPDFText_GetUnicode(mpTextPage, index); |