From ddd1be04ef7f786c9376cd5187d7c148267c65bd Mon Sep 17 00:00:00 2001 From: kichikuou Date: Sat, 4 Sep 2021 09:59:40 +0900 Subject: [PATCH] Map gaiji to Unicode Private Use Area U+E000-U+E0BB --- src/sys/ags_text.cpp | 14 ++++++++------ src/utfsjis.cpp | 12 ++++++++++-- src/utfsjis.h | 4 ++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sys/ags_text.cpp b/src/sys/ags_text.cpp index 3a895ab..43c23b4 100644 --- a/src/sys/ags_text.cpp +++ b/src/sys/ags_text.cpp @@ -57,26 +57,28 @@ void AGS::draw_text(const char* string, bool text_wait) if(is_2byte_message(c)) { code = (code << 8) | (uint8)string[p++]; } + if(draw_hankaku) { code = convert_hankaku(code); } else { code = convert_zenkaku(code); } + code = sjis_to_unicode(code); + // 文字出力 - if((0xeb9f <= code && code <= 0xebfc) || (0xec40 <= code && code <= 0xec9e)) { + if (GAIJI_FIRST <= code && code <= GAIJI_LAST) { // Use unadjusted dest_y here. draw_gaiji(screen, dest_x, draw_menu ? menu_dest_y : text_dest_y, code, font_size, font_color); dest_x += font_size; } else { - int unicode = sjis_to_unicode(code); if (!draw_menu) - texthook_character(nact->get_scenario_page(), unicode); + texthook_character(nact->get_scenario_page(), code); if (antialias) - draw_char_antialias(screen, dest_x, dest_y, unicode, font, font_color, antialias_cache); + draw_char_antialias(screen, dest_x, dest_y, code, font, font_color, antialias_cache); else - draw_char(screen, dest_x, dest_y, unicode, font, font_color); + draw_char(screen, dest_x, dest_y, code, font, font_color); int miny, maxy, advance; TTF_GlyphMetrics(font, code, NULL, NULL, &miny, &maxy, &advance); @@ -175,7 +177,7 @@ void AGS::draw_char_antialias(int dest, int dest_x, int dest_y, uint16 code, TTF void AGS::draw_gaiji(int dest, int dest_x, int dest_y, uint16 code, int size, uint8 color) { - int index = (0xeb9f <= code && code <= 0xebfc) ? code - 0xeb9f : (0xec40 <= code && code <= 0xec9e) ? code - 0xec40 + 94 : 0; + int index = code - GAIJI_FIRST; bool pattern[16][16]; // パターン取得 diff --git a/src/utfsjis.cpp b/src/utfsjis.cpp index d0bce1d..8da335b 100644 --- a/src/utfsjis.cpp +++ b/src/utfsjis.cpp @@ -21,10 +21,18 @@ int unicode_to_sjis(int u) { uint16 sjis_to_unicode(uint16 code) { + // ASCII characters. + if (code < 0x80) + return code; + // 1-byte kana characters. if (code >= 0xa0 && code <= 0xdf) return 0xff60 + code - 0xa0; - if (code < 0x100) - return code; + // Gaiji characters. + if (0xeb9f <= code && code <= 0xebfc) + return code - 0xeb9f + GAIJI_FIRST; + if (0xec40 <= code && code <= 0xec9e) + return code - 0xec40 + 94 + GAIJI_FIRST; + return s2u[(code >> 8) - 0x80][(code & 0xff) - 0x40]; } diff --git a/src/utfsjis.h b/src/utfsjis.h index e5c84ec..d640217 100644 --- a/src/utfsjis.h +++ b/src/utfsjis.h @@ -3,6 +3,10 @@ #include "common.h" +// Gaiji characters are mapped to Unicode Private Use Area U+E000-U+E0BB. +const int GAIJI_FIRST = 0xE000; +const int GAIJI_LAST = 0xE0BB; + uint16 sjis_to_unicode(uint16 code); char* sjis2utf(char* src); char* utf2sjis(char* src);