Skip to content

Commit 2ac31ec

Browse files
committed
Merge pull request godotengine#107030 from bruvzg/font_validate_script
Check script sample characters to filter out incorrect script support information.
2 parents 0e9a59b + c464a30 commit 2ac31ec

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

modules/text_server_adv/text_server_adv.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,33 @@ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_font_data, const
17621762
}
17631763
}
17641764

1765+
// Validate script sample strings.
1766+
{
1767+
LocalVector<uint32_t> failed_scripts;
1768+
1769+
Vector<UChar> sample_buf;
1770+
sample_buf.resize(255);
1771+
for (const uint32_t &scr_tag : p_font_data->supported_scripts) {
1772+
if ((hb_script_t)scr_tag == HB_SCRIPT_COMMON) {
1773+
continue;
1774+
}
1775+
UErrorCode icu_err = U_ZERO_ERROR;
1776+
int32_t len = uscript_getSampleString(hb_icu_script_from_script((hb_script_t)scr_tag), sample_buf.ptrw(), 255, &icu_err);
1777+
if (U_SUCCESS(icu_err) && len > 0) {
1778+
String sample = String::utf16(sample_buf.ptr(), len);
1779+
for (int ch = 0; ch < sample.length(); ch++) {
1780+
if (FT_Get_Char_Index(fd->face, sample[ch]) == 0) {
1781+
failed_scripts.push_back(scr_tag);
1782+
break;
1783+
}
1784+
}
1785+
}
1786+
}
1787+
for (const uint32_t &scr_tag : failed_scripts) {
1788+
p_font_data->supported_scripts.erase(scr_tag);
1789+
}
1790+
}
1791+
17651792
// Read OpenType feature tags.
17661793
p_font_data->supported_features.clear();
17671794
count = hb_ot_layout_table_get_feature_tags(hb_face, HB_OT_TAG_GSUB, 0, nullptr, nullptr);

0 commit comments

Comments
 (0)