From 43187455e407258cc4c304064777c59ceb0d13ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=B1=E9=A2=A8=E8=B0=B7=E6=97=A9=E8=8B=97=20=28?= =?UTF-8?q?=E3=81=93=E3=81=A1=E3=82=84=E3=81=95=E3=81=AA=E3=81=88=29?= Date: Wed, 26 Feb 2020 18:55:09 +0800 Subject: [PATCH] Added Font::hasGlyph() --- include/SFML/Graphics/Font.hpp | 22 ++++++++++++++++++++++ src/SFML/Graphics/Font.cpp | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index 49a9f8632..2e57c9b76 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -166,6 +166,10 @@ public: /// might be available. If the glyph is not available at the /// requested size, an empty glyph is returned. /// + /// You may want to use \ref hasGlyph to determine if the + /// glyph exists before requesting it. If the glyph does not + /// exist, a font specific default is returned. + /// /// Be aware that using a negative value for the outline /// thickness will cause distorted rendering. /// @@ -179,6 +183,24 @@ public: //////////////////////////////////////////////////////////// const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness = 0) const; + //////////////////////////////////////////////////////////// + /// \brief Determine if this font has a glyph representing the requested code point + /// + /// Most fonts only include a very limited selection of glyphs from + /// specific Unicode subsets, like Latin, Cyrillic, or Asian characters. + /// + /// While code points without representation will return a font specific + /// default character, it might be useful to verify whether specific + /// code points are included to determine whether a font is suited + /// to display text in a specific language. + /// + /// \param codePoint Unicode code point to check + /// + /// \return True if the codepoint has a glyph representation, false otherwise + /// + //////////////////////////////////////////////////////////// + bool hasGlyph(Uint32 codePoint) const; + //////////////////////////////////////////////////////////// /// \brief Get the kerning offset of two glyphs /// diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 4576987c1..e5616ffe7 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -365,6 +365,13 @@ const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool b } +//////////////////////////////////////////////////////////// +bool Font::hasGlyph(Uint32 codePoint) const +{ + return FT_Get_Char_Index(static_cast(m_face), codePoint) != 0; +} + + //////////////////////////////////////////////////////////// float Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) const {