summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-01-28 21:04:35 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-01-29 08:56:23 +0100
commit4f3987e0b1a995431478769c898b5ef151745254 (patch)
tree4d0ca726a5e7229a041c85109206dfab778ac010
parent977f66ccd6161da8ec37d4eac0f85515e0cf1df0 (diff)
pdfium: add wrapper for FPDFText_FindClose()
So we can call it in the dtor, so we can't forget calling it. Change-Id: I9cea58ca53763d85a4c239fd90611ac1c398564d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110092 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--include/vcl/filter/PDFiumLibrary.hxx15
-rw-r--r--vcl/source/graphic/VectorGraphicSearch.cxx19
-rw-r--r--vcl/source/pdf/PDFiumLibrary.cxx11
3 files changed, 35 insertions, 10 deletions
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 0fbcf4fe2199..418feede99b6 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -149,6 +149,21 @@ public:
virtual bool getDrawMode(PDFFillMode& eFillMode, bool& bStroke) = 0;
};
+class VCL_DLLPUBLIC PDFiumSearchHandle final
+{
+private:
+ FPDF_SCHHANDLE mpSearchHandle;
+
+ PDFiumSearchHandle(const PDFiumSearchHandle&) = delete;
+ PDFiumSearchHandle& operator=(const PDFiumSearchHandle&) = delete;
+
+public:
+ PDFiumSearchHandle(FPDF_SCHHANDLE pSearchHandle);
+ ~PDFiumSearchHandle();
+
+ FPDF_SCHHANDLE getPointer() { return mpSearchHandle; }
+};
+
class VCL_DLLPUBLIC PDFiumTextPage final
{
private:
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index 083dc6cf2741..3ac33db37cc3 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -30,7 +30,7 @@ private:
std::unique_ptr<vcl::pdf::PDFiumDocument>& mpPdfDocument;
std::unique_ptr<vcl::pdf::PDFiumPage> mpPage;
std::unique_ptr<vcl::pdf::PDFiumTextPage> mpTextPage;
- FPDF_SCHHANDLE mpSearchHandle;
+ std::unique_ptr<vcl::pdf::PDFiumSearchHandle> mpSearchHandle;
public:
sal_Int32 mnPageIndex;
@@ -40,7 +40,6 @@ public:
SearchContext(std::unique_ptr<vcl::pdf::PDFiumDocument>& pPdfDocument, sal_Int32 nPageIndex)
: mpPdfDocument(pPdfDocument)
- , mpSearchHandle(nullptr)
, mnPageIndex(nPageIndex)
, mnCurrentIndex(-1)
{
@@ -49,7 +48,7 @@ public:
~SearchContext()
{
if (mpSearchHandle)
- FPDFText_FindClose(mpSearchHandle);
+ mpSearchHandle.reset();
if (mpTextPage)
mpTextPage.reset();
if (mpPage)
@@ -77,7 +76,7 @@ public:
return true;
if (mpSearchHandle)
- FPDFText_FindClose(mpSearchHandle);
+ mpSearchHandle.reset();
if (mpTextPage)
mpTextPage.reset();
@@ -114,15 +113,15 @@ public:
if (maOptions.mbMatchWholeWord)
nSearchFlags |= FPDF_MATCHWHOLEWORD;
- mpSearchHandle
- = FPDFText_FindStart(mpTextPage->getPointer(), pString, nSearchFlags, nStartIndex);
+ mpSearchHandle = std::make_unique<vcl::pdf::PDFiumSearchHandle>(
+ FPDFText_FindStart(mpTextPage->getPointer(), pString, nSearchFlags, nStartIndex));
return mpSearchHandle != nullptr;
}
bool next()
{
- if (mpSearchHandle && FPDFText_FindNext(mpSearchHandle))
+ if (mpSearchHandle && FPDFText_FindNext(mpSearchHandle->getPointer()))
{
mnCurrentIndex = index();
return true;
@@ -132,7 +131,7 @@ public:
bool previous()
{
- if (mpSearchHandle && FPDFText_FindPrev(mpSearchHandle))
+ if (mpSearchHandle && FPDFText_FindPrev(mpSearchHandle->getPointer()))
{
mnCurrentIndex = index();
return true;
@@ -143,14 +142,14 @@ public:
int index()
{
if (mpSearchHandle)
- return FPDFText_GetSchResultIndex(mpSearchHandle);
+ return FPDFText_GetSchResultIndex(mpSearchHandle->getPointer());
return -1;
}
int size()
{
if (mpSearchHandle)
- return FPDFText_GetSchCount(mpSearchHandle);
+ return FPDFText_GetSchCount(mpSearchHandle->getPointer());
return -1;
}
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 886549031596..fce8d4d539bd 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -1100,6 +1100,17 @@ unsigned int PDFiumTextPage::getUnicode(int index)
return FPDFText_GetUnicode(mpTextPage, index);
}
+PDFiumSearchHandle::PDFiumSearchHandle(FPDF_SCHHANDLE pSearchHandle)
+ : mpSearchHandle(pSearchHandle)
+{
+}
+
+PDFiumSearchHandle::~PDFiumSearchHandle()
+{
+ if (mpSearchHandle)
+ FPDFText_FindClose(mpSearchHandle);
+}
+
} // end vcl::pdf
#endif // HAVE_FEATURE_PDFIUM