* Add multilingual support for utf-8.
* Use japanese as a test case (removing the old tentative support).
* A number of shortcomings affect this code.
  + Bugs :
    - This splits algorithms used to determine the length of a string
      and to render it in two: either the string starts with an ascii
      char and the monobyte, variable-space algorithm is used, or it
      does not and a multibyte but fixed-space algorithm is used.
      This shortcoming also exists in the code to support chinese.
    - From the above comes the biggest limitation: any string that
      starts with an ascii character but include non-ascii characters
      will not be rendered correctly.
    - This does not and cannot support chars outside the BMP. This
      probably won't matter, ever.
  + Todos, fixmes, wishlist :
    - Single-width characters with diacritics are reported as
      double-space chars. It doesn't matter too much at the moment, but
      should be fixed in the future.
    - Font support currently only includes japanese.
  + Performance and compatibility notes :
    - Chinese code has not been switched to utf-8, to maintain backward
      compatibility. We should switch it at some point in the future,
      but ponder the right way to do it first.
    - Retaining the support for chinese with a non-international
      charset hurts performance (by making some methods uselessly
      virtual).
* Still, this generally works and is extensible (it can be used to
  implement korean, traditional chinese, etc, without any more code).
  Implementing languages with diacritics needs an improvement of the
  bool doubleWidthChar() method.
This commit is contained in:
jean.chalard
2010-11-14 16:24:29 +00:00
parent 3cedeb4d85
commit 1317eb0d29
12 changed files with 1521 additions and 1130 deletions

View File

@@ -24,7 +24,7 @@ namespace
{
const std::string kExtension_png(".png");
const std::string kExtension_gbk(".gbk");
const std::string kExtension_sjis(".sjis");
const std::string kExtension_font(".font");
}
int WResourceManager::RetrieveError(){
@@ -861,7 +861,7 @@ void WResourceManager::InitFonts(const std::string& inLang)
if (inLang.compare("jp") == 0)
{
mFontFileExtension = kExtension_sjis;
mFontFileExtension = kExtension_font;
LoadWFont("simon", 12, Fonts::MAIN_FONT);
LoadWFont("f3", 16, Fonts::MENU_FONT);
LoadWFont("magic", 16, Fonts::MAGIC_FONT);
@@ -899,21 +899,15 @@ WFont* WResourceManager::LoadWFont(const string& inFontname, int inFontHeight, i
string mFontName = inFontname + mFontFileExtension;
string path = graphicsFile(mFontName);
if (mFontFileExtension == kExtension_gbk)
{
if (mFontFileExtension == kExtension_font)
font = NEW WUFont(inFontID, path.c_str(), inFontHeight, true);
else if (mFontFileExtension == kExtension_gbk)
font = NEW WGBKFont(inFontID, path.c_str(), inFontHeight, true);
}
else if (mFontFileExtension == kExtension_sjis)
{
font = NEW WSJISFont(inFontID, path.c_str(), inFontHeight, true);
}
else
{
font = NEW WLBFont(inFontID, path.c_str(), inFontHeight, true);
}
mWFontMap[inFontID] = font;
return font;
}