Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/classes/BaseMaterial3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@
<member name="msdf_pixel_range" type="float" setter="set_msdf_pixel_range" getter="get_msdf_pixel_range" default="4.0">
The width of the range around the shape between the minimum and maximum representable signed distance.
</member>
<member name="msdf_rounded_outline" type="float" setter="set_msdf_rounded_outline" getter="get_msdf_rounded_outline" default="1.0">
MSDF outline rounding factor. [code]0.0[/code] is a sharp outline, while [code]1.0[/code] is a rounded outline. Values between result in a slightly rounded outline.
</member>
<member name="no_depth_test" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], depth testing is disabled and the object will be drawn in render order.
</member>
Expand Down
1 change: 1 addition & 0 deletions doc/classes/CanvasItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
<param index="4" name="outline" type="float" default="0.0" />
<param index="5" name="pixel_range" type="float" default="4.0" />
<param index="6" name="scale" type="float" default="1.0" />
<param index="7" name="msdf_rounded_outline" type="float" default="1.0" />
<description>
Draws a textured rectangle region of the multichannel signed distance field texture at a given position, optionally modulated by a color. The [param rect] is defined in local space. See [member FontFile.multichannel_signed_distance_field] for more information and caveats about MSDF font rendering.
If [param outline] is positive, each alpha channel value of pixel in region is set to maximum value of true distance in the [param outline] radius.
Expand Down
1 change: 1 addition & 0 deletions doc/classes/Font.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<param index="6" name="spacing_space" type="int" default="0" />
<param index="7" name="spacing_glyph" type="int" default="0" />
<param index="8" name="baseline_offset" type="float" default="0.0" />
<param index="9" name="msdf_rounded_outline" type="float" default="1.0" />
<description>
Returns [TextServer] RID of the font cache for specific variation.
</description>
Expand Down
15 changes: 15 additions & 0 deletions doc/classes/FontFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@
Returns extra baseline offset (as a fraction of font height).
</description>
</method>
<method name="get_extra_msdf_rounded_outline" qualifiers="const">
<return type="float" />
<param index="0" name="cache_index" type="int" />
<description>
Returns the MSDF outline rounding factor.
</description>
</method>
<method name="get_extra_spacing" qualifiers="const">
<return type="int" />
<param index="0" name="cache_index" type="int" />
Expand Down Expand Up @@ -460,6 +467,14 @@
Sets extra baseline offset (as a fraction of font height).
</description>
</method>
<method name="set_extra_msdf_rounded_outline">
<return type="void" />
<param index="0" name="cache_index" type="int" />
<param index="1" name="msdf_rounded_outline" type="float" />
<description>
Sets the MSDF outline rounding factor. [code]0.0[/code] is a sharp outline, while [code]1.0[/code] is a rounded outline. Values between result in a slightly rounded outline.
</description>
</method>
<method name="set_extra_spacing">
<return type="void" />
<param index="0" name="cache_index" type="int" />
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/FontVariation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<member name="baseline_offset" type="float" setter="set_baseline_offset" getter="get_baseline_offset" default="0.0">
Extra baseline offset (as a fraction of font height).
</member>
<member name="msdf_rounded_outline" type="float" setter="set_msdf_rounded_outline" getter="get_msdf_rounded_outline" default="1.0">
MSDF outline rounding factor. [code]0.0[/code] is a sharp outline, while [code]1.0[/code] is a rounded outline. Values between result in a slightly rounded outline.
</member>
<member name="opentype_features" type="Dictionary" setter="set_opentype_features" getter="get_opentype_features" default="{}">
A set of OpenType feature tags. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url].
</member>
Expand Down
1 change: 1 addition & 0 deletions doc/classes/RenderingServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
<param index="5" name="outline_size" type="int" default="0" />
<param index="6" name="px_range" type="float" default="1.0" />
<param index="7" name="scale" type="float" default="1.0" />
<param index="8" name="msdf_rounded_outline" type="float" default="1.0" />
<description>
See also [method CanvasItem.draw_msdf_texture_rect_region].
</description>
Expand Down
15 changes: 15 additions & 0 deletions doc/classes/TextServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@
Returns the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="font_get_msdf_rounded_outline" qualifiers="const">
<return type="float" />
<param index="0" name="font_rid" type="RID" />
<description>
Returns the MSDF outline rounding factor.
</description>
</method>
<method name="font_get_msdf_size" qualifiers="const">
<return type="int" />
<param index="0" name="font_rid" type="RID" />
Expand Down Expand Up @@ -895,6 +902,14 @@
Sets the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="font_set_msdf_rounded_outline">
<return type="void" />
<param index="0" name="font_rid" type="RID" />
<param index="1" name="msdf_rounded_outline" type="float" />
<description>
Sets the MSDF outline rounding factor. [code]0.0[/code] is a sharp outline, while [code]1.0[/code] is a rounded outline. Values between result in a slightly rounded outline.
</description>
</method>
<method name="font_set_msdf_size">
<return type="void" />
<param index="0" name="font_rid" type="RID" />
Expand Down
15 changes: 15 additions & 0 deletions doc/classes/TextServerExtension.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@
Returns the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="_font_get_msdf_rounded_outline" qualifiers="virtual const">
<return type="float" />
<param index="0" name="font_rid" type="RID" />
<description>
Returns the MSDF outline rounding factor.
</description>
</method>
<method name="_font_get_msdf_size" qualifiers="virtual const">
<return type="int" />
<param index="0" name="font_rid" type="RID" />
Expand Down Expand Up @@ -879,6 +886,14 @@
Sets the width of the range around the shape between the minimum and maximum representable signed distance.
</description>
</method>
<method name="_font_set_msdf_rounded_outline" qualifiers="virtual">
<return type="void" />
<param index="0" name="font_rid" type="RID" />
<param index="1" name="msdf_rounded_outline" type="float" />
<description>
Sets the MSDF outline rounding factor. [code]0.0[/code] is a sharp outline, while [code]1.0[/code] is a rounded outline. Values between result in a slightly rounded outline.
</description>
</method>
<method name="_font_set_msdf_size" qualifiers="virtual">
<return type="void" />
<param index="0" name="font_rid" type="RID" />
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ void RasterizerCanvasGLES3::_record_item_commands(const Item *p_item, RID p_rend
state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_USE_MSDF;
state.instance_data_array[r_index].msdf[0] = rect->px_range; // Pixel range.
state.instance_data_array[r_index].msdf[1] = rect->outline; // Outline size.
state.instance_data_array[r_index].msdf[2] = 0.f; // Reserved.
state.instance_data_array[r_index].msdf[2] = rect->msdf_rounded_outline; // Outline true distance blending.
state.instance_data_array[r_index].msdf[3] = 0.f; // Reserved.
} else if (rect->flags & CANVAS_RECT_LCD) {
state.instance_data_array[r_index].flags |= INSTANCE_FLAGS_USE_LCD;
Expand Down
4 changes: 3 additions & 1 deletion drivers/gles3/shaders/canvas.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ void main() {
if (bool(read_draw_data_flags & INSTANCE_FLAGS_USE_MSDF)) {
float px_range = read_draw_data_ninepatch_margins.x;
float outline_thickness = read_draw_data_ninepatch_margins.y;
float msdf_rounded_outline = read_draw_data_ninepatch_margins.z;
//float reserved = read_draw_data_ninepatch_margins.w;

vec4 msdf_sample = texture(color_texture, uv);
vec2 msdf_size = vec2(textureSize(color_texture, 0));
Expand All @@ -610,7 +612,7 @@ void main() {

if (outline_thickness > 0.0) {
float cr = clamp(outline_thickness, 0.0, (px_range / 2.0) - 1.0) / px_range;
d = min(d, msdf_sample.a);
d = mix(d, msdf_sample.a, msdf_rounded_outline);
float a = clamp((d - 0.5 + cr) * px_size, 0.0, 1.0);
color.a = a * color.a;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GH-80954
--------
Validate extension JSON: Error: Field 'classes/Font/methods/find_variation/arguments': size changed value in new API, from 4 to 9.
Validate extension JSON: Error: Field 'classes/Font/methods/find_variation/arguments': size changed value in new API, from 4 to 10.

Added optional arguments. Compatibility method registered.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GH-87668
--------
Validate extension JSON: Error: Field 'classes/Font/methods/find_variation/arguments': size changed value in new API, from 8 to 9.
Validate extension JSON: Error: Field 'classes/Font/methods/find_variation/arguments': size changed value in new API, from 8 to 10.

Added optional "baseline_offset" argument. Compatibility method registered.
7 changes: 7 additions & 0 deletions misc/extension_api_validation/4.5-stable/GH-109629.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GH-109629
---------
Validate extension JSON: Error: Field 'classes/CanvasItem/methods/draw_msdf_texture_rect_region/arguments': size changed value in new API, from 7 to 8.
Validate extension JSON: Error: Field 'classes/Font/methods/find_variation/arguments': size changed value in new API, from 9 to 10.
Validate extension JSON: Error: Field 'classes/RenderingServer/methods/canvas_item_add_msdf_texture_rect_region/arguments': size changed value in new API, from 8 to 9.

Optional argument added. Compatibility methods registered.
35 changes: 33 additions & 2 deletions modules/text_server_adv/text_server_adv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2738,6 +2738,37 @@ double TextServerAdvanced::_font_get_baseline_offset(const RID &p_font_rid) cons
}
}

void TextServerAdvanced::_font_set_msdf_rounded_outline(const RID &p_font_rid, double p_msdf_rounded_outline) {
FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
if (fdv) {
if (fdv->msdf_rounded_outline != p_msdf_rounded_outline) {
fdv->msdf_rounded_outline = p_msdf_rounded_outline;
}
} else {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_NULL(fd);

MutexLock lock(fd->mutex);
if (fd->msdf_rounded_outline != p_msdf_rounded_outline) {
_font_clear_cache(fd);
fd->msdf_rounded_outline = p_msdf_rounded_outline;
}
}
}

double TextServerAdvanced::_font_get_msdf_rounded_outline(const RID &p_font_rid) const {
FontAdvancedLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
if (fdv) {
return fdv->msdf_rounded_outline;
} else {
FontAdvanced *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_NULL_V(fd, 0.0);

MutexLock lock(fd->mutex);
return fd->msdf_rounded_outline;
}
}

void TextServerAdvanced::_font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) {
FontAdvanced *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
Expand Down Expand Up @@ -4061,7 +4092,7 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
Point2 cpos = p_pos;
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size, _font_get_msdf_rounded_outline(p_font_rid));
} else {
Point2 cpos = p_pos;
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
Expand Down Expand Up @@ -4203,7 +4234,7 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
Point2 cpos = p_pos;
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size, _font_get_msdf_rounded_outline(p_font_rid));
} else {
Point2 cpos = p_pos;
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
Expand Down
10 changes: 9 additions & 1 deletion modules/text_server_adv/text_server_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ class TextServerAdvanced : public TextServerExtension {
RID base_font;
int extra_spacing[4] = { 0, 0, 0, 0 };
double baseline_offset = 0.0;
double msdf_rounded_outline = 1.0;
};

struct FontAdvanced {
Expand Down Expand Up @@ -354,6 +355,7 @@ class TextServerAdvanced : public TextServerExtension {
int stretch = 100;
int extra_spacing[4] = { 0, 0, 0, 0 };
double baseline_offset = 0.0;
double msdf_rounded_outline = 1.0;

HashMap<Vector2i, FontForSizeAdvanced *> cache;

Expand Down Expand Up @@ -620,9 +622,10 @@ class TextServerAdvanced : public TextServerExtension {
Transform2D transform;
int extra_spacing[4] = { 0, 0, 0, 0 };
double baseline_offset = 0.0;
double msdf_rounded_outline = 1.0;

bool operator==(const SystemFontKey &p_b) const {
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) && (keep_rounding_remainders == p_b.keep_rounding_remainders) && (variation_coordinates == p_b.variation_coordinates) && (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) && (keep_rounding_remainders == p_b.keep_rounding_remainders) && (variation_coordinates == p_b.variation_coordinates) && (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) && (msdf_rounded_outline == p_b.msdf_rounded_outline);
}

SystemFontKey(const String &p_font_name, bool p_italic, int p_weight, int p_stretch, RID p_font, const TextServerAdvanced *p_fb) {
Expand All @@ -649,6 +652,7 @@ class TextServerAdvanced : public TextServerExtension {
extra_spacing[SPACING_SPACE] = p_fb->_font_get_spacing(p_font, SPACING_SPACE);
extra_spacing[SPACING_GLYPH] = p_fb->_font_get_spacing(p_font, SPACING_GLYPH);
baseline_offset = p_fb->_font_get_baseline_offset(p_font);
msdf_rounded_outline = p_fb->_font_get_msdf_rounded_outline(p_font);
}
};

Expand Down Expand Up @@ -681,6 +685,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);
hash = hash_murmur3_one_double(p_a.msdf_rounded_outline, 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) | ((int)p_a.keep_rounding_remainders << 15), hash));
}
};
Expand Down Expand Up @@ -919,6 +924,9 @@ class TextServerAdvanced : public TextServerExtension {
MODBIND2(font_set_baseline_offset, const RID &, double);
MODBIND1RC(double, font_get_baseline_offset, const RID &);

MODBIND2(font_set_msdf_rounded_outline, const RID &, double);
MODBIND1RC(double, font_get_msdf_rounded_outline, const RID &);

MODBIND2(font_set_transform, const RID &, const Transform2D &);
MODBIND1RC(Transform2D, font_get_transform, const RID &);

Expand Down
35 changes: 33 additions & 2 deletions modules/text_server_fb/text_server_fb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,37 @@ double TextServerFallback::_font_get_baseline_offset(const RID &p_font_rid) cons
}
}

void TextServerFallback::_font_set_msdf_rounded_outline(const RID &p_font_rid, double p_msdf_rounded_outline) {
FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
if (fdv) {
if (fdv->msdf_rounded_outline != p_msdf_rounded_outline) {
fdv->msdf_rounded_outline = p_msdf_rounded_outline;
}
} else {
FontFallback *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_NULL(fd);

MutexLock lock(fd->mutex);
if (fd->msdf_rounded_outline != p_msdf_rounded_outline) {
_font_clear_cache(fd);
fd->msdf_rounded_outline = p_msdf_rounded_outline;
}
}
}

double TextServerFallback::_font_get_msdf_rounded_outline(const RID &p_font_rid) const {
FontFallbackLinkedVariation *fdv = font_var_owner.get_or_null(p_font_rid);
if (fdv) {
return fdv->msdf_rounded_outline;
} else {
FontFallback *fd = font_owner.get_or_null(p_font_rid);
ERR_FAIL_NULL_V(fd, 0.0);

MutexLock lock(fd->mutex);
return fd->msdf_rounded_outline;
}
}

void TextServerFallback::_font_set_transform(const RID &p_font_rid, const Transform2D &p_transform) {
FontFallback *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
Expand Down Expand Up @@ -2952,7 +2983,7 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
Point2 cpos = p_pos;
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, 0, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size, _font_get_msdf_rounded_outline(p_font_rid));
} else {
Point2 cpos = p_pos;
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
Expand Down Expand Up @@ -3094,7 +3125,7 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
Point2 cpos = p_pos;
cpos += fgl.rect.position * (double)p_size / (double)fd->msdf_source_size;
Size2 csize = fgl.rect.size * (double)p_size / (double)fd->msdf_source_size;
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size);
RenderingServer::get_singleton()->canvas_item_add_msdf_texture_rect_region(p_canvas, Rect2(cpos, csize), texture, fgl.uv_rect, modulate, p_outline_size, fd->msdf_range, (double)p_size / (double)fd->msdf_source_size, _font_get_msdf_rounded_outline(p_font_rid));
} else {
Point2 cpos = p_pos;
double scale = _font_get_scale(p_font_rid, p_size) / oversampling_factor;
Expand Down
Loading