From 03bff1b6b953e4b7a54d2fb7bbf366bea7e959d9 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Tue, 1 Nov 2016 23:15:44 +0200 Subject: [PATCH] tdf#71603: Improve font fallback on Windows a bit Check all missing characters, not just the first one. Also the calling sites for GlyphFallbackFontSubstitution hook expect the OUString to be updated to have only any characters not supported by the returned font. Change-Id: Ife56d692c05433f2f7fe02db3ef1562181dc3d53 --- vcl/win/gdi/salfont.cxx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx index c8c9893385de..8d6f0656b1fa 100644 --- a/vcl/win/gdi/salfont.cxx +++ b/vcl/win/gdi/salfont.cxx @@ -151,7 +151,7 @@ class WinGlyphFallbackSubstititution bool FindFontSubstitute( FontSelectPattern&, OUString& rMissingChars ) const override; private: HDC mhDC; - bool HasMissingChars( PhysicalFontFace*, const OUString& rMissingChars ) const; + bool HasMissingChars(PhysicalFontFace*, OUString& rMissingChars) const; }; inline WinGlyphFallbackSubstititution::WinGlyphFallbackSubstititution( HDC hDC ) @@ -159,7 +159,7 @@ inline WinGlyphFallbackSubstititution::WinGlyphFallbackSubstititution( HDC hDC ) {} // does a font face hold the given missing characters? -bool WinGlyphFallbackSubstititution::HasMissingChars( PhysicalFontFace* pFace, const OUString& rMissingChars ) const +bool WinGlyphFallbackSubstititution::HasMissingChars(PhysicalFontFace* pFace, OUString& rMissingChars) const { WinFontFace* pWinFont = static_cast< WinFontFace* >(pFace); FontCharMapRef xFontCharMap = pWinFont->GetFontCharMap(); @@ -194,19 +194,24 @@ bool WinGlyphFallbackSubstititution::HasMissingChars( PhysicalFontFace* pFace, c return false; int nMatchCount = 0; - // static const int nMaxMatchCount = 1; // TODO: tolerate more missing characters? + std::vector rRemainingCodes; const sal_Int32 nStrLen = rMissingChars.getLength(); - for( sal_Int32 nStrIdx = 0; nStrIdx < nStrLen; /* ++nStrIdx unreachable code, see the 'break' below */ ) + sal_Int32 nStrIdx = 0; + while (nStrIdx < nStrLen) { const sal_UCS4 uChar = rMissingChars.iterateCodePoints( &nStrIdx ); - nMatchCount += xFontCharMap->HasChar( uChar ) ? 1 : 0; - break; // for now + if (xFontCharMap->HasChar(uChar)) + nMatchCount++; + else + rRemainingCodes.push_back(uChar); } xFontCharMap = nullptr; - const bool bHasMatches = (nMatchCount > 0); - return bHasMatches; + if (nMatchCount > 0) + rMissingChars = OUString(rRemainingCodes.data(), rRemainingCodes.size()); + + return nMatchCount > 0; } namespace