mirror of https://github.com/axmolengine/axmol.git
CCLabel: fix fontName attribute (#19095)
* add method for FontAtlas * break empty font * reduce string constrution
This commit is contained in:
parent
7770234367
commit
d63f554bf2
|
@ -482,6 +482,17 @@ void FontAtlas::setLineHeight(float newHeight)
|
|||
_lineHeight = newHeight;
|
||||
}
|
||||
|
||||
std::string FontAtlas::getFontName() const
|
||||
{
|
||||
std::string fontName = _fontFreeType ? _fontFreeType->getFontName() : "";
|
||||
if(fontName.empty()) return fontName;
|
||||
auto idx = fontName.rfind("/");
|
||||
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
|
||||
idx = fontName.rfind("\\");
|
||||
if (idx != std::string::npos) { return fontName.substr(idx + 1); }
|
||||
return fontName;
|
||||
}
|
||||
|
||||
void FontAtlas::setAliasTexParameters()
|
||||
{
|
||||
if (_antialiasEnabled)
|
||||
|
|
|
@ -84,6 +84,8 @@ public:
|
|||
float getLineHeight() const { return _lineHeight; }
|
||||
void setLineHeight(float newHeight);
|
||||
|
||||
std::string getFontName() const;
|
||||
|
||||
Texture2D* getTexture(int slot);
|
||||
const Font* getFont() const { return _font; }
|
||||
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
|
||||
int getFontAscender() const;
|
||||
const char* getFontFamily() const;
|
||||
std::string getFontName() const { return _fontName; }
|
||||
|
||||
virtual FontAtlas* createFontAtlas() override;
|
||||
virtual int getFontMaxHeight() const override { return _lineHeight; }
|
||||
|
|
|
@ -2084,7 +2084,11 @@ void Label::removeChild(Node* child, bool cleanup /* = true */)
|
|||
FontDefinition Label::_getFontDefinition() const
|
||||
{
|
||||
FontDefinition systemFontDef;
|
||||
systemFontDef._fontName = _systemFont;
|
||||
|
||||
std::string fontName = _systemFont;
|
||||
if (_fontAtlas && !_fontAtlas->getFontName().empty()) fontName = _fontAtlas->getFontName();
|
||||
|
||||
systemFontDef._fontName = fontName;
|
||||
systemFontDef._fontSize = _systemFontSize;
|
||||
systemFontDef._alignment = _hAlignment;
|
||||
systemFontDef._vertAlignment = _vAlignment;
|
||||
|
|
Loading…
Reference in New Issue