@@ -3908,12 +3908,24 @@ void TextServerAdvanced::_font_render_glyph(const RID &p_font_rid, const Vector2
3908
3908
#endif
3909
3909
}
3910
3910
3911
- void TextServerAdvanced::_font_draw_glyph (const RID &p_font_rid, const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
3911
+ #ifdef GDEXTENSION
3912
+ void TextServerAdvanced::_font_get_glyph_draw_info (const RID &p_font, int64_t p_priority, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling, GDExtensionPtr<GlyphDrawCall> p_ret) const {
3913
+ *p_ret = font_get_glyph_draw_info (p_font, p_priority, p_size, p_pos, p_index, p_color, p_oversampling);
3914
+ }
3915
+
3916
+ void TextServerAdvanced::_font_get_glyph_outline_draw_info (const RID &p_font, int64_t p_priority, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling, GDExtensionPtr<GlyphDrawCall> p_ret) const {
3917
+ *p_ret = font_get_glyph_outline_draw_info (p_font, p_priority, p_size, p_outline_size, p_pos, p_index, p_color, p_oversampling);
3918
+ }
3919
+ #endif
3920
+
3921
+ GlyphDrawCall TextServerAdvanced::font_get_glyph_draw_info (const RID &p_font, int64_t p_priority, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
3922
+ GlyphDrawCall ret;
3923
+
3912
3924
if (p_index == 0 ) {
3913
- return ; // Non visual character, skip.
3925
+ return ret ; // Non visual character, skip.
3914
3926
}
3915
- FontAdvanced *fd = _get_font_data (p_font_rid );
3916
- ERR_FAIL_NULL (fd);
3927
+ FontAdvanced *fd = _get_font_data (p_font );
3928
+ ERR_FAIL_NULL_V (fd, ret );
3917
3929
3918
3930
MutexLock lock (fd->mutex );
3919
3931
@@ -3946,7 +3958,7 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
3946
3958
}
3947
3959
3948
3960
FontForSizeAdvanced *ffsd = nullptr ;
3949
- ERR_FAIL_COND (!_ensure_cache_for_size (fd, size, ffsd, false , viewport_oversampling ? 64 * oversampling_factor : 0 ));
3961
+ ERR_FAIL_COND_V (!_ensure_cache_for_size (fd, size, ffsd, false , viewport_oversampling ? 64 * oversampling_factor : 0 ), ret );
3950
3962
3951
3963
int32_t index = p_index & 0xffffff ; // Remove subpixel shifts.
3952
3964
bool lcd_aa = false ;
@@ -3974,11 +3986,11 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
3974
3986
3975
3987
FontGlyph fgl;
3976
3988
if (!_ensure_glyph (fd, size, index, fgl, viewport_oversampling ? 64 * oversampling_factor : 0 )) {
3977
- return ; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
3989
+ return ret ; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
3978
3990
}
3979
3991
3980
3992
if (fgl.found ) {
3981
- ERR_FAIL_COND (fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures .size ());
3993
+ ERR_FAIL_COND_V (fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures .size (), ret );
3982
3994
3983
3995
if (fgl.texture_idx != -1 ) {
3984
3996
Color modulate = p_color;
@@ -4011,10 +4023,18 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
4011
4023
Point2 cpos = p_pos;
4012
4024
cpos += fgl.rect .position * (double )p_size / (double )fd->msdf_source_size ;
4013
4025
Size2 csize = fgl.rect .size * (double )p_size / (double )fd->msdf_source_size ;
4014
- 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 );
4026
+ ret.priority = p_priority;
4027
+ ret.texture = texture;
4028
+ ret.dst_rect = Rect2 (cpos, csize);
4029
+ ret.src_rect = fgl.uv_rect ;
4030
+ ret.modulate = modulate;
4031
+ ret.outline_size = 0 ;
4032
+ ret.px_range = fd->msdf_range ;
4033
+ ret.scale = (double )p_size / (double )fd->msdf_source_size ;
4034
+ ret.draw_type = DRAW_CALL_MSDF;
4015
4035
} else {
4016
4036
Point2 cpos = p_pos;
4017
- double scale = _font_get_scale (p_font_rid , p_size) / oversampling_factor;
4037
+ double scale = _font_get_scale (p_font , p_size) / oversampling_factor;
4018
4038
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE * 64 )) {
4019
4039
cpos.x = cpos.x + 0.125 ;
4020
4040
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE * 64 )) {
@@ -4043,23 +4063,30 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
4043
4063
csize /= oversampling_factor;
4044
4064
}
4045
4065
cpos += gpos;
4046
- if (lcd_aa) {
4047
- RenderingServer::get_singleton ()->canvas_item_add_lcd_texture_rect_region (p_canvas, Rect2 (cpos, csize), texture, fgl.uv_rect , modulate);
4048
- } else {
4049
- RenderingServer::get_singleton ()->canvas_item_add_texture_rect_region (p_canvas, Rect2 (cpos, csize), texture, fgl.uv_rect , modulate, false , false );
4050
- }
4066
+ ret.priority = p_priority;
4067
+ ret.texture = texture;
4068
+ ret.dst_rect = Rect2 (cpos, csize);
4069
+ ret.src_rect = fgl.uv_rect ;
4070
+ ret.modulate = modulate;
4071
+ ret.outline_size = 0 ;
4072
+ ret.px_range = 0.0 ;
4073
+ ret.scale = 0.0 ;
4074
+ ret.draw_type = lcd_aa ? DRAW_CALL_LCD : DRAW_CALL_NORMAL;
4051
4075
}
4052
4076
}
4053
4077
}
4054
4078
}
4079
+
4080
+ return ret;
4055
4081
}
4056
4082
4057
- void TextServerAdvanced::_font_draw_glyph_outline (const RID &p_font_rid, const RID &p_canvas, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
4083
+ GlyphDrawCall TextServerAdvanced::font_get_glyph_outline_draw_info (const RID &p_font, int64_t p_priority, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
4084
+ GlyphDrawCall ret;
4058
4085
if (p_index == 0 ) {
4059
- return ; // Non visual character, skip.
4086
+ return ret ; // Non visual character, skip.
4060
4087
}
4061
- FontAdvanced *fd = _get_font_data (p_font_rid );
4062
- ERR_FAIL_NULL (fd);
4088
+ FontAdvanced *fd = _get_font_data (p_font );
4089
+ ERR_FAIL_NULL_V (fd, ret );
4063
4090
4064
4091
MutexLock lock (fd->mutex );
4065
4092
@@ -4092,7 +4119,7 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
4092
4119
}
4093
4120
4094
4121
FontForSizeAdvanced *ffsd = nullptr ;
4095
- ERR_FAIL_COND (!_ensure_cache_for_size (fd, size, ffsd, false , viewport_oversampling ? 64 * oversampling_factor : 0 ));
4122
+ ERR_FAIL_COND_V (!_ensure_cache_for_size (fd, size, ffsd, false , viewport_oversampling ? 64 * oversampling_factor : 0 ), ret );
4096
4123
4097
4124
int32_t index = p_index & 0xffffff ; // Remove subpixel shifts.
4098
4125
bool lcd_aa = false ;
@@ -4120,11 +4147,11 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
4120
4147
4121
4148
FontGlyph fgl;
4122
4149
if (!_ensure_glyph (fd, size, index, fgl, viewport_oversampling ? 64 * oversampling_factor : 0 )) {
4123
- return ; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
4150
+ return ret ; // Invalid or non-graphical glyph, do not display errors, nothing to draw.
4124
4151
}
4125
4152
4126
4153
if (fgl.found ) {
4127
- ERR_FAIL_COND (fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures .size ());
4154
+ ERR_FAIL_COND_V (fgl.texture_idx < -1 || fgl.texture_idx >= ffsd->textures .size (), ret );
4128
4155
4129
4156
if (fgl.texture_idx != -1 ) {
4130
4157
Color modulate = p_color;
@@ -4153,10 +4180,18 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
4153
4180
Point2 cpos = p_pos;
4154
4181
cpos += fgl.rect .position * (double )p_size / (double )fd->msdf_source_size ;
4155
4182
Size2 csize = fgl.rect .size * (double )p_size / (double )fd->msdf_source_size ;
4156
- 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 );
4183
+ ret.priority = p_priority;
4184
+ ret.texture = texture;
4185
+ ret.dst_rect = Rect2 (cpos, csize);
4186
+ ret.src_rect = fgl.uv_rect ;
4187
+ ret.modulate = modulate;
4188
+ ret.outline_size = p_outline_size;
4189
+ ret.px_range = fd->msdf_range ;
4190
+ ret.scale = (double )p_size / (double )fd->msdf_source_size ;
4191
+ ret.draw_type = DRAW_CALL_MSDF;
4157
4192
} else {
4158
4193
Point2 cpos = p_pos;
4159
- double scale = _font_get_scale (p_font_rid , p_size) / oversampling_factor;
4194
+ double scale = _font_get_scale (p_font , p_size) / oversampling_factor;
4160
4195
if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_QUARTER) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_QUARTER_MAX_SIZE * 64 )) {
4161
4196
cpos.x = cpos.x + 0.125 ;
4162
4197
} else if ((fd->subpixel_positioning == SUBPIXEL_POSITIONING_ONE_HALF) || (fd->subpixel_positioning == SUBPIXEL_POSITIONING_AUTO && size.x <= SUBPIXEL_POSITIONING_ONE_HALF_MAX_SIZE * 64 )) {
@@ -4185,15 +4220,46 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
4185
4220
csize /= oversampling_factor;
4186
4221
}
4187
4222
cpos += gpos;
4188
- if (lcd_aa) {
4189
- RenderingServer::get_singleton ()->canvas_item_add_lcd_texture_rect_region (p_canvas, Rect2 (cpos, csize), texture, fgl.uv_rect , modulate);
4190
- } else {
4191
- RenderingServer::get_singleton ()->canvas_item_add_texture_rect_region (p_canvas, Rect2 (cpos, csize), texture, fgl.uv_rect , modulate, false , false );
4192
- }
4223
+ ret.priority = p_priority;
4224
+ ret.texture = texture;
4225
+ ret.dst_rect = Rect2 (cpos, csize);
4226
+ ret.src_rect = fgl.uv_rect ;
4227
+ ret.modulate = modulate;
4228
+ ret.outline_size = p_outline_size;
4229
+ ret.px_range = 0.0 ;
4230
+ ret.scale = 0.0 ;
4231
+ ret.draw_type = lcd_aa ? DRAW_CALL_LCD : DRAW_CALL_NORMAL;
4193
4232
}
4194
4233
}
4195
4234
}
4196
4235
}
4236
+ return ret;
4237
+ }
4238
+
4239
+ void TextServerAdvanced::_font_draw_glyph (const RID &p_font_rid, const RID &p_canvas, int64_t p_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
4240
+ if (RenderingServer::get_singleton () != nullptr ) {
4241
+ const GlyphDrawCall &ret = font_get_glyph_draw_info (p_font_rid, 0 , p_size, p_pos, p_index, p_color, p_oversampling);
4242
+ if (ret.draw_type == DRAW_CALL_MSDF) {
4243
+ RenderingServer::get_singleton ()->canvas_item_add_msdf_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate , 0 , ret.px_range , ret.scale );
4244
+ } else if (ret.draw_type == DRAW_CALL_LCD) {
4245
+ RenderingServer::get_singleton ()->canvas_item_add_lcd_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate );
4246
+ } else if (ret.draw_type == DRAW_CALL_NORMAL) {
4247
+ RenderingServer::get_singleton ()->canvas_item_add_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate , false , false );
4248
+ }
4249
+ }
4250
+ }
4251
+
4252
+ void TextServerAdvanced::_font_draw_glyph_outline (const RID &p_font_rid, const RID &p_canvas, int64_t p_size, int64_t p_outline_size, const Vector2 &p_pos, int64_t p_index, const Color &p_color, float p_oversampling) const {
4253
+ if (RenderingServer::get_singleton () != nullptr ) {
4254
+ const GlyphDrawCall &ret = font_get_glyph_outline_draw_info (p_font_rid, 0 , p_size, p_outline_size, p_pos, p_index, p_color, p_oversampling);
4255
+ if (ret.draw_type == DRAW_CALL_MSDF) {
4256
+ RenderingServer::get_singleton ()->canvas_item_add_msdf_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate , ret.outline_size , ret.px_range , ret.scale );
4257
+ } else if (ret.draw_type == DRAW_CALL_LCD) {
4258
+ RenderingServer::get_singleton ()->canvas_item_add_lcd_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate );
4259
+ } else if (ret.draw_type == DRAW_CALL_NORMAL) {
4260
+ RenderingServer::get_singleton ()->canvas_item_add_texture_rect_region (p_canvas, ret.dst_rect , ret.texture , ret.src_rect , ret.modulate , false , false );
4261
+ }
4262
+ }
4197
4263
}
4198
4264
4199
4265
bool TextServerAdvanced::_font_is_language_supported (const RID &p_font_rid, const String &p_language) const {
0 commit comments