From 215bede6ff494bb371fa610b6d003fe1cb7d1c7d Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 20 Jan 2022 09:30:42 +0200 Subject: [TextServer] Add function to change font, font size, and OpenType features without invalidating line break points, justification points, or recreating shaped text buffer. --- servers/text/text_server_extension.cpp | 34 +++++++++++++++++++++++++++++++--- servers/text/text_server_extension.h | 11 +++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) (limited to 'servers/text') diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index d7e7960496..db1f589334 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -210,10 +210,14 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_shaped_text_set_preserve_control, "shaped", "enabled"); GDVIRTUAL_BIND(_shaped_text_get_preserve_control, "shaped"); - GDVIRTUAL_BIND(_shaped_text_add_string, "shaped", "text", "fonts", "size", "opentype_features", "language"); + GDVIRTUAL_BIND(_shaped_text_add_string, "shaped", "text", "fonts", "size", "opentype_features", "language", "meta"); GDVIRTUAL_BIND(_shaped_text_add_object, "shaped", "key", "size", "inline_align", "length"); GDVIRTUAL_BIND(_shaped_text_resize_object, "shaped", "key", "size", "inline_align"); + GDVIRTUAL_BIND(_shaped_get_span_count, "shaped"); + GDVIRTUAL_BIND(_shaped_get_span_meta, "shaped", "index"); + GDVIRTUAL_BIND(_shaped_set_span_update_font, "shaped", "index", "fonts", "size", "opentype_features"); + GDVIRTUAL_BIND(_shaped_text_substr, "shaped", "start", "length"); GDVIRTUAL_BIND(_shaped_text_get_parent, "shaped"); @@ -1018,13 +1022,13 @@ bool TextServerExtension::shaped_text_get_preserve_control(RID p_shaped) const { return false; } -bool TextServerExtension::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { +bool TextServerExtension::shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language, const Variant &p_meta) { bool ret; Array fonts; for (int i = 0; i < p_fonts.size(); i++) { fonts.push_back(p_fonts[i]); } - if (GDVIRTUAL_CALL(_shaped_text_add_string, p_shaped, p_text, fonts, p_size, p_opentype_features, p_language, ret)) { + if (GDVIRTUAL_CALL(_shaped_text_add_string, p_shaped, p_text, fonts, p_size, p_opentype_features, p_language, p_meta, ret)) { return ret; } return false; @@ -1046,6 +1050,30 @@ bool TextServerExtension::shaped_text_resize_object(RID p_shaped, Variant p_key, return false; } +int TextServerExtension::shaped_get_span_count(RID p_shaped) const { + int ret; + if (GDVIRTUAL_CALL(_shaped_get_span_count, p_shaped, ret)) { + return ret; + } + return 0; +} + +Variant TextServerExtension::shaped_get_span_meta(RID p_shaped, int p_index) const { + Variant ret; + if (GDVIRTUAL_CALL(_shaped_get_span_meta, p_shaped, p_index, ret)) { + return ret; + } + return false; +} + +void TextServerExtension::shaped_set_span_update_font(RID p_shaped, int p_index, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features) { + Array fonts; + for (int i = 0; i < p_fonts.size(); i++) { + fonts.push_back(p_fonts[i]); + } + GDVIRTUAL_CALL(_shaped_set_span_update_font, p_shaped, p_index, fonts, p_size, p_opentype_features); +} + RID TextServerExtension::shaped_text_substr(RID p_shaped, int p_start, int p_length) const { RID ret; if (GDVIRTUAL_CALL(_shaped_text_substr, p_shaped, p_start, p_length, ret)) { diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index 6e203f22ee..df1f1d7a70 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -343,13 +343,20 @@ public: GDVIRTUAL2(_shaped_text_set_preserve_control, RID, bool); GDVIRTUAL1RC(bool, _shaped_text_get_preserve_control, RID); - virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "") override; + virtual bool shaped_text_add_string(RID p_shaped, const String &p_text, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary(), const String &p_language = "", const Variant &p_meta = Variant()) override; virtual bool shaped_text_add_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1) override; virtual bool shaped_text_resize_object(RID p_shaped, Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER) override; - GDVIRTUAL6R(bool, _shaped_text_add_string, RID, const String &, const Array &, int, const Dictionary &, const String &); + GDVIRTUAL7R(bool, _shaped_text_add_string, RID, const String &, const Array &, int, const Dictionary &, const String &, const Variant &); GDVIRTUAL5R(bool, _shaped_text_add_object, RID, Variant, const Size2 &, InlineAlignment, int); GDVIRTUAL4R(bool, _shaped_text_resize_object, RID, Variant, const Size2 &, InlineAlignment); + virtual int shaped_get_span_count(RID p_shaped) const override; + virtual Variant shaped_get_span_meta(RID p_shaped, int p_index) const override; + virtual void shaped_set_span_update_font(RID p_shaped, int p_index, const Vector &p_fonts, int p_size, const Dictionary &p_opentype_features = Dictionary()) override; + GDVIRTUAL1RC(int, _shaped_get_span_count, RID); + GDVIRTUAL2RC(Variant, _shaped_get_span_meta, RID, int); + GDVIRTUAL5(_shaped_set_span_update_font, RID, int, const Array &, int, const Dictionary &); + virtual RID shaped_text_substr(RID p_shaped, int p_start, int p_length) const override; virtual RID shaped_text_get_parent(RID p_shaped) const override; GDVIRTUAL3RC(RID, _shaped_text_substr, RID, int, int); -- cgit v1.2.3