mirror of https://github.com/axmolengine/axmol.git
Merge pull request #12774 from WenhaiLin/v3-label-createfail
Label:Fixed create fail if the font(TTF) not contain a Unicode charmap.
This commit is contained in:
commit
c151ba89e5
|
@ -137,9 +137,28 @@ bool FontFreeType::createFontObject(const std::string &fontName, int fontSize)
|
|||
if (FT_New_Memory_Face(getFTLibrary(), s_cacheFontData[fontName].data.getBytes(), s_cacheFontData[fontName].data.getSize(), 0, &face ))
|
||||
return false;
|
||||
|
||||
//we want to use unicode
|
||||
if (FT_Select_Charmap(face, FT_ENCODING_UNICODE))
|
||||
return false;
|
||||
{
|
||||
int foundIndex = -1;
|
||||
for (int charmapIndex = 0; charmapIndex < face->num_charmaps; charmapIndex++)
|
||||
{
|
||||
if (face->charmaps[charmapIndex]->encoding != FT_ENCODING_NONE)
|
||||
{
|
||||
foundIndex = charmapIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundIndex == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (FT_Select_Charmap(face, face->charmaps[foundIndex]->encoding))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// set the requested font size
|
||||
int dpi = 72;
|
||||
|
|
|
@ -481,6 +481,7 @@ void Label::setFontAtlas(FontAtlas* atlas,bool distanceFieldEnabled /* = false *
|
|||
|
||||
if (_fontAtlas)
|
||||
{
|
||||
_batchNodes.clear();
|
||||
FontAtlasCache::releaseFontAtlas(_fontAtlas);
|
||||
_fontAtlas = nullptr;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ NewLabelTests::NewLabelTests()
|
|||
ADD_TEST_CASE(LabelIssue12259Test);
|
||||
ADD_TEST_CASE(LabelIssue12409Test);
|
||||
ADD_TEST_CASE(LabelAddChildTest);
|
||||
ADD_TEST_CASE(LabelIssue12775Test);
|
||||
};
|
||||
|
||||
LabelTTFAlignmentNew::LabelTTFAlignmentNew()
|
||||
|
@ -2035,3 +2036,22 @@ std::string LabelAddChildTest::title() const
|
|||
{
|
||||
return "Label support add child nodes";
|
||||
}
|
||||
|
||||
LabelIssue12775Test::LabelIssue12775Test()
|
||||
{
|
||||
auto center = VisibleRect::center();
|
||||
|
||||
auto label = Label::createWithTTF("Hello", "fonts/xingkai-incomplete.ttf", 30);
|
||||
label->setPosition(center.x, center.y);
|
||||
addChild(label);
|
||||
}
|
||||
|
||||
std::string LabelIssue12775Test::title() const
|
||||
{
|
||||
return "Test for Issue #12775";
|
||||
}
|
||||
|
||||
std::string LabelIssue12775Test::subtitle() const
|
||||
{
|
||||
return "Should not crash if the font not contain a Unicode charmap.";
|
||||
}
|
||||
|
|
|
@ -619,4 +619,15 @@ public:
|
|||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class LabelIssue12775Test : public AtlasDemoNew
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(LabelIssue12775Test);
|
||||
|
||||
LabelIssue12775Test();
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue