Merge pull request #49496 from bruvzg/ctl_improve_font_selection

[CTL] Improve font fallback order selection.
This commit is contained in:
Rémi Verschelde 2021-06-11 00:26:10 +02:00 committed by GitHub
commit 7e1a6befda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 23 deletions

View File

@ -2352,24 +2352,22 @@ bool TextServerAdvanced::shaped_text_shape(RID p_shaped) {
sd->glyphs.push_back(gl); sd->glyphs.push_back(gl);
} else { } else {
Vector<RID> fonts; Vector<RID> fonts;
// Push fonts with the language and script support first. Vector<RID> fonts_scr_only;
for (int l = 0; l < span.fonts.size(); l++) { Vector<RID> fonts_no_match;
if ((font_is_language_supported(span.fonts[l], span.language)) && (font_is_script_supported(span.fonts[l], script))) { int font_count = span.fonts.size();
fonts.push_back(sd->spans[k].fonts[l]); for (int l = 0; l < font_count; l++) {
} if (font_is_script_supported(span.fonts[l], script)) {
} if (font_is_language_supported(span.fonts[l], span.language)) {
// Push fonts with the script support. fonts.push_back(sd->spans[k].fonts[l]);
for (int l = 0; l < sd->spans[k].fonts.size(); l++) { } else {
if (!(font_is_language_supported(span.fonts[l], span.language)) && (font_is_script_supported(span.fonts[l], script))) { fonts_scr_only.push_back(sd->spans[k].fonts[l]);
fonts.push_back(sd->spans[k].fonts[l]); }
} } else {
} fonts_no_match.push_back(sd->spans[k].fonts[l]);
// Push the rest valid fonts.
for (int l = 0; l < sd->spans[k].fonts.size(); l++) {
if (!(font_is_language_supported(span.fonts[l], span.language)) && !(font_is_script_supported(span.fonts[l], script))) {
fonts.push_back(sd->spans[k].fonts[l]);
} }
} }
fonts.append_array(fonts_scr_only);
fonts.append_array(fonts_no_match);
_shape_run(sd, MAX(sd->spans[k].start, script_run_start), MIN(sd->spans[k].end, script_run_end), sd->script_iter->script_ranges[j].script, bidi_run_direction, fonts, k, 0); _shape_run(sd, MAX(sd->spans[k].start, script_run_start), MIN(sd->spans[k].end, script_run_end), sd->script_iter->script_ranges[j].script, bidi_run_direction, fonts, k, 0);
} }
} }

View File

@ -634,17 +634,17 @@ bool TextServerFallback::shaped_text_add_string(RID p_shaped, const String &p_te
span.start = sd->text.length(); span.start = sd->text.length();
span.end = span.start + p_text.length(); span.end = span.start + p_text.length();
// Pre-sort fonts, push fonts with the language support first. // Pre-sort fonts, push fonts with the language support first.
for (int i = 0; i < p_fonts.size(); i++) { Vector<RID> fonts_no_match;
int font_count = p_fonts.size();
for (int i = 0; i < font_count; i++) {
if (font_is_language_supported(p_fonts[i], p_language)) { if (font_is_language_supported(p_fonts[i], p_language)) {
span.fonts.push_back(p_fonts[i]); span.fonts.push_back(p_fonts[i]);
} else {
fonts_no_match.push_back(p_fonts[i]);
} }
} }
// Push the rest valid fonts. span.fonts.append_array(fonts_no_match);
for (int i = 0; i < p_fonts.size(); i++) {
if (!font_is_language_supported(p_fonts[i], p_language)) {
span.fonts.push_back(p_fonts[i]);
}
}
ERR_FAIL_COND_V(span.fonts.is_empty(), false); ERR_FAIL_COND_V(span.fonts.is_empty(), false);
span.font_size = p_size; span.font_size = p_size;
span.language = p_language; span.language = p_language;