diff --git a/SDL2pp/Font.cc b/SDL2pp/Font.cc index 1882b15..de545c8 100644 --- a/SDL2pp/Font.cc +++ b/SDL2pp/Font.cc @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include @@ -178,6 +180,12 @@ Point Font::GetSizeUNICODE(const Uint16* text) const { return Point(w, h); } +Point Font::GetSizeUNICODE(const std::u16string& text) const { + std::vector uint16_text(text.length() + 1); + std::copy(text.begin(), text.end(), uint16_text.begin()); + return GetSizeUNICODE(uint16_text.data()); +} + Surface Font::RenderText_Solid(const std::string& text, SDL_Color fg) { SDL_Surface* surface = TTF_RenderText_Solid(font_, text.c_str(), fg); if (surface == nullptr) @@ -199,6 +207,12 @@ Surface Font::RenderUNICODE_Solid(const Uint16* text, SDL_Color fg) { return Surface(surface); } +Surface Font::RenderUNICODE_Solid(const std::u16string& text, SDL_Color fg) { + std::vector uint16_text(text.length() + 1); + std::copy(text.begin(), text.end(), uint16_text.begin()); + return Font::RenderUNICODE_Solid(uint16_text.data(), fg); +} + Surface Font::RenderGlyph_Solid(Uint16 ch, SDL_Color fg) { SDL_Surface* surface = TTF_RenderGlyph_Solid(font_, ch, fg); if (surface == nullptr) @@ -227,6 +241,12 @@ Surface Font::RenderUNICODE_Shaded(const Uint16* text, SDL_Color fg, SDL_Color b return Surface(surface); } +Surface Font::RenderUNICODE_Shaded(const std::u16string& text, SDL_Color fg, SDL_Color bg) { + std::vector uint16_text(text.length() + 1); + std::copy(text.begin(), text.end(), uint16_text.begin()); + return Font::RenderUNICODE_Shaded(uint16_text.data(), fg, bg); +} + Surface Font::RenderGlyph_Shaded(Uint16 ch, SDL_Color fg, SDL_Color bg) { SDL_Surface* surface = TTF_RenderGlyph_Shaded(font_, ch, fg, bg); if (surface == nullptr) @@ -255,6 +275,12 @@ Surface Font::RenderUNICODE_Blended(const Uint16* text, SDL_Color fg) { return Surface(surface); } +Surface Font::RenderUNICODE_Blended(const std::u16string& text, SDL_Color fg) { + std::vector uint16_text(text.length() + 1); + std::copy(text.begin(), text.end(), uint16_text.begin()); + return Font::RenderUNICODE_Blended(uint16_text.data(), fg); +} + Surface Font::RenderGlyph_Blended(Uint16 ch, SDL_Color fg) { SDL_Surface* surface = TTF_RenderGlyph_Blended(font_, ch, fg); if (surface == nullptr) diff --git a/SDL2pp/Font.hh b/SDL2pp/Font.hh index b7e7b1e..0ebb48a 100644 --- a/SDL2pp/Font.hh +++ b/SDL2pp/Font.hh @@ -518,6 +518,24 @@ public: //////////////////////////////////////////////////////////// Point GetSizeUNICODE(const Uint16* text) const; + //////////////////////////////////////////////////////////// + /// \brief Calculate the resulting surface size of the UNICODE encoded text rendered using font + /// + /// \param[in] text UNICODE null terminated string to size up + /// + /// \returns Point representing dimensions of the rendered text + /// + /// \throws SDL2pp::Exception + /// + /// No actual rendering is done, however correct kerning is done + /// to get the actual width. The height returned in h is the same + /// as you can get using GetHeight() + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC41 + /// + //////////////////////////////////////////////////////////// + Point GetSizeUNICODE(const std::u16string& text) const; + //////////////////////////////////////////////////////////// /// \brief Render LATIN1 text using solid mode /// @@ -563,6 +581,21 @@ public: //////////////////////////////////////////////////////////// Surface RenderUNICODE_Solid(const Uint16* text, SDL_Color fg); + //////////////////////////////////////////////////////////// + /// \brief Render UNICODE encoded text using solid mode + /// + /// \param[in] text UNICODE encoded string to render + /// \param[in] fg Color to render the text in + /// + /// \returns Surface containing rendered text + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC45 + /// + //////////////////////////////////////////////////////////// + Surface RenderUNICODE_Solid(const std::u16string& text, SDL_Color fg); + //////////////////////////////////////////////////////////// /// \brief Render the glyph for UNICODE character using solid mode /// @@ -626,6 +659,22 @@ public: //////////////////////////////////////////////////////////// Surface RenderUNICODE_Shaded(const Uint16* text, SDL_Color fg, SDL_Color bg); + //////////////////////////////////////////////////////////// + /// \brief Render UNICODE encoded text using shaded mode + /// + /// \param[in] text UNICODE encoded string to render + /// \param[in] fg Color to render the text in + /// \param[in] bg Color to render the background box in + /// + /// \returns Surface containing rendered text + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC49 + /// + //////////////////////////////////////////////////////////// + Surface RenderUNICODE_Shaded(const std::u16string& text, SDL_Color fg, SDL_Color bg); + //////////////////////////////////////////////////////////// /// \brief Render the glyph for UNICODE character using shaded mode /// @@ -687,6 +736,21 @@ public: //////////////////////////////////////////////////////////// Surface RenderUNICODE_Blended(const Uint16* text, SDL_Color fg); + //////////////////////////////////////////////////////////// + /// \brief Render UNICODE encoded text using blended mode + /// + /// \param[in] text UNICODE encoded string to render + /// \param[in] fg Color to render the text in + /// + /// \returns Surface containing rendered text + /// + /// \throws SDL2pp::Exception + /// + /// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC53 + /// + //////////////////////////////////////////////////////////// + Surface RenderUNICODE_Blended(const std::u16string& text, SDL_Color fg); + //////////////////////////////////////////////////////////// /// \brief Render the glyph for UNICODE character using blended mode ///