From b8a45b3a2df2379b4301bf3bd5949b9a105be4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= Date: Thu, 20 Jun 2024 17:26:43 +0200 Subject: [PATCH] BFont: allow skipping fallbacks in GetHasGlyphs Change-Id: I5a68008d25cce34596fb5ce6fb07259ae56c3a3d Reviewed-on: https://review.haiku-os.org/c/haiku/+/7829 Tested-by: Commit checker robot Reviewed-by: Adrien Destugues Haiku-Format: Haiku-format Bot --- docs/user/interface/Font.dox | 35 +++++++++++++++++++++++++++++----- headers/os/interface/Font.h | 2 ++ src/kits/interface/Font.cpp | 10 ++++++++++ src/servers/app/ServerApp.cpp | 7 +++++-- src/servers/app/ServerFont.cpp | 6 +++--- src/servers/app/ServerFont.h | 2 +- 6 files changed, 51 insertions(+), 11 deletions(-) diff --git a/docs/user/interface/Font.dox b/docs/user/interface/Font.dox index 2f18ec7e15..47965efa3b 100644 --- a/docs/user/interface/Font.dox +++ b/docs/user/interface/Font.dox @@ -1740,12 +1740,18 @@ /*! \fn void BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) const - \brief Fills out \a hasArray with whether or not each characters in - \a charArray has a glyph for the font. + \brief Fills out \a hasArray with whether or not the font has a glyph + for each character in \a charArray. - \c true is written in \a hasArray if the character has a glyph in the - current font and \c false is written in \a hasArray if the character - does NOT have a glyph in the current font. + \c true is written in \a hasArray if a glyph is found for the character, + \c false otherwise. + + \remark After the introduction of fallback fonts for missing glyphs, + this is not exaclty what the name or the original desciption imply. As + the objective of this method is to know if a string can be presented + to the user without getting "no glyph" symbols, it will still write + \c true if the queried font does not provide a glyph for a character + but a fallback font does. \param charArray The source character array. \param numChars The number of characters to consider in \a charArray. @@ -1755,6 +1761,25 @@ */ +/*! + \fn void BFont::GetHasGlyphs(const char charArray[], int32 numChars, + bool hasArray[], bool useFallbacks) const + \brief Fills out \a hasArray with whether or not the font has a glyph + for each character in \a charArray. + + \c true is written in \a hasArray if the character has a glyph in the + current font and \c false otherwise. Fallback fonts are also considered + in the search if \a useFallbacks is \c true. + + \param charArray The source character array. + \param numChars The number of characters to consider in \a charArray. + \param hasArray The destination array of booleans. + \param useFallbacks Whether to consider fallback fonts in the answer. + + \since Haiku R1 +*/ + + /*! \fn BFont& BFont::operator=(const BFont &font) \brief Assignment overload method. diff --git a/headers/os/interface/Font.h b/headers/os/interface/Font.h index a6a9e4651f..a972dd4ae9 100644 --- a/headers/os/interface/Font.h +++ b/headers/os/interface/Font.h @@ -275,6 +275,8 @@ public: void GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) const; + void GetHasGlyphs(const char charArray[], int32 numChars, + bool hasArray[], bool useFallbacks) const; BFont& operator=(const BFont& font); bool operator==(const BFont& font) const; diff --git a/src/kits/interface/Font.cpp b/src/kits/interface/Font.cpp index 6155373ffb..66dbaac265 100644 --- a/src/kits/interface/Font.cpp +++ b/src/kits/interface/Font.cpp @@ -1345,6 +1345,14 @@ BFont::GetGlyphShapes(const char charArray[], int32 numChars, void BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[]) const +{ + GetHasGlyphs(charArray, numChars, hasArray, true); +} + + +void +BFont::GetHasGlyphs(const char charArray[], int32 numChars, bool hasArray[], + bool useFallbacks) const { if (!charArray || numChars < 1 || !hasArray) return; @@ -1361,6 +1369,8 @@ BFont::GetHasGlyphs(const char charArray[], int32 numChars, link.Attach(bytesInBuffer); link.Attach(charArray, bytesInBuffer); + link.Attach(useFallbacks); + if (link.FlushWithReply(code) != B_OK || code != B_OK) return; diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index f1dd65c82d..c2c55bb26b 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -2487,6 +2487,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) // 3) int32 - numChars // 4) int32 - numBytes // 5) char - the char buffer with size numBytes + // 6) bool - whether to try fallback fonts uint16 familyID, styleID; link.Read(&familyID); @@ -2506,13 +2507,15 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) link.Read(charArray, numBytes); + bool useFallbacks; + link.Read(&useFallbacks); + ServerFont font; status_t status = font.SetFamilyAndStyle(familyID, styleID, fAppFontManager); if (status == B_OK) { - status = font.GetHasGlyphs(charArray, numBytes, numChars, - hasArray); + status = font.GetHasGlyphs(charArray, numBytes, numChars, hasArray, useFallbacks); if (status == B_OK) { fLink.StartMessage(B_OK); fLink.Attach(hasArray, numChars * sizeof(bool)); diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 182e526134..566c682007 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -692,8 +692,8 @@ ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock) status_t -ServerFont::GetHasGlyphs(const char* string, int32 numBytes, int32 numChars, - bool* hasArray) const +ServerFont::GetHasGlyphs(const char* string, int32 numBytes, int32 numChars, bool* hasArray, + bool useFallbacks) const { if (string == NULL || numBytes <= 0 || numChars <= 0 || hasArray == NULL) return B_BAD_DATA; @@ -714,7 +714,7 @@ ServerFont::GetHasGlyphs(const char* string, int32 numBytes, int32 numChars, while (charIndex < numChars && (charCode = UTF8ToCharCode(&string)) != 0) { hasArray[charIndex] = entry->CanCreateGlyph(charCode); - if (hasArray[charIndex] == false) { + if (hasArray[charIndex] == false && useFallbacks) { if (fallbacks.IsEmpty()) GlyphLayoutEngine::PopulateFallbacks(fallbacks, *this, false); diff --git a/src/servers/app/ServerFont.h b/src/servers/app/ServerFont.h index 0d36e79eb1..f02dd2869b 100644 --- a/src/servers/app/ServerFont.h +++ b/src/servers/app/ServerFont.h @@ -123,7 +123,7 @@ class ServerFont { status_t GetHasGlyphs(const char charArray[], int32 numBytes, int32 numChars, - bool hasArray[]) const; + bool hasArray[], bool useFallbacks) const; status_t GetEdges(const char charArray[], int32 numBytes, int32 numChars, edge_info edgeArray[])