[Libreoffice-commits] core.git: include/vcl vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Thu Feb 4 08:12:00 UTC 2021


 include/vcl/filter/PDFiumLibrary.hxx       |    3 +-
 include/vcl/pdf/PDFFindFlags.hxx           |   34 +++++++++++++++++++++++++++++
 vcl/source/graphic/VectorGraphicSearch.cxx |   14 +++++------
 vcl/source/pdf/PDFiumLibrary.cxx           |   11 +++++++--
 4 files changed, 52 insertions(+), 10 deletions(-)

New commits:
commit 71c32c31dab86fe9c6d5893eee6821beaa3a3f43
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Feb 3 21:00:58 2021 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Thu Feb 4 09:11:14 2021 +0100

    pdfium: add PDFFindFlags wrapper
    
    So that vcl::pdf::PDFiumTextPage::findStart() can be called without
    including fpdf_text.h.
    
    Change-Id: I6a765be6176ec77ca24f592e2e2210654debe075
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110391
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 667fa614da70..ab0b5db7e608 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -36,6 +36,7 @@
 #include <vcl/pdf/PDFObjectType.hxx>
 #include <vcl/pdf/PDFTextRenderMode.hxx>
 #include <vcl/pdf/PDFFillMode.hxx>
+#include <vcl/pdf/PDFFindFlags.hxx>
 
 #include <fpdf_doc.h>
 
@@ -180,7 +181,7 @@ public:
 
     int countChars();
     unsigned int getUnicode(int index);
-    std::unique_ptr<PDFiumSearchHandle> findStart(const OUString& rFindWhat, sal_uInt64 nFlags,
+    std::unique_ptr<PDFiumSearchHandle> findStart(const OUString& rFindWhat, PDFFindFlags nFlags,
                                                   sal_Int32 nStartIndex);
 };
 
diff --git a/include/vcl/pdf/PDFFindFlags.hxx b/include/vcl/pdf/PDFFindFlags.hxx
new file mode 100644
index 000000000000..f43efc7a6f7d
--- /dev/null
+++ b/include/vcl/pdf/PDFFindFlags.hxx
@@ -0,0 +1,34 @@
+/* -*- 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
+
+#include <o3tl/typed_flags_set.hxx>
+
+namespace vcl::pdf
+{
+enum class PDFFindFlags : sal_uInt32
+{
+    MatchCase = 0x00000001,
+    MatchWholeWord = 0x00000002,
+    Consecutive = 0x00000004,
+};
+
+} // namespace vcl::pdf
+
+namespace o3tl
+{
+template <>
+struct typed_flags<vcl::pdf::PDFFindFlags> : is_typed_flags<vcl::pdf::PDFFindFlags, 0x00000007>
+{
+};
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index 01b76fb28b06..59e51ea795e2 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -101,15 +101,15 @@ public:
         if (mnCurrentIndex >= 0)
             nStartIndex = mnCurrentIndex;
 
-        // FPDF_MATCHCASE, FPDF_MATCHWHOLEWORD, FPDF_CONSECUTIVE
-        // FPDF_MATCHCASE - If not set, it will not match case by default.
-        // FPDF_MATCHWHOLEWORD - If not set, it will not match the whole word by default.
-        // FPDF_CONSECUTIVE - If not set, it will skip past the current match to look for the next match.
-        int nSearchFlags = 0;
+        // vcl::pdf::PDFFindFlags::MatchCase, vcl::pdf::PDFFindFlags::MatchWholeWord, vcl::pdf::PDFFindFlags::Consecutive
+        // vcl::pdf::PDFFindFlags::MatchCase - If not set, it will not match case by default.
+        // vcl::pdf::PDFFindFlags::MatchWholeWord - If not set, it will not match the whole word by default.
+        // vcl::pdf::PDFFindFlags::Consecutive - If not set, it will skip past the current match to look for the next match.
+        vcl::pdf::PDFFindFlags nSearchFlags{};
         if (maOptions.mbMatchCase)
-            nSearchFlags |= FPDF_MATCHCASE;
+            nSearchFlags |= vcl::pdf::PDFFindFlags::MatchCase;
         if (maOptions.mbMatchWholeWord)
-            nSearchFlags |= FPDF_MATCHWHOLEWORD;
+            nSearchFlags |= vcl::pdf::PDFFindFlags::MatchWholeWord;
 
         mpSearchHandle = mpTextPage->findStart(maSearchString, nSearchFlags, nStartIndex);
 
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index c1571682f4b3..9a13ae930fb5 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -114,6 +114,13 @@ static_assert(static_cast<int>(vcl::pdf::PDFFillMode::Alternate) == FPDF_FILLMOD
 static_assert(static_cast<int>(vcl::pdf::PDFFillMode::Winding) == FPDF_FILLMODE_WINDING,
               "PDFFillMode::Winding value mismatch");
 
+static_assert(static_cast<int>(vcl::pdf::PDFFindFlags::MatchCase) == FPDF_MATCHCASE,
+              "PDFFindFlags::MatchCase value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFFindFlags::MatchWholeWord) == FPDF_MATCHWHOLEWORD,
+              "PDFFindFlags::MatchWholeWord value mismatch");
+static_assert(static_cast<int>(vcl::pdf::PDFFindFlags::Consecutive) == FPDF_CONSECUTIVE,
+              "PDFFindFlags::Consecutive value mismatch");
+
 namespace
 {
 /// Callback class to be used with FPDF_SaveWithVersion().
@@ -1101,11 +1108,11 @@ unsigned int PDFiumTextPage::getUnicode(int index)
 }
 
 std::unique_ptr<PDFiumSearchHandle>
-PDFiumTextPage::findStart(const OUString& rFindWhat, sal_uInt64 nFlags, sal_Int32 nStartIndex)
+PDFiumTextPage::findStart(const OUString& rFindWhat, PDFFindFlags nFlags, sal_Int32 nStartIndex)
 {
     FPDF_WIDESTRING pFindWhat = reinterpret_cast<FPDF_WIDESTRING>(rFindWhat.getStr());
     return std::make_unique<vcl::pdf::PDFiumSearchHandle>(
-        FPDFText_FindStart(mpTextPage, pFindWhat, nFlags, nStartIndex));
+        FPDFText_FindStart(mpTextPage, pFindWhat, static_cast<sal_uInt32>(nFlags), nStartIndex));
 }
 
 PDFiumSearchHandle::PDFiumSearchHandle(FPDF_SCHHANDLE pSearchHandle)


More information about the Libreoffice-commits mailing list