From bf0f6b8b6d15cc66a255f8cfd4cba3fe8582c8fb Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Tue, 6 Jun 2017 13:24:43 +0800 Subject: [PATCH] Add more functions to class Font --- MiniEngine.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ MiniEngine.h | 18 ++++++++++ 2 files changed, 109 insertions(+) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index dccbaae..2a2cf6a 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -1535,6 +1535,97 @@ namespace MiniEngine return _internal::getFontStyleVecFromMixedTTFFontStyle(styles); } + int Font::getFontHeight() const + { + return TTF_FontHeight(_get()); + } + + int Font::getFontAscent() const + { + return TTF_FontAscent(_get()); + } + + int Font::getFontDescent() const + { + return TTF_FontDescent(_get()); + } + + int Font::getFontLineSkip() const + { + return TTF_FontLineSkip(_get()); + } + + bool Font::isFontKerning() const + { + return (TTF_GetFontKerning(_get())!=0); + } + + void Font::setFontKerning(bool enableKerning) + { + TTF_SetFontKerning(_get(),enableKerning?1:0); + } + + long Font::getFontFaceNum() const + { + return TTF_FontFaces(_get()); + } + + int Font::getFontFaceIsFixedWidth() const + { + return TTF_FontFaceIsFixedWidth(_get()); + } + + std::string Font::getFontFaceFamilyName() const + { + return std::string(TTF_FontFaceFamilyName(_get())); + } + + std::string Font::getFontFaceStyleName() const + { + return std::string(TTF_FontFaceStyleName(_get())); + } + + FontHint Font::getFontHint() const + { + switch(TTF_GetFontHinting(_get())) + { + case TTF_HINTING_NORMAL: + return FontHint::Normal; + case TTF_HINTING_LIGHT: + return FontHint::Light; + case TTF_HINTING_MONO: + return FontHint::Mono; + case TTF_HINTING_NONE: + return FontHint::None; + } + /// Return Error on default. + return FontHint::Error; + } + + void Font::setFontHint(FontHint hint) + { + int v=0; + switch(hint) + { + case FontHint::Normal: + v=TTF_HINTING_NORMAL; + break; + case FontHint::Light: + v=TTF_HINTING_LIGHT; + break; + case FontHint::Mono: + v=TTF_HINTING_MONO; + break; + case FontHint::None: + v=TTF_HINTING_NONE; + break; + case FontHint::Error: + /// No Action on FontHint::Error. + return; + } + TTF_SetFontHinting(_get(),v); + } + Rect Font::sizeText(const std::string& Text) const throw (ErrorViewer) { int w=0,h=0; diff --git a/MiniEngine.h b/MiniEngine.h index 83a7ae7..3ab9fe6 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -394,6 +394,7 @@ namespace MiniEngine }; enum class FontStyle { Normal, Bold, Italic, UnderLine, StrikeThrough }; + enum class FontHint { Normal, Light, Mono, None , Error }; class Font { @@ -430,6 +431,23 @@ namespace MiniEngine std::vector getFontStyles() const; + int getFontHeight() const; + int getFontAscent() const; + int getFontDescent() const; + int getFontLineSkip() const; + + bool isFontKerning() const; + void setFontKerning(bool enableKerning); + + long getFontFaceNum() const; + int getFontFaceIsFixedWidth() const; + std::string getFontFaceFamilyName() const; + std::string getFontFaceStyleName() const; + + FontHint getFontHint() const; + void setFontHint(FontHint hint); + + Rect sizeText(const std::string& Text) const throw (ErrorViewer); Rect sizeUTF8(const std::string& Text) const throw (ErrorViewer); Rect sizeUnicode(const uint16_t* Text) const throw (ErrorViewer);