summaryrefslogtreecommitdiff
path: root/modules/text_server_fb
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-02-15 11:10:42 +0100
committerGitHub <noreply@github.com>2021-02-15 11:10:42 +0100
commitd8691e8ce28fd6899a20bdf76623ee1471862bab (patch)
treefe968dab5b461a24f61f1a0f2c6f98b42b16db93 /modules/text_server_fb
parentfa06d3cf6303506e8d65fe23f9f3c71e49960b88 (diff)
parentf4d095cdd3d04b3215d42928e6b7ac412d78c4c5 (diff)
Merge pull request #46043 from bruvzg/restore_char_and_space_extra_spacing
[TextServer] Restore character and space extra spacing support.
Diffstat (limited to 'modules/text_server_fb')
-rw-r--r--modules/text_server_fb/font_fb.h14
-rw-r--r--modules/text_server_fb/text_server_fb.cpp33
-rw-r--r--modules/text_server_fb/text_server_fb.h6
3 files changed, 53 insertions, 0 deletions
diff --git a/modules/text_server_fb/font_fb.h b/modules/text_server_fb/font_fb.h
index cc72919542..7fccbe06b5 100644
--- a/modules/text_server_fb/font_fb.h
+++ b/modules/text_server_fb/font_fb.h
@@ -37,6 +37,8 @@ struct FontDataFallback {
Map<String, bool> lang_support_overrides;
Map<String, bool> script_support_overrides;
bool valid = false;
+ int spacing_space = 0;
+ int spacing_glyph = 0;
virtual void clear_cache() = 0;
@@ -50,6 +52,18 @@ struct FontDataFallback {
virtual float get_underline_position(int p_size) const = 0;
virtual float get_underline_thickness(int p_size) const = 0;
+ virtual int get_spacing_space() const { return spacing_space; };
+ virtual void set_spacing_space(int p_value) {
+ spacing_space = p_value;
+ clear_cache();
+ };
+
+ virtual int get_spacing_glyph() const { return spacing_glyph; };
+ virtual void set_spacing_glyph(int p_value) {
+ spacing_glyph = p_value;
+ clear_cache();
+ };
+
virtual void set_antialiased(bool p_antialiased) = 0;
virtual bool get_antialiased() const = 0;
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index e60d269408..5cbe0f8277 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -179,6 +179,34 @@ float TextServerFallback::font_get_underline_thickness(RID p_font, int p_size) c
return fd->get_underline_thickness(p_size);
}
+int TextServerFallback::font_get_spacing_space(RID p_font) const {
+ _THREAD_SAFE_METHOD_
+ const FontDataFallback *fd = font_owner.getornull(p_font);
+ ERR_FAIL_COND_V(!fd, 0);
+ return fd->get_spacing_space();
+}
+
+void TextServerFallback::font_set_spacing_space(RID p_font, int p_value) {
+ _THREAD_SAFE_METHOD_
+ FontDataFallback *fd = font_owner.getornull(p_font);
+ ERR_FAIL_COND(!fd);
+ fd->set_spacing_space(p_value);
+}
+
+int TextServerFallback::font_get_spacing_glyph(RID p_font) const {
+ _THREAD_SAFE_METHOD_
+ const FontDataFallback *fd = font_owner.getornull(p_font);
+ ERR_FAIL_COND_V(!fd, 0);
+ return fd->get_spacing_glyph();
+}
+
+void TextServerFallback::font_set_spacing_glyph(RID p_font, int p_value) {
+ _THREAD_SAFE_METHOD_
+ FontDataFallback *fd = font_owner.getornull(p_font);
+ ERR_FAIL_COND(!fd);
+ fd->set_spacing_glyph(p_value);
+}
+
void TextServerFallback::font_set_antialiased(RID p_font, bool p_antialiased) {
_THREAD_SAFE_METHOD_
FontDataFallback *fd = font_owner.getornull(p_font);
@@ -1184,6 +1212,11 @@ bool TextServerFallback::shaped_text_shape(RID p_shaped) {
sd->descent = MAX(sd->descent, Math::round(fd->get_advance(gl.index, gl.font_size).x * 0.5));
}
}
+ if (fd->get_spacing_space() && is_whitespace(sd->text[j])) {
+ gl.advance += fd->get_spacing_space();
+ } else {
+ gl.advance += fd->get_spacing_glyph();
+ }
sd->upos = MAX(sd->upos, fd->get_underline_position(gl.font_size));
sd->uthk = MAX(sd->uthk, fd->get_underline_thickness(gl.font_size));
diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h
index d142b320e4..c14a444872 100644
--- a/modules/text_server_fb/text_server_fb.h
+++ b/modules/text_server_fb/text_server_fb.h
@@ -89,6 +89,12 @@ public:
virtual float font_get_underline_position(RID p_font, int p_size) const override;
virtual float font_get_underline_thickness(RID p_font, int p_size) const override;
+ virtual int font_get_spacing_space(RID p_font) const override;
+ virtual void font_set_spacing_space(RID p_font, int p_value) override;
+
+ virtual int font_get_spacing_glyph(RID p_font) const override;
+ virtual void font_set_spacing_glyph(RID p_font, int p_value) override;
+
virtual void font_set_antialiased(RID p_font, bool p_antialiased) override;
virtual bool font_get_antialiased(RID p_font) const override;