Add Unicode fonts on Windows for CJK

This commit is contained in:
David Capello 2017-03-07 14:53:40 -03:00
parent e83f9c18aa
commit 147a8eb194
4 changed files with 45 additions and 17 deletions

View File

@ -8,19 +8,41 @@
<font name="Arial Unicode"
type="truetype"
file_win="ARIALUNI.TTF"
file_win="arialuni.ttf"
file_mac="Arial Unicode.ttf" />
<font name="Unicode Korean"
type="truetype"
file_win="malgun.ttf">
<fallback font="Arial Unicode" />
</font>
<font name="Unicode Chinese"
type="truetype"
file_win="msjh.ttc">
<fallback font="Unicode Korean" size="8" />
</font>
<font name="Unicode Japanese"
type="truetype"
file_win="YuGothR.ttc">
<fallback font="Unicode Chinese" size="8" />
</font>
<font name="Unicode"
type="truetype"
file="Arial.ttf"
file_mac="Arial Unicode.ttf">
<fallback font="Unicode Japanese" size="8" />
</font>
<font name="Aseprite"
type="spritesheet"
file="aseprite_font.png">
<fallback font="Arial Unicode" size="8" />
<fallback font="Unicode" size="8" />
</font>
<font name="Aseprite Mini"
type="spritesheet"
file="aseprite_mini.png">
<fallback font="Arial Unicode" size="6" />
<fallback font="Unicode" size="6" />
</font>
</fonts>

View File

@ -28,7 +28,8 @@ FontData::~FontData()
{
// Destroy all fonts
for (auto& it : m_fonts)
it.second->dispose();
if (it.second)
it.second->dispose();
}
she::Font* FontData::getFont(int size)
@ -53,9 +54,14 @@ she::Font* FontData::getFont(int size)
break;
}
if (font && m_fallback)
font->setFallback(m_fallback->getFont(m_fallbackSize));
if (m_fallback) {
she::Font* fallback = m_fallback->getFont(m_fallbackSize);
if (font)
font->setFallback(fallback);
else
font = fallback;
}
return m_fonts[size] = font;
}

View File

@ -156,15 +156,15 @@ static FontData* load_font(std::map<std::string, FontData*>& fonts,
if (fileStr && fontFilename.empty())
fontFilename = app::find_font(fileStr);
if (!fontFilename.empty()) {
font.reset(new FontData(she::FontType::kTrueType));
font->setFilename(fontFilename);
font->setAntialias(antialias);
}
else {
throw base::Exception("Invalid file for <font name=\"%s\" ...> in '%s'\n",
name.c_str(), xmlFilename.c_str());
}
// The filename can be empty if the font was not found, anyway we
// want to keep the font information (e.g. to use the fallback
// information of this font).
font.reset(new FontData(she::FontType::kTrueType));
font->setFilename(fontFilename);
font->setAntialias(antialias);
if (!fontFilename.empty())
LOG(VERBOSE) << "SKIN: Font file '" << fontFilename << "' not found\n";
}
else {
throw base::Exception("Invalid type=\"%s\" in '%s' for <font name=\"%s\" ...>\n",

View File

@ -20,7 +20,7 @@ namespace ft {
class HBFace : public FaceFT {
public:
HBFace(FT_Face face) : FaceFT(face) {
m_font = hb_ft_font_create((FT_Face)face, nullptr);
m_font = (face ? hb_ft_font_create((FT_Face)face, nullptr): nullptr);
m_buffer = hb_buffer_create();
}