vcl/inc/sft.hxx | 4 ++ vcl/source/fontsubset/sft.cxx | 53 ++++++++++++++++++++++++++++ vcl/unx/generic/fontmanager/fontmanager.cxx | 51 -------------------------- 3 files changed, 58 insertions(+), 50 deletions(-)
New commits: commit 0a098f5b9bd6f3cdfc387282d106031803707839 Author: Caolán McNamara <[email protected]> AuthorDate: Thu Sep 18 20:03:18 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Sat Oct 4 15:19:11 2025 +0200 extract an analyzeSfntName function Change-Id: I7ad26b1d1f3784e03aa819a208b781773211a3b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191161 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191820 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/vcl/inc/sft.hxx b/vcl/inc/sft.hxx index 259bfbbe44db..3bfac9963237 100644 --- a/vcl/inc/sft.hxx +++ b/vcl/inc/sft.hxx @@ -55,6 +55,8 @@ #include "font/TTFStructure.hxx" +class LanguageTag; + namespace vcl { @@ -606,6 +608,8 @@ void GetTTGlobalFontInfo(const AbstractTrueTypeFont *ttf, TTGlobalFontInfo *info */ bool GetTTGlobalFontHeadInfo(const AbstractTrueTypeFont *ttf, int& xMin, int& yMin, int& xMax, int& yMax, sal_uInt16& macStyle); +OUString analyzeSfntName(const TrueTypeFont* pTTFont, sal_uInt16 nameId, const LanguageTag& rPrefLang); + /*- private definitions */ /* indexes into TrueTypeFont::tables[] and TrueTypeFont::tlens[] */ diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index dab5aff157ec..b1a9940c1d99 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -1936,6 +1936,59 @@ OUString convertSfntName( const NameRecord& rNameRecord ) return aValue; } +OUString analyzeSfntName(const TrueTypeFont* pTTFont, sal_uInt16 nameId, const LanguageTag& rPrefLang) +{ + OUString aResult; + + std::vector<NameRecord> aNameRecords; + GetTTNameRecords(pTTFont, aNameRecords); + if( !aNameRecords.empty() ) + { + LanguageType eLang = rPrefLang.getLanguageType(); + int nLastMatch = -1; + for( size_t i = 0; i < aNameRecords.size(); i++ ) + { + if( aNameRecords[i].nameID != nameId || aNameRecords[i].sptr.empty() ) + continue; + int nMatch = -1; + if( aNameRecords[i].platformID == 0 ) // Unicode + nMatch = 4000; + else if( aNameRecords[i].platformID == 3 ) + { + // this bases on the LanguageType actually being a Win LCID + if (aNameRecords[i].languageID == eLang) + nMatch = 8000; + else if( aNameRecords[i].languageID == LANGUAGE_ENGLISH_US ) + nMatch = 2000; + else if( aNameRecords[i].languageID == LANGUAGE_ENGLISH || + aNameRecords[i].languageID == LANGUAGE_ENGLISH_UK ) + nMatch = 1500; + else + nMatch = 1000; + } + else if (aNameRecords[i].platformID == 1) + { + AppleLanguageId aAppleId = static_cast<AppleLanguageId>(static_cast<sal_uInt16>(aNameRecords[i].languageID)); + LanguageTag aApple(makeLanguageTagFromAppleLanguageId(aAppleId)); + if (aApple == rPrefLang) + nMatch = 8000; + else if (aAppleId == AppleLanguageId::ENGLISH) + nMatch = 2000; + else + nMatch = 1000; + } + OUString aName = convertSfntName( aNameRecords[i] ); + if (!(aName.isEmpty()) && nMatch >= nLastMatch) + { + nLastMatch = nMatch; + aResult = aName; + } + } + } + + return aResult; +} + } // namespace vcl int TestFontSubset(const void* data, sal_uInt32 size) diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index fd2b1dbad382..f0c40c7cecbd 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -301,56 +301,7 @@ namespace { OUString analyzeSfntFamilyName(void const * pTTFont) { - OUString aFamily; - - std::vector<NameRecord> aNameRecords; - GetTTNameRecords( static_cast<TrueTypeFont const *>(pTTFont), aNameRecords ); - if( !aNameRecords.empty() ) - { - LanguageTag aUILang(SvtSysLocaleOptions().GetRealUILanguageTag()); - LanguageType eLang = aUILang.getLanguageType(); - int nLastMatch = -1; - for( size_t i = 0; i < aNameRecords.size(); i++ ) - { - if( aNameRecords[i].nameID != 1 || aNameRecords[i].sptr.empty() ) - continue; - int nMatch = -1; - if( aNameRecords[i].platformID == 0 ) // Unicode - nMatch = 4000; - else if( aNameRecords[i].platformID == 3 ) - { - // this bases on the LanguageType actually being a Win LCID - if (aNameRecords[i].languageID == eLang) - nMatch = 8000; - else if( aNameRecords[i].languageID == LANGUAGE_ENGLISH_US ) - nMatch = 2000; - else if( aNameRecords[i].languageID == LANGUAGE_ENGLISH || - aNameRecords[i].languageID == LANGUAGE_ENGLISH_UK ) - nMatch = 1500; - else - nMatch = 1000; - } - else if (aNameRecords[i].platformID == 1) - { - AppleLanguageId aAppleId = static_cast<AppleLanguageId>(static_cast<sal_uInt16>(aNameRecords[i].languageID)); - LanguageTag aApple(makeLanguageTagFromAppleLanguageId(aAppleId)); - if (aApple == aUILang) - nMatch = 8000; - else if (aAppleId == AppleLanguageId::ENGLISH) - nMatch = 2000; - else - nMatch = 1000; - } - OUString aName = convertSfntName( aNameRecords[i] ); - if (!(aName.isEmpty()) && nMatch >= nLastMatch) - { - nLastMatch = nMatch; - aFamily = aName; - } - } - } - - return aFamily; + return analyzeSfntName(static_cast<TrueTypeFont const *>(pTTFont), 1, SvtSysLocaleOptions().GetRealUILanguageTag()); } }
