From 911fa38d3a0dc71aa99ffcef474b5bae15805e8d Mon Sep 17 00:00:00 2001
From: bruvzg <7645683+bruvzg@users.noreply.github.com>
Date: Mon, 11 Mar 2024 13:42:16 +0200
Subject: [PATCH] [Font] Add option to disable embedded bitmaps loading.
---
doc/classes/FontFile.xml | 3 ++
doc/classes/ResourceImporterDynamicFont.xml | 3 ++
doc/classes/SystemFont.xml | 3 ++
doc/classes/TextServer.xml | 15 +++++++
doc/classes/TextServerExtension.xml | 13 ++++++
.../import/dynamic_font_import_settings.cpp | 4 ++
.../import/resource_importer_dynamic_font.cpp | 3 ++
modules/text_server_adv/text_server_adv.cpp | 22 +++++++++-
modules/text_server_adv/text_server_adv.h | 10 ++++-
modules/text_server_fb/text_server_fb.cpp | 22 +++++++++-
modules/text_server_fb/text_server_fb.h | 10 ++++-
scene/resources/font.cpp | 42 +++++++++++++++++++
scene/resources/font.h | 8 ++++
servers/text/text_server_extension.cpp | 13 ++++++
servers/text/text_server_extension.h | 5 +++
servers/text_server.cpp | 3 ++
servers/text_server.h | 3 ++
17 files changed, 176 insertions(+), 6 deletions(-)
diff --git a/doc/classes/FontFile.xml b/doc/classes/FontFile.xml
index acc12e04f29..424f1931ff9 100644
--- a/doc/classes/FontFile.xml
+++ b/doc/classes/FontFile.xml
@@ -601,6 +601,9 @@
Contents of the dynamic font source file.
+
+ If set to [code]true[/code], embedded font bitmap loading is disabled (bitmap-only and color fonts ignore this property).
+
Font size, used only for the bitmap fonts.
diff --git a/doc/classes/ResourceImporterDynamicFont.xml b/doc/classes/ResourceImporterDynamicFont.xml
index 437b3c8a96c..f100670e08b 100644
--- a/doc/classes/ResourceImporterDynamicFont.xml
+++ b/doc/classes/ResourceImporterDynamicFont.xml
@@ -25,6 +25,9 @@
If [code]true[/code], uses lossless compression for the resulting font.
+
+ If set to [code]true[/code], embedded font bitmap loading is disabled (bitmap-only and color fonts ignore this property).
+
List of font fallbacks to use if a glyph isn't found in this dynamic font. Fonts at the beginning of the array are attempted first, but fallback fonts that don't support the glyph's language and script are attempted last (see [member language_support] and [member script_support]). See also [member allow_system_fallback].
diff --git a/doc/classes/SystemFont.xml b/doc/classes/SystemFont.xml
index fe93571fbe4..38d6e27c856 100644
--- a/doc/classes/SystemFont.xml
+++ b/doc/classes/SystemFont.xml
@@ -19,6 +19,9 @@
Font anti-aliasing mode.
+
+ If set to [code]true[/code], embedded font bitmap loading is disabled (bitmap-only and color fonts ignore this property).
+
If set to [code]true[/code], italic or oblique font is preferred.
diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml
index 9a17fb3def5..c37ccc7e274 100644
--- a/doc/classes/TextServer.xml
+++ b/doc/classes/TextServer.xml
@@ -144,6 +144,13 @@
Returns the font descent (number of pixels below the baseline).
+
+
+
+
+ Returns whether the font's embedded bitmap loading is disabled.
+
+
@@ -672,6 +679,14 @@
Sets the font descent (number of pixels below the baseline).
+
+
+
+
+
+ If set to [code]true[/code], embedded font bitmap loading is disabled (bitmap-only and color fonts ignore this property).
+
+
diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xml
index 5beb5797dbd..4b64fb0bbf1 100644
--- a/doc/classes/TextServerExtension.xml
+++ b/doc/classes/TextServerExtension.xml
@@ -126,6 +126,12 @@
+
+
+
+
+
+
@@ -588,6 +594,13 @@
+
+
+
+
+
+
+
diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp
index 5e6ed02de91..b892324ba42 100644
--- a/editor/import/dynamic_font_import_settings.cpp
+++ b/editor/import/dynamic_font_import_settings.cpp
@@ -464,6 +464,8 @@ void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_
font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int());
} else if (p_edited_property == "generate_mipmaps") {
font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps"));
+ } else if (p_edited_property == "disable_embedded_bitmaps") {
+ font_preview->set_disable_embedded_bitmaps(import_settings_data->get("disable_embedded_bitmaps"));
} else if (p_edited_property == "multichannel_signed_distance_field") {
font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
_variation_selected();
@@ -938,6 +940,7 @@ void DynamicFontImportSettingsDialog::_re_import() {
main_settings["face_index"] = import_settings_data->get("face_index");
main_settings["antialiasing"] = import_settings_data->get("antialiasing");
main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps");
+ main_settings["disable_embedded_bitmaps"] = import_settings_data->get("disable_embedded_bitmaps");
main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field");
main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range");
main_settings["msdf_size"] = import_settings_data->get("msdf_size");
@@ -1245,6 +1248,7 @@ DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() {
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), true));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cpp
index 9d4c5edebce..c52f53146e0 100644
--- a/editor/import/resource_importer_dynamic_font.cpp
+++ b/editor/import/resource_importer_dynamic_font.cpp
@@ -110,6 +110,7 @@ void ResourceImporterDynamicFont::get_import_options(const String &p_path, List<
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), (msdf) ? true : false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
@@ -145,6 +146,7 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
int antialiasing = p_options["antialiasing"];
bool generate_mipmaps = p_options["generate_mipmaps"];
+ bool disable_embedded_bitmaps = p_options["disable_embedded_bitmaps"];
bool msdf = p_options["multichannel_signed_distance_field"];
int px_range = p_options["msdf_pixel_range"];
int px_size = p_options["msdf_size"];
@@ -165,6 +167,7 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
font.instantiate();
font->set_data(data);
font->set_antialiasing((TextServer::FontAntialiasing)antialiasing);
+ font->set_disable_embedded_bitmaps(disable_embedded_bitmaps);
font->set_generate_mipmaps(generate_mipmaps);
font->set_multichannel_signed_distance_field(msdf);
font->set_msdf_pixel_range(px_range);
diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp
index 3da19aaee8c..5d9bc69d038 100644
--- a/modules/text_server_adv/text_server_adv.cpp
+++ b/modules/text_server_adv/text_server_adv.cpp
@@ -1201,7 +1201,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
if (p_font_data->force_autohinter) {
flags |= FT_LOAD_FORCE_AUTOHINT;
}
- if (outline) {
+ if (outline || (p_font_data->disable_embedded_bitmaps && !FT_HAS_COLOR(fd->face))) {
flags |= FT_LOAD_NO_BITMAP;
} else if (FT_HAS_COLOR(fd->face)) {
flags |= FT_LOAD_COLOR;
@@ -2177,6 +2177,25 @@ TextServer::FontAntialiasing TextServerAdvanced::_font_get_antialiasing(const RI
return fd->antialiasing;
}
+void TextServerAdvanced::_font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) {
+ FontAdvanced *fd = _get_font_data(p_font_rid);
+ ERR_FAIL_NULL(fd);
+
+ MutexLock lock(fd->mutex);
+ if (fd->disable_embedded_bitmaps != p_disable_embedded_bitmaps) {
+ _font_clear_cache(fd);
+ fd->disable_embedded_bitmaps = p_disable_embedded_bitmaps;
+ }
+}
+
+bool TextServerAdvanced::_font_get_disable_embedded_bitmaps(const RID &p_font_rid) const {
+ FontAdvanced *fd = _get_font_data(p_font_rid);
+ ERR_FAIL_NULL_V(fd, false);
+
+ MutexLock lock(fd->mutex);
+ return fd->disable_embedded_bitmaps;
+}
+
void TextServerAdvanced::_font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) {
FontAdvanced *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@@ -4997,6 +5016,7 @@ RID TextServerAdvanced::_find_sys_font_for_text(const RID &p_fdef, const String
}
_font_set_antialiasing(sysf.rid, key.antialiasing);
+ _font_set_disable_embedded_bitmaps(sysf.rid, key.disable_embedded_bitmaps);
_font_set_generate_mipmaps(sysf.rid, key.mipmaps);
_font_set_multichannel_signed_distance_field(sysf.rid, key.msdf);
_font_set_msdf_pixel_range(sysf.rid, key.msdf_range);
diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h
index 3f04c17d9cb..a43ea1e7da1 100644
--- a/modules/text_server_adv/text_server_adv.h
+++ b/modules/text_server_adv/text_server_adv.h
@@ -303,6 +303,7 @@ class TextServerAdvanced : public TextServerExtension {
Mutex mutex;
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
+ bool disable_embedded_bitmaps = true;
bool mipmaps = false;
bool msdf = false;
int msdf_range = 14;
@@ -559,6 +560,7 @@ class TextServerAdvanced : public TextServerExtension {
struct SystemFontKey {
String font_name;
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
+ bool disable_embedded_bitmaps = true;
bool italic = false;
bool mipmaps = false;
bool msdf = false;
@@ -578,7 +580,7 @@ class TextServerAdvanced : public TextServerExtension {
float baseline_offset = 0.0;
bool operator==(const SystemFontKey &p_b) const {
- return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
+ return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (disable_embedded_bitmaps == p_b.disable_embedded_bitmaps) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
}
SystemFontKey(const String &p_font_name, bool p_italic, int p_weight, int p_stretch, RID p_font, const TextServerAdvanced *p_fb) {
@@ -587,6 +589,7 @@ class TextServerAdvanced : public TextServerExtension {
weight = p_weight;
stretch = p_stretch;
antialiasing = p_fb->_font_get_antialiasing(p_font);
+ disable_embedded_bitmaps = p_fb->_font_get_disable_embedded_bitmaps(p_font);
mipmaps = p_fb->_font_get_generate_mipmaps(p_font);
msdf = p_fb->_font_is_multichannel_signed_distance_field(p_font);
msdf_range = p_fb->_font_get_msdf_pixel_range(p_font);
@@ -637,7 +640,7 @@ class TextServerAdvanced : public TextServerExtension {
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_SPACE], hash);
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_GLYPH], hash);
hash = hash_murmur3_one_double(p_a.baseline_offset, hash);
- return hash_fmix32(hash_murmur3_one_32(((int)p_a.mipmaps) | ((int)p_a.msdf << 1) | ((int)p_a.italic << 2) | ((int)p_a.force_autohinter << 3) | ((int)p_a.hinting << 4) | ((int)p_a.subpixel_positioning << 8) | ((int)p_a.antialiasing << 12), hash));
+ return hash_fmix32(hash_murmur3_one_32(((int)p_a.mipmaps) | ((int)p_a.msdf << 1) | ((int)p_a.italic << 2) | ((int)p_a.force_autohinter << 3) | ((int)p_a.hinting << 4) | ((int)p_a.subpixel_positioning << 8) | ((int)p_a.antialiasing << 12) | ((int)p_a.disable_embedded_bitmaps << 14), hash));
}
};
mutable HashMap system_fonts;
@@ -751,6 +754,9 @@ public:
MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing);
MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &);
+ MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool);
+ MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &);
+
MODBIND2(font_set_generate_mipmaps, const RID &, bool);
MODBIND1RC(bool, font_get_generate_mipmaps, const RID &);
diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp
index 7e34de0bbc6..75374ecab46 100644
--- a/modules/text_server_fb/text_server_fb.cpp
+++ b/modules/text_server_fb/text_server_fb.cpp
@@ -636,7 +636,7 @@ _FORCE_INLINE_ bool TextServerFallback::_ensure_glyph(FontFallback *p_font_data,
if (p_font_data->force_autohinter) {
flags |= FT_LOAD_FORCE_AUTOHINT;
}
- if (outline) {
+ if (outline || (p_font_data->disable_embedded_bitmaps && !FT_HAS_COLOR(fd->face))) {
flags |= FT_LOAD_NO_BITMAP;
} else if (FT_HAS_COLOR(fd->face)) {
flags |= FT_LOAD_COLOR;
@@ -1170,6 +1170,25 @@ TextServer::FontAntialiasing TextServerFallback::_font_get_antialiasing(const RI
return fd->antialiasing;
}
+void TextServerFallback::_font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) {
+ FontFallback *fd = _get_font_data(p_font_rid);
+ ERR_FAIL_NULL(fd);
+
+ MutexLock lock(fd->mutex);
+ if (fd->disable_embedded_bitmaps != p_disable_embedded_bitmaps) {
+ _font_clear_cache(fd);
+ fd->disable_embedded_bitmaps = p_disable_embedded_bitmaps;
+ }
+}
+
+bool TextServerFallback::_font_get_disable_embedded_bitmaps(const RID &p_font_rid) const {
+ FontFallback *fd = _get_font_data(p_font_rid);
+ ERR_FAIL_NULL_V(fd, false);
+
+ MutexLock lock(fd->mutex);
+ return fd->disable_embedded_bitmaps;
+}
+
void TextServerFallback::_font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) {
FontFallback *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@@ -3805,6 +3824,7 @@ RID TextServerFallback::_find_sys_font_for_text(const RID &p_fdef, const String
}
_font_set_antialiasing(sysf.rid, key.antialiasing);
+ _font_set_disable_embedded_bitmaps(sysf.rid, key.disable_embedded_bitmaps);
_font_set_generate_mipmaps(sysf.rid, key.mipmaps);
_font_set_multichannel_signed_distance_field(sysf.rid, key.msdf);
_font_set_msdf_pixel_range(sysf.rid, key.msdf_range);
diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h
index 9cdf20f3fab..54a2a949f06 100644
--- a/modules/text_server_fb/text_server_fb.h
+++ b/modules/text_server_fb/text_server_fb.h
@@ -254,6 +254,7 @@ class TextServerFallback : public TextServerExtension {
Mutex mutex;
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
+ bool disable_embedded_bitmaps = true;
bool mipmaps = false;
bool msdf = false;
FixedSizeScaleMode fixed_size_scale_mode = FIXED_SIZE_SCALE_DISABLE;
@@ -475,6 +476,7 @@ class TextServerFallback : public TextServerExtension {
struct SystemFontKey {
String font_name;
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
+ bool disable_embedded_bitmaps = true;
bool italic = false;
bool mipmaps = false;
bool msdf = false;
@@ -494,7 +496,7 @@ class TextServerFallback : public TextServerExtension {
float baseline_offset = 0.0;
bool operator==(const SystemFontKey &p_b) const {
- return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
+ return (font_name == p_b.font_name) && (antialiasing == p_b.antialiasing) && (italic == p_b.italic) && (disable_embedded_bitmaps == p_b.disable_embedded_bitmaps) && (mipmaps == p_b.mipmaps) && (msdf == p_b.msdf) && (force_autohinter == p_b.force_autohinter) && (weight == p_b.weight) && (stretch == p_b.stretch) && (msdf_range == p_b.msdf_range) && (msdf_source_size == p_b.msdf_source_size) && (fixed_size == p_b.fixed_size) && (hinting == p_b.hinting) && (subpixel_positioning == p_b.subpixel_positioning) && (variation_coordinates == p_b.variation_coordinates) && (oversampling == p_b.oversampling) && (embolden == p_b.embolden) && (transform == p_b.transform) && (extra_spacing[SPACING_TOP] == p_b.extra_spacing[SPACING_TOP]) && (extra_spacing[SPACING_BOTTOM] == p_b.extra_spacing[SPACING_BOTTOM]) && (extra_spacing[SPACING_SPACE] == p_b.extra_spacing[SPACING_SPACE]) && (extra_spacing[SPACING_GLYPH] == p_b.extra_spacing[SPACING_GLYPH]) && (baseline_offset == p_b.baseline_offset);
}
SystemFontKey(const String &p_font_name, bool p_italic, int p_weight, int p_stretch, RID p_font, const TextServerFallback *p_fb) {
@@ -503,6 +505,7 @@ class TextServerFallback : public TextServerExtension {
weight = p_weight;
stretch = p_stretch;
antialiasing = p_fb->_font_get_antialiasing(p_font);
+ disable_embedded_bitmaps = p_fb->_font_get_disable_embedded_bitmaps(p_font);
mipmaps = p_fb->_font_get_generate_mipmaps(p_font);
msdf = p_fb->_font_is_multichannel_signed_distance_field(p_font);
msdf_range = p_fb->_font_get_msdf_pixel_range(p_font);
@@ -553,7 +556,7 @@ class TextServerFallback : public TextServerExtension {
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_SPACE], hash);
hash = hash_murmur3_one_32(p_a.extra_spacing[SPACING_GLYPH], hash);
hash = hash_murmur3_one_double(p_a.baseline_offset, hash);
- return hash_fmix32(hash_murmur3_one_32(((int)p_a.mipmaps) | ((int)p_a.msdf << 1) | ((int)p_a.italic << 2) | ((int)p_a.force_autohinter << 3) | ((int)p_a.hinting << 4) | ((int)p_a.subpixel_positioning << 8) | ((int)p_a.antialiasing << 12), hash));
+ return hash_fmix32(hash_murmur3_one_32(((int)p_a.mipmaps) | ((int)p_a.msdf << 1) | ((int)p_a.italic << 2) | ((int)p_a.force_autohinter << 3) | ((int)p_a.hinting << 4) | ((int)p_a.subpixel_positioning << 8) | ((int)p_a.antialiasing << 12) | ((int)p_a.disable_embedded_bitmaps << 14), hash));
}
};
mutable HashMap system_fonts;
@@ -619,6 +622,9 @@ public:
MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing);
MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &);
+ MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool);
+ MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &);
+
MODBIND2(font_set_generate_mipmaps, const RID &, bool);
MODBIND1RC(bool, font_get_generate_mipmaps, const RID &);
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 884fb7ba2bb..f2efa7fcbab 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -576,6 +576,7 @@ _FORCE_INLINE_ void FontFile::_ensure_rid(int p_cache_index, int p_make_linked_f
TS->font_set_data_ptr(cache[p_cache_index], data_ptr, data_size);
TS->font_set_antialiasing(cache[p_cache_index], antialiasing);
TS->font_set_generate_mipmaps(cache[p_cache_index], mipmaps);
+ TS->font_set_disable_embedded_bitmaps(cache[p_cache_index], disable_embedded_bitmaps);
TS->font_set_multichannel_signed_distance_field(cache[p_cache_index], msdf);
TS->font_set_msdf_pixel_range(cache[p_cache_index], msdf_pixel_range);
TS->font_set_msdf_size(cache[p_cache_index], msdf_size);
@@ -881,6 +882,9 @@ void FontFile::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_antialiasing", "antialiasing"), &FontFile::set_antialiasing);
ClassDB::bind_method(D_METHOD("get_antialiasing"), &FontFile::get_antialiasing);
+ ClassDB::bind_method(D_METHOD("set_disable_embedded_bitmaps", "disable_embedded_bitmaps"), &FontFile::set_disable_embedded_bitmaps);
+ ClassDB::bind_method(D_METHOD("get_disable_embedded_bitmaps"), &FontFile::get_disable_embedded_bitmaps);
+
ClassDB::bind_method(D_METHOD("set_generate_mipmaps", "generate_mipmaps"), &FontFile::set_generate_mipmaps);
ClassDB::bind_method(D_METHOD("get_generate_mipmaps"), &FontFile::get_generate_mipmaps);
@@ -1012,6 +1016,7 @@ void FontFile::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_data", "get_data");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_mipmaps", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_generate_mipmaps", "get_generate_mipmaps");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_disable_embedded_bitmaps", "get_disable_embedded_bitmaps");
ADD_PROPERTY(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_STORAGE), "set_antialiasing", "get_antialiasing");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "font_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_name", "get_font_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "style_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_style_name", "get_font_style_name");
@@ -1381,6 +1386,7 @@ void FontFile::reset_state() {
antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
mipmaps = false;
+ disable_embedded_bitmaps = true;
msdf = false;
force_autohinter = false;
allow_system_fallback = true;
@@ -1415,6 +1421,7 @@ Error FontFile::load_bitmap_font(const String &p_path) {
antialiasing = TextServer::FONT_ANTIALIASING_NONE;
mipmaps = false;
+ disable_embedded_bitmaps = true;
msdf = false;
force_autohinter = false;
allow_system_fallback = true;
@@ -2091,6 +2098,21 @@ TextServer::FontAntialiasing FontFile::get_antialiasing() const {
return antialiasing;
}
+void FontFile::set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps) {
+ if (disable_embedded_bitmaps != p_disable_embedded_bitmaps) {
+ disable_embedded_bitmaps = p_disable_embedded_bitmaps;
+ for (int i = 0; i < cache.size(); i++) {
+ _ensure_rid(i);
+ TS->font_set_disable_embedded_bitmaps(cache[i], disable_embedded_bitmaps);
+ }
+ emit_changed();
+ }
+}
+
+bool FontFile::get_disable_embedded_bitmaps() const {
+ return disable_embedded_bitmaps;
+}
+
void FontFile::set_generate_mipmaps(bool p_generate_mipmaps) {
if (mipmaps != p_generate_mipmaps) {
mipmaps = p_generate_mipmaps;
@@ -3012,6 +3034,9 @@ void SystemFont::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_antialiasing", "antialiasing"), &SystemFont::set_antialiasing);
ClassDB::bind_method(D_METHOD("get_antialiasing"), &SystemFont::get_antialiasing);
+ ClassDB::bind_method(D_METHOD("set_disable_embedded_bitmaps", "disable_embedded_bitmaps"), &SystemFont::set_disable_embedded_bitmaps);
+ ClassDB::bind_method(D_METHOD("get_disable_embedded_bitmaps"), &SystemFont::get_disable_embedded_bitmaps);
+
ClassDB::bind_method(D_METHOD("set_generate_mipmaps", "generate_mipmaps"), &SystemFont::set_generate_mipmaps);
ClassDB::bind_method(D_METHOD("get_generate_mipmaps"), &SystemFont::get_generate_mipmaps);
@@ -3053,6 +3078,7 @@ void SystemFont::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "font_stretch", PROPERTY_HINT_RANGE, "50,200,25"), "set_font_stretch", "get_font_stretch");
ADD_PROPERTY(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_STORAGE), "set_antialiasing", "get_antialiasing");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_mipmaps"), "set_generate_mipmaps", "get_generate_mipmaps");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), "set_disable_embedded_bitmaps", "get_disable_embedded_bitmaps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_system_fallback"), "set_allow_system_fallback", "is_allow_system_fallback");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_autohinter"), "set_force_autohinter", "is_force_autohinter");
ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), "set_hinting", "get_hinting");
@@ -3156,6 +3182,7 @@ void SystemFont::_update_base_font() {
// Apply font rendering settings.
file->set_antialiasing(antialiasing);
file->set_generate_mipmaps(mipmaps);
+ file->set_disable_embedded_bitmaps(disable_embedded_bitmaps);
file->set_force_autohinter(force_autohinter);
file->set_allow_system_fallback(allow_system_fallback);
file->set_hinting(hinting);
@@ -3199,6 +3226,7 @@ void SystemFont::reset_state() {
stretch = 100;
antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
mipmaps = false;
+ disable_embedded_bitmaps = true;
force_autohinter = false;
allow_system_fallback = true;
hinting = TextServer::HINTING_LIGHT;
@@ -3272,6 +3300,20 @@ TextServer::FontAntialiasing SystemFont::get_antialiasing() const {
return antialiasing;
}
+void SystemFont::set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps) {
+ if (disable_embedded_bitmaps != p_disable_embedded_bitmaps) {
+ disable_embedded_bitmaps = p_disable_embedded_bitmaps;
+ if (base_font.is_valid()) {
+ base_font->set_disable_embedded_bitmaps(disable_embedded_bitmaps);
+ }
+ emit_changed();
+ }
+}
+
+bool SystemFont::get_disable_embedded_bitmaps() const {
+ return disable_embedded_bitmaps;
+}
+
void SystemFont::set_generate_mipmaps(bool p_generate_mipmaps) {
if (mipmaps != p_generate_mipmaps) {
mipmaps = p_generate_mipmaps;
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 1cce46a3e35..a435d14a02e 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -187,6 +187,7 @@ class FontFile : public Font {
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
bool mipmaps = false;
+ bool disable_embedded_bitmaps = true;
bool msdf = false;
int msdf_pixel_range = 16;
int msdf_size = 48;
@@ -244,6 +245,9 @@ public:
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing);
virtual TextServer::FontAntialiasing get_antialiasing() const;
+ virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps);
+ virtual bool get_disable_embedded_bitmaps() const;
+
virtual void set_generate_mipmaps(bool p_generate_mipmaps);
virtual bool get_generate_mipmaps() const;
@@ -469,6 +473,7 @@ class SystemFont : public Font {
TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY;
bool mipmaps = false;
+ bool disable_embedded_bitmaps = true;
bool force_autohinter = false;
bool allow_system_fallback = true;
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
@@ -492,6 +497,9 @@ public:
virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing);
virtual TextServer::FontAntialiasing get_antialiasing() const;
+ virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps);
+ virtual bool get_disable_embedded_bitmaps() const;
+
virtual void set_generate_mipmaps(bool p_generate_mipmaps);
virtual bool get_generate_mipmaps() const;
diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp
index d5080e586d1..a01408f1510 100644
--- a/servers/text/text_server_extension.cpp
+++ b/servers/text/text_server_extension.cpp
@@ -80,6 +80,9 @@ void TextServerExtension::_bind_methods() {
GDVIRTUAL_BIND(_font_set_antialiasing, "font_rid", "antialiasing");
GDVIRTUAL_BIND(_font_get_antialiasing, "font_rid");
+ GDVIRTUAL_BIND(_font_set_disable_embedded_bitmaps, "font_rid", "disable_embedded_bitmaps");
+ GDVIRTUAL_BIND(_font_get_disable_embedded_bitmaps, "font_rid");
+
GDVIRTUAL_BIND(_font_set_generate_mipmaps, "font_rid", "generate_mipmaps");
GDVIRTUAL_BIND(_font_get_generate_mipmaps, "font_rid");
@@ -518,6 +521,16 @@ TextServer::FontAntialiasing TextServerExtension::font_get_antialiasing(const RI
return ret;
}
+void TextServerExtension::font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) {
+ GDVIRTUAL_CALL(_font_set_disable_embedded_bitmaps, p_font_rid, p_disable_embedded_bitmaps);
+}
+
+bool TextServerExtension::font_get_disable_embedded_bitmaps(const RID &p_font_rid) const {
+ bool ret = false;
+ GDVIRTUAL_CALL(_font_get_disable_embedded_bitmaps, p_font_rid, ret);
+ return ret;
+}
+
void TextServerExtension::font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) {
GDVIRTUAL_CALL(_font_set_generate_mipmaps, p_font_rid, p_generate_mipmaps);
}
diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h
index 4f9ea55d33d..935752e25a6 100644
--- a/servers/text/text_server_extension.h
+++ b/servers/text/text_server_extension.h
@@ -128,6 +128,11 @@ public:
GDVIRTUAL2(_font_set_antialiasing, RID, TextServer::FontAntialiasing);
GDVIRTUAL1RC(TextServer::FontAntialiasing, _font_get_antialiasing, RID);
+ virtual void font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) override;
+ virtual bool font_get_disable_embedded_bitmaps(const RID &p_font_rid) const override;
+ GDVIRTUAL2(_font_set_disable_embedded_bitmaps, RID, bool);
+ GDVIRTUAL1RC(bool, _font_get_disable_embedded_bitmaps, RID);
+
virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) override;
virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const override;
GDVIRTUAL2(_font_set_generate_mipmaps, RID, bool);
diff --git a/servers/text_server.cpp b/servers/text_server.cpp
index d1dadbc8399..267e6008c7b 100644
--- a/servers/text_server.cpp
+++ b/servers/text_server.cpp
@@ -234,6 +234,9 @@ void TextServer::_bind_methods() {
ClassDB::bind_method(D_METHOD("font_set_antialiasing", "font_rid", "antialiasing"), &TextServer::font_set_antialiasing);
ClassDB::bind_method(D_METHOD("font_get_antialiasing", "font_rid"), &TextServer::font_get_antialiasing);
+ ClassDB::bind_method(D_METHOD("font_set_disable_embedded_bitmaps", "font_rid", "disable_embedded_bitmaps"), &TextServer::font_set_disable_embedded_bitmaps);
+ ClassDB::bind_method(D_METHOD("font_get_disable_embedded_bitmaps", "font_rid"), &TextServer::font_get_disable_embedded_bitmaps);
+
ClassDB::bind_method(D_METHOD("font_set_generate_mipmaps", "font_rid", "generate_mipmaps"), &TextServer::font_set_generate_mipmaps);
ClassDB::bind_method(D_METHOD("font_get_generate_mipmaps", "font_rid"), &TextServer::font_get_generate_mipmaps);
diff --git a/servers/text_server.h b/servers/text_server.h
index dfd6140fde1..45c0117b898 100644
--- a/servers/text_server.h
+++ b/servers/text_server.h
@@ -274,6 +274,9 @@ public:
virtual void font_set_antialiasing(const RID &p_font_rid, FontAntialiasing p_antialiasing) = 0;
virtual FontAntialiasing font_get_antialiasing(const RID &p_font_rid) const = 0;
+ virtual void font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) = 0;
+ virtual bool font_get_disable_embedded_bitmaps(const RID &p_font_rid) const = 0;
+
virtual void font_set_generate_mipmaps(const RID &p_font_rid, bool p_generate_mipmaps) = 0;
virtual bool font_get_generate_mipmaps(const RID &p_font_rid) const = 0;