vcl/quartz/SystemFontList.cxx |   54 +++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 13 deletions(-)

New commits:
commit 2a30aa03b63cf1598a16f3fa165f06cafc9ec6fa
Author:     Patrick Luby <guibmac...@gmail.com>
AuthorDate: Mon Sep 30 19:58:56 2024 -0400
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Wed Oct 2 17:48:15 2024 +0200

    tdf#163000 don't add any fonts with an 'hvgl' font table
    
    macOS Sequoia added a new PingFangUI.ttc font file which
    contains all of the PingFang font families. However, any
    fonts loaded from this font file result in the following
    failures:
    
    - Skia renders font with wrong glyphs
    - Export to PDF contain a damaged embedded font
    
    Despite the fact that the fonts in this new font file have
    a TrueType font type, they are missing a 'glyf' font table
    and, instead, have a new, undefined 'hvgl' font table. See
    the following link for more details about the new 'hvgl'
    font table:
    
    https://gitlab.freedesktop.org/freetype/freetype/-/issues/1281
    
    Change-Id: I18170b1b226de86f79402ad0e45df8620c693f83
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174305
    Reviewed-by: Patrick Luby <guibomac...@gmail.com>
    Tested-by: Jenkins
    Reviewed-by: Jonathan Clark <jonat...@libreoffice.org>
    Reviewed-by: خالد حسني <kha...@libreoffice.org>
    (cherry picked from commit a4e9584c554ea018691b2c97d38cce3d83f8ea9a)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174332
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/vcl/quartz/SystemFontList.cxx b/vcl/quartz/SystemFontList.cxx
index c04c8fdd1f72..738dc393f748 100644
--- a/vcl/quartz/SystemFontList.cxx
+++ b/vcl/quartz/SystemFontList.cxx
@@ -212,29 +212,57 @@ static void fontEnumCallBack( const void* pValue, void* 
pContext )
 {
     CTFontDescriptorRef pFD = static_cast<CTFontDescriptorRef>(pValue);
 
-    // tdf#163000 don't add any fonts in the system "reserved fonts" folder
+    // tdf#163000 don't add any fonts with an 'hvgl' font table
     // macOS Sequoia added a new PingFangUI.ttc font file which
     // contains all of the PingFang font families. However, any
     // fonts loaded from this font file result in the following
     // failures:
     // - Skia renders font with wrong glyphs
     // - Export to PDF contain a damaged embedded font
-    // macOS Sequoia still has separate, downloadable Type 3
-    // bitmap fonts for the PingFang font family so ignore
-    // any fonts in the PingFangUI.ttc font file and, just to
-    // be safe, ignore any other font files in the system
-    // "reserved fonts" folder that may be added in the future.
-    CFURLRef pFontURL = 
static_cast<CFURLRef>(CTFontDescriptorCopyAttribute(pFD, kCTFontURLAttribute));
-    if (pFontURL)
+    // Despite the fact that the fonts in this new font file have
+    // a TrueType font type, they are missing a 'glyf' font table
+    // and, instead, have a new, undefined 'hvgl' font table. See
+    // the following link for more details about the new 'hvgl'
+    // font table:
+    // https://gitlab.freedesktop.org/freetype/freetype/-/issues/1281
+    CFNumberRef pFontFormat = 
static_cast<CFNumberRef>(CTFontDescriptorCopyAttribute(pFD, 
kCTFontFormatAttribute));
+    if (pFontFormat)
     {
         bool bSkipFont = false;
-        CFStringRef pFontPath = CFURLCopyFileSystemPath(pFontURL, 
kCFURLPOSIXPathStyle);
-        if (pFontPath)
+        int nFontFormat;
+        // At least for the PingFangUI.ttc font file, the font format is
+        // different on macOS and iOS
+        if (CFNumberGetValue(pFontFormat, kCFNumberIntType, &nFontFormat) && 
(nFontFormat == kCTFontFormatOpenTypeTrueType || nFontFormat == 
kCTFontFormatTrueType))
         {
-            bSkipFont = CFStringHasPrefix(pFontPath, 
CFSTR("/System/Library/PrivateFrameworks/FontServices.framework/Resources/Reserved/"));
-            CFRelease(pFontPath);
+            CTFontRef pFont = CTFontCreateWithFontDescriptor(pFD, 0.0, 
nullptr);
+            if (pFont)
+            {
+                CFArrayRef pFontTableTags = CTFontCopyAvailableTables(pFont, 
kCTFontTableOptionNoOptions);
+                if (pFontTableTags)
+                {
+                    bool bGlyfTableFound = false;
+                    bool bHvglTableFound = false;
+                    CFIndex nFontTableTagCount = 
CFArrayGetCount(pFontTableTags);
+                    for (CFIndex i = 0; i < nFontTableTagCount; i++)
+                    {
+                        CTFontTableTag nTag = 
reinterpret_cast<uintptr_t>(CFArrayGetValueAtIndex(pFontTableTags, i));
+                        if (nTag == kCTFontTableGlyf)
+                        {
+                            bGlyfTableFound = true;
+                            break;
+                        }
+                        else if (nTag == 'hvgl')
+                        {
+                            bHvglTableFound = true;
+                        }
+                    }
+                    bSkipFont = !bGlyfTableFound && bHvglTableFound;
+                    CFRelease(pFontTableTags);
+                }
+                CFRelease(pFont);
+            }
         }
-        CFRelease(pFontURL);
+        CFRelease(pFontFormat);
 
         if (bSkipFont)
             return;

Reply via email to