- client/CMessage.cpp
in function CMessage::breakText(), line 153
// added by [email protected], 2013-08-28 // If the text[z] is less than 0, it is the first byte of a UTF8 Chinese word.#ifdef ZH_CN else if (text[z] < 0){ z++; z++; lineLength += graphics->fonts[font]->getSymbolWidth(text[z]); }#endif
- client/gui/Fonts.cpp
in function CTrueTypeFont::getStringWidth(), line 255
// added by [email protected], 2013-08-28 // If we are handling simplified chinese, it is a UTF8 string#ifdef ZH_CN TTF_SizeUTF8(font.get(), data.c_str(), &width, NULL);#else TTF_SizeText(font.get(), data.c_str(), &width, NULL);#endif
in function CTrueTypeFont::renderText(), line 279
if (blended) // added by [email protected], 2013-09-28 Sat // If we are handling simplified chinese game data, it is a UTF8 string#ifdef ZH_CN rendered = TTF_RenderUTF8_Blended(font.get(), data.c_str(), color);#else rendered = TTF_RenderText_Blended(font.get(), data.c_str(), color);#endif else // added by [email protected], 2013-09-28 Sat // If we are handling simplified chinese game data, it is a UTF8 string#ifdef ZH_CN rendered = TTF_RenderUTF8_Solid(font.get(), data.c_str(), color);#else rendered = TTF_RenderText_Solid(font.get(), data.c_str(), color);#endif
- add lib/ConvertEncoding.cpp and lib/ConvertEncoding.h
The content of ConvertEncoding.h is:
char * convert_enc(char *src_enc, char *dest_enc, const char * src_string);
The content of ConvertEncoding.cpp is:
/* * ConvertEncoding.cpp, for vcmi using CJK(China/Japan/Korea) data. * * Authors: Wu Jiqing ([email protected]) * * License: GNU General Public License v2.0 or later * */// added by jiqingwu([email protected])// 2013-09-27 Fri#include <stdio.h>#include <iconv.h>#include <string.h>// added by [email protected], 2013-09-27 Frichar * convert_enc(char *src_enc, char *dest_enc, const char * src_string){#define UTF8_STR_LEN 5000 static char out_string[UTF8_STR_LEN], *sin, *sout; int in_len, out_len, ret; iconv_t c_pt; if ((c_pt = iconv_open(dest_enc, src_enc)) == (iconv_t)-1) { printf("iconv open failed!\n"); return NULL; } // iconv(c_pt, NULL, NULL, NULL, NULL); in_len = strlen(src_string) + 1; out_len = UTF8_STR_LEN; sin = (char *)src_string; sout = out_string; ret = iconv(c_pt, &sin, (size_t *)&in_len, &sout, (size_t *)&out_len); if (ret == -1) { return NULL; } iconv_close(c_pt); return out_string;}
to link ConvertEncoding.o into library, add two lines into lib/CMakeLists.txt:
set(lib_SRCS ... ConvertEncoding.cpp)set(lib_HEADERS ... ConvertEncoding.h)
- lib/CGeneralTextHandler.cpp,
To include "ConvertEncoding.h"
// added by jiqingwu([email protected])// 2013-09-27 Fri#include "ConvertEncoding.h"
in function CLegacyConfigParser::readString(), line 112
// added by [email protected], 2013-09-27 Fri // convert gbk string to utf-8 string. // (For simplified Chinese game data, the string is GBK encoded)#ifdef ZH_CN char * utf8_str = convert_enc("GBK", "UTF8", ret.c_str()); return std::string((const char*)utf8_str);#else return ret;#endif
- lib/filesystem/CBinaryReader.cpp,
to include "ConvertEncoding.h":
// added by <[email protected]>, 2013-09-28 Sat#include "../ConvertEncoding.h"
in function CBinaryReader::readString(), line 95
// added by [email protected], 2013-08-22 // If we are handling chinese data, convert gbk string to utf-8 string.#ifdef ZH_CN char * utf8_str = convert_enc("GBK", "UTF8", ret.c_str()); return std::string((const char*)utf8_str);#else return ret;#endif
- add such a line into ./CMakeLists.txt to enable supporting Simplifed Chinese Game Data
add_definitions(-DZH_CN)
- make a directory
build under the source dir
mkdir build
- create makefiles
cd buildcmake ..
This may take a short while.
- compile
make
- install (root privilege is needed)
make install
Check the directories of vcmi
vcmiclient -v
You will see the result like this:
Starting... VCMI 0.93 data directory: /usr/local/share/vcmi library directory: /usr/local/lib/vcmi path to server: /usr/local/bin/vcmiserver
Here, vcmi is installed under /usr/local
- Use the Data from the chinese version of Death of Shadow. Link the ‘Data‘, ‘Maps‘, ‘Mp3‘ directories under
/usr/local/share/vcmi like this (You need have root privilege):
cd /usr/local/share/vcmiln -s /Data/Dir/of/ChineseGame Dataln -s /Maps/Dir/of/ChineseGame Mapsln -s /Mp3/Dir/of/ChineseGame Mp3
- To show chinese characters in this game, you need put a true type font which supports Chinese into
/usr/local/share/vcmi/Data.
cp /chinese/font/path /usr/local/share/vcmi/Data
Edit the /usr/local/share/vcmi/config/fonts.json, modify the truetype font section like this:
"trueType":{ "BIGFONT" : { "file" : "ChineseFont.ttf", "size" : 22, "blend" : true}, "CALLI10R" : { "file" : "ChineseFont.ttf", "size" : 10, "blend" : true}, "CREDITS" : { "file" : "ChineseFont.ttf", "size" : 28, "blend" : true}, "HISCORE" : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true}, "MEDFONT" : { "file" : "ChineseFont.ttf", "size" : 16, "blend" : true}, "SMALFONT" : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true}, "TIMES08R" : { "file" : "ChineseFont.ttf", "size" : 11, "blend" : true}, "TINY" : { "file" : "ChineseFont.ttf", "size" : 11, "blend" : true}, "VERD10B" : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true}}
Where ChineseFont.ttf is your true type font.
- Play Game
vcmiclient