From 9158da60c2da5cddb1a7bda237b2c301208f2584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 23 Jun 2021 19:39:32 +0200 Subject: [PATCH] Refcounted Font, added Fallback property --- GlitchyEngine/src/Renderer/Text/Font.bf | 24 +++++++++++++++++++++--- Sandbox/src/SandboxApp2D.bf | 11 +++++------ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/GlitchyEngine/src/Renderer/Text/Font.bf b/GlitchyEngine/src/Renderer/Text/Font.bf index 471d779..dabca53 100644 --- a/GlitchyEngine/src/Renderer/Text/Font.bf +++ b/GlitchyEngine/src/Renderer/Text/Font.bf @@ -7,9 +7,9 @@ using internal GlitchyEngine.Renderer.Text; namespace GlitchyEngine.Renderer.Text { - public class Font + public class Font : RefCounted { - public class GlyphDescriptor + internal class GlyphDescriptor { //public FT_Face Face; public Font Font; @@ -30,7 +30,7 @@ namespace GlitchyEngine.Renderer.Text private GraphicsContext _context ~ _.ReleaseRef(); internal FT_Face _face ~ FreeType.Done_Face(_face); - private Font _fallback; + private Font _fallback ~ _?.ReleaseRef(); private uint32 _fontSize; private int32 _faceIndex; @@ -46,6 +46,24 @@ namespace GlitchyEngine.Renderer.Text private SamplerState _sampler ~ _.ReleaseRef(); + /** + * Gets or sets the fallback Font for this Font. + * The Fallback font will be used to render Glyphs that are not defined in the current font. + * @remarks Example: "Arial" doesn't define emojis. Without a fallback font the FontRenderer would draw the null-Glyph (probably just a rectangle). + * By defining "Segoe UI Emoji" as the Fallback the FontRenderer will use "Arial" to render letters and "Segoe UI Emoji" to render emojis. + */ + public Font Fallback + { + get => _fallback; + set + { + if(_fallback == value) + return; + + _fallback = value..AddRef(); + } + } + /** * Gets or sets the Sampler that will be used to sample the spritefont. * Setting to null will result in the use of LinearClamp diff --git a/Sandbox/src/SandboxApp2D.bf b/Sandbox/src/SandboxApp2D.bf index 3aed0cd..184d945 100644 --- a/Sandbox/src/SandboxApp2D.bf +++ b/Sandbox/src/SandboxApp2D.bf @@ -117,17 +117,16 @@ namespace Sandbox .Blue, .White); _testTexture.SetData(&colors, 0, 1, 1, 1); - //_testTexture.SetData(&colors, 0, 0, 2, 2); - fonty = new Font(_context, "C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16);//C:\\Windows\\Fonts\\seguiemj.ttf - emojies = new Font(_context, "C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1); - fonty.[Friend]_fallback = emojies; + fonty = new Font(_context, "C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16); + var emojis = new Font(_context, "C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1); + fonty.Fallback = emojis..ReleaseRefNoDelete(); fontRenderer = new FontRenderer(_context); } - Font fonty ~ delete _; - Font emojies ~ delete _; + Font fonty ~ _.ReleaseRef(); + FontRenderer fontRenderer ~ delete _; VertexLayout layout ~ delete _;