summaryrefslogtreecommitdiffstats
path: root/servers
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2021-11-18 23:36:22 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-01-09 19:03:48 +0200
commitc89c515ccf941a62bf2ec501095fad57d72cb1f7 (patch)
tree66c06be5dd3a43e7cdf32b089320a4fb4b47f183 /servers
parent5a61822d7ccab39b00ddd5c9bcc01fb04112b976 (diff)
downloadredot-engine-c89c515ccf941a62bf2ec501095fad57d72cb1f7.tar.gz
[TextServer] Improve ligature cursor handling.
Fix mid-grapheme hit test. Fix OpenType features property handling, add default features override option. Enable mid-grapheme cursor by default.
Diffstat (limited to 'servers')
-rw-r--r--servers/text/text_server_extension.cpp15
-rw-r--r--servers/text/text_server_extension.h5
-rw-r--r--servers/text_server.cpp32
-rw-r--r--servers/text_server.h3
4 files changed, 53 insertions, 2 deletions
diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp
index 2b0510680e..a51b62e730 100644
--- a/servers/text/text_server_extension.cpp
+++ b/servers/text/text_server_extension.cpp
@@ -174,6 +174,9 @@ void TextServerExtension::_bind_methods() {
GDVIRTUAL_BIND(_font_remove_script_support_override, "font_rid", "script");
GDVIRTUAL_BIND(_font_get_script_support_overrides, "font_rid");
+ GDVIRTUAL_BIND(_font_set_opentype_feature_overrides, "font_rid", "overrides");
+ GDVIRTUAL_BIND(_font_get_opentype_feature_overrides, "font_rid");
+
GDVIRTUAL_BIND(_font_supported_feature_list, "font_rid");
GDVIRTUAL_BIND(_font_supported_variation_list, "font_rid");
@@ -869,6 +872,18 @@ Vector<String> TextServerExtension::font_get_script_support_overrides(RID p_font
return Vector<String>();
}
+void TextServerExtension::font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) {
+ GDVIRTUAL_CALL(_font_set_opentype_feature_overrides, p_font_rid, p_overrides);
+}
+
+Dictionary TextServerExtension::font_get_opentype_feature_overrides(RID p_font_rid) const {
+ Dictionary ret;
+ if (GDVIRTUAL_CALL(_font_get_opentype_feature_overrides, p_font_rid, ret)) {
+ return ret;
+ }
+ return Dictionary();
+}
+
Dictionary TextServerExtension::font_supported_feature_list(RID p_font_rid) const {
Dictionary ret;
if (GDVIRTUAL_CALL(_font_supported_feature_list, p_font_rid, ret)) {
diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h
index 5c97401118..9b456c2dd7 100644
--- a/servers/text/text_server_extension.h
+++ b/servers/text/text_server_extension.h
@@ -285,6 +285,11 @@ public:
GDVIRTUAL2(_font_remove_script_support_override, RID, const String &);
GDVIRTUAL1R(Vector<String>, _font_get_script_support_overrides, RID);
+ virtual void font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) override;
+ virtual Dictionary font_get_opentype_feature_overrides(RID p_font_rid) const override;
+ GDVIRTUAL2(_font_set_opentype_feature_overrides, RID, const Dictionary &);
+ GDVIRTUAL1RC(Dictionary, _font_get_opentype_feature_overrides, RID);
+
virtual Dictionary font_supported_feature_list(RID p_font_rid) const override;
virtual Dictionary font_supported_variation_list(RID p_font_rid) const override;
GDVIRTUAL1RC(Dictionary, _font_supported_feature_list, RID);
diff --git a/servers/text_server.cpp b/servers/text_server.cpp
index d547bcc75e..143cda985d 100644
--- a/servers/text_server.cpp
+++ b/servers/text_server.cpp
@@ -327,6 +327,9 @@ void TextServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("font_remove_script_support_override", "font_rid", "script"), &TextServer::font_remove_script_support_override);
ClassDB::bind_method(D_METHOD("font_get_script_support_overrides", "font_rid"), &TextServer::font_get_script_support_overrides);
+ ClassDB::bind_method(D_METHOD("font_set_opentype_feature_overrides", "font_rid", "overrides"), &TextServer::font_set_opentype_feature_overrides);
+ ClassDB::bind_method(D_METHOD("font_get_opentype_feature_overrides", "font_rid"), &TextServer::font_get_opentype_feature_overrides);
+
ClassDB::bind_method(D_METHOD("font_supported_feature_list", "font_rid"), &TextServer::font_supported_feature_list);
ClassDB::bind_method(D_METHOD("font_supported_variation_list", "font_rid"), &TextServer::font_supported_variation_list);
@@ -989,9 +992,9 @@ Vector<Vector2> TextServer::shaped_text_get_selection(RID p_shaped, int p_start,
}
real_t char_adv = advance / (real_t)(glyphs[i].end - glyphs[i].start);
if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
- ranges.push_back(Vector2(off, off + char_adv * (start - glyphs[i].start)));
+ ranges.push_back(Vector2(off, off + char_adv * (glyphs[i].end - start)));
} else {
- ranges.push_back(Vector2(off + char_adv * (glyphs[i].end - start), off + advance));
+ ranges.push_back(Vector2(off + char_adv * (start - glyphs[i].start), off + advance));
}
}
// Selection range is within grapheme.
@@ -1099,6 +1102,31 @@ int TextServer::shaped_text_hit_test_position(RID p_shaped, float p_coords) cons
return glyphs[i].start;
}
}
+ // Ligature, handle mid-grapheme hit.
+ if (p_coords >= off && p_coords < off + advance && glyphs[i].end > glyphs[i].start + 1) {
+ int cnt = glyphs[i].end - glyphs[i].start;
+ real_t char_adv = advance / (real_t)(cnt);
+ real_t sub_off = off;
+ for (int j = 0; j < cnt; j++) {
+ // Place caret to the left of clicked sub-grapheme.
+ if (p_coords >= sub_off && p_coords < sub_off + char_adv / 2) {
+ if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
+ return glyphs[i].end - j;
+ } else {
+ return glyphs[i].start + j;
+ }
+ }
+ // Place caret to the right of clicked sub-grapheme.
+ if (p_coords >= sub_off + char_adv / 2 && p_coords < sub_off + char_adv) {
+ if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
+ return glyphs[i].start + (cnt - 1) - j;
+ } else {
+ return glyphs[i].end - (cnt - 1) + j;
+ }
+ }
+ sub_off += char_adv;
+ }
+ }
// Place caret to the left of clicked grapheme.
if (p_coords >= off && p_coords < off + advance / 2) {
if ((glyphs[i].flags & GRAPHEME_IS_RTL) == GRAPHEME_IS_RTL) {
diff --git a/servers/text_server.h b/servers/text_server.h
index e9c5248866..d5dccc0edb 100644
--- a/servers/text_server.h
+++ b/servers/text_server.h
@@ -350,6 +350,9 @@ public:
virtual void font_remove_script_support_override(RID p_font_rid, const String &p_script) = 0;
virtual Vector<String> font_get_script_support_overrides(RID p_font_rid) = 0;
+ virtual void font_set_opentype_feature_overrides(RID p_font_rid, const Dictionary &p_overrides) = 0;
+ virtual Dictionary font_get_opentype_feature_overrides(RID p_font_rid) const = 0;
+
virtual Dictionary font_supported_feature_list(RID p_font_rid) const = 0;
virtual Dictionary font_supported_variation_list(RID p_font_rid) const = 0;