diff options
Diffstat (limited to 'servers/text_server.cpp')
-rw-r--r-- | servers/text_server.cpp | 151 |
1 files changed, 102 insertions, 49 deletions
diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 7d9945f5d7..2bf0837d88 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -75,7 +75,7 @@ void TextServerManager::remove_interface(const Ref<TextServer> &p_interface) { }; }; - ERR_FAIL_COND(idx == -1); + ERR_FAIL_COND_MSG(idx == -1, "Interface not found."); print_verbose("TextServer: Removed interface \"" + p_interface->get_name() + "\""); emit_signal(SNAME("interface_removed"), p_interface->get_name()); interfaces.remove_at(idx); @@ -99,7 +99,7 @@ Ref<TextServer> TextServerManager::find_interface(const String &p_name) const { }; }; - ERR_FAIL_COND_V(idx == -1, nullptr); + ERR_FAIL_COND_V_MSG(idx == -1, nullptr, "Interface not found."); return interfaces[idx]; } @@ -208,6 +208,11 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_set_data", "font_rid", "data"), &TextServer::font_set_data); + ClassDB::bind_method(D_METHOD("font_set_face_index", "font_rid", "face_index"), &TextServer::font_set_face_index); + ClassDB::bind_method(D_METHOD("font_get_face_index", "font_rid"), &TextServer::font_get_face_index); + + ClassDB::bind_method(D_METHOD("font_get_face_count", "font_rid"), &TextServer::font_get_face_count); + ClassDB::bind_method(D_METHOD("font_set_style", "font_rid", "style"), &TextServer::font_set_style); ClassDB::bind_method(D_METHOD("font_get_style", "font_rid"), &TextServer::font_get_style); @@ -275,9 +280,6 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_set_scale", "font_rid", "size", "scale"), &TextServer::font_set_scale); ClassDB::bind_method(D_METHOD("font_get_scale", "font_rid", "size"), &TextServer::font_get_scale); - ClassDB::bind_method(D_METHOD("font_set_spacing", "font_rid", "size", "spacing", "value"), &TextServer::font_set_spacing); - ClassDB::bind_method(D_METHOD("font_get_spacing", "font_rid", "size", "spacing"), &TextServer::font_get_spacing); - ClassDB::bind_method(D_METHOD("font_get_texture_count", "font_rid", "size"), &TextServer::font_get_texture_count); ClassDB::bind_method(D_METHOD("font_clear_textures", "font_rid", "size"), &TextServer::font_clear_textures); ClassDB::bind_method(D_METHOD("font_remove_texture", "font_rid", "size", "texture_index"), &TextServer::font_remove_texture); @@ -378,6 +380,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("shaped_text_set_preserve_control", "shaped", "enabled"), &TextServer::shaped_text_set_preserve_control); ClassDB::bind_method(D_METHOD("shaped_text_get_preserve_control", "shaped"), &TextServer::shaped_text_get_preserve_control); + ClassDB::bind_method(D_METHOD("shaped_text_set_spacing", "shaped", "spacing", "value"), &TextServer::shaped_text_set_spacing); + ClassDB::bind_method(D_METHOD("shaped_text_get_spacing", "shaped", "spacing"), &TextServer::shaped_text_get_spacing); + ClassDB::bind_method(D_METHOD("shaped_text_add_string", "shaped", "text", "fonts", "size", "opentype_features", "language", "meta"), &TextServer::shaped_text_add_string, DEFVAL(Dictionary()), DEFVAL(""), DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("shaped_text_add_object", "shaped", "key", "size", "inline_align", "length"), &TextServer::shaped_text_add_object, DEFVAL(INLINE_ALIGNMENT_CENTER), DEFVAL(1)); ClassDB::bind_method(D_METHOD("shaped_text_resize_object", "shaped", "key", "size", "inline_align"), &TextServer::shaped_text_resize_object, DEFVAL(INLINE_ALIGNMENT_CENTER)); @@ -408,7 +413,7 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyphs", "shaped"), &TextServer::_shaped_text_get_ellipsis_glyphs_wrapper); ClassDB::bind_method(D_METHOD("shaped_text_get_ellipsis_glyph_count", "shaped"), &TextServer::shaped_text_get_ellipsis_glyph_count); - ClassDB::bind_method(D_METHOD("shaped_text_overrun_trim_to_width", "shaped", "width", "overrun_trim_flags"), &TextServer::shaped_text_overrun_trim_to_width, DEFVAL(0), DEFVAL(OVERRUN_NO_TRIMMING)); + ClassDB::bind_method(D_METHOD("shaped_text_overrun_trim_to_width", "shaped", "width", "overrun_trim_flags"), &TextServer::shaped_text_overrun_trim_to_width, DEFVAL(0), DEFVAL(OVERRUN_NO_TRIM)); ClassDB::bind_method(D_METHOD("shaped_text_get_objects", "shaped"), &TextServer::shaped_text_get_objects); ClassDB::bind_method(D_METHOD("shaped_text_get_object_rect", "shaped", "key"), &TextServer::shaped_text_get_object_rect); @@ -441,7 +446,11 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("string_get_word_breaks", "string", "language"), &TextServer::string_get_word_breaks, DEFVAL("")); + ClassDB::bind_method(D_METHOD("is_confusable", "string", "dict"), &TextServer::is_confusable); + ClassDB::bind_method(D_METHOD("spoof_check", "string"), &TextServer::spoof_check); + ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics); + ClassDB::bind_method(D_METHOD("is_valid_identifier", "string"), &TextServer::is_valid_identifier); ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL("")); ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL("")); @@ -458,40 +467,61 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(ORIENTATION_VERTICAL); /* JustificationFlag */ - BIND_ENUM_CONSTANT(JUSTIFICATION_NONE); - BIND_ENUM_CONSTANT(JUSTIFICATION_KASHIDA); - BIND_ENUM_CONSTANT(JUSTIFICATION_WORD_BOUND); - BIND_ENUM_CONSTANT(JUSTIFICATION_TRIM_EDGE_SPACES); - BIND_ENUM_CONSTANT(JUSTIFICATION_AFTER_LAST_TAB); - BIND_ENUM_CONSTANT(JUSTIFICATION_CONSTRAIN_ELLIPSIS); + BIND_BITFIELD_FLAG(JUSTIFICATION_NONE); + BIND_BITFIELD_FLAG(JUSTIFICATION_KASHIDA); + BIND_BITFIELD_FLAG(JUSTIFICATION_WORD_BOUND); + BIND_BITFIELD_FLAG(JUSTIFICATION_TRIM_EDGE_SPACES); + BIND_BITFIELD_FLAG(JUSTIFICATION_AFTER_LAST_TAB); + BIND_BITFIELD_FLAG(JUSTIFICATION_CONSTRAIN_ELLIPSIS); + + /* AutowrapMode */ + BIND_ENUM_CONSTANT(AUTOWRAP_OFF); + BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY); + BIND_ENUM_CONSTANT(AUTOWRAP_WORD); + BIND_ENUM_CONSTANT(AUTOWRAP_WORD_SMART); /* LineBreakFlag */ - BIND_ENUM_CONSTANT(BREAK_NONE); - BIND_ENUM_CONSTANT(BREAK_MANDATORY); - BIND_ENUM_CONSTANT(BREAK_WORD_BOUND); - BIND_ENUM_CONSTANT(BREAK_GRAPHEME_BOUND); - BIND_ENUM_CONSTANT(BREAK_WORD_BOUND_ADAPTIVE); + BIND_BITFIELD_FLAG(BREAK_NONE); + BIND_BITFIELD_FLAG(BREAK_MANDATORY); + BIND_BITFIELD_FLAG(BREAK_WORD_BOUND); + BIND_BITFIELD_FLAG(BREAK_GRAPHEME_BOUND); + BIND_BITFIELD_FLAG(BREAK_ADAPTIVE); + + /* VisibleCharactersBehavior */ + BIND_ENUM_CONSTANT(VC_CHARS_BEFORE_SHAPING); + BIND_ENUM_CONSTANT(VC_CHARS_AFTER_SHAPING); + BIND_ENUM_CONSTANT(VC_GLYPHS_AUTO); + BIND_ENUM_CONSTANT(VC_GLYPHS_LTR); + BIND_ENUM_CONSTANT(VC_GLYPHS_RTL); + + /* OverrunBehavior */ + BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING); + BIND_ENUM_CONSTANT(OVERRUN_TRIM_CHAR); + BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD); + BIND_ENUM_CONSTANT(OVERRUN_TRIM_ELLIPSIS); + BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ELLIPSIS); /* TextOverrunFlag */ - BIND_ENUM_CONSTANT(OVERRUN_NO_TRIMMING); - BIND_ENUM_CONSTANT(OVERRUN_TRIM); - BIND_ENUM_CONSTANT(OVERRUN_TRIM_WORD_ONLY); - BIND_ENUM_CONSTANT(OVERRUN_ADD_ELLIPSIS); - BIND_ENUM_CONSTANT(OVERRUN_ENFORCE_ELLIPSIS); - BIND_ENUM_CONSTANT(OVERRUN_JUSTIFICATION_AWARE); + BIND_BITFIELD_FLAG(OVERRUN_NO_TRIM); + BIND_BITFIELD_FLAG(OVERRUN_TRIM); + BIND_BITFIELD_FLAG(OVERRUN_TRIM_WORD_ONLY); + BIND_BITFIELD_FLAG(OVERRUN_ADD_ELLIPSIS); + BIND_BITFIELD_FLAG(OVERRUN_ENFORCE_ELLIPSIS); + BIND_BITFIELD_FLAG(OVERRUN_JUSTIFICATION_AWARE); /* GraphemeFlag */ - BIND_ENUM_CONSTANT(GRAPHEME_IS_VALID); - BIND_ENUM_CONSTANT(GRAPHEME_IS_RTL); - BIND_ENUM_CONSTANT(GRAPHEME_IS_VIRTUAL); - BIND_ENUM_CONSTANT(GRAPHEME_IS_SPACE); - BIND_ENUM_CONSTANT(GRAPHEME_IS_BREAK_HARD); - BIND_ENUM_CONSTANT(GRAPHEME_IS_BREAK_SOFT); - BIND_ENUM_CONSTANT(GRAPHEME_IS_TAB); - BIND_ENUM_CONSTANT(GRAPHEME_IS_ELONGATION); - BIND_ENUM_CONSTANT(GRAPHEME_IS_PUNCTUATION); - BIND_ENUM_CONSTANT(GRAPHEME_IS_UNDERSCORE); - BIND_ENUM_CONSTANT(GRAPHEME_IS_CONNECTED); + BIND_BITFIELD_FLAG(GRAPHEME_IS_VALID); + BIND_BITFIELD_FLAG(GRAPHEME_IS_RTL); + BIND_BITFIELD_FLAG(GRAPHEME_IS_VIRTUAL); + BIND_BITFIELD_FLAG(GRAPHEME_IS_SPACE); + BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_HARD); + BIND_BITFIELD_FLAG(GRAPHEME_IS_BREAK_SOFT); + BIND_BITFIELD_FLAG(GRAPHEME_IS_TAB); + BIND_BITFIELD_FLAG(GRAPHEME_IS_ELONGATION); + BIND_BITFIELD_FLAG(GRAPHEME_IS_PUNCTUATION); + BIND_BITFIELD_FLAG(GRAPHEME_IS_UNDERSCORE); + BIND_BITFIELD_FLAG(GRAPHEME_IS_CONNECTED); + BIND_BITFIELD_FLAG(GRAPHEME_IS_SAFE_TO_INSERT_TATWEEL); /* Hinting */ BIND_ENUM_CONSTANT(HINTING_NONE); @@ -520,6 +550,8 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_FONT_VARIABLE); BIND_ENUM_CONSTANT(FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION); BIND_ENUM_CONSTANT(FEATURE_USE_SUPPORT_DATA); + BIND_ENUM_CONSTANT(FEATURE_UNICODE_IDENTIFIERS); + BIND_ENUM_CONSTANT(FEATURE_UNICODE_SECURITY); /* FT Contour Point Types */ BIND_ENUM_CONSTANT(CONTOUR_CURVE_TAG_ON); @@ -531,11 +563,12 @@ void TextServer::_bind_methods() { BIND_ENUM_CONSTANT(SPACING_SPACE); BIND_ENUM_CONSTANT(SPACING_TOP); BIND_ENUM_CONSTANT(SPACING_BOTTOM); + BIND_ENUM_CONSTANT(SPACING_MAX); /* Font Style */ - BIND_ENUM_CONSTANT(FONT_BOLD); - BIND_ENUM_CONSTANT(FONT_ITALIC); - BIND_ENUM_CONSTANT(FONT_FIXED_WIDTH); + BIND_BITFIELD_FLAG(FONT_BOLD); + BIND_BITFIELD_FLAG(FONT_ITALIC); + BIND_BITFIELD_FLAG(FONT_FIXED_WIDTH); /* Structured text parser */ BIND_ENUM_CONSTANT(STRUCTURED_TEXT_DEFAULT); @@ -625,7 +658,7 @@ void TextServer::draw_hex_code_box(const RID &p_canvas, int64_t p_size, const Ve } } -PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped, const PackedFloat32Array &p_width, int64_t p_start, bool p_once, int64_t /*TextBreakFlag*/ p_break_flags) const { +PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped, const PackedFloat32Array &p_width, int64_t p_start, bool p_once, BitField<TextServer::LineBreakFlag> p_break_flags) const { PackedInt32Array lines; ERR_FAIL_COND_V(p_width.is_empty(), lines); @@ -662,7 +695,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped } continue; } - if ((p_break_flags & BREAK_MANDATORY) == BREAK_MANDATORY) { + if (p_break_flags.has_flag(BREAK_MANDATORY)) { if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) { lines.push_back(line_start); lines.push_back(l_gl[i].end); @@ -676,12 +709,12 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped continue; } } - if ((p_break_flags & BREAK_WORD_BOUND) == BREAK_WORD_BOUND) { + if (p_break_flags.has_flag(BREAK_WORD_BOUND)) { if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { last_safe_break = i; } } - if ((p_break_flags & BREAK_GRAPHEME_BOUND) == BREAK_GRAPHEME_BOUND) { + if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND)) { last_safe_break = i; } } @@ -701,7 +734,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks_adv(const RID &p_shaped return lines; } -PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, double p_width, int64_t p_start, int64_t /*TextBreakFlag*/ p_break_flags) const { +PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, double p_width, int64_t p_start, BitField<TextServer::LineBreakFlag> p_break_flags) const { PackedInt32Array lines; const_cast<TextServer *>(this)->shaped_text_update_breaks(p_shaped); @@ -730,7 +763,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do word_count = 0; continue; } - if ((p_break_flags & BREAK_MANDATORY) == BREAK_MANDATORY) { + if (p_break_flags.has_flag(BREAK_MANDATORY)) { if ((l_gl[i].flags & GRAPHEME_IS_BREAK_HARD) == GRAPHEME_IS_BREAK_HARD) { lines.push_back(line_start); lines.push_back(l_gl[i].end); @@ -740,16 +773,16 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do continue; } } - if ((p_break_flags & BREAK_WORD_BOUND) == BREAK_WORD_BOUND) { + if (p_break_flags.has_flag(BREAK_WORD_BOUND)) { if ((l_gl[i].flags & GRAPHEME_IS_BREAK_SOFT) == GRAPHEME_IS_BREAK_SOFT) { last_safe_break = i; word_count++; } + if (p_break_flags.has_flag(BREAK_ADAPTIVE) && word_count == 0) { + last_safe_break = i; + } } - if (((p_break_flags & BREAK_WORD_BOUND_ADAPTIVE) == BREAK_WORD_BOUND_ADAPTIVE) && word_count == 0) { - last_safe_break = i; - } - if ((p_break_flags & BREAK_GRAPHEME_BOUND) == BREAK_GRAPHEME_BOUND) { + if (p_break_flags.has_flag(BREAK_GRAPHEME_BOUND)) { last_safe_break = i; } } @@ -769,7 +802,7 @@ PackedInt32Array TextServer::shaped_text_get_line_breaks(const RID &p_shaped, do return lines; } -PackedInt32Array TextServer::shaped_text_get_word_breaks(const RID &p_shaped, int64_t p_grapheme_flags) const { +PackedInt32Array TextServer::shaped_text_get_word_breaks(const RID &p_shaped, BitField<TextServer::GraphemeFlag> p_grapheme_flags) const { PackedInt32Array words; const_cast<TextServer *>(this)->shaped_text_update_justification_ops(p_shaped); @@ -1704,6 +1737,26 @@ Array TextServer::_shaped_text_get_ellipsis_glyphs_wrapper(const RID &p_shaped) return ret; } +bool TextServer::is_valid_identifier(const String &p_string) const { + const char32_t *str = p_string.ptr(); + int len = p_string.length(); + + if (len == 0) { + return false; // Empty string. + } + + if (!is_unicode_identifier_start(str[0])) { + return false; + } + + for (int i = 1; i < len; i++) { + if (!is_unicode_identifier_continue(str[i])) { + return false; + } + } + return true; +} + TextServer::TextServer() { _init_diacritics_map(); } |