configure.ac                                   |   12 ++----------
 distro-configs/LibreOfficeCoverity.conf        |    2 --
 external/harfbuzz/UnpackedTarball_harfbuzz.mk  |    3 ---
 external/harfbuzz/harfbuzz-fd-hack.patch.0     |   24 ------------------------
 vcl/inc/unx/freetype_glyphcache.hxx            |    1 +
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |   25 +++++++++++++++++++++++--
 6 files changed, 26 insertions(+), 41 deletions(-)

New commits:
commit a881850d5828dba3a19f2d53c995e9610d6d87b1
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Tue Feb 21 17:04:02 2023 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Feb 22 09:02:40 2023 +0000

    vcl: Avoid the need to patch HarfBuzz
    
    Reverts parts of d552b4a549d614a03aa9328e017dec27bd3ff41e and
    97e2e73e87479a742b798f362eda4baafb89497c.
    
    Instead of patching HarfBuzz, lets make use of the already mmap’ed file
    we use with FreeType.
    
    Change-Id: Ia81222118162a30cadb8c988bc477ad3ce36166d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147410
    Tested-by: Jenkins
    Reviewed-by: Tor Lillqvist <t...@collabora.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/configure.ac b/configure.ac
index a346bde17e87..c5afd41afeba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10830,16 +10830,8 @@ 
GRAPHITE_CFLAGS_internal="-I${WORKDIR}/UnpackedTarball/graphite/include -DGRAPHI
 GRAPHITE_LIBS_internal="-L${WORKDIR}/LinkTarget/StaticLibrary -lgraphite"
 HARFBUZZ_CFLAGS_internal="-I${WORKDIR}/UnpackedTarball/harfbuzz/src"
 HARFBUZZ_LIBS_internal="-L${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs 
-lharfbuzz"
-case "$_os" in
-    Linux)
-        libo_CHECK_SYSTEM_MODULE([graphite],[GRAPHITE],[graphite2 >= 
0.9.3],,,TRUE)
-        libo_CHECK_SYSTEM_MODULE([harfbuzz],[HARFBUZZ],[harfbuzz-icu >= 
$harfbuzz_required_version],,,TRUE)
-        ;;
-    *)
-        libo_CHECK_SYSTEM_MODULE([graphite],[GRAPHITE],[graphite2 >= 0.9.3])
-        libo_CHECK_SYSTEM_MODULE([harfbuzz],[HARFBUZZ],[harfbuzz-icu >= 
$harfbuzz_required_version])
-        ;;
-esac
+libo_CHECK_SYSTEM_MODULE([graphite],[GRAPHITE],[graphite2 >= 0.9.3])
+libo_CHECK_SYSTEM_MODULE([harfbuzz],[HARFBUZZ],[harfbuzz-icu >= 
$harfbuzz_required_version])
 
 if test "$COM" = "MSC"; then # override the above
     GRAPHITE_LIBS="${WORKDIR}/LinkTarget/StaticLibrary/graphite.lib"
diff --git a/distro-configs/LibreOfficeCoverity.conf 
b/distro-configs/LibreOfficeCoverity.conf
index 25e5c5d1af87..5b301570b8fc 100644
--- a/distro-configs/LibreOfficeCoverity.conf
+++ b/distro-configs/LibreOfficeCoverity.conf
@@ -9,8 +9,6 @@
 --enable-gstreamer-1-0
 --enable-option-checking=fatal
 --with-system-libs
---with-system-graphite
---with-system-harfbuzz
 --with-system-headers
 --without-system-cppunit
 --without-system-libfixmath
diff --git a/external/harfbuzz/UnpackedTarball_harfbuzz.mk 
b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
index 37c5946a5ce4..9bc9e326b426 100644
--- a/external/harfbuzz/UnpackedTarball_harfbuzz.mk
+++ b/external/harfbuzz/UnpackedTarball_harfbuzz.mk
@@ -16,9 +16,6 @@ $(eval $(call 
gb_UnpackedTarball_update_autoconf_configs,harfbuzz))
 $(eval $(call gb_UnpackedTarball_set_patchlevel,harfbuzz,0))
 
 $(eval $(call gb_UnpackedTarball_add_patches,harfbuzz, \
-    $(if $(filter LINUX,$(OS)), \
-        external/harfbuzz/harfbuzz-fd-hack.patch.0 \
-    ) \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/external/harfbuzz/harfbuzz-fd-hack.patch.0 
b/external/harfbuzz/harfbuzz-fd-hack.patch.0
deleted file mode 100644
index 1cc5820fd49c..000000000000
--- a/external/harfbuzz/harfbuzz-fd-hack.patch.0
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- Mode: Diff -*-
---- src/hb-blob.cc
-+++ src/hb-blob.cc
-@@ -737,7 +737,19 @@
-   char *data = (char *) hb_malloc (allocated);
-   if (unlikely (!data)) return nullptr;
- 
--  FILE *fp = fopen (file_name, "rb");
-+  FILE *fp;
-+  int nFD;
-+  int n;
-+  if (sscanf (file_name, "/:FD:/%d%n", &nFD, &n) == 1 && file_name[n] == '\0')
-+  {
-+    lseek (nFD, 0, SEEK_SET);
-+    fp = fdopen (dup (nFD), "rb");
-+  }
-+  else
-+  {
-+    fp = fopen (file_name, "rb");
-+  }
-+
-   if (unlikely (!fp)) goto fread_fail_without_close;
- 
-   while (!feof (fp))
diff --git a/vcl/inc/unx/freetype_glyphcache.hxx 
b/vcl/inc/unx/freetype_glyphcache.hxx
index c80642b6126c..7602ec0ba1d8 100644
--- a/vcl/inc/unx/freetype_glyphcache.hxx
+++ b/vcl/inc/unx/freetype_glyphcache.hxx
@@ -61,6 +61,7 @@ public:
     FT_FaceRec_*          GetFaceFT();
     void                  ReleaseFaceFT();
 
+    FreetypeFontFile*     GetFontFile() const       { return mpFontFile; }
     const OString&        GetFontFileName() const   { return 
mpFontFile->GetFileName(); }
     int                   GetFontFaceIndex() const  { return mnFaceNum; }
     int                   GetFontFaceVariation() const  { return 
mnFaceVariation; }
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx 
b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index d3c507a28e98..af9f656b17d5 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -317,13 +317,34 @@ rtl::Reference<LogicalFontInstance> 
FreetypeFontFace::CreateFontInstance(const v
     return new FreetypeFontInstance(*this, rFSD);
 }
 
+namespace
+{
+hb_blob_t* CreateHbBlob(FreetypeFontFile* pFontFile)
+{
+    auto pFileName = pFontFile->GetFileName().getStr();
+    int nFD;
+    int n;
+    if (sscanf(pFileName, "/:FD:/%d%n", &nFD, &n) == 1 && pFileName[n] == '\0')
+    {
+        if (pFontFile->Map())
+            return hb_blob_create(
+                reinterpret_cast<const char*>(pFontFile->GetBuffer()), 
pFontFile->GetFileSize(),
+                HB_MEMORY_MODE_READONLY, pFontFile,
+                [](void* data) { 
static_cast<FreetypeFontFile*>(data)->Unmap(); });
+        pFontFile->Unmap();
+        return hb_blob_get_empty();
+    }
+    return hb_blob_create_from_file(pFileName);
+}
+}
+
 hb_face_t* FreetypeFontFace::GetHbFace() const
 {
     if (!mpHbFace)
     {
-        auto* pFileName = mpFreetypeFontInfo->GetFontFileName().getStr();
+        auto pFontFile = mpFreetypeFontInfo->GetFontFile();
         auto nIndex = mpFreetypeFontInfo->GetFontFaceIndex();
-        hb_blob_t* pHbBlob = hb_blob_create_from_file(pFileName);
+        auto pHbBlob = CreateHbBlob(pFontFile);
         mpHbFace = hb_face_create(pHbBlob, nIndex);
         hb_blob_destroy(pHbBlob);
     }

Reply via email to