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
|
@ -477,11 +477,22 @@ Texture2D* FontAtlas::getTexture(int slot)
|
||||||
return _atlasTextures[slot];
|
return _atlasTextures[slot];
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontAtlas::setLineHeight(float newHeight)
|
void FontAtlas::setLineHeight(float newHeight)
|
||||||
{
|
{
|
||||||
_lineHeight = 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()
|
void FontAtlas::setAliasTexParameters()
|
||||||
{
|
{
|
||||||
if (_antialiasEnabled)
|
if (_antialiasEnabled)
|
||||||
|
|
|
@ -84,6 +84,8 @@ public:
|
||||||
float getLineHeight() const { return _lineHeight; }
|
float getLineHeight() const { return _lineHeight; }
|
||||||
void setLineHeight(float newHeight);
|
void setLineHeight(float newHeight);
|
||||||
|
|
||||||
|
std::string getFontName() const;
|
||||||
|
|
||||||
Texture2D* getTexture(int slot);
|
Texture2D* getTexture(int slot);
|
||||||
const Font* getFont() const { return _font; }
|
const Font* getFont() const { return _font; }
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
|
|
||||||
int getFontAscender() const;
|
int getFontAscender() const;
|
||||||
const char* getFontFamily() const;
|
const char* getFontFamily() const;
|
||||||
|
std::string getFontName() const { return _fontName; }
|
||||||
|
|
||||||
virtual FontAtlas* createFontAtlas() override;
|
virtual FontAtlas* createFontAtlas() override;
|
||||||
virtual int getFontMaxHeight() const override { return _lineHeight; }
|
virtual int getFontMaxHeight() const override { return _lineHeight; }
|
||||||
|
|
|
@ -2084,7 +2084,11 @@ void Label::removeChild(Node* child, bool cleanup /* = true */)
|
||||||
FontDefinition Label::_getFontDefinition() const
|
FontDefinition Label::_getFontDefinition() const
|
||||||
{
|
{
|
||||||
FontDefinition systemFontDef;
|
FontDefinition systemFontDef;
|
||||||
systemFontDef._fontName = _systemFont;
|
|
||||||
|
std::string fontName = _systemFont;
|
||||||
|
if (_fontAtlas && !_fontAtlas->getFontName().empty()) fontName = _fontAtlas->getFontName();
|
||||||
|
|
||||||
|
systemFontDef._fontName = fontName;
|
||||||
systemFontDef._fontSize = _systemFontSize;
|
systemFontDef._fontSize = _systemFontSize;
|
||||||
systemFontDef._alignment = _hAlignment;
|
systemFontDef._alignment = _hAlignment;
|
||||||
systemFontDef._vertAlignment = _vAlignment;
|
systemFontDef._vertAlignment = _vAlignment;
|
||||||
|
|
Loading…
Reference in New Issue