Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/release-windows.yml
#	src/company_base.h
#	src/company_cmd.cpp
#	src/company_gui.cpp
#	src/console_cmds.cpp
#	src/economy.cpp
#	src/economy_cmd.h
#	src/fios.h
#	src/goal.cpp
#	src/group_gui.cpp
#	src/network/core/config.h
#	src/network/network_admin.cpp
#	src/newgrf_config.cpp
#	src/os/windows/win32.cpp
#	src/saveload/afterload.cpp
#	src/saveload/company_sl.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload_error.hpp
#	src/settings_gui.cpp
#	src/ship_cmd.cpp
#	src/stdafx.h
#	src/story.cpp
#	src/story_base.h
#	src/string.cpp
#	src/table/settings/economy_settings.ini
#	src/tests/CMakeLists.txt
#	src/tests/math_func.cpp
This commit is contained in:
Jonathan G Rennison
2023-05-30 00:49:14 +01:00
156 changed files with 2979 additions and 4098 deletions

View File

@@ -323,7 +323,7 @@ void MacOSSetCurrentLocaleName(const char *iso_code)
* @param s2 Second string to compare.
* @return 1 if s1 < s2, 2 if s1 == s2, 3 if s1 > s2, or 0 if not supported by the OS.
*/
int MacOSStringCompare(const char *s1, const char *s2)
int MacOSStringCompare(std::string_view s1, std::string_view s2)
{
static bool supported = MacOSVersionIsAtLeast(10, 5, 0);
if (!supported) return 0;
@@ -332,8 +332,8 @@ int MacOSStringCompare(const char *s1, const char *s2)
CFStringCompareFlags flags = kCFCompareCaseInsensitive | kCFCompareNumerically | kCFCompareLocalized | kCFCompareWidthInsensitive | kCFCompareForcedOrdering;
CFAutoRelease<CFStringRef> cf1(CFStringCreateWithCString(kCFAllocatorDefault, s1, kCFStringEncodingUTF8));
CFAutoRelease<CFStringRef> cf2(CFStringCreateWithCString(kCFAllocatorDefault, s2, kCFStringEncodingUTF8));
CFAutoRelease<CFStringRef> cf1(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s1.data(), s1.size(), kCFStringEncodingUTF8, false));
CFAutoRelease<CFStringRef> cf2(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)s2.data(), s2.size(), kCFStringEncodingUTF8, false));
/* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
if (cf1 == nullptr || cf2 == nullptr) return 0;

View File

@@ -83,7 +83,7 @@ public:
void MacOSResetScriptCache(FontSize size);
void MacOSSetCurrentLocaleName(const char *iso_code);
int MacOSStringCompare(const char *s1, const char *s2);
int MacOSStringCompare(std::string_view s1, std::string_view s2);
void MacOSRegisterExternalFont(const char *file_path);

View File

@@ -78,11 +78,12 @@ void FiosGetDrives(FileList &file_list)
fios->type = FIOS_TYPE_DRIVE;
fios->mtime = 0;
#ifndef __INNOTEK_LIBC__
snprintf(fios->name, lengthof(fios->name), "%c:", 'A' + disk - 1);
fios->name += 'A' + disk - 1;
#else
snprintf(fios->name, lengthof(fios->name), "%c:", disk);
fios->name += (char)disk;
#endif
strecpy(fios->title, fios->name, lastof(fios->title));
fios->name += ':';
fios->title = fios->name;
}
}

View File

@@ -70,12 +70,12 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
FcPatternGetString(fs->fonts[i], FC_STYLE, 0, &style) == FcResultMatch) {
/* The correct style? */
if (font_style != nullptr && strcasecmp(font_style, (char *)style) != 0) continue;
if (font_style != nullptr && !StrEqualsIgnoreCase(font_style, (char *)style)) continue;
/* Font config takes the best shot, which, if the family name is spelled
* wrongly a 'random' font, so check whether the family name is the
* same as the supplied name */
if (strcasecmp(font_family, (char *)family) == 0) {
if (StrEqualsIgnoreCase(font_family, (char *)family)) {
err = FT_New_Face(_library, (char *)file, 0, face);
}
}

View File

@@ -134,9 +134,9 @@ FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
err = FT_New_Face(_library, font_path, index, face);
if (err != FT_Err_Ok) break;
if (strncasecmp(font_name, (*face)->family_name, strlen((*face)->family_name)) == 0) break;
if (StrStartsWithIgnoreCase(font_name, (*face)->family_name)) break;
/* Try english name if font name failed */
if (strncasecmp(font_name + strlen(font_name) + 1, (*face)->family_name, strlen((*face)->family_name)) == 0) break;
if (StrStartsWithIgnoreCase(font_name + strlen(font_name) + 1, (*face)->family_name)) break;
err = FT_Err_Cannot_Open_Resource;
} while ((FT_Long)++index != (*face)->num_faces);

View File

@@ -347,7 +347,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
}
/* If the text does not fit into the available width, find a suitable breaking point. */
int remaing_offset = (last_run - 1)->len;
int remaining_offset = (last_run - 1)->len;
int whitespace_count = 0;
if (cur_width > max_width) {
std::vector<SCRIPT_LOGATTR> log_attribs;
@@ -380,19 +381,19 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
num_chars = last_cluster;
}
/* Include whitespace characters after the breaking point. */
while (num_chars < (int)log_attribs.size() && log_attribs[num_chars].fWhiteSpace) {
num_chars++;
}
/* Eat any whitespace characters before the breaking point. */
while (num_chars - 1 > this->cur_range_offset && log_attribs[num_chars - 1].fWhiteSpace) num_chars--;
/* Count whitespace after the breaking point. */
while (num_chars + whitespace_count < (int)log_attribs.size() && log_attribs[num_chars + whitespace_count].fWhiteSpace) whitespace_count++;
/* Get last run that corresponds to the number of characters to show. */
for (std::vector<UniscribeRun>::iterator run = start_run; run != last_run; run++) {
num_chars -= run->len;
if (num_chars <= 0) {
remaing_offset = num_chars + run->len + 1;
remaining_offset = num_chars + run->len + 1;
last_run = run + 1;
assert(remaing_offset - 1 > 0);
assert(remaining_offset - 1 > 0);
break;
}
}
@@ -415,8 +416,8 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
UniscribeRun run = *i_run;
/* Partial run after line break (either start or end)? Reshape run to get the first/last glyphs right. */
if (i_run == last_run - 1 && remaing_offset < (last_run - 1)->len) {
run.len = remaing_offset - 1;
if (i_run == last_run - 1 && remaining_offset < (last_run - 1)->len) {
run.len = remaining_offset - 1;
if (!UniscribeShapeRun(this->text_buffer, run)) return nullptr;
}
@@ -432,9 +433,9 @@ static std::vector<SCRIPT_ITEM> UniscribeItemizeString(UniscribeParagraphLayoutF
cur_pos += run.total_advance;
}
if (remaing_offset < (last_run - 1)->len) {
if (remaining_offset + whitespace_count < (last_run - 1)->len) {
/* We didn't use up all of the last run, store remainder for the next line. */
this->cur_range_offset = remaing_offset - 1;
this->cur_range_offset = remaining_offset + whitespace_count - 1;
this->cur_range = last_run - 1;
assert(this->cur_range->len > this->cur_range_offset);
} else {

View File

@@ -218,8 +218,9 @@ void FiosGetDrives(FileList &file_list)
FiosItem *fios = &file_list.emplace_back();
fios->type = FIOS_TYPE_DRIVE;
fios->mtime = 0;
seprintf(fios->name, lastof(fios->name), "%c:", s[0] & 0xFF);
strecpy(fios->title, fios->name, lastof(fios->title));
fios->name += (char)(s[0] & 0xFF);
fios->name += ':';
fios->title = fios->name;
while (*s++ != '\0') { /* Nothing */ }
}
}
@@ -503,7 +504,7 @@ void DetermineBasePaths(const char *exe)
} else {
/* Use the folder of the config file as working directory. */
wchar_t config_dir[MAX_PATH];
wcsncpy(path, convert_to_fs(_config_file.c_str(), path, lengthof(path)), lengthof(path));
wcsncpy(path, convert_to_fs(_config_file, path, lengthof(path)), lengthof(path));
if (!GetFullPathName(path, lengthof(config_dir), config_dir, nullptr)) {
DEBUG(misc, 0, "GetFullPathName failed (%lu)\n", GetLastError());
_searchpaths[SP_WORKING_DIR].clear();
@@ -628,10 +629,10 @@ char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen)
* @param console_cp convert to the console encoding instead of the normal system encoding.
* @return pointer to system_buf. If conversion fails the string is of zero-length
*/
wchar_t *convert_to_fs(const char *name, wchar_t *system_buf, size_t buflen)
wchar_t *convert_to_fs(const std::string_view name, wchar_t *system_buf, size_t buflen)
{
int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen);
if (len == 0) system_buf[0] = '\0';
int len = MultiByteToWideChar(CP_UTF8, 0, name.data(), (int)name.size(), system_buf, (int)buflen);
system_buf[len] = '\0';
return system_buf;
}
@@ -675,7 +676,7 @@ void Win32SetCurrentLocaleName(const char *iso_code)
MultiByteToWideChar(CP_UTF8, 0, iso, -1, _cur_iso_locale, lengthof(_cur_iso_locale));
}
int OTTDStringCompare(const char *s1, const char *s2)
int OTTDStringCompare(std::string_view s1, std::string_view s2)
{
typedef int (WINAPI *PFNCOMPARESTRINGEX)(LPCWSTR, DWORD, LPCWCH, int, LPCWCH, int, LPVOID, LPVOID, LPARAM);
static PFNCOMPARESTRINGEX _CompareStringEx = nullptr;
@@ -695,15 +696,15 @@ int OTTDStringCompare(const char *s1, const char *s2)
if (_CompareStringEx != nullptr) {
/* CompareStringEx takes UTF-16 strings, even in ANSI-builds. */
int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1, -1, nullptr, 0);
int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2, -1, nullptr, 0);
int len_s1 = MultiByteToWideChar(CP_UTF8, 0, s1.data(), (int)s1.size(), nullptr, 0);
int len_s2 = MultiByteToWideChar(CP_UTF8, 0, s2.data(), (int)s2.size(), nullptr, 0);
if (len_s1 != 0 && len_s2 != 0) {
LPWSTR str_s1 = AllocaM(WCHAR, len_s1);
LPWSTR str_s2 = AllocaM(WCHAR, len_s2);
MultiByteToWideChar(CP_UTF8, 0, s1, -1, str_s1, len_s1);
MultiByteToWideChar(CP_UTF8, 0, s2, -1, str_s2, len_s2);
MultiByteToWideChar(CP_UTF8, 0, s1.data(), (int)s1.size(), str_s1, len_s1);
MultiByteToWideChar(CP_UTF8, 0, s2.data(), (int)s2.size(), str_s2, len_s2);
int result = _CompareStringEx(_cur_iso_locale, LINGUISTIC_IGNORECASE | SORT_DIGITSASNUMBERS, str_s1, -1, str_s2, -1, nullptr, nullptr, 0);
if (result != 0) return result;

View File

@@ -17,14 +17,14 @@ typedef void (*Function)(int);
bool LoadLibraryList(Function proc[], const char *dll);
char *convert_from_fs(const wchar_t *name, char *utf8_buf, size_t buflen);
wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen);
wchar_t *convert_to_fs(const std::string_view name, wchar_t *utf16_buf, size_t buflen);
#if defined(__MINGW32__) && !defined(__MINGW64__) && !(_WIN32_IE >= 0x0500)
#define SHGFP_TYPE_CURRENT 0
#endif /* __MINGW32__ */
void Win32SetCurrentLocaleName(const char *iso_code);
int OTTDStringCompare(const char *s1, const char *s2);
int OTTDStringCompare(std::string_view s1, std::string_view s2);
#ifdef __MINGW32__
/* GCC doesn't understand the expected usage of GetProcAddress(). */