diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-11-02 16:20:23 +0000 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-11-02 20:06:33 +0100 |
commit | 6fbd5a72c83a6d50a650fe9ae5f5ed0e54dbdd59 (patch) | |
tree | 3265068acaa39ab2705eee44f8e36dc4e99778b7 | |
parent | 142e7d985f2f6cdb1e37dc0540d77e1fbd6f1bfd (diff) |
tdf#157939 drop duplicates from the FontConfig Set
when we drop them from our own font list, that way we don't get
suggestions for glyph fallback which we can't satisfy
Also prefer our application fonts to system fonts when they
share the same version number where they should be the same, but
more than once we have a system-side font with oddities.
Change-Id: I90bd3311e0f37bacd60d20e1c1a6769b551b8b76
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158841
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | vcl/unx/generic/fontmanager/fontconfig.cxx | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx index d793d45cb51d..f1bcd3cbc193 100644 --- a/vcl/unx/generic/fontmanager/fontconfig.cxx +++ b/vcl/unx/generic/fontmanager/fontconfig.cxx @@ -155,6 +155,7 @@ public: void addFontSet( FcSetName ); FcFontSet* getFontSet(); + void replaceFontSet(FcFontSet* pFilteredFontSet); void clear(); @@ -315,9 +316,15 @@ FcFontSet* FontCfgWrapper::getFontSet() return getenv("SAL_NON_APPLICATION_FONT_USE") != nullptr; }(); #endif + // Add the application fonts before the system fonts. + // tdf#157939 We will remove duplicate fonts, where the duplicate is + // the one with a smaller version number. If the same version font is + // available system-wide or bundled with our application, then we + // prefer via stable-sort the first one we see. Load application fonts + // first to prefer the one we bundle in the application in that case. + addFontSet( FcSetApplication ); if (!bRestrictFontSetToApplicationFonts) addFontSet( FcSetSystem ); - addFontSet( FcSetApplication ); std::stable_sort(m_pFontSet->fonts,m_pFontSet->fonts+m_pFontSet->nfont,SortFont()); } @@ -325,6 +332,13 @@ FcFontSet* FontCfgWrapper::getFontSet() return m_pFontSet; } +void FontCfgWrapper::replaceFontSet(FcFontSet* pFilteredFontSet) +{ + if (m_pFontSet) + FcFontSetDestroy(m_pFontSet); + m_pFontSet = pFilteredFontSet; +} + FontCfgWrapper::~FontCfgWrapper() { clear(); @@ -578,6 +592,9 @@ void PrintFontManager::countFontconfigFonts() if( pFSet ) { SAL_INFO("vcl.fonts", "found " << pFSet->nfont << " entries in fontconfig fontset"); + + FcFontSet* pFilteredSet = FcFontSetCreate(); + for( int i = 0; i < pFSet->nfont; i++ ) { FcChar8* file = nullptr; @@ -672,8 +689,21 @@ void PrintFontManager::countFontconfigFonts() m_aFonts.emplace(nFontID, aFont); m_aFontFileToFontID[aBase].insert(nFontID); nFonts++; + + FcPattern* pPattern = pFSet->fonts[i]; + FcPatternReference(pPattern); + FcFontSetAdd(pFilteredSet, pPattern); + SAL_INFO("vcl.fonts.detail", "inserted font " << family << " as fontID " << nFontID); } + + // tdf#157939 if we drop fonts, drop them from the FcConfig set too so they are not + // candidates for suggestions by fontconfig + if (pFSet->nfont != pFilteredSet->nfont) + rWrapper.replaceFontSet(pFilteredSet); + else + FcFontSetDestroy(pFilteredSet); + } // how does one get rid of the config ? |