1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

Merge pull request #112661 from bruvzg/lang_shape

Improve language selection when shaping text.
This commit is contained in:
Rémi Verschelde
2025-12-18 14:23:42 +01:00
9 changed files with 791 additions and 50 deletions

View File

@@ -32,6 +32,7 @@
#include "core/io/dir_access.h"
#include "core/os/os.h"
#include "core/string/translation_server.h"
#include "editor/editor_string_names.h"
#include "editor/settings/editor_settings.h"
#include "editor/themes/builtin_fonts.gen.h"
@@ -164,13 +165,34 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
String noto_cjk_path;
String noto_cjk_bold_path;
String var_suffix[] = { "HK", "KR", "SC", "TC", "JP" }; // Note: All Noto Sans CJK versions support all glyph variations, it should not match current locale.
for (size_t i = 0; i < std_size(var_suffix); i++) {
if (noto_cjk_path.is_empty()) {
noto_cjk_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 400, 100);
{
Vector<String> var_suffix;
// Note: Most Noto Sans CJK versions support all glyph variations, but select the best matching one in case it's not.
String locale = TranslationServer::get_singleton()->get_tool_locale();
if (!locale.begins_with("zh") && !locale.begins_with("ja") && !locale.begins_with("ko")) {
locale = OS::get_singleton()->get_locale();
}
if (noto_cjk_bold_path.is_empty()) {
noto_cjk_bold_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 800, 100);
if (locale.begins_with("zh") && (locale.contains("Hans") || locale.contains("CN") || locale.contains("SG"))) {
var_suffix = { "SC", "TC", "HK", "KR", "JP" };
} else if (locale.begins_with("zh") && locale.contains("HK")) {
var_suffix = { "HK", "TC", "SC", "KR", "JP" };
} else if (locale.begins_with("zh") && (locale.contains("Hant") || locale.contains("MO") || locale.contains("TW"))) {
var_suffix = { "TC", "HK", "SC", "KR", "JP" };
} else if (locale.begins_with("ko")) {
var_suffix = { "KR", "HK", "SC", "TC", "JP" };
} else if (locale.begins_with("ko")) {
var_suffix = { "JP", "HK", "KR", "SC", "TC" };
} else {
var_suffix = { "HK", "KR", "SC", "TC", "JP" };
}
for (int64_t i = 0; i < var_suffix.size(); i++) {
if (noto_cjk_path.is_empty()) {
noto_cjk_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 400, 100);
}
if (noto_cjk_bold_path.is_empty()) {
noto_cjk_bold_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 800, 100);
}
}
}
@@ -190,7 +212,15 @@ void editor_register_fonts(const Ref<Theme> &p_theme) {
load_external_font(noto_cjk_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
}
Ref<FontFile> fallback_font = load_internal_font(_font_DroidSansFallback, _font_DroidSansFallback_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
fallback_font->set_language_support_override("ja", false);
fallback_font->set_language_support_override("zh", true);
fallback_font->set_language_support_override("ko", true);
fallback_font->set_language_support_override("*", false);
Ref<FontFile> japanese_font = load_internal_font(_font_DroidSansJapanese, _font_DroidSansJapanese_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
japanese_font->set_language_support_override("ja", true);
japanese_font->set_language_support_override("zh", false);
japanese_font->set_language_support_override("ko", false);
japanese_font->set_language_support_override("*", false);
default_font->set_fallbacks(fallbacks);
default_font_msdf->set_fallbacks(fallbacks);