mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 19:05:59 -04:00
Add two convenience functons for gllyph metrics retrieval
This commit is contained in:
parent
5fd7eea480
commit
c5554f5853
@ -135,6 +135,20 @@ void Font::GetGlyphMetrics(Uint16 ch, int& minx, int& maxx, int& miny, int& maxy
|
||||
throw Exception("TTF_GlyphMetrics failed");
|
||||
}
|
||||
|
||||
Rect Font::GetGlyphRect(Uint16 ch) const {
|
||||
int minx, maxx, miny, maxy;
|
||||
if (TTF_GlyphMetrics(font_, ch, &minx, &maxx, &miny, &maxy, nullptr) != 0)
|
||||
throw Exception("TTF_GlyphMetrics failed");
|
||||
return Rect(minx, miny, maxx - minx + 1, maxy - miny + 1);
|
||||
}
|
||||
|
||||
int Font::GetGlyphAdvance(Uint16 ch) const {
|
||||
int advance;
|
||||
if (TTF_GlyphMetrics(font_, ch, nullptr, nullptr, nullptr, nullptr, &advance) != 0)
|
||||
throw Exception("TTF_GlyphMetrics failed");
|
||||
return advance;
|
||||
}
|
||||
|
||||
Point Font::GetSizeText(const std::string& text) const {
|
||||
int w, h;
|
||||
if (TTF_SizeText(font_, text.c_str(), &w, &h) != 0)
|
||||
|
@ -407,6 +407,36 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
void GetGlyphMetrics(Uint16 ch, int& minx, int& maxx, int& miny, int& maxy, int& advance) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get rect part of glyph metrics of the UNICODE char
|
||||
///
|
||||
/// \param ch UNICODE char to get the glyph metrics for
|
||||
///
|
||||
/// \returns Rect representing glyph offset info
|
||||
///
|
||||
/// \throws SDL2pp::Exception
|
||||
///
|
||||
/// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC38
|
||||
/// \see http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect GetGlyphRect(Uint16 ch) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get advance part of glyph metrics of the UNICODE char
|
||||
///
|
||||
/// \param ch UNICODE char to get the glyph metrics for
|
||||
///
|
||||
/// \returns Advance offset into
|
||||
///
|
||||
/// \throws SDL2pp::Exception
|
||||
///
|
||||
/// \see https://www.libsdl.org/projects/SDL_ttf/docs/SDL_ttf.html#SEC38
|
||||
/// \see http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int GetGlyphAdvance(Uint16 ch) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Calculate the resulting surface size of the LATIN1 encoded text rendered using font
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user