From 2f9f6132015550a9b974a8d9c5598ccb6bb97245 Mon Sep 17 00:00:00 2001 From: Richard Jenkins Date: Tue, 23 May 2017 08:30:13 +0100 Subject: [PATCH] Fix #3178: Precompose file name strings on macOS to prevent mojibake when displayed * Precompose file name strings on macOS to prevent mojibake when displayed * Ensure decomp-to-precomp string replacement is handled safely * Add macOS non-ASCII handling to changelog; add comments to relevant block * Fix #ifdef alignment * Fix comment alignment --- distribution/changelog.txt | 1 + src/openrct2/platform/posix.c | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 4909f67104..491bed7d59 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.0.8 (in development) ------------------------------------------------------------------------ +- Fix: [#3178, #5456] Paths with non-ASCII characters not handled properly on macOS. - Fix: [#3681] Steel Twister rollercoaster always shows all track designs - Fix: Track components added by OpenRCT2 are now usable in older scenarios. diff --git a/src/openrct2/platform/posix.c b/src/openrct2/platform/posix.c index b0678be14f..7f41b447fd 100644 --- a/src/openrct2/platform/posix.c +++ b/src/openrct2/platform/posix.c @@ -391,6 +391,17 @@ sint32 platform_enumerate_files_begin(const utf8 *pattern) safe_strcpy(paths[idx], dir_name, path_len); safe_strcat_path(paths[idx], d->d_name, path_len); log_verbose("paths[%d] = %s", idx, paths[idx]); + +// macOS uses decomposed Unicode strings (e.g. an 'e' and a combining accent) in filenames +// This causes problems with the sprite font, as the font only contains precomposed characters +// The block below converts all filename strings to their precomposed form, preventing mojibake +#ifdef __MACOSX__ + utf8* precomp_path = macos_str_decomp_to_precomp(paths[idx]); + size_t precomp_len = sizeof(utf8) * min(MAX_PATH, strnlen(precomp_path, MAX_PATH) + 2); + paths[idx] = malloc(precomp_len); + safe_strcpy(paths[idx], precomp_path, precomp_len); + log_verbose("macOS decomp-to-precomp fix - paths[%d] = %s", idx, paths[idx]); +#endif } enumFileInfo->handle = 0; enumFileInfo->active = 1; @@ -798,12 +809,12 @@ time_t platform_file_get_modified_time(const utf8* path){ } uint8 platform_get_locale_temperature_format(){ - // LC_MEASUREMENT is GNU specific. - #ifdef LC_MEASUREMENT +// LC_MEASUREMENT is GNU specific. +#ifdef LC_MEASUREMENT const char *langstring = setlocale(LC_MEASUREMENT, ""); - #else +#else const char *langstring = setlocale(LC_ALL, ""); - #endif +#endif if(langstring != NULL){ if (!fnmatch("*_US*", langstring, 0) ||