vcl/quartz/ctfonts.cxx |   39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

New commits:
commit d7083fe6dd383ac4144fbe53e300bc3d34f26ef6
Author:     Khaled Hosny <kha...@aliftype.com>
AuthorDate: Sat Oct 1 10:24:00 2022 +0200
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Sat Oct 1 13:10:22 2022 +0200

    tdf#72456: Support font embedding on macOS
    
    With the previous commit, when we want the full font data we pass 0 for
    table tag. This does not work with CoreText’s CTFontCopyTable(), we we
    emulate it by using hb_face_builder to construct a full font from
    individual font tables.
    
    Change-Id: I0edb10982434872221466e9ec9ef9cd39087967a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140831
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx
index 9166d323f7dd..eb98b24569df 100644
--- a/vcl/quartz/ctfonts.cxx
+++ b/vcl/quartz/ctfonts.cxx
@@ -234,6 +234,41 @@ bool CoreTextStyle::GetGlyphOutline(sal_GlyphId nId, 
basegfx::B2DPolyPolygon& rR
 
 hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const
 {
+    hb_blob_t* pBlob = nullptr;
+
+    if (!nTag)
+    {
+        // If nTag is 0, the whole font data is requested. CoreText does not
+        // give us that, so we will construct an HarfBuzz face from CoreText
+        // table data and return the blob of that face.
+        auto pFontDesc = reinterpret_cast<CTFontDescriptorRef>(GetFontId());
+        auto rCTFont = CTFontCreateWithFontDescriptor(pFontDesc, 0.0, nullptr);
+
+        auto pTags = CTFontCopyAvailableTables(rCTFont, 
kCTFontTableOptionNoOptions);
+        if (pTags)
+        {
+            auto nTags = CFArrayGetCount(pTags);
+            if (!nTags)
+                return nullptr;
+
+            hb_face_t* pHbFace = hb_face_builder_create();
+            for (auto i = 0u; i < nTags; i++)
+            {
+                auto nTable = 
reinterpret_cast<intptr_t>(CFArrayGetValueAtIndex(pTags, i));
+                assert(nTable);
+                auto pTable = GetHbTable(nTable);
+                assert(pTable);
+                hb_face_builder_add_table(pHbFace, nTable, pTable);
+            }
+            pBlob = hb_face_reference_blob(pHbFace);
+
+            hb_face_destroy(pHbFace);
+            CFRelease(pTags);
+        }
+
+        return pBlob;
+    }
+
     sal_uLong nLength = 0;
     unsigned char* pBuffer = nullptr;
     nLength = GetFontTable(nTag, nullptr);
@@ -243,7 +278,6 @@ hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const
         GetFontTable(nTag, pBuffer);
     }
 
-    hb_blob_t* pBlob = nullptr;
     if (pBuffer != nullptr)
         pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), 
nLength, HB_MEMORY_MODE_READONLY,
                                pBuffer, [](void* data){ delete[] 
static_cast<unsigned char*>(data); });
@@ -307,8 +341,7 @@ int CoreTextFontFace::GetFontTable(uint32_t nTagCode, 
unsigned char* pResultBuf
     // get the raw table length
     CTFontDescriptorRef pFontDesc = reinterpret_cast<CTFontDescriptorRef>( 
GetFontId());
     CTFontRef rCTFont = CTFontCreateWithFontDescriptor( pFontDesc, 0.0, 
nullptr);
-    const uint32_t opts( kCTFontTableOptionNoOptions );
-    CFDataRef pDataRef = CTFontCopyTable( rCTFont, nTagCode, opts);
+    CFDataRef pDataRef = CTFontCopyTable(rCTFont, nTagCode, 
kCTFontTableOptionNoOptions);
     CFRelease( rCTFont);
     if( !pDataRef)
         return 0;

Reply via email to