diff options
author | Ruslan Mustakov <r.mustakov@gmail.com> | 2018-03-17 15:44:34 +0700 |
---|---|---|
committer | Ruslan Mustakov <r.mustakov@gmail.com> | 2018-05-08 13:45:24 +0700 |
commit | 5cd12f6649387f91d08fd17bf3c70e732798ab58 (patch) | |
tree | cc0e4fd2ce69997c67df9aa36b7390cb52c0534c /scene/resources/dynamic_font_stb.cpp | |
parent | 6e8e401359ba86d33253fb3d3241cf09a742c8e4 (diff) |
Perfect FreeType-based outlines for DynamicFonts
- Implement outlines based on FreeType Stroker API. This allows
artifact-free results, similar to what you will see in Web or any text
editing tools. Outline is a part of DynamicFont rather than Label,
because outlines have to be baked into the font's atlas. Font has a
default outline_color and a Label can specify font_outline_modulator
that will be multiplied with the Font's color to get the final result.
- draw_char now has to be called twice to fully render a text - first
with p_outline == true for each character and then with
p_outline == false for each character.
- Number of draw-calls is reduced from 5 to 2 per outlined character.
- Overall cleanup of DynamicFont code, extracted duplicated code pieces
into separate methods.
- The change is backward-compatible - Labels still have outline
properties that work exactly as they worked before.
Closes #16279.
Diffstat (limited to 'scene/resources/dynamic_font_stb.cpp')
-rw-r--r-- | scene/resources/dynamic_font_stb.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/scene/resources/dynamic_font_stb.cpp b/scene/resources/dynamic_font_stb.cpp index 098b794a95..29f1106d16 100644 --- a/scene/resources/dynamic_font_stb.cpp +++ b/scene/resources/dynamic_font_stb.cpp @@ -162,7 +162,7 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next) const { return ret; } -float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); @@ -172,13 +172,15 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT return 0; } - Point2 cpos = p_pos; - cpos.x += c->h_align; - cpos.y -= get_ascent(); - cpos.y += c->v_align; - ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); - if (c->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate); + if (!p_outline) { + Point2 cpos = p_pos; + cpos.x += c->h_align; + cpos.y -= get_ascent(); + cpos.y += c->v_align; + ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); + if (c->texture_idx != -1) + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate); + } //textures[c->texture_idx].texture->draw(p_canvas_item,Vector2()); @@ -459,12 +461,12 @@ bool DynamicFont::is_distance_field_hint() const { return false; } -float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { if (!data_at_size.is_valid()) return 0; - return data_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate); + return data_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline); } DynamicFont::DynamicFont() { |