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" <font name="Arial Unicode"
type="truetype" type="truetype"
file_win="ARIALUNI.TTF" file_win="arialuni.ttf"
file_mac="Arial Unicode.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" <font name="Aseprite"
type="spritesheet" type="spritesheet"
file="aseprite_font.png"> file="aseprite_font.png">
<fallback font="Arial Unicode" size="8" /> <fallback font="Unicode" size="8" />
</font> </font>
<font name="Aseprite Mini" <font name="Aseprite Mini"
type="spritesheet" type="spritesheet"
file="aseprite_mini.png"> file="aseprite_mini.png">
<fallback font="Arial Unicode" size="6" /> <fallback font="Unicode" size="6" />
</font> </font>
</fonts> </fonts>

View File

@ -28,6 +28,7 @@ FontData::~FontData()
{ {
// Destroy all fonts // Destroy all fonts
for (auto& it : m_fonts) for (auto& it : m_fonts)
if (it.second)
it.second->dispose(); it.second->dispose();
} }
@ -53,8 +54,13 @@ she::Font* FontData::getFont(int size)
break; break;
} }
if (font && m_fallback) if (m_fallback) {
font->setFallback(m_fallback->getFont(m_fallbackSize)); she::Font* fallback = m_fallback->getFont(m_fallbackSize);
if (font)
font->setFallback(fallback);
else
font = fallback;
}
return m_fonts[size] = font; 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()) if (fileStr && fontFilename.empty())
fontFilename = app::find_font(fileStr); fontFilename = app::find_font(fileStr);
if (!fontFilename.empty()) { // 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.reset(new FontData(she::FontType::kTrueType));
font->setFilename(fontFilename); font->setFilename(fontFilename);
font->setAntialias(antialias); font->setAntialias(antialias);
}
else { if (!fontFilename.empty())
throw base::Exception("Invalid file for <font name=\"%s\" ...> in '%s'\n", LOG(VERBOSE) << "SKIN: Font file '" << fontFilename << "' not found\n";
name.c_str(), xmlFilename.c_str());
}
} }
else { else {
throw base::Exception("Invalid type=\"%s\" in '%s' for <font name=\"%s\" ...>\n", 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 { class HBFace : public FaceFT {
public: public:
HBFace(FT_Face face) : FaceFT(face) { 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(); m_buffer = hb_buffer_create();
} }