From 2d9bcb6e4f752a4fefc7dcafd3bed0338455e849 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 13 Mar 2023 16:35:28 +0000 Subject: [PATCH] Select correct face from a .ttc file. Fixes https://gitlab.com/kicad/code/kicad/issues/13314 (cherry picked from commit 7b3e01ce526c8be8fddb16138958e83badb54945) --- common/font/fontconfig.cpp | 10 +++++++--- common/font/outline_font.cpp | 9 +++++---- include/font/fontconfig.h | 2 +- include/font/outline_font.h | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/common/font/fontconfig.cpp b/common/font/fontconfig.cpp index 494d383a90..c6832eabd9 100644 --- a/common/font/fontconfig.cpp +++ b/common/font/fontconfig.cpp @@ -152,7 +152,7 @@ std::string FONTCONFIG::getFamilyStringByLang( FONTCONFIG_PAT& aPat, const wxStr FONTCONFIG::FF_RESULT FONTCONFIG::FindFont( const wxString &aFontName, wxString &aFontFile, - bool aBold, bool aItalic ) + int& aFaceIndex, bool aBold, bool aItalic ) { FF_RESULT retval = FF_RESULT::FF_ERROR; wxString qualifiedFontName = aFontName; @@ -184,6 +184,8 @@ FONTCONFIG::FF_RESULT FONTCONFIG::FindFont( const wxString &aFontName, wxString if( FcPatternGetString( font, FC_FILE, 0, &file ) == FcResultMatch ) { aFontFile = wxString::FromUTF8( (char*) file ); + aFaceIndex = 0; + wxString styleStr; FcChar8* family = nullptr; FcChar8* style = nullptr; @@ -192,9 +194,13 @@ FONTCONFIG::FF_RESULT FONTCONFIG::FindFont( const wxString &aFontName, wxString std::unordered_map famStrings; FONTCONFIG_PAT patHolder{ font }; + getAllFamilyStrings( patHolder, famStrings ); + if( FcPatternGetString( font, FC_FAMILY, 0, &family ) == FcResultMatch ) { + FcPatternGetInteger( font, FC_INDEX, 0, &aFaceIndex ); + fontName = wxString::FromUTF8( (char*) family ); if( FcPatternGetString( font, FC_STYLE, 0, &style ) == FcResultMatch ) @@ -248,8 +254,6 @@ FONTCONFIG::FF_RESULT FONTCONFIG::FindFont( const wxString &aFontName, wxString break; } } - - } } diff --git a/common/font/outline_font.cpp b/common/font/outline_font.cpp index 497495ed38..a39b8e09d1 100644 --- a/common/font/outline_font.cpp +++ b/common/font/outline_font.cpp @@ -98,9 +98,10 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo std::unique_ptr font = std::make_unique(); wxString fontFile; + int faceIndex; using fc = fontconfig::FONTCONFIG; - fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, aBold, aItalic ); + fc::FF_RESULT retval = Fontconfig()->FindFont( aFontName, fontFile, faceIndex, aBold, aItalic ); if( retval == fc::FF_RESULT::FF_ERROR ) return nullptr; @@ -111,7 +112,7 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo if( retval == fc::FF_RESULT::FF_MISSING_ITAL || retval == fc::FF_RESULT::FF_MISSING_BOLD_ITAL ) font->SetFakeItal(); - if( font->loadFace( fontFile ) != 0 ) + if( font->loadFace( fontFile, faceIndex ) != 0 ) return nullptr; font->m_fontName = aFontName; // Keep asked-for name, even if we substituted. @@ -121,13 +122,13 @@ OUTLINE_FONT* OUTLINE_FONT::LoadFont( const wxString& aFontName, bool aBold, boo } -FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName ) +FT_Error OUTLINE_FONT::loadFace( const wxString& aFontFileName, int aFaceIndex ) { std::lock_guard guard( m_freeTypeMutex ); // TODO: check that going from wxString to char* with UTF-8 // conversion for filename makes sense on any/all platforms - FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), 0, &m_face ); + FT_Error e = FT_New_Face( m_freeType, aFontFileName.mb_str( wxConvUTF8 ), aFaceIndex, &m_face ); if( !e ) { diff --git a/include/font/fontconfig.h b/include/font/fontconfig.h index 1536fa166f..15a4426e5c 100644 --- a/include/font/fontconfig.h +++ b/include/font/fontconfig.h @@ -57,7 +57,7 @@ public: * * A return value of false indicates a serious error in the font system. */ - FF_RESULT FindFont( const wxString& aFontName, wxString& aFontFile, bool aBold, bool aItalic ); + FF_RESULT FindFont( const wxString& aFontName, wxString& aFontFile, int& aFaceIndex, bool aBold, bool aItalic ); /** * List the current available font families. diff --git a/include/font/outline_font.h b/include/font/outline_font.h index d04ce98d28..c753e73391 100644 --- a/include/font/outline_font.h +++ b/include/font/outline_font.h @@ -124,7 +124,7 @@ public: #endif protected: - FT_Error loadFace( const wxString& aFontFileName ); + FT_Error loadFace( const wxString& aFontFileName, int aFaceIndex ); double getOverbarOffset( int ascender, int height, int thickness ) const;