From 4dcd8c81b12790b0ad7661f3ab8742ae619996be Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 21 May 2020 19:34:13 +0200 Subject: [PATCH] app_server: fix font fallback Actually check that the replacement font contains the needed glyph. Change-Id: I6d774361fcf16a36dc3d05ce8b0fe1cb407fabff Reviewed-on: https://review.haiku-os.org/c/haiku/+/2767 Reviewed-by: waddlesplash --- src/servers/app/font/FontCacheEntry.cpp | 10 ++++++++++ src/servers/app/font/FontCacheEntry.h | 1 + src/servers/app/font/GlyphLayoutEngine.h | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/src/servers/app/font/FontCacheEntry.cpp b/src/servers/app/font/FontCacheEntry.cpp index fd2428d891..edc18d5380 100644 --- a/src/servers/app/font/FontCacheEntry.cpp +++ b/src/servers/app/font/FontCacheEntry.cpp @@ -266,6 +266,16 @@ FontCacheEntry::CachedGlyph(uint32 glyphCode) } +bool +FontCacheEntry::CanCreateGlyph(uint32 glyphCode) +{ + // Note that this bypass any fallback or caching because it is used in + // the fallback code itself. + uint32 glyphIndex = fEngine.GlyphIndexForGlyphCode(glyphCode); + return glyphIndex != 0; +} + + const GlyphCache* FontCacheEntry::CreateGlyph(uint32 glyphCode, FontCacheEntry* fallbackEntry) { diff --git a/src/servers/app/font/FontCacheEntry.h b/src/servers/app/font/FontCacheEntry.h index abe085adec..233c510d5c 100644 --- a/src/servers/app/font/FontCacheEntry.h +++ b/src/servers/app/font/FontCacheEntry.h @@ -112,6 +112,7 @@ class FontCacheEntry : public MultiLocker, public BReferenceable { const GlyphCache* CachedGlyph(uint32 glyphCode); const GlyphCache* CreateGlyph(uint32 glyphCode, FontCacheEntry* fallbackEntry = NULL); + bool CanCreateGlyph(uint32 glyphCode); void InitAdaptors(const GlyphCache* glyph, double x, double y, diff --git a/src/servers/app/font/GlyphLayoutEngine.h b/src/servers/app/font/GlyphLayoutEngine.h index 7bd51d41ae..910b88e189 100644 --- a/src/servers/app/font/GlyphLayoutEngine.h +++ b/src/servers/app/font/GlyphLayoutEngine.h @@ -147,6 +147,11 @@ GlyphLayoutEngine::FontCacheEntryFor(const ServerFont& font, bool forceVector, return NULL; } + if (glyphCode != 0 && !entry->CanCreateGlyph(glyphCode)) { + cache->Recycle(entry); + return NULL; + } + if (needsWriteLock) { if (!entry->WriteLock()) { cache->Recycle(entry); @@ -163,6 +168,7 @@ GlyphLayoutEngine::FontCacheEntryFor(const ServerFont& font, bool forceVector, // proper mode. We can setup the FontCacheReference so it takes care of // the locking and recycling from now and return the entry. cacheReference.SetTo(entry, needsWriteLock); + return entry; }