From a6c02c2bdebc196e5e7113aecbfd8d2debf4bb06 Mon Sep 17 00:00:00 2001 From: Patrick Luby Date: Mon, 30 Sep 2024 19:58:56 -0400 Subject: tdf#163000 don't add any fonts with an 'hvgl' font table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Tested-by: Jenkins Reviewed-by: Jonathan Clark Reviewed-by: خالد حسني (cherry picked from commit a4e9584c554ea018691b2c97d38cce3d83f8ea9a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174331 --- vcl/quartz/SystemFontList.cxx | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'vcl') diff --git a/vcl/quartz/SystemFontList.cxx b/vcl/quartz/SystemFontList.cxx index 3ca09bfcf21e..d39327c4c823 100644 --- a/vcl/quartz/SystemFontList.cxx +++ b/vcl/quartz/SystemFontList.cxx @@ -205,6 +205,62 @@ static void fontEnumCallBack( const void* pValue, void* pContext ) { CTFontDescriptorRef pFD = static_cast(pValue); + // 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 + CFNumberRef pFontFormat = static_cast(CTFontDescriptorCopyAttribute(pFD, kCTFontFormatAttribute)); + if (pFontFormat) + { + bool bSkipFont = false; + 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)) + { + 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(CFArrayGetValueAtIndex(pFontTableTags, i)); + if (nTag == kCTFontTableGlyf) + { + bGlyfTableFound = true; + break; + } + else if (nTag == 'hvgl') + { + bHvglTableFound = true; + } + } + bSkipFont = !bGlyfTableFound && bHvglTableFound; + CFRelease(pFontTableTags); + } + CFRelease(pFont); + } + } + CFRelease(pFontFormat); + + if (bSkipFont) + return; + } + bool bFontEnabled; FontAttributes rDFA = DevFontFromCTFontDescriptor( pFD, &bFontEnabled ); -- cgit