Start of font preparation

This commit is contained in:
Simon Lübeß
2022-01-07 18:42:43 +01:00
parent 5373d92297
commit e292029015
6 changed files with 381 additions and 4 deletions
+25
View File
@@ -4,6 +4,7 @@ using GlitchyEngine.Math;
using GlitchyEngine.Core;
using System.Collections;
using msdfgen;
using System.Diagnostics;
using static FreeType.HarfBuzz;
using internal GlitchyEngine.Renderer.Text;
@@ -64,6 +65,9 @@ namespace GlitchyEngine.Renderer.Text
internal double _range = 4.0;
/// The space between two lines.
internal double _linespace;
/**
* 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.
@@ -132,6 +136,8 @@ namespace GlitchyEngine.Renderer.Text
_range = 4.0 / _geometryScaler;
_linespace = ((_face.size.metrics.ascender - _face.size.metrics.descender) / 64);
GlyphDescriptor nullDesc = new GlyphDescriptor(){Font = this};
nullDesc.GlyphIndex = FreeType.Get_Char_Index(_face, '\0');
_glyphs.Add('\0', nullDesc);
@@ -162,6 +168,25 @@ namespace GlitchyEngine.Renderer.Text
UpdateAtlas();
}
/// Returns the font that can draw the char
static internal Font GetDrawingFont(char32 char, Font font)
{
uint32 glyphId = FreeType.Get_Char_Index(font._face, char);
if (glyphId != 0)
{
return font;
}
else if (font.Fallback != null)
{
return GetDrawingFont(char, font.Fallback);
}
else
{
return null;
}
}
internal GlyphDescriptor GetGlyph(uint32 glyphId, bool allowDynamicLoading = true)
{
GlyphDescriptor desc;