Permalink
Browse files

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
  • Loading branch information...
1 parent d66ec48 commit 03bff1b6b953e4b7a54d2fb7bbf366bea7e959d9 @khaledhosny khaledhosny committed Nov 1, 2016
Showing with 13 additions and 8 deletions.
  1. +13 −8 vcl/win/gdi/salfont.cxx
View
@@ -151,15 +151,15 @@ 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 )
: mhDC( 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<sal_UCS4> 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

0 comments on commit 03bff1b

Please sign in to comment.