[TextServer] Do not draw non-visual characters.

This commit is contained in:
bruvzg 2023-12-12 12:08:42 +02:00
parent 15a03ed98e
commit 575e1201cb
3 changed files with 53 additions and 19 deletions

View File

@ -3504,6 +3504,9 @@ void TextServerAdvanced::_font_render_glyph(const RID &p_font_rid, const Vector2
}
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) const {
if (p_index == 0) {
return; // Non visual character, skip.
}
FontAdvanced *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@ -3541,6 +3544,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
const FontGlyph &gl = fd->cache[size]->glyph_map[index];
if (gl.found) {
if (gl.uv_rect.size.x <= 2 || gl.uv_rect.size.y <= 2) {
return; // Nothing to draw.
}
ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
if (gl.texture_idx != -1) {
@ -3608,6 +3614,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
}
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) const {
if (p_index == 0) {
return; // Non visual character, skip.
}
FontAdvanced *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@ -3645,6 +3654,9 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R
const FontGlyph &gl = fd->cache[size]->glyph_map[index];
if (gl.found) {
if (gl.uv_rect.size.x <= 2 || gl.uv_rect.size.y <= 2) {
return; // Nothing to draw.
}
ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
if (gl.texture_idx != -1) {

View File

@ -2439,6 +2439,9 @@ void TextServerFallback::_font_render_glyph(const RID &p_font_rid, const Vector2
}
void TextServerFallback::_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) const {
if (p_index == 0) {
return; // Non visual character, skip.
}
FontFallback *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@ -2476,6 +2479,9 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
const FontGlyph &gl = fd->cache[size]->glyph_map[index];
if (gl.found) {
if (gl.uv_rect.size.x <= 2 || gl.uv_rect.size.y <= 2) {
return; // Nothing to draw.
}
ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
if (gl.texture_idx != -1) {
@ -2543,6 +2549,9 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca
}
void TextServerFallback::_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) const {
if (p_index == 0) {
return; // Non visual character, skip.
}
FontFallback *fd = _get_font_data(p_font_rid);
ERR_FAIL_NULL(fd);
@ -2580,6 +2589,9 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R
const FontGlyph &gl = fd->cache[size]->glyph_map[index];
if (gl.found) {
if (gl.uv_rect.size.x <= 2 || gl.uv_rect.size.y <= 2) {
return; // Nothing to draw.
}
ERR_FAIL_COND(gl.texture_idx < -1 || gl.texture_idx >= fd->cache[size]->textures.size());
if (gl.texture_idx != -1) {

View File

@ -326,16 +326,20 @@ Ref<TriangleMesh> Label3D::generate_triangle_mesh() const {
}
void Label3D::_generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset, const Color &p_modulate, int p_priority, int p_outline_size) {
for (int j = 0; j < p_glyph.repeat; j++) {
if (p_glyph.index == 0) {
r_offset.x += p_glyph.advance * pixel_size * p_glyph.repeat; // Non visual character, skip.
return;
}
Vector2 gl_of;
Vector2 gl_sz;
Rect2 gl_uv;
Size2 texs;
RID tex;
if (p_glyph.font_rid != RID()) {
if (p_glyph.font_rid.is_valid()) {
tex = TS->font_get_glyph_texture_rid(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index);
if (tex != RID()) {
if (tex.is_valid()) {
gl_of = (TS->font_get_glyph_offset(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index) + Vector2(p_glyph.x_off, p_glyph.y_off)) * pixel_size;
gl_sz = TS->font_get_glyph_size(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index) * pixel_size;
gl_uv = TS->font_get_glyph_uv_rect(p_glyph.font_rid, Vector2i(p_glyph.font_size, p_outline_size), p_glyph.index);
@ -346,8 +350,14 @@ void Label3D::_generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset,
gl_of = Vector2(0, -gl_sz.y);
}
if (gl_uv.size.x <= 2 || gl_uv.size.y <= 2) {
r_offset.x += p_glyph.advance * pixel_size * p_glyph.repeat; // Nothing to draw.
return;
}
bool msdf = TS->font_is_multichannel_signed_distance_field(p_glyph.font_rid);
for (int j = 0; j < p_glyph.repeat; j++) {
SurfaceKey key = SurfaceKey(tex.get_id(), p_priority, p_outline_size);
if (!surfaces.has(key)) {
SurfaceData surf;
@ -420,7 +430,7 @@ void Label3D::_generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset,
}
}
if (tex != RID()) {
if (tex.is_valid()) {
s.mesh_uvs.write[(s.offset * 4) + 3] = Vector2(gl_uv.position.x / texs.x, (gl_uv.position.y + gl_uv.size.y) / texs.y);
s.mesh_uvs.write[(s.offset * 4) + 2] = Vector2((gl_uv.position.x + gl_uv.size.x) / texs.x, (gl_uv.position.y + gl_uv.size.y) / texs.y);
s.mesh_uvs.write[(s.offset * 4) + 1] = Vector2((gl_uv.position.x + gl_uv.size.x) / texs.x, gl_uv.position.y / texs.y);