Skip to content

Commit c23832b

Browse files
committed
Merge pull request #104878 from bruvzg/color_mod_f
Add font import flag to toggle modulation of colored glyphs.
2 parents 03d460f + 19f360d commit c23832b

18 files changed

+170
-2
lines changed

doc/classes/FontFile.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@
634634
<member name="keep_rounding_remainders" type="bool" setter="set_keep_rounding_remainders" getter="get_keep_rounding_remainders" default="true">
635635
If set to [code]true[/code], when aligning glyphs to the pixel boundaries rounding remainders are accumulated to ensure more uniform glyph distribution. This setting has no effect if subpixel positioning is enabled.
636636
</member>
637+
<member name="modulate_color_glyphs" type="bool" setter="set_modulate_color_glyphs" getter="is_modulate_color_glyphs" default="false">
638+
If set to [code]true[/code], color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
639+
</member>
637640
<member name="msdf_pixel_range" type="int" setter="set_msdf_pixel_range" getter="get_msdf_pixel_range" default="16">
638641
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]16[/code] allows outline sizes up to [code]8[/code] to look correct.
639642
</member>

doc/classes/ResourceImporterDynamicFont.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<member name="language_support" type="Dictionary" setter="" getter="" default="{}">
5151
Override the list of languages supported by this font. If left empty, this is supplied by the font metadata. There is usually no need to change this. See also [member script_support].
5252
</member>
53+
<member name="modulate_color_glyphs" type="bool" setter="" getter="" default="false">
54+
If set to [code]true[/code], color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
55+
</member>
5356
<member name="msdf_pixel_range" type="int" setter="" getter="" default="8">
5457
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]8[/code] allows outline sizes up to [code]4[/code] to look correct.
5558
</member>

doc/classes/SystemFont.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
<member name="keep_rounding_remainders" type="bool" setter="set_keep_rounding_remainders" getter="get_keep_rounding_remainders" default="true">
4747
If set to [code]true[/code], when aligning glyphs to the pixel boundaries rounding remainders are accumulated to ensure more uniform glyph distribution. This setting has no effect if subpixel positioning is enabled.
4848
</member>
49+
<member name="modulate_color_glyphs" type="bool" setter="set_modulate_color_glyphs" getter="is_modulate_color_glyphs" default="false">
50+
If set to [code]true[/code], color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
51+
</member>
4952
<member name="msdf_pixel_range" type="int" setter="set_msdf_pixel_range" getter="get_msdf_pixel_range" default="16">
5053
The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]16[/code] allows outline sizes up to [code]8[/code] to look correct.
5154
</member>

doc/classes/TextServer.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,13 @@
571571
Returns [code]true[/code], if font supports given language ([url=https://en.wikipedia.org/wiki/ISO_639-1]ISO 639[/url] code).
572572
</description>
573573
</method>
574+
<method name="font_is_modulate_color_glyphs" qualifiers="const">
575+
<return type="bool" />
576+
<param index="0" name="font_rid" type="RID" />
577+
<description>
578+
Returns [code]true[/code], if color modulation is applied when drawing colored glyphs.
579+
</description>
580+
</method>
574581
<method name="font_is_multichannel_signed_distance_field" qualifiers="const">
575582
<return type="bool" />
576583
<param index="0" name="font_rid" type="RID" />
@@ -858,6 +865,14 @@
858865
Adds override for [method font_is_language_supported].
859866
</description>
860867
</method>
868+
<method name="font_set_modulate_color_glyphs">
869+
<return type="void" />
870+
<param index="0" name="font_rid" type="RID" />
871+
<param index="1" name="force_autohinter" type="bool" />
872+
<description>
873+
If set to [code]true[/code], color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
874+
</description>
875+
</method>
861876
<method name="font_set_msdf_pixel_range">
862877
<return type="void" />
863878
<param index="0" name="font_rid" type="RID" />

doc/classes/TextServerExtension.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,14 @@
617617
Returns [code]true[/code], if font supports given language ([url=https://en.wikipedia.org/wiki/ISO_639-1]ISO 639[/url] code).
618618
</description>
619619
</method>
620+
<method name="_font_is_modulate_color_glyphs" qualifiers="virtual const">
621+
<return type="bool" />
622+
<param index="0" name="font_rid" type="RID" />
623+
<description>
624+
[b]Optional.[/b]
625+
Returns [code]true[/code], if color modulation is applied when drawing colored glyphs.
626+
</description>
627+
</method>
620628
<method name="_font_is_multichannel_signed_distance_field" qualifiers="virtual const">
621629
<return type="bool" />
622630
<param index="0" name="font_rid" type="RID" />
@@ -942,6 +950,15 @@
942950
Adds override for [method _font_is_language_supported].
943951
</description>
944952
</method>
953+
<method name="_font_set_modulate_color_glyphs" qualifiers="virtual">
954+
<return type="void" />
955+
<param index="0" name="font_rid" type="RID" />
956+
<param index="1" name="modulate" type="bool" />
957+
<description>
958+
[b]Optional.[/b]
959+
If set to [code]true[/code], color modulation is applied when drawing colored glyphs, otherwise it's applied to the monochrome glyphs only.
960+
</description>
961+
</method>
945962
<method name="_font_set_msdf_pixel_range" qualifiers="virtual">
946963
<return type="void" />
947964
<param index="0" name="font_rid" type="RID" />

editor/import/dynamic_font_import_settings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_
490490
font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
491491
} else if (p_edited_property == "force_autohinter") {
492492
font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
493+
} else if (p_edited_property == "modulate_color_glyphs") {
494+
font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs"));
493495
} else if (p_edited_property == "hinting") {
494496
font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
495497
} else if (p_edited_property == "subpixel_positioning") {
@@ -977,6 +979,7 @@ void DynamicFontImportSettingsDialog::_re_import() {
977979
main_settings["msdf_size"] = import_settings_data->get("msdf_size");
978980
main_settings["allow_system_fallback"] = import_settings_data->get("allow_system_fallback");
979981
main_settings["force_autohinter"] = import_settings_data->get("force_autohinter");
982+
main_settings["modulate_color_glyphs"] = import_settings_data->get("modulate_color_glyphs");
980983
main_settings["hinting"] = import_settings_data->get("hinting");
981984
main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning");
982985
main_settings["keep_rounding_remainders"] = import_settings_data->get("keep_rounding_remainders");
@@ -1281,6 +1284,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {
12811284
font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
12821285
font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
12831286
font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
1287+
font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs"));
12841288
font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
12851289
int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int();
12861290
if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) {
@@ -1322,6 +1326,7 @@ DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() {
13221326
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
13231327
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "allow_system_fallback"), true));
13241328
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
1329+
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "modulate_color_glyphs"), false));
13251330
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
13261331
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));
13271332
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true));

editor/import/resource_importer_dynamic_font.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void ResourceImporterDynamicFont::get_import_options(const String &p_path, List<
116116

117117
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "allow_system_fallback"), true));
118118
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
119+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "modulate_color_glyphs"), false));
119120
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
120121
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));
121122
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true));
@@ -153,6 +154,7 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Str
153154
Dictionary ot_ov = p_options["opentype_features"];
154155

155156
bool autohinter = p_options["force_autohinter"];
157+
bool modulate_color_glyphs = p_options["modulate_color_glyphs"];
156158
bool allow_system_fallback = p_options["allow_system_fallback"];
157159
int hinting = p_options["hinting"];
158160
int subpixel_positioning = p_options["subpixel_positioning"];
@@ -176,6 +178,7 @@ Error ResourceImporterDynamicFont::import(ResourceUID::ID p_source_id, const Str
176178
font->set_opentype_feature_overrides(ot_ov);
177179
font->set_fixed_size(0);
178180
font->set_force_autohinter(autohinter);
181+
font->set_modulate_color_glyphs(modulate_color_glyphs);
179182
font->set_allow_system_fallback(allow_system_fallback);
180183
font->set_hinting((TextServer::Hinting)hinting);
181184
font->set_oversampling(oversampling);

editor/import/resource_importer_imagefont.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Error ResourceImporterImageFont::import(ResourceUID::ID p_source_id, const Strin
114114
font->set_subpixel_positioning(TextServer::SUBPIXEL_POSITIONING_DISABLED);
115115
font->set_keep_rounding_remainders(true);
116116
font->set_force_autohinter(false);
117+
font->set_modulate_color_glyphs(false);
117118
font->set_allow_system_fallback(false);
118119
font->set_hinting(TextServer::HINTING_NONE);
119120
font->set_oversampling(1.0f);

modules/text_server_adv/text_server_adv.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,24 @@ bool TextServerAdvanced::_font_is_force_autohinter(const RID &p_font_rid) const
24402440
return fd->force_autohinter;
24412441
}
24422442

2443+
void TextServerAdvanced::_font_set_modulate_color_glyphs(const RID &p_font_rid, bool p_modulate) {
2444+
FontAdvanced *fd = _get_font_data(p_font_rid);
2445+
ERR_FAIL_NULL(fd);
2446+
2447+
MutexLock lock(fd->mutex);
2448+
if (fd->modulate_color_glyphs != p_modulate) {
2449+
fd->modulate_color_glyphs = p_modulate;
2450+
}
2451+
}
2452+
2453+
bool TextServerAdvanced::_font_is_modulate_color_glyphs(const RID &p_font_rid) const {
2454+
FontAdvanced *fd = _get_font_data(p_font_rid);
2455+
ERR_FAIL_NULL_V(fd, false);
2456+
2457+
MutexLock lock(fd->mutex);
2458+
return fd->modulate_color_glyphs;
2459+
}
2460+
24432461
void TextServerAdvanced::_font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) {
24442462
FontAdvanced *fd = _get_font_data(p_font_rid);
24452463
ERR_FAIL_NULL(fd);
@@ -3800,7 +3818,7 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
38003818
if (fgl.texture_idx != -1) {
38013819
Color modulate = p_color;
38023820
#ifdef MODULE_FREETYPE_ENABLED
3803-
if (!fgl.from_svg && ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
3821+
if (!fd->modulate_color_glyphs && ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
38043822
modulate.r = modulate.g = modulate.b = 1.0;
38053823
}
38063824
#endif

modules/text_server_adv/text_server_adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class TextServerAdvanced : public TextServerExtension {
330330
int fixed_size = 0;
331331
bool allow_system_fallback = true;
332332
bool force_autohinter = false;
333+
bool modulate_color_glyphs = false;
333334
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
334335
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
335336
bool keep_rounding_remainders = true;
@@ -807,6 +808,9 @@ class TextServerAdvanced : public TextServerExtension {
807808
MODBIND2(font_set_force_autohinter, const RID &, bool);
808809
MODBIND1RC(bool, font_is_force_autohinter, const RID &);
809810

811+
MODBIND2(font_set_modulate_color_glyphs, const RID &, bool);
812+
MODBIND1RC(bool, font_is_modulate_color_glyphs, const RID &);
813+
810814
MODBIND2(font_set_subpixel_positioning, const RID &, SubpixelPositioning);
811815
MODBIND1RC(SubpixelPositioning, font_get_subpixel_positioning, const RID &);
812816

modules/text_server_fb/text_server_fb.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,24 @@ bool TextServerFallback::_font_is_force_autohinter(const RID &p_font_rid) const
14421442
return fd->force_autohinter;
14431443
}
14441444

1445+
void TextServerFallback::_font_set_modulate_color_glyphs(const RID &p_font_rid, bool p_modulate) {
1446+
FontFallback *fd = _get_font_data(p_font_rid);
1447+
ERR_FAIL_NULL(fd);
1448+
1449+
MutexLock lock(fd->mutex);
1450+
if (fd->modulate_color_glyphs != p_modulate) {
1451+
fd->modulate_color_glyphs = p_modulate;
1452+
}
1453+
}
1454+
1455+
bool TextServerFallback::_font_is_modulate_color_glyphs(const RID &p_font_rid) const {
1456+
FontFallback *fd = _get_font_data(p_font_rid);
1457+
ERR_FAIL_NULL_V(fd, false);
1458+
1459+
MutexLock lock(fd->mutex);
1460+
return fd->modulate_color_glyphs;
1461+
}
1462+
14451463
void TextServerFallback::_font_set_hinting(const RID &p_font_rid, TextServer::Hinting p_hinting) {
14461464
FontFallback *fd = _get_font_data(p_font_rid);
14471465
ERR_FAIL_NULL(fd);
@@ -2741,7 +2759,7 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
27412759
if (fgl.texture_idx != -1) {
27422760
Color modulate = p_color;
27432761
#ifdef MODULE_FREETYPE_ENABLED
2744-
if (!fgl.from_svg && ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
2762+
if (!fd->modulate_color_glyphs && ffsd->face && ffsd->textures[fgl.texture_idx].image.is_valid() && (ffsd->textures[fgl.texture_idx].image->get_format() == Image::FORMAT_RGBA8) && !lcd_aa && !fd->msdf) {
27452763
modulate.r = modulate.g = modulate.b = 1.0;
27462764
}
27472765
#endif

modules/text_server_fb/text_server_fb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class TextServerFallback : public TextServerExtension {
268268
int fixed_size = 0;
269269
bool force_autohinter = false;
270270
bool allow_system_fallback = true;
271+
bool modulate_color_glyphs = false;
271272
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
272273
TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
273274
bool keep_rounding_remainders = true;
@@ -662,6 +663,9 @@ class TextServerFallback : public TextServerExtension {
662663
MODBIND2(font_set_force_autohinter, const RID &, bool);
663664
MODBIND1RC(bool, font_is_force_autohinter, const RID &);
664665

666+
MODBIND2(font_set_modulate_color_glyphs, const RID &, bool);
667+
MODBIND1RC(bool, font_is_modulate_color_glyphs, const RID &);
668+
665669
MODBIND2(font_set_subpixel_positioning, const RID &, SubpixelPositioning);
666670
MODBIND1RC(SubpixelPositioning, font_get_subpixel_positioning, const RID &);
667671

0 commit comments

Comments
 (0)