From 22e99a4901e35dec77fb18da1bf719ebc9cb1139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Thu, 19 Jun 2025 15:05:52 +0300 Subject: [PATCH] Restore per font oversampling override. --- doc/classes/FontFile.xml | 4 +- doc/classes/ResourceImporterDynamicFont.xml | 3 ++ doc/classes/SystemFont.xml | 4 +- doc/classes/TextServer.xml | 8 ++-- doc/classes/TextServerExtension.xml | 4 +- .../import/dynamic_font_import_settings.cpp | 7 ++- .../import/resource_importer_dynamic_font.cpp | 6 +++ modules/text_server_adv/text_server_adv.cpp | 27 +++++++++++- modules/text_server_adv/text_server_adv.h | 4 ++ modules/text_server_fb/text_server_fb.cpp | 27 +++++++++++- modules/text_server_fb/text_server_fb.h | 4 ++ scene/resources/font.cpp | 43 +++++++++++++++---- scene/resources/font.h | 14 +++--- servers/text/text_server_extension.cpp | 8 ++-- servers/text/text_server_extension.h | 2 - servers/text_server.cpp | 2 - servers/text_server.h | 6 +-- 17 files changed, 130 insertions(+), 43 deletions(-) diff --git a/doc/classes/FontFile.xml b/doc/classes/FontFile.xml index eed4524ee0..d3f5b520b1 100644 --- a/doc/classes/FontFile.xml +++ b/doc/classes/FontFile.xml @@ -651,8 +651,8 @@ Font OpenType feature set override. - - Deprecated. This property does nothing. + + If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Font style name. diff --git a/doc/classes/ResourceImporterDynamicFont.xml b/doc/classes/ResourceImporterDynamicFont.xml index 097c01a5fc..633f2662d7 100644 --- a/doc/classes/ResourceImporterDynamicFont.xml +++ b/doc/classes/ResourceImporterDynamicFont.xml @@ -66,6 +66,9 @@ The OpenType features to enable, disable or set a value for this font. This can be used to enable optional features provided by the font, such as ligatures or alternative glyphs. The list of supported OpenType features varies on a per-font basis. + + If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. + The glyph ranges to prerender. This can avoid stuttering during gameplay when new characters need to be rendered, especially if [member subpixel_positioning] is enabled. The downside of using preloading is that initial project load times will increase, as well as memory usage. diff --git a/doc/classes/SystemFont.xml b/doc/classes/SystemFont.xml index 73c7d663fe..3488a2c625 100644 --- a/doc/classes/SystemFont.xml +++ b/doc/classes/SystemFont.xml @@ -58,8 +58,8 @@ If set to [code]true[/code], glyphs of all sizes are rendered using single multichannel signed distance field generated from the dynamic font vector data. - - Deprecated. This property does nothing. + + If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Font glyph subpixel positioning mode. Subpixel positioning provides shaper text and better kerning for smaller font sizes, at the cost of memory usage and font rasterization speed. Use [constant TextServer.SUBPIXEL_POSITIONING_AUTO] to automatically enable it based on the font size. diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml index 438b0d2cb3..56c4d53369 100644 --- a/doc/classes/TextServer.xml +++ b/doc/classes/TextServer.xml @@ -399,11 +399,11 @@ Returns [Dictionary] with OpenType font name strings (localized font names, version, description, license information, sample text, etc.). - + - Deprecated. This method always returns [code]1.0[/code]. + Returns oversampling factor override. If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Used by dynamic fonts only. @@ -928,12 +928,12 @@ Sets font OpenType feature set override. - + - Deprecated. This method does nothing. + If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Used by dynamic fonts only. diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xml index 00326119ef..6eb9244691 100644 --- a/doc/classes/TextServerExtension.xml +++ b/doc/classes/TextServerExtension.xml @@ -381,7 +381,7 @@ - Returns font oversampling factor, if set to [code]0.0[/code] global oversampling factor is used instead. Used by dynamic fonts only. + Returns oversampling factor override. If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Used by dynamic fonts only. @@ -916,7 +916,7 @@ - Sets font oversampling factor, if set to [code]0.0[/code] global oversampling factor is used instead. Used by dynamic fonts only. + If set to a positive value, overrides the oversampling factor of the viewport this font is used in. See [member Viewport.oversampling]. This value doesn't override the [code skip-lint]oversampling[/code] parameter of [code skip-lint]draw_*[/code] methods. Used by dynamic fonts only. diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index 633485d92c..90b4b08446 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -71,7 +71,7 @@ bool DynamicFontImportSettingsData::_get(const StringName &p_name, Variant &r_re void DynamicFontImportSettingsData::_get_property_list(List *p_list) const { for (const List::Element *E = options.front(); E; E = E->next()) { if (owner && owner->import_settings_data.is_valid()) { - if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size")) { + if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size" || E->get().option.name == "oversampling")) { continue; } if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) { @@ -159,6 +159,8 @@ void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_ _variations_validate(); } else if (p_edited_property == "keep_rounding_remainders") { font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders")); + } else if (p_edited_property == "oversampling") { + font_preview->set_oversampling(import_settings_data->get("oversampling")); } } @@ -633,6 +635,7 @@ void DynamicFontImportSettingsDialog::_re_import() { main_settings["hinting"] = import_settings_data->get("hinting"); main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning"); main_settings["keep_rounding_remainders"] = import_settings_data->get("keep_rounding_remainders"); + main_settings["oversampling"] = import_settings_data->get("oversampling"); main_settings["fallbacks"] = import_settings_data->get("fallbacks"); main_settings["compress"] = import_settings_data->get("compress"); @@ -944,6 +947,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { } font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning); font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders")); + font_preview->set_oversampling(import_settings_data->get("oversampling")); } font_preview_label->add_theme_font_override(SceneStringName(font), font_preview); font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE); @@ -977,6 +981,7 @@ DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() { options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1)); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel,Auto (Except Pixel Fonts)"), 4)); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0)); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary())); diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cpp index 0020916f31..b5b1427ac9 100644 --- a/editor/import/resource_importer_dynamic_font.cpp +++ b/editor/import/resource_importer_dynamic_font.cpp @@ -82,6 +82,9 @@ bool ResourceImporterDynamicFont::get_option_visibility(const String &p_path, co if (p_option == "antialiasing" && bool(p_options["multichannel_signed_distance_field"])) { return false; } + if (p_option == "oversampling" && bool(p_options["multichannel_signed_distance_field"])) { + return false; + } if (p_option == "subpixel_positioning" && bool(p_options["multichannel_signed_distance_field"])) { return false; } @@ -124,6 +127,7 @@ void ResourceImporterDynamicFont::get_import_options(const String &p_path, List< r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel,Auto (Except Pixel Fonts)"), 4)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0)); r_options->push_back(ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); r_options->push_back(ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")), Array())); @@ -162,6 +166,7 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Str int hinting = p_options["hinting"]; int subpixel_positioning = p_options["subpixel_positioning"]; bool keep_rounding_remainders = p_options["keep_rounding_remainders"]; + real_t oversampling = p_options["oversampling"]; Array fallbacks = p_options["fallbacks"]; // Load base font data. @@ -183,6 +188,7 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Str font->set_modulate_color_glyphs(modulate_color_glyphs); font->set_allow_system_fallback(allow_system_fallback); font->set_hinting((TextServer::Hinting)hinting); + font->set_oversampling(oversampling); font->set_fallbacks(fallbacks); if (subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) { diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index b1141ac1be..69866bbf53 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -2718,6 +2718,25 @@ void TextServerAdvanced::_font_set_variation_coordinates(const RID &p_font_rid, } } +double TextServerAdvanced::_font_get_oversampling(const RID &p_font_rid) const { + FontAdvanced *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, -1.0); + + MutexLock lock(fd->mutex); + return fd->oversampling_override; +} + +void TextServerAdvanced::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) { + FontAdvanced *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); + + MutexLock lock(fd->mutex); + if (fd->oversampling_override != p_oversampling) { + _font_clear_cache(fd); + fd->oversampling_override = p_oversampling; + } +} + Dictionary TextServerAdvanced::_font_get_variation_coordinates(const RID &p_font_rid) const { FontAdvanced *fd = _get_font_data(p_font_rid); ERR_FAIL_NULL_V(fd, Dictionary()); @@ -3902,7 +3921,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca bool viewport_oversampling = false; float oversampling_factor = p_oversampling; if (p_oversampling <= 0.0) { - if (vp_oversampling > 0.0) { + if (fd->oversampling_override > 0.0) { + oversampling_factor = fd->oversampling_override; + } else if (vp_oversampling > 0.0) { oversampling_factor = vp_oversampling; viewport_oversampling = true; } else { @@ -4046,7 +4067,9 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R bool viewport_oversampling = false; float oversampling_factor = p_oversampling; if (p_oversampling <= 0.0) { - if (vp_oversampling > 0.0) { + if (fd->oversampling_override > 0.0) { + oversampling_factor = fd->oversampling_override; + } else if (vp_oversampling > 0.0) { oversampling_factor = vp_oversampling; viewport_oversampling = true; } else { diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index a6b67afa93..254430037f 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -344,6 +344,7 @@ class TextServerAdvanced : public TextServerExtension { TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; bool keep_rounding_remainders = true; Dictionary variation_coordinates; + double oversampling_override = 0.0; double embolden = 0.0; Transform2D transform; @@ -849,6 +850,9 @@ public: MODBIND2(font_set_variation_coordinates, const RID &, const Dictionary &); MODBIND1RC(Dictionary, font_get_variation_coordinates, const RID &); + MODBIND2(font_set_oversampling, const RID &, double); + MODBIND1RC(double, font_get_oversampling, const RID &); + MODBIND2(font_set_hinting, const RID &, TextServer::Hinting); MODBIND1RC(TextServer::Hinting, font_get_hinting, const RID &); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index b5750dfea8..29aca7168a 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -1693,6 +1693,25 @@ void TextServerFallback::_font_set_variation_coordinates(const RID &p_font_rid, } } +double TextServerFallback::_font_get_oversampling(const RID &p_font_rid) const { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, -1.0); + + MutexLock lock(fd->mutex); + return fd->oversampling_override; +} + +void TextServerFallback::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); + + MutexLock lock(fd->mutex); + if (fd->oversampling_override != p_oversampling) { + _font_clear_cache(fd); + fd->oversampling_override = p_oversampling; + } +} + Dictionary TextServerFallback::_font_get_variation_coordinates(const RID &p_font_rid) const { FontFallback *fd = _get_font_data(p_font_rid); ERR_FAIL_NULL_V(fd, Dictionary()); @@ -2815,7 +2834,9 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca bool viewport_oversampling = false; float oversampling_factor = p_oversampling; if (p_oversampling <= 0.0) { - if (vp_oversampling > 0.0) { + if (fd->oversampling_override > 0.0) { + oversampling_factor = fd->oversampling_override; + } else if (vp_oversampling > 0.0) { oversampling_factor = vp_oversampling; viewport_oversampling = true; } else { @@ -2959,7 +2980,9 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R bool viewport_oversampling = false; float oversampling_factor = p_oversampling; if (p_oversampling <= 0.0) { - if (vp_oversampling > 0.0) { + if (fd->oversampling_override > 0.0) { + oversampling_factor = fd->oversampling_override; + } else if (vp_oversampling > 0.0) { oversampling_factor = vp_oversampling; viewport_oversampling = true; } else { diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index 0283a0a920..8349f37c18 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -283,6 +283,7 @@ class TextServerFallback : public TextServerExtension { TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; bool keep_rounding_remainders = true; Dictionary variation_coordinates; + double oversampling_override = 0.0; double embolden = 0.0; Transform2D transform; @@ -704,6 +705,9 @@ public: MODBIND2(font_set_variation_coordinates, const RID &, const Dictionary &); MODBIND1RC(Dictionary, font_get_variation_coordinates, const RID &); + MODBIND2(font_set_oversampling, const RID &, double); + MODBIND1RC(double, font_get_oversampling, const RID &); + MODBIND2(font_set_hinting, const RID &, TextServer::Hinting); MODBIND1RC(TextServer::Hinting, font_get_hinting, const RID &); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index f554ef4726..904d73cf3d 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -607,6 +607,7 @@ _FORCE_INLINE_ void FontFile::_ensure_rid(int p_cache_index, int p_make_linked_f TS->font_set_hinting(cache[p_cache_index], hinting); TS->font_set_subpixel_positioning(cache[p_cache_index], subpixel_positioning); TS->font_set_keep_rounding_remainders(cache[p_cache_index], keep_rounding_remainders); + TS->font_set_oversampling(cache[p_cache_index], oversampling_override); } } } @@ -941,13 +942,9 @@ void FontFile::_bind_methods() { ClassDB::bind_method(D_METHOD("set_keep_rounding_remainders", "keep_rounding_remainders"), &FontFile::set_keep_rounding_remainders); ClassDB::bind_method(D_METHOD("get_keep_rounding_remainders"), &FontFile::get_keep_rounding_remainders); -#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_oversampling", "oversampling"), &FontFile::set_oversampling); ClassDB::bind_method(D_METHOD("get_oversampling"), &FontFile::get_oversampling); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_NONE, "", 0), "set_oversampling", "get_oversampling"); -#endif - ClassDB::bind_method(D_METHOD("get_cache_count"), &FontFile::get_cache_count); ClassDB::bind_method(D_METHOD("clear_cache"), &FontFile::clear_cache); ClassDB::bind_method(D_METHOD("remove_cache", "cache_index"), &FontFile::remove_cache); @@ -1066,6 +1063,7 @@ void FontFile::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_fixed_size", "get_fixed_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_size_scale_mode", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_fixed_size_scale_mode", "get_fixed_size_scale_mode"); ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "opentype_feature_overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_opentype_feature_overrides", "get_opentype_feature_overrides"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_oversampling", "get_oversampling"); } void FontFile::_validate_property(PropertyInfo &p_property) const { @@ -1426,6 +1424,7 @@ void FontFile::reset_state() { hinting = TextServer::HINTING_LIGHT; subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED; keep_rounding_remainders = true; + oversampling_override = 0.0; msdf_pixel_range = 14; msdf_size = 128; fixed_size = 0; @@ -2339,6 +2338,21 @@ bool FontFile::get_keep_rounding_remainders() const { return keep_rounding_remainders; } +void FontFile::set_oversampling(real_t p_oversampling) { + if (oversampling_override != p_oversampling) { + oversampling_override = p_oversampling; + for (int i = 0; i < cache.size(); i++) { + _ensure_rid(i); + TS->font_set_oversampling(cache[i], oversampling_override); + } + emit_changed(); + } +} + +real_t FontFile::get_oversampling() const { + return oversampling_override; +} + RID FontFile::find_variation(const Dictionary &p_variation_coordinates, int p_face_index, float p_strength, Transform2D p_transform, int p_spacing_top, int p_spacing_bottom, int p_spacing_space, int p_spacing_glyph, float p_baseline_offset) const { // Find existing variation cache. const Dictionary &supported_coords = get_supported_variation_list(); @@ -3129,13 +3143,9 @@ void SystemFont::_bind_methods() { ClassDB::bind_method(D_METHOD("set_msdf_size", "msdf_size"), &SystemFont::set_msdf_size); ClassDB::bind_method(D_METHOD("get_msdf_size"), &SystemFont::get_msdf_size); -#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_oversampling", "oversampling"), &SystemFont::set_oversampling); ClassDB::bind_method(D_METHOD("get_oversampling"), &SystemFont::get_oversampling); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_NONE, "", 0), "set_oversampling", "get_oversampling"); -#endif - ClassDB::bind_method(D_METHOD("get_font_names"), &SystemFont::get_font_names); ClassDB::bind_method(D_METHOD("set_font_names", "names"), &SystemFont::set_font_names); @@ -3160,6 +3170,7 @@ void SystemFont::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field"), "set_multichannel_signed_distance_field", "is_multichannel_signed_distance_field"); ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_pixel_range"), "set_msdf_pixel_range", "get_msdf_pixel_range"); ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_size"), "set_msdf_size", "get_msdf_size"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "oversampling"), "set_oversampling", "get_oversampling"); } void SystemFont::_update_rids() const { @@ -3263,6 +3274,7 @@ void SystemFont::_update_base_font() { file->set_hinting(hinting); file->set_subpixel_positioning(subpixel_positioning); file->set_keep_rounding_remainders(keep_rounding_remainders); + file->set_oversampling(oversampling_override); file->set_multichannel_signed_distance_field(msdf); file->set_msdf_pixel_range(msdf_pixel_range); file->set_msdf_size(msdf_size); @@ -3307,6 +3319,7 @@ void SystemFont::reset_state() { hinting = TextServer::HINTING_LIGHT; subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED; keep_rounding_remainders = true; + oversampling_override = 0.0; msdf = false; Font::reset_state(); @@ -3487,6 +3500,20 @@ bool SystemFont::get_keep_rounding_remainders() const { return keep_rounding_remainders; } +void SystemFont::set_oversampling(real_t p_oversampling) { + if (oversampling_override != p_oversampling) { + oversampling_override = p_oversampling; + if (base_font.is_valid()) { + base_font->set_oversampling(oversampling_override); + } + emit_changed(); + } +} + +real_t SystemFont::get_oversampling() const { + return oversampling_override; +} + void SystemFont::set_multichannel_signed_distance_field(bool p_msdf) { if (msdf != p_msdf) { msdf = p_msdf; diff --git a/scene/resources/font.h b/scene/resources/font.h index 08e140d8ff..52cf8036e6 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -203,6 +203,7 @@ class FontFile : public Font { TextServer::Hinting hinting = TextServer::HINTING_LIGHT; TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; bool keep_rounding_remainders = true; + double oversampling_override = 0.0; #ifndef DISABLE_DEPRECATED real_t bmp_height = 0.0; @@ -291,10 +292,8 @@ public: virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders); virtual bool get_keep_rounding_remainders() const; -#ifndef DISABLE_DEPRECATED - virtual void set_oversampling(real_t p_oversampling) {} - virtual real_t get_oversampling() const { return 1.0; } -#endif + virtual void set_oversampling(real_t p_oversampling); + virtual real_t get_oversampling() const; // Cache. virtual RID find_variation(const Dictionary &p_variation_coordinates, int p_face_index = 0, float p_strength = 0.0, Transform2D p_transform = Transform2D(), int p_spacing_top = 0, int p_spacing_bottom = 0, int p_spacing_space = 0, int p_spacing_glyph = 0, float p_baseline_offset = 0.0) const override; @@ -495,6 +494,7 @@ class SystemFont : public Font { TextServer::Hinting hinting = TextServer::HINTING_LIGHT; TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; bool keep_rounding_remainders = true; + double oversampling_override = 0.0; bool msdf = false; int msdf_pixel_range = 16; int msdf_size = 48; @@ -538,10 +538,8 @@ public: virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders); virtual bool get_keep_rounding_remainders() const; -#ifndef DISABLE_DEPRECATED - virtual void set_oversampling(real_t p_oversampling) {} - virtual real_t get_oversampling() const { return 1.0; } -#endif + virtual void set_oversampling(real_t p_oversampling); + virtual real_t get_oversampling() const; virtual void set_multichannel_signed_distance_field(bool p_msdf); virtual bool is_multichannel_signed_distance_field() const; diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index 97749b1621..28fd2ff50c 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -756,15 +756,15 @@ Dictionary TextServerExtension::font_get_variation_coordinates(const RID &p_font return ret; } -#ifndef DISABLE_DEPRECATED void TextServerExtension::font_set_oversampling(const RID &p_font_rid, double p_oversampling) { - // NOP + GDVIRTUAL_CALL(_font_set_oversampling, p_font_rid, p_oversampling); } double TextServerExtension::font_get_oversampling(const RID &p_font_rid) const { - return 1.0; + double ret = -1.0; + GDVIRTUAL_CALL(_font_get_oversampling, p_font_rid, ret); + return ret; } -#endif TypedArray TextServerExtension::font_get_size_cache_list(const RID &p_font_rid) const { TypedArray ret; diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index 48c94c0c9d..a5c0a06e96 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -221,12 +221,10 @@ public: GDVIRTUAL2(_font_set_variation_coordinates, RID, Dictionary); GDVIRTUAL1RC(Dictionary, _font_get_variation_coordinates, RID); -#ifndef DISABLE_DEPRECATED virtual void font_set_oversampling(const RID &p_font_rid, double p_oversampling) override; virtual double font_get_oversampling(const RID &p_font_rid) const override; GDVIRTUAL2(_font_set_oversampling, RID, double); GDVIRTUAL1RC(double, _font_get_oversampling, RID); -#endif virtual TypedArray font_get_size_cache_list(const RID &p_font_rid) const override; virtual void font_clear_size_cache(const RID &p_font_rid) override; diff --git a/servers/text_server.cpp b/servers/text_server.cpp index 2a3c5fd07c..16d574c320 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -293,10 +293,8 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_set_variation_coordinates", "font_rid", "variation_coordinates"), &TextServer::font_set_variation_coordinates); ClassDB::bind_method(D_METHOD("font_get_variation_coordinates", "font_rid"), &TextServer::font_get_variation_coordinates); -#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("font_set_oversampling", "font_rid", "oversampling"), &TextServer::font_set_oversampling); ClassDB::bind_method(D_METHOD("font_get_oversampling", "font_rid"), &TextServer::font_get_oversampling); -#endif ClassDB::bind_method(D_METHOD("font_get_size_cache_list", "font_rid"), &TextServer::font_get_size_cache_list); ClassDB::bind_method(D_METHOD("font_clear_size_cache", "font_rid"), &TextServer::font_clear_size_cache); diff --git a/servers/text_server.h b/servers/text_server.h index 7130e6f0db..50d2683909 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -352,10 +352,8 @@ public: virtual void font_set_variation_coordinates(const RID &p_font_rid, const Dictionary &p_variation_coordinates) = 0; virtual Dictionary font_get_variation_coordinates(const RID &p_font_rid) const = 0; -#ifndef DISABLE_DEPRECATED - virtual void font_set_oversampling(const RID &p_font_rid, double p_oversampling) {} - virtual double font_get_oversampling(const RID &p_font_rid) const { return 1.0; } -#endif + virtual void font_set_oversampling(const RID &p_font_rid, double p_oversampling) = 0; + virtual double font_get_oversampling(const RID &p_font_rid) const = 0; virtual TypedArray font_get_size_cache_list(const RID &p_font_rid) const = 0; virtual void font_clear_size_cache(const RID &p_font_rid) = 0;