Skip to content

Commit 22e99a4

Browse files
committed
Restore per font oversampling override.
1 parent 8de08c7 commit 22e99a4

17 files changed

+130
-43
lines changed

doc/classes/FontFile.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@
651651
<member name="opentype_feature_overrides" type="Dictionary" setter="set_opentype_feature_overrides" getter="get_opentype_feature_overrides" default="{}">
652652
Font OpenType feature set override.
653653
</member>
654-
<member name="oversampling" type="float" setter="set_oversampling" getter="get_oversampling" deprecated="Use the [code skip-lint]oversampling[/code] argument of the [code skip-lint]draw_*[/code] methods instead.">
655-
Deprecated. This property does nothing.
654+
<member name="oversampling" type="float" setter="set_oversampling" getter="get_oversampling" default="0.0">
655+
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.
656656
</member>
657657
<member name="style_name" type="String" setter="set_font_style_name" getter="get_font_style_name" default="&quot;&quot;">
658658
Font style name.

doc/classes/ResourceImporterDynamicFont.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<member name="opentype_features" type="Dictionary" setter="" getter="" default="{}">
6767
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.
6868
</member>
69+
<member name="oversampling" type="float" setter="" getter="" default="0.0">
70+
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.
71+
</member>
6972
<member name="preload" type="Array" setter="" getter="" default="[]">
7073
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.
7174
</member>

doc/classes/SystemFont.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
<member name="multichannel_signed_distance_field" type="bool" setter="set_multichannel_signed_distance_field" getter="is_multichannel_signed_distance_field" default="false">
5959
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.
6060
</member>
61-
<member name="oversampling" type="float" setter="set_oversampling" getter="get_oversampling" deprecated="Use the [code skip-lint]oversampling[/code] argument of the [code skip-lint]draw_*[/code] methods instead.">
62-
Deprecated. This property does nothing.
61+
<member name="oversampling" type="float" setter="set_oversampling" getter="get_oversampling" default="0.0">
62+
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.
6363
</member>
6464
<member name="subpixel_positioning" type="int" setter="set_subpixel_positioning" getter="get_subpixel_positioning" enum="TextServer.SubpixelPositioning" default="1">
6565
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.

doc/classes/TextServer.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@
399399
Returns [Dictionary] with OpenType font name strings (localized font names, version, description, license information, sample text, etc.).
400400
</description>
401401
</method>
402-
<method name="font_get_oversampling" qualifiers="const" deprecated="Use [Viewport] oversampling, or the [code skip-lint]oversampling[/code] argument of the [code skip-lint]draw_*[/code] methods instead.">
402+
<method name="font_get_oversampling" qualifiers="const">
403403
<return type="float" />
404404
<param index="0" name="font_rid" type="RID" />
405405
<description>
406-
Deprecated. This method always returns [code]1.0[/code].
406+
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.
407407
</description>
408408
</method>
409409
<method name="font_get_scale" qualifiers="const">
@@ -928,12 +928,12 @@
928928
Sets font OpenType feature set override.
929929
</description>
930930
</method>
931-
<method name="font_set_oversampling" deprecated="Use [Viewport] oversampling, or the [code skip-lint]oversampling[/code] argument of the [code skip-lint]draw_*[/code] methods instead.">
931+
<method name="font_set_oversampling">
932932
<return type="void" />
933933
<param index="0" name="font_rid" type="RID" />
934934
<param index="1" name="oversampling" type="float" />
935935
<description>
936-
Deprecated. This method does nothing.
936+
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.
937937
</description>
938938
</method>
939939
<method name="font_set_scale">

doc/classes/TextServerExtension.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
<return type="float" />
382382
<param index="0" name="font_rid" type="RID" />
383383
<description>
384-
Returns font oversampling factor, if set to [code]0.0[/code] global oversampling factor is used instead. Used by dynamic fonts only.
384+
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.
385385
</description>
386386
</method>
387387
<method name="_font_get_scale" qualifiers="virtual required const">
@@ -916,7 +916,7 @@
916916
<param index="0" name="font_rid" type="RID" />
917917
<param index="1" name="oversampling" type="float" />
918918
<description>
919-
Sets font oversampling factor, if set to [code]0.0[/code] global oversampling factor is used instead. Used by dynamic fonts only.
919+
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.
920920
</description>
921921
</method>
922922
<method name="_font_set_scale" qualifiers="virtual required">

editor/import/dynamic_font_import_settings.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bool DynamicFontImportSettingsData::_get(const StringName &p_name, Variant &r_re
7171
void DynamicFontImportSettingsData::_get_property_list(List<PropertyInfo> *p_list) const {
7272
for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
7373
if (owner && owner->import_settings_data.is_valid()) {
74-
if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size")) {
74+
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")) {
7575
continue;
7676
}
7777
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_
159159
_variations_validate();
160160
} else if (p_edited_property == "keep_rounding_remainders") {
161161
font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders"));
162+
} else if (p_edited_property == "oversampling") {
163+
font_preview->set_oversampling(import_settings_data->get("oversampling"));
162164
}
163165
}
164166

@@ -633,6 +635,7 @@ void DynamicFontImportSettingsDialog::_re_import() {
633635
main_settings["hinting"] = import_settings_data->get("hinting");
634636
main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning");
635637
main_settings["keep_rounding_remainders"] = import_settings_data->get("keep_rounding_remainders");
638+
main_settings["oversampling"] = import_settings_data->get("oversampling");
636639
main_settings["fallbacks"] = import_settings_data->get("fallbacks");
637640
main_settings["compress"] = import_settings_data->get("compress");
638641

@@ -944,6 +947,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {
944947
}
945948
font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning);
946949
font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders"));
950+
font_preview->set_oversampling(import_settings_data->get("oversampling"));
947951
}
948952
font_preview_label->add_theme_font_override(SceneStringName(font), font_preview);
949953
font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE);
@@ -977,6 +981,7 @@ DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() {
977981
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
978982
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));
979983
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true));
984+
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0));
980985

981986
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
982987
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary()));

editor/import/resource_importer_dynamic_font.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ bool ResourceImporterDynamicFont::get_option_visibility(const String &p_path, co
8282
if (p_option == "antialiasing" && bool(p_options["multichannel_signed_distance_field"])) {
8383
return false;
8484
}
85+
if (p_option == "oversampling" && bool(p_options["multichannel_signed_distance_field"])) {
86+
return false;
87+
}
8588
if (p_option == "subpixel_positioning" && bool(p_options["multichannel_signed_distance_field"])) {
8689
return false;
8790
}
@@ -124,6 +127,7 @@ void ResourceImporterDynamicFont::get_import_options(const String &p_path, List<
124127
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
125128
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));
126129
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true));
130+
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0));
127131

128132
r_options->push_back(ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
129133
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
162166
int hinting = p_options["hinting"];
163167
int subpixel_positioning = p_options["subpixel_positioning"];
164168
bool keep_rounding_remainders = p_options["keep_rounding_remainders"];
169+
real_t oversampling = p_options["oversampling"];
165170
Array fallbacks = p_options["fallbacks"];
166171

167172
// Load base font data.
@@ -183,6 +188,7 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Str
183188
font->set_modulate_color_glyphs(modulate_color_glyphs);
184189
font->set_allow_system_fallback(allow_system_fallback);
185190
font->set_hinting((TextServer::Hinting)hinting);
191+
font->set_oversampling(oversampling);
186192
font->set_fallbacks(fallbacks);
187193

188194
if (subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) {

modules/text_server_adv/text_server_adv.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,25 @@ void TextServerAdvanced::_font_set_variation_coordinates(const RID &p_font_rid,
27182718
}
27192719
}
27202720

2721+
double TextServerAdvanced::_font_get_oversampling(const RID &p_font_rid) const {
2722+
FontAdvanced *fd = _get_font_data(p_font_rid);
2723+
ERR_FAIL_NULL_V(fd, -1.0);
2724+
2725+
MutexLock lock(fd->mutex);
2726+
return fd->oversampling_override;
2727+
}
2728+
2729+
void TextServerAdvanced::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) {
2730+
FontAdvanced *fd = _get_font_data(p_font_rid);
2731+
ERR_FAIL_NULL(fd);
2732+
2733+
MutexLock lock(fd->mutex);
2734+
if (fd->oversampling_override != p_oversampling) {
2735+
_font_clear_cache(fd);
2736+
fd->oversampling_override = p_oversampling;
2737+
}
2738+
}
2739+
27212740
Dictionary TextServerAdvanced::_font_get_variation_coordinates(const RID &p_font_rid) const {
27222741
FontAdvanced *fd = _get_font_data(p_font_rid);
27232742
ERR_FAIL_NULL_V(fd, Dictionary());
@@ -3902,7 +3921,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
39023921
bool viewport_oversampling = false;
39033922
float oversampling_factor = p_oversampling;
39043923
if (p_oversampling <= 0.0) {
3905-
if (vp_oversampling > 0.0) {
3924+
if (fd->oversampling_override > 0.0) {
3925+
oversampling_factor = fd->oversampling_override;
3926+
} else if (vp_oversampling > 0.0) {
39063927
oversampling_factor = vp_oversampling;
39073928
viewport_oversampling = true;
39083929
} else {
@@ -4046,7 +4067,9 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
40464067
bool viewport_oversampling = false;
40474068
float oversampling_factor = p_oversampling;
40484069
if (p_oversampling <= 0.0) {
4049-
if (vp_oversampling > 0.0) {
4070+
if (fd->oversampling_override > 0.0) {
4071+
oversampling_factor = fd->oversampling_override;
4072+
} else if (vp_oversampling > 0.0) {
40504073
oversampling_factor = vp_oversampling;
40514074
viewport_oversampling = true;
40524075
} else {

modules/text_server_adv/text_server_adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class TextServerAdvanced : public TextServerExtension {
344344
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
345345
bool keep_rounding_remainders = true;
346346
Dictionary variation_coordinates;
347+
double oversampling_override = 0.0;
347348
double embolden = 0.0;
348349
Transform2D transform;
349350

@@ -849,6 +850,9 @@ class TextServerAdvanced : public TextServerExtension {
849850
MODBIND2(font_set_variation_coordinates, const RID &, const Dictionary &);
850851
MODBIND1RC(Dictionary, font_get_variation_coordinates, const RID &);
851852

853+
MODBIND2(font_set_oversampling, const RID &, double);
854+
MODBIND1RC(double, font_get_oversampling, const RID &);
855+
852856
MODBIND2(font_set_hinting, const RID &, TextServer::Hinting);
853857
MODBIND1RC(TextServer::Hinting, font_get_hinting, const RID &);
854858

modules/text_server_fb/text_server_fb.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,25 @@ void TextServerFallback::_font_set_variation_coordinates(const RID &p_font_rid,
16931693
}
16941694
}
16951695

1696+
double TextServerFallback::_font_get_oversampling(const RID &p_font_rid) const {
1697+
FontFallback *fd = _get_font_data(p_font_rid);
1698+
ERR_FAIL_NULL_V(fd, -1.0);
1699+
1700+
MutexLock lock(fd->mutex);
1701+
return fd->oversampling_override;
1702+
}
1703+
1704+
void TextServerFallback::_font_set_oversampling(const RID &p_font_rid, double p_oversampling) {
1705+
FontFallback *fd = _get_font_data(p_font_rid);
1706+
ERR_FAIL_NULL(fd);
1707+
1708+
MutexLock lock(fd->mutex);
1709+
if (fd->oversampling_override != p_oversampling) {
1710+
_font_clear_cache(fd);
1711+
fd->oversampling_override = p_oversampling;
1712+
}
1713+
}
1714+
16961715
Dictionary TextServerFallback::_font_get_variation_coordinates(const RID &p_font_rid) const {
16971716
FontFallback *fd = _get_font_data(p_font_rid);
16981717
ERR_FAIL_NULL_V(fd, Dictionary());
@@ -2815,7 +2834,9 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
28152834
bool viewport_oversampling = false;
28162835
float oversampling_factor = p_oversampling;
28172836
if (p_oversampling <= 0.0) {
2818-
if (vp_oversampling > 0.0) {
2837+
if (fd->oversampling_override > 0.0) {
2838+
oversampling_factor = fd->oversampling_override;
2839+
} else if (vp_oversampling > 0.0) {
28192840
oversampling_factor = vp_oversampling;
28202841
viewport_oversampling = true;
28212842
} else {
@@ -2959,7 +2980,9 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
29592980
bool viewport_oversampling = false;
29602981
float oversampling_factor = p_oversampling;
29612982
if (p_oversampling <= 0.0) {
2962-
if (vp_oversampling > 0.0) {
2983+
if (fd->oversampling_override > 0.0) {
2984+
oversampling_factor = fd->oversampling_override;
2985+
} else if (vp_oversampling > 0.0) {
29632986
oversampling_factor = vp_oversampling;
29642987
viewport_oversampling = true;
29652988
} else {

0 commit comments

Comments
 (0)