From f4cc8758614fb56e3f539552c3e150440eb9fb1c Mon Sep 17 00:00:00 2001 From: dolphin6k Date: Sat, 12 Feb 2022 10:20:18 +0900 Subject: [PATCH] Finally fixed space bug with labels on windows correctly --- src/tuxpaint.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 52483addc..d79bf0363 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -23898,26 +23898,15 @@ static void load_info_about_label_surface(FILE * lfi) #endif #ifdef WIN32 - fgets(tmpstr, 1024, lfi); - nwchar = mbstowcs(wtmpstr, tmpstr, 1024) - 2; - /* FIXME: */ - /* - According to the document, return value of MultiByteToWideChar() is the number of - characters written to the buffer. - - https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar - - However, it seems to return a value 2 larger here. - - 2022/02/11 Shin-ichi TOYAMA - */ + /* Using fancy "%[]" operator to scan until the end of a line */ + tmp_fscanf_return = fscanf(lfi, "%[^\n]\n", tmpstr); + mbstowcs(wtmpstr, tmpstr, 1024); for (l = 0; l < new_node->save_texttool_len; l++) new_node->save_texttool_str[l] = wtmpstr[l]; new_node->save_texttool_str[l] = L'\0'; #else /* Using fancy "%[]" operator to scan until the end of a line */ tmp_fscanf_return = fscanf(lfi, "%l[^\n]\n", new_node->save_texttool_str); - nwchar = wcslen(new_node->save_texttool_str); #endif #ifdef DEBUG @@ -23926,6 +23915,7 @@ static void load_info_about_label_surface(FILE * lfi) /* If the string is shorter than what we expect (new_node->save_texttool_len), then it must have been prefixed with spaces that we lost. */ + nwchar = wcslen(new_node->save_texttool_str); if (nwchar < new_node->save_texttool_len) { wchar_t *wtmpstr;