From 8b2201590947b4e1685bd684c3bb5803b933f697 Mon Sep 17 00:00:00 2001 From: Wengier Date: Wed, 14 Jul 2021 22:09:40 -0400 Subject: [PATCH] support STDFONT.15 for dosv=tw --- CHANGELOG | 7 +-- .../installer/dosbox-x.reference.setup.conf | 6 ++- dosbox-x.reference.conf | 3 +- dosbox-x.reference.full.conf | 6 ++- src/dosbox.cpp | 6 ++- src/ints/int_dosv.cpp | 51 ++++++++++++++----- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 36287a274..6e768ba31 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,9 +22,10 @@ VGA fonts rather than 16-pixel VGA fonts for SBCS characters to look better. (Wengier) - You can now also load HZK14/HZK16 font files (for - 14- and 16-pixel height) via the "fontxdbcs" and - "fontxdbcs14" options for the Simplified Chinese - DOS/V (dosv=cn) emulation. (Wengier) + 14- and 16-pixel height) and STDFONT.15 font file + via the "fontxdbcs" and "fontxdbcs14" options for + Simplified Chinese DOS/V (dosv=cn) and Traditional + Chinese DOS/V (dosv=tw) emulations. (Wengier) - Improved the DOS/V font acquisition function on the Linux platform (both SDL1 & SDL2). A config option "getsysfont" is added which when set to diff --git a/contrib/windows/installer/dosbox-x.reference.setup.conf b/contrib/windows/installer/dosbox-x.reference.setup.conf index 2200f9391..a3882fc95 100644 --- a/contrib/windows/installer/dosbox-x.reference.setup.conf +++ b/contrib/windows/installer/dosbox-x.reference.setup.conf @@ -672,9 +672,11 @@ pc-98 anex86 font = #DOSBOX-X-ADV:# fontxsbcs16: FONTX2 file used to rendering SBCS characters (8x16) in DOS/V mode. #DOSBOX-X-ADV:# fontxsbcs24: FONTX2 file used to rendering SBCS characters (12x24) in DOS/V mode. # fontxdbcs: FONTX2 file used to rendering DBCS characters (16x16) in DOS/V or JEGA mode. If not specified, the default one will be used. -# Loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V. +# For Simplified Chinese DOS/V, loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported. +# For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported. #DOSBOX-X-ADV:# fontxdbcs14: FONTX2 file used to rendering SBCS characters (14x14) for the Configuration Tool. If not specified, the default one will be used. -#DOSBOX-X-ADV:# Loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V. +#DOSBOX-X-ADV:# For Simplified Chinese DOS/V, loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported. +#DOSBOX-X-ADV:# For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported. #DOSBOX-X-ADV:# fontxdbcs24: FONTX2 file used to rendering SBCS characters (24x24) in DOS/V mode. # gbk: Enables the GBK extension (in addition to the standard GB2312 charset) for the Simplified Chinese DOS/V emulation or TTF output. # yen: Enables the yen symbol (¥) at 5ch if it is found at 7fh in a custom SBCS font for the Japanese DOS/V or JEGA emulation. diff --git a/dosbox-x.reference.conf b/dosbox-x.reference.conf index 8fb199e7c..f0cc75628 100644 --- a/dosbox-x.reference.conf +++ b/dosbox-x.reference.conf @@ -309,7 +309,8 @@ pc-98 anex86 font = # getsysfont: If enabled, DOSBox-X will try to get and use the system fonts on Windows and Linux platforms for the DOS/V emulation. # fontxsbcs: FONTX2 file used to rendering SBCS characters (8x19) in DOS/V or JEGA mode. If not specified, the default one will be used. # fontxdbcs: FONTX2 file used to rendering DBCS characters (16x16) in DOS/V or JEGA mode. If not specified, the default one will be used. -# Loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V. +# For Simplified Chinese DOS/V, loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported. +# For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported. # gbk: Enables the GBK extension (in addition to the standard GB2312 charset) for the Simplified Chinese DOS/V emulation or TTF output. # yen: Enables the yen symbol (¥) at 5ch if it is found at 7fh in a custom SBCS font for the Japanese DOS/V or JEGA emulation. # fepcontrol: FEP control API for the DOS/V emulation. diff --git a/dosbox-x.reference.full.conf b/dosbox-x.reference.full.conf index 3eed884ea..a2521f73d 100644 --- a/dosbox-x.reference.full.conf +++ b/dosbox-x.reference.full.conf @@ -652,9 +652,11 @@ pc-98 show graphics layer on initialize = true # fontxsbcs16: FONTX2 file used to rendering SBCS characters (8x16) in DOS/V mode. # fontxsbcs24: FONTX2 file used to rendering SBCS characters (12x24) in DOS/V mode. # fontxdbcs: FONTX2 file used to rendering DBCS characters (16x16) in DOS/V or JEGA mode. If not specified, the default one will be used. -# Loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V. +# For Simplified Chinese DOS/V, loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported. +# For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported. # fontxdbcs14: FONTX2 file used to rendering SBCS characters (14x14) for the Configuration Tool. If not specified, the default one will be used. -# Loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V. +# For Simplified Chinese DOS/V, loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported. +# For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported. # fontxdbcs24: FONTX2 file used to rendering SBCS characters (24x24) in DOS/V mode. # gbk: Enables the GBK extension (in addition to the standard GB2312 charset) for the Simplified Chinese DOS/V emulation or TTF output. # yen: Enables the yen symbol (¥) at 5ch if it is found at 7fh in a custom SBCS font for the Japanese DOS/V or JEGA emulation. diff --git a/src/dosbox.cpp b/src/dosbox.cpp index d1ad9b12e..05fe6c087 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -2049,12 +2049,14 @@ void DOSBOX_SetupConfigSections(void) { Pstring = secprop->Add_path("fontxdbcs",Property::Changeable::OnlyAtStart,""); Pstring->Set_help("FONTX2 file used to rendering DBCS characters (16x16) in DOS/V or JEGA mode. If not specified, the default one will be used.\n" - "Loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V."); + "For Simplified Chinese DOS/V, loading the HZK16 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported.\n" + "For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported."); Pstring->SetBasic(true); Pstring = secprop->Add_path("fontxdbcs14",Property::Changeable::OnlyAtStart,""); Pstring->Set_help("FONTX2 file used to rendering SBCS characters (14x14) for the Configuration Tool. If not specified, the default one will be used.\n" - "Loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported for Simplified Chinese DOS/V."); + "For Simplified Chinese DOS/V, loading the HZK14 font file (https://github.com/aguegu/BitmapFont/tree/master/font) is also supported.\n" + "For Traditional Chinese DOS/V, loading the STDFONT.15 font file from the ETen Chinese DOS system is also supported."); Pstring = secprop->Add_path("fontxdbcs24",Property::Changeable::OnlyAtStart,""); Pstring->Set_help("FONTX2 file used to rendering SBCS characters (24x24) in DOS/V mode."); diff --git a/src/ints/int_dosv.cpp b/src/ints/int_dosv.cpp index e3ac7b94d..2a23f6f5d 100644 --- a/src/ints/int_dosv.cpp +++ b/src/ints/int_dosv.cpp @@ -190,16 +190,19 @@ static bool LoadFontxFile(const char *fname, int height = 16) { #endif } if (getfontx2header(mfile, &head) != 0) { - if (dos.loaded_codepage == 936) { + long int sz = 0; + if (dos.loaded_codepage == 936 || dos.loaded_codepage == 950) { fseek(mfile, 0L, SEEK_END); long int sz = ftell(mfile); rewind(mfile); if (height==14) { + if (!sz||(sz%14)&&(sz%15)) {fclose(mfile);return false;} fontdata14 = (uint8_t *)malloc(sizeof(uint8_t)*sz); if (!fontdata14) {fclose(mfile);return false;} fread(fontdata14, sizeof(uint8_t), sz, mfile); fontsize14 = sizeof(uint8_t)*sz; } else if (height==16) { + if (!sz||(sz%15)&&(sz%16)) {fclose(mfile);return false;} fontdata16 = (uint8_t *)malloc(sizeof(uint8_t)*sz); if (!fontdata16) {fclose(mfile);return false;} fread(fontdata16, sizeof(uint8_t), sz, mfile); @@ -481,12 +484,23 @@ uint8_t *GetDbcsFont(Bitu code) memcpy(&jfont_dbcs_16[code * 32], jfont_dbcs, 32); jfont_cache_dbcs_16[code] = 1; } else { - if (dos.loaded_codepage == 936 && (code/0x100)>0xa0 && (code/0x100)<0xff && fontdata16) { - int offset = (94 * (unsigned int)((code/0x100) - 0xa0 - 1) + ((code%0x100) - 0xa0 - 1)) * 32; - if (offset + 32 <= fontsize16) { - memcpy(&jfont_dbcs_16[code * 32], fontdata16+offset, 32); - jfont_cache_dbcs_16[code] = 1; - return &jfont_dbcs_16[code * 32]; + if (fontdata16) { + if (dos.loaded_codepage == 936 && !(fontsize16%16) && (code/0x100)>0xa0 && (code/0x100)<0xff) { + int offset = (94 * (unsigned int)((code/0x100) - 0xa0 - 1) + ((code%0x100) - 0xa0 - 1)) * 32; + if (offset + 32 <= fontsize16) { + memcpy(&jfont_dbcs_16[code * 32], fontdata16+offset, 32); + jfont_cache_dbcs_16[code] = 1; + return &jfont_dbcs_16[code * 32]; + } + } else if (dos.loaded_codepage == 950 && !(fontsize16%15) && isKanji1(code/0x100)) { + int offset = -1, ser = (code/0x100 - 161) * 157 + ((code%0x100) - ((code%0x100)>160?161:64)) + ((code%0x100)>160?64:1); + if (ser >= 472 && ser <= 5872) offset = (ser-472)*30; + else if (ser >= 6281 && ser <= 13973) offset = (ser-6281)*30+162030; + if (offset>-1) { + memcpy(&jfont_dbcs_16[code * 32], fontdata16+offset, 30); + jfont_cache_dbcs_16[code] = 1; + return &jfont_dbcs_16[code * 32]; + } } } if (!IS_JDOSV && (dos.loaded_codepage == 936 || dos.loaded_codepage == 949 || dos.loaded_codepage == 950)) @@ -527,12 +541,23 @@ uint8_t *GetDbcs14Font(Bitu code, bool &is14) is14 = true; return jfont_dbcs; } else { - if (dos.loaded_codepage == 936 && (code/0x100)>0xa0 && (code/0x100)<0xff && fontdata14) { - int offset = (94 * (unsigned int)((code/0x100) - 0xa0 - 1) + ((code%0x100) - 0xa0 - 1)) * 28; - if (offset + 28 <= fontsize14) { - memcpy(&jfont_dbcs_14[code * 28], fontdata14+offset, 28); - jfont_cache_dbcs_14[code] = 1; - return &jfont_dbcs_14[code * 28]; + if (fontdata14) { + if (dos.loaded_codepage == 936 && !(fontsize14%14) && (code/0x100)>0xa0 && (code/0x100)<0xff) { + int offset = (94 * (unsigned int)((code/0x100) - 0xa0 - 1) + ((code%0x100) - 0xa0 - 1)) * 28; + if (offset + 28 <= fontsize14) { + memcpy(&jfont_dbcs_14[code * 28], fontdata14+offset, 28); + jfont_cache_dbcs_14[code] = 1; + return &jfont_dbcs_14[code * 28]; + } + } else if (dos.loaded_codepage == 950 && !(fontsize16%15) && isKanji1(code/0x100)) { + int offset = -1, ser = (code/0x100 - 161) * 157 + ((code%0x100) - ((code%0x100)>160?161:64)) + ((code%0x100)>160?64:1); + if (ser >= 472 && ser <= 5872) offset = (ser-472)*30; + else if (ser >= 6281 && ser <= 13973) offset = (ser-6281)*30+162030; + if (offset>-1) { + memcpy(&jfont_dbcs_14[code * 28], fontdata14+offset, 28); + jfont_cache_dbcs_14[code] = 1; + return &jfont_dbcs_14[code * 28]; + } } } if (!IS_JDOSV && (dos.loaded_codepage == 936 || dos.loaded_codepage == 949 || dos.loaded_codepage == 950))