Refcounted Font, added Fallback property

This commit is contained in:
Simon Lübeß
2021-06-23 19:39:32 +02:00
parent 7f8379ea6c
commit 9158da60c2
2 changed files with 26 additions and 9 deletions
+21 -3
View File
@@ -7,9 +7,9 @@ using internal GlitchyEngine.Renderer.Text;
namespace 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 FT_Face Face;
public Font Font; public Font Font;
@@ -30,7 +30,7 @@ namespace GlitchyEngine.Renderer.Text
private GraphicsContext _context ~ _.ReleaseRef(); private GraphicsContext _context ~ _.ReleaseRef();
internal FT_Face _face ~ FreeType.Done_Face(_face); internal FT_Face _face ~ FreeType.Done_Face(_face);
private Font _fallback; private Font _fallback ~ _?.ReleaseRef();
private uint32 _fontSize; private uint32 _fontSize;
private int32 _faceIndex; private int32 _faceIndex;
@@ -46,6 +46,24 @@ namespace GlitchyEngine.Renderer.Text
private SamplerState _sampler ~ _.ReleaseRef(); 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. * Gets or sets the Sampler that will be used to sample the spritefont.
* Setting to null will result in the use of LinearClamp * Setting to null will result in the use of LinearClamp
+5 -6
View File
@@ -117,17 +117,16 @@ namespace Sandbox
.Blue, .White); .Blue, .White);
_testTexture.SetData<Color>(&colors, 0, 1, 1, 1); _testTexture.SetData<Color>(&colors, 0, 1, 1, 1);
//_testTexture.SetData<Color>(&colors, 0, 0, 2, 2);
fonty = new Font(_context, "C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16);//C:\\Windows\\Fonts\\seguiemj.ttf fonty = new Font(_context, "C:\\Windows\\Fonts\\arial.ttf", 64, true, 'A', 16);
emojies = new Font(_context, "C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1); var emojis = new Font(_context, "C:\\Windows\\Fonts\\seguiemj.ttf", 64, true, '😂' - 10, 1);
fonty.[Friend]_fallback = emojies; fonty.Fallback = emojis..ReleaseRefNoDelete();
fontRenderer = new FontRenderer(_context); fontRenderer = new FontRenderer(_context);
} }
Font fonty ~ delete _; Font fonty ~ _.ReleaseRef();
Font emojies ~ delete _;
FontRenderer fontRenderer ~ delete _; FontRenderer fontRenderer ~ delete _;
VertexLayout layout ~ delete _; VertexLayout layout ~ delete _;