mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
COMMON: Support transcoding Traditional Chinese to Simplified
This commit is contained in:
1 parent
510d97dae8
commit
fb045768e3
2 files changed
+41
No files matched your search
@@ -102,6 +102,7 @@ static const uint16 *windows950ConversionTable = 0;
|
||||
static uint16 *windows950ReverseConversionTable = 0;
|
||||
static const uint16 *johabConversionTable = 0;
|
||||
static const uint16 *johabReverseConversionTable = 0;
|
||||
static const uint16 *traditional2SimplifiedChineseConversionTable = 0;
|
||||
|
||||
static const uint16 *loadCJKTable(File &f, int idx, size_t sz) {
|
||||
f.seek(16 + idx * 4);
|
||||
@@ -116,6 +117,23 @@ static const uint16 *loadCJKTable(File &f, int idx, size_t sz) {
|
||||
return res;
|
||||
}
|
||||
|
||||
static void loadChineseT2S(File &f) {
|
||||
f.seek(16 + 5 * 4);
|
||||
uint32 off = f.readUint32LE();
|
||||
f.seek(off);
|
||||
uint16 *res = new uint16[0x10000];
|
||||
for (uint i = 0; i < 0x10000; i++) {
|
||||
res[i] = i;
|
||||
}
|
||||
uint32 num_entries = f.readUint32LE();
|
||||
for (uint i = 0; i < num_entries; i++) {
|
||||
uint16 t = f.readUint16LE();
|
||||
uint16 s = f.readUint16LE();
|
||||
res[t] = s;
|
||||
}
|
||||
traditional2SimplifiedChineseConversionTable = res;
|
||||
}
|
||||
|
||||
static void loadCJKTables() {
|
||||
File f;
|
||||
|
||||
@@ -153,6 +171,8 @@ static void loadCJKTables() {
|
||||
johabConversionTable = loadCJKTable(f, 3, 80 * 188);
|
||||
if (num_tables >= 5)
|
||||
windows936ConversionTable = loadCJKTable(f, 4, 126 * 190);
|
||||
if (num_tables >= 6)
|
||||
loadChineseT2S(f);
|
||||
}
|
||||
|
||||
void releaseCJKTables() {
|
||||
@@ -1213,4 +1233,22 @@ StringEncodingResult U32String::encode(String &outString, CodePage page, char er
|
||||
return outString.encodeInternal(*this, page, errorChar);
|
||||
}
|
||||
|
||||
U32String U32String::transcodeChineseT2S() const {
|
||||
if (!cjk_tables_loaded)
|
||||
loadCJKTables();
|
||||
|
||||
if (!traditional2SimplifiedChineseConversionTable)
|
||||
return *this;
|
||||
|
||||
U32String simplified;
|
||||
for (uint32 i = 0; i < size(); i++) {
|
||||
uint32 ch = _str[i];
|
||||
if (ch >= 0x10000)
|
||||
simplified += ch;
|
||||
else
|
||||
simplified += traditional2SimplifiedChineseConversionTable[ch];
|
||||
}
|
||||
return simplified;
|
||||
}
|
||||
|
||||
} // End of namespace Common
|
||||
@@ -187,6 +187,9 @@ public:
|
||||
/** Transform a U32String into UTF-16 representation (native encoding). The result must be freed. */
|
||||
uint16 *encodeUTF16Native(uint *len = nullptr) const;
|
||||
|
||||
/** Transform Traditional Chinese string into Simplified. */
|
||||
U32String transcodeChineseT2S() const;
|
||||
|
||||
private:
|
||||
static U32String formatInternal(const U32String *fmt, ...);
|
||||
|
||||
|
||||
Reference in new issue
Block a user