vcl/inc/unx/fontmanager.hxx | 2 vcl/unx/generic/fontmanager/fontmanager.cxx | 68 ++++++---------------------- 2 files changed, 15 insertions(+), 55 deletions(-)
New commits: commit 790ccec0bdb65adca32e7cde6d1b42c59ca6d567 Author: Khaled Hosny <[email protected]> AuthorDate: Tue Aug 1 17:45:53 2023 +0000 Commit: خالد حسني <[email protected]> CommitDate: Wed Aug 2 11:58:10 2023 +0200 vcl: Simplify analyzeSfntFamilyName We only need a family name not a set of name, and drop a work around for a broken font that is probably long obsolete. Change-Id: I219ec58e65826250d08b3e88462fdcc1e2e2b7f4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155195 Tested-by: Jenkins Reviewed-by: خالد حسني <[email protected]> diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx index a81975f21931..1a1421aef77a 100644 --- a/vcl/inc/unx/fontmanager.hxx +++ b/vcl/inc/unx/fontmanager.hxx @@ -92,8 +92,6 @@ class VCL_PLUGIN_PUBLIC PrintFontManager OString getFontFile(const PrintFont& rFont) const; std::vector<PrintFont> analyzeFontFile(int nDirID, const OString& rFileName, const char *pFormat=nullptr) const; - static OUString convertSfntName( const vcl::NameRecord& rNameRecord ); // format font subsetting code - static void analyzeSfntFamilyName( void const * pTTFont, std::vector< OUString >& rnames ); // actually a TrueTypeFont* from font subsetting code bool analyzeSfntFile(PrintFont& rFont) const; // finds the font id for the nFaceIndex face in this font file // There may be multiple font ids for font collections diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index a3d77c6ae99e..c60495d5b905 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -287,7 +287,9 @@ std::vector<fontID> PrintFontManager::findFontFileIDs( int nDirID, const OString return aIds; } -OUString PrintFontManager::convertSfntName( const NameRecord& rNameRecord ) +namespace { + +OUString convertSfntName( const NameRecord& rNameRecord ) { OUString aValue; if( @@ -413,36 +415,10 @@ OUString PrintFontManager::convertSfntName( const NameRecord& rNameRecord ) return aValue; } -//fdo#33349.There exists an archaic Berling Antiqua font which has a "Times New -//Roman" name field in it. We don't want the "Times New Roman" name to take -//precedence in this case. We take Berling Antiqua as a higher priority name, -//and erase the "Times New Roman" name -namespace -{ - bool isBadTNR(std::u16string_view rName, ::std::set< OUString >& rSet) - { - bool bRet = false; - if ( rName == u"Berling Antiqua" ) - { - ::std::set< OUString >::iterator aEnd = rSet.end(); - ::std::set< OUString >::iterator aI = rSet.find("Times New Roman"); - if (aI != aEnd) - { - bRet = true; - rSet.erase(aI); - } - } - return bRet; - } -} - -void PrintFontManager::analyzeSfntFamilyName( void const * pTTFont, ::std::vector< OUString >& rNames ) +OUString analyzeSfntFamilyName(void const * pTTFont) { OUString aFamily; - rNames.clear(); - ::std::set< OUString > aSet; - std::vector<NameRecord> aNameRecords; GetTTNameRecords( static_cast<TrueTypeFont const *>(pTTFont), aNameRecords ); if( !aNameRecords.empty() ) @@ -482,23 +458,17 @@ void PrintFontManager::analyzeSfntFamilyName( void const * pTTFont, ::std::vecto nMatch = 1000; } OUString aName = convertSfntName( aNameRecords[i] ); - aSet.insert( aName ); - if (aName.isEmpty()) - continue; - if( nMatch > nLastMatch || isBadTNR(aName, aSet) ) + if (!(aName.isEmpty()) && nMatch > nLastMatch) { nLastMatch = nMatch; aFamily = aName; } } } - if( !aFamily.isEmpty() ) - { - rNames.push_back( aFamily ); - for (auto const& elem : aSet) - if( elem != aFamily ) - rNames.push_back(elem); - } + + return aFamily; +} + } bool PrintFontManager::analyzeSfntFile( PrintFont& rFont ) const @@ -519,26 +489,18 @@ bool PrintFontManager::analyzeSfntFile( PrintFont& rFont ) const if (rDFA.GetFamilyName().isEmpty()) { - ::std::vector< OUString > aNames; - analyzeSfntFamilyName( pTTFont, aNames ); - - if( !aNames.empty() ) + OUString aFamily = analyzeSfntFamilyName(pTTFont); + if (aFamily.isEmpty()) { - rDFA.SetFamilyName(aNames.front()); - aNames.erase(aNames.begin()); - } - else - { - sal_Int32 dotIndex; - // poor font does not have a family name // name it to file name minus the extension - dotIndex = rFont.m_aFontFile.lastIndexOf( '.' ); + sal_Int32 dotIndex = rFont.m_aFontFile.lastIndexOf('.'); if ( dotIndex == -1 ) dotIndex = rFont.m_aFontFile.getLength(); - - rDFA.SetFamilyName(OStringToOUString(rFont.m_aFontFile.subView(0, dotIndex), aEncoding)); + aFamily = OStringToOUString(rFont.m_aFontFile.subView(0, dotIndex), aEncoding); } + + rDFA.SetFamilyName(aFamily); } if( !aInfo.usubfamily.isEmpty() )
