Fixed crash in font code, updated font loading code to allow splitting our huge XML file so that chinese can be in a separate file, switched to wqyMicroHei for chinese font (font not included in SVN because of size)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5808 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4ead096539
commit
e79025b041
Binary file not shown.
@ -54,6 +54,7 @@ ScalableFont::ScalableFont(IGUIEnvironment *env, const io::path& filename)
|
|||||||
|
|
||||||
setInvisibleCharacters ( L" " );
|
setInvisibleCharacters ( L" " );
|
||||||
|
|
||||||
|
// FIXME: need to delete the created XML reader?
|
||||||
load( file_manager->createXMLReader(filename.c_str()) );
|
load( file_manager->createXMLReader(filename.c_str()) );
|
||||||
assert(Areas.size() > 0);
|
assert(Areas.size() > 0);
|
||||||
}
|
}
|
||||||
@ -75,17 +76,26 @@ void ScalableFont::setShadow(irr::video::SColor col)
|
|||||||
m_shadow_color = col;
|
m_shadow_color = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! loads a font file from xml
|
void ScalableFont::doReadXmlFile(io::IXMLReader* xml)
|
||||||
bool ScalableFont::load(io::IXMLReader* xml)
|
|
||||||
{
|
{
|
||||||
if (!SpriteBank)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
while (xml->read())
|
while (xml->read())
|
||||||
{
|
{
|
||||||
if (io::EXN_ELEMENT == xml->getNodeType())
|
if (io::EXN_ELEMENT == xml->getNodeType())
|
||||||
{
|
{
|
||||||
if (core::stringw(L"Texture") == xml->getNodeName())
|
if (core::stringw(L"include") == xml->getNodeName())
|
||||||
|
{
|
||||||
|
core::stringc filename = xml->getAttributeValue(L"file");
|
||||||
|
// FIXME: need to delete the created XML reader?
|
||||||
|
io::IXMLReader* included = file_manager->createXMLReader(
|
||||||
|
file_manager->getFontFile(filename.c_str()));
|
||||||
|
printf("FONT: including '%s'\n", file_manager->getFontFile(filename.c_str()).c_str());
|
||||||
|
if (included == NULL) printf("Include not found :( :(\n");
|
||||||
|
if (included != NULL)
|
||||||
|
{
|
||||||
|
doReadXmlFile(included);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (core::stringw(L"Texture") == xml->getNodeName())
|
||||||
{
|
{
|
||||||
// add a texture
|
// add a texture
|
||||||
core::stringc filename = xml->getAttributeValue(L"filename");
|
core::stringc filename = xml->getAttributeValue(L"filename");
|
||||||
@ -197,6 +207,16 @@ bool ScalableFont::load(io::IXMLReader* xml)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//! loads a font file from xml
|
||||||
|
bool ScalableFont::load(io::IXMLReader* xml)
|
||||||
|
{
|
||||||
|
if (!SpriteBank)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
doReadXmlFile(xml);
|
||||||
|
|
||||||
// set bad character
|
// set bad character
|
||||||
WrongCharacter = getAreaIDFromCharacter(L' ', NULL);
|
WrongCharacter = getAreaIDFromCharacter(L' ', NULL);
|
||||||
|
|
||||||
@ -289,17 +309,18 @@ s32 ScalableFont::getAreaIDFromCharacter(const wchar_t c, bool* fallback_font) c
|
|||||||
if (n != CharacterMap.end())
|
if (n != CharacterMap.end())
|
||||||
{
|
{
|
||||||
if (fallback_font != NULL) *fallback_font = false;
|
if (fallback_font != NULL) *fallback_font = false;
|
||||||
|
// std::cout << "Character " << (int)c << " found in font\n";
|
||||||
return (*n).second;
|
return (*n).second;
|
||||||
}
|
}
|
||||||
else if (m_fallback_font != NULL && fallback_font != NULL)
|
else if (m_fallback_font != NULL && fallback_font != NULL)
|
||||||
{
|
{
|
||||||
//std::wcout << L"Font does not have this character : <" << c << L">, trying fallback font" << std::endl;
|
// std::cout << "Font does not have this character : <" << (int)c << ">, trying fallback font" << std::endl;
|
||||||
*fallback_font = true;
|
*fallback_font = true;
|
||||||
return m_fallback_font->getAreaIDFromCharacter(c, NULL);
|
return m_fallback_font->getAreaIDFromCharacter(c, NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//std::cout << "The font does not have this character : <" << (int)c << ">" << std::endl;
|
// std::cout << "The font does not have this character : <" << (int)c << ">" << std::endl;
|
||||||
if (fallback_font != NULL) *fallback_font = false;
|
if (fallback_font != NULL) *fallback_font = false;
|
||||||
return WrongCharacter;
|
return WrongCharacter;
|
||||||
}
|
}
|
||||||
@ -309,7 +330,8 @@ const ScalableFont::SFontArea &ScalableFont::getAreaFromCharacter(const wchar_t
|
|||||||
bool* fallback_font) const
|
bool* fallback_font) const
|
||||||
{
|
{
|
||||||
const int area_id = getAreaIDFromCharacter(c, fallback_font);
|
const int area_id = getAreaIDFromCharacter(c, fallback_font);
|
||||||
assert(area_id < (int)Areas.size());
|
|
||||||
|
|
||||||
if(m_mono_space_digits && ( (c>=L'0' && c<=L'9') || c==L' ' ) )
|
if(m_mono_space_digits && ( (c>=L'0' && c<=L'9') || c==L' ' ) )
|
||||||
{
|
{
|
||||||
const SFontArea &area = (fallback_font && *fallback_font)
|
const SFontArea &area = (fallback_font && *fallback_font)
|
||||||
@ -319,9 +341,19 @@ const ScalableFont::SFontArea &ScalableFont::getAreaFromCharacter(const wchar_t
|
|||||||
return m_max_digit_area;
|
return m_max_digit_area;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool use_fallback_font = (fallback_font && *fallback_font);
|
||||||
|
|
||||||
|
if (use_fallback_font)
|
||||||
|
{
|
||||||
|
assert(area_id < (int)m_fallback_font->Areas.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assert(area_id < (int)Areas.size());
|
||||||
|
}
|
||||||
|
|
||||||
// Note: fallback_font can be NULL
|
// Note: fallback_font can be NULL
|
||||||
return ( (fallback_font && *fallback_font) ? m_fallback_font->Areas[area_id]
|
return ( use_fallback_font ? m_fallback_font->Areas[area_id] : Areas[area_id]);
|
||||||
: Areas[area_id]);
|
|
||||||
} // getAreaFromCharacter
|
} // getAreaFromCharacter
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ class ScalableFont : public IGUIFontBitmap
|
|||||||
|
|
||||||
void lazyLoadTexture(int texID);
|
void lazyLoadTexture(int texID);
|
||||||
|
|
||||||
|
void doReadXmlFile(io::IXMLReader* xml);
|
||||||
|
|
||||||
bool m_is_hollow_copy;
|
bool m_is_hollow_copy;
|
||||||
bool m_rtl;
|
bool m_rtl;
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user