Skip to content

Commit

Permalink
Fix codepage change when language file is loaded in TTF mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maron2000 committed Sep 19, 2024
1 parent b259046 commit c8aee7e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
9 changes: 8 additions & 1 deletion src/dos/dos_keyboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern int tryconvertcp, toSetCodePage(DOS_Shell *shell, int newCP, int opt);
extern bool jfont_init;
extern int32_t msgcodepage;
bool CheckDBCSCP(int32_t codepage);
void Load_Language(std::string name);

static FILE* OpenDosboxFile(const char* name) {
uint8_t drive;
Expand Down Expand Up @@ -1747,8 +1748,14 @@ class DOS_KeyboardLayout: public Module_base {
}
if(isSupportedCP(msgcodepage)) {
SwitchLanguage(dos.loaded_codepage, msgcodepage, false);
#if defined(USE_TTF)
if (ttf.inUse)
toSetCodePage(NULL, msgcodepage, -1);
else
#endif
if(!CheckDBCSCP(msgcodepage))DOS_ChangeCodepage(msgcodepage, "auto");
dos.loaded_codepage = msgcodepage;
Load_Language(layoutname);
dos.loaded_codepage=msgcodepage;
}
}

Expand Down
1 change: 0 additions & 1 deletion src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ void DetachFromBios(imageDisk* image) {
}

void SwitchLanguage(int oldcp, int newcp, bool confirm) {
(void)oldcp; //unused
auto iterold = langcp_map.find(lastmsgcp), iternew = langcp_map.find(newcp);
std::string langold = iterold != langcp_map.end() ? iterold->second : "", langnew = iternew != langcp_map.end() ? iternew->second : "";
if (loadlang && langnew.size() && strcasecmp(langold.c_str(), langnew.c_str())) {
Expand Down
3 changes: 1 addition & 2 deletions src/misc/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Bitu DOS_ChangeKeyboardLayout(const char* layoutname, int32_t codepage);
Bitu DOS_ChangeCodepage(int32_t codepage, const char* codepagefile);
Bitu DOS_LoadKeyboardLayout(const char* layoutname, int32_t codepage, const char* codepagefile);
bool CheckDBCSCP(int32_t codepage);
void Load_Language(std::string name);

#define LINE_IN_MAXLEN 2048

Expand Down Expand Up @@ -219,10 +218,10 @@ void SetKEYBCP() {
if (IS_PC98_ARCH || IS_JEGA_ARCH || IS_DOSV || dos_kernel_disabled || !strcmp(RunningProgram, "LOADLIN")) return;
Bitu return_code;
if(CheckDBCSCP(msgcodepage)) {
dos.loaded_codepage = msgcodepage;
ShutFontHandle();
InitFontHandle();
JFONT_Init();
dos.loaded_codepage = msgcodepage;
}
if (!CheckDBCSCP(msgcodepage) && DOS_ChangeCodepage(msgcodepage, "auto") == KEYB_NOERROR){
dos.loaded_codepage = msgcodepage;
Expand Down
11 changes: 6 additions & 5 deletions src/misc/programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ bool set_ver(char *s), GFX_IsFullscreen(void);

void Load_Language(std::string name) {
if (control->opt_lang != "") control->opt_lang = name;
dos.loaded_codepage = msgcodepage;
MSG_Init();
#if DOSBOXMENU_TYPE == DOSBOXMENU_HMENU || DOSBOXMENU_TYPE == DOSBOXMENU_NSMENU
mainMenu.unbuild();
Expand All @@ -738,12 +739,12 @@ void Load_Language(std::string name) {
#if defined(USE_TTF)
if (TTF_using()) resetFontSize();
#endif
if (!uselangcp && !incall) {
int oldmsgcp = msgcodepage;
msgcodepage = dos.loaded_codepage;
//if (!uselangcp && !incall) {
//int oldmsgcp = msgcodepage;
//dos.loaded_codepage = msgcodepage;
SetKEYBCP();
msgcodepage = oldmsgcp;
}
//msgcodepage = oldmsgcp;
//}
}

void ApplySetting(std::string pvar, std::string inputline, bool quiet) {
Expand Down
7 changes: 5 additions & 2 deletions src/shell/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ extern bool startcmd, startwait, startquiet, internal_program;
extern bool addovl, addipx, addne2k, enableime, showdbcs;
extern bool halfwidthkana, force_conversion, gbk;
extern const char* RunningProgram;
extern int enablelfn, msgcodepage, lastmsgcp;
extern int enablelfn;
extern int32_t msgcodepage, lastmsgcp;
extern uint16_t countryNo;
extern unsigned int dosbox_shell_env_size;
bool outcon = true, usecon = true, pipetmpdev = true;
Expand All @@ -81,6 +82,8 @@ void SwitchLanguage(int oldcp, int newcp, bool confirm);
void CALLBACK_DeAllocate(Bitu in), DOSBox_ConsolePauseWait();
void GFX_SetTitle(int32_t cycles, int frameskip, Bits timing, bool paused);
bool isDBCSCP(), InitCodePage(), isKanji1(uint8_t chr), shiftjis_lead_byte(int c), sdl_wait_on_error();
void Load_Language(std::string name);
bool CheckDBCSCP(int32_t codepage);

Bitu call_shellstop = 0;
/* Larger scope so shell_del autoexec can use it to
Expand Down Expand Up @@ -883,7 +886,7 @@ void DOS_Shell::Prepare(void) {
else if (IS_TDOSV) newCP=950;
}
const char* name = DOS_GetLoadedLayout();
if (newCP==932||newCP==936||newCP==949||newCP==950||newCP==951) {
if (CheckDBCSCP(newCP)) {
dos.loaded_codepage=newCP;
SetupDBCSTable();
runRescan("-A -Q");
Expand Down
21 changes: 15 additions & 6 deletions src/shell/shell_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ extern void MAPPER_AutoType(std::vector<std::string> &sequence, const uint32_t w
extern void DOS_SetCountry(uint16_t countryNo), DOSV_FillScreen(void);
std::string GetDOSBoxXPath(bool withexe=false);
FILE *testLoadLangFile(const char *fname);
bool CheckDBCSCP(int32_t codepage);

/* support functions */
static char empty_char = 0;
Expand Down Expand Up @@ -4599,13 +4600,16 @@ void DOS_Shell::CMD_CHCP(char * args) {
int32_t cp = dos.loaded_codepage;
Bitu keyb_error;
if(n == 1) {
if(newCP == 932 || newCP == 936 || newCP == 949 || newCP == 950 || newCP == 951
if(CheckDBCSCP(newCP)
#if defined(USE_TTF)
|| (ttf.inUse && (newCP >= 1250 && newCP <= 1258))
#endif
) {
missing = toSetCodePage(this, newCP, -1);
if(missing > -1) SwitchLanguage(cp, newCP, true);
if(missing > -1) {
SwitchLanguage(cp, newCP, true);
missing = toSetCodePage(this, newCP, -1);
}
if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
}
else {
Expand All @@ -4630,13 +4634,14 @@ void DOS_Shell::CMD_CHCP(char * args) {
return;
}
}
Load_Language(layout_name);
WriteOut(MSG_Get("SHELL_CMD_CHCP_ACTIVE"), dos.loaded_codepage);
}
else if(n == 2 && strlen(buff)) {
std::string name = buff + 1;
if(*buff == ':' && strchr(StripArg(args), ':')) {
std::string name = buff + 1;
if(name.empty() && iter != langcp_map.end()) name = iter->second;
if(newCP == 932 || newCP == 936 || newCP == 949 || newCP == 950 || newCP == 951) {
if(CheckDBCSCP(newCP)) {
missing = toSetCodePage(this, newCP, -1);
if(missing > -1) SwitchLanguage(cp, newCP, true);
if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
Expand Down Expand Up @@ -4676,7 +4681,10 @@ void DOS_Shell::CMD_CHCP(char * args) {
if(ttf.inUse) {
if(isSupportedCP(newCP)) {
missing = toSetCodePage(this, newCP, -1);
if(missing > -1) SwitchLanguage(cp, newCP, true);
if(missing > -1) {
SwitchLanguage(cp, newCP, true);
missing = toSetCodePage(this, newCP, -1);
}
if(missing > 0) WriteOut(MSG_Get("SHELL_CMD_CHCP_MISSING"), missing);
LOG_MSG("CHCP: Loading cpi/cpx files ignored for TTF output");
}
Expand All @@ -4685,6 +4693,7 @@ void DOS_Shell::CMD_CHCP(char * args) {
LOG_MSG("CHCP: Codepage %d not supported for TTF output", newCP);
return;
}
Load_Language(name);
}
else {
#endif
Expand All @@ -4694,7 +4703,7 @@ void DOS_Shell::CMD_CHCP(char * args) {
FILE* file = fopen(cpfile.c_str(), "r"); /* should check the result */
std::string exepath = GetDOSBoxXPath();
if(!file && exepath.size()) file = fopen((exepath + CROSS_FILESPLIT + cpfile).c_str(), "r");
if(file && newCP > 0 && newCP != 932 && newCP != 936 && newCP != 949 && newCP != 950 && newCP != 951) {
if(file && newCP > 0 && !CheckDBCSCP(newCP)) {
altcp = newCP;
char line[256], * l = line;
while(fgets(line, sizeof(line), file)) {
Expand Down

0 comments on commit c8aee7e

Please sign in to comment.