Fixed fallback font rendering

This commit is contained in:
Simon Lübeß
2022-02-22 20:18:06 +01:00
parent 373980d5ad
commit 6f999da1b8
2 changed files with 17 additions and 17 deletions
+13 -13
View File
@@ -141,6 +141,14 @@ namespace GlitchyEngine.Renderer.Text
Log.EngineLogger.Assert(res.Success, scope $"Set_Pixel_Sizes failed({(int)res}): {res}"); Log.EngineLogger.Assert(res.Success, scope $"Set_Pixel_Sizes failed({(int)res}): {res}");
} }
// HarfBuzz
{
Debug.Profiler.ProfileResourceScope!("hb_ft_font_create_referenced");
_harfBuzzFont = hb_ft_font_create_referenced(_face);
hb_font_set_scale(_harfBuzzFont, (.)fontSize * 64, (.)fontSize * 64);
}
double unitsPerEm = F26Dot6ToDouble(_face.units_per_EM); double unitsPerEm = F26Dot6ToDouble(_face.units_per_EM);
_geometryScaler = _fontSize / unitsPerEm; _geometryScaler = _fontSize / unitsPerEm;
@@ -155,14 +163,6 @@ namespace GlitchyEngine.Renderer.Text
LoadGlyphs(firstChar, charCount); LoadGlyphs(firstChar, charCount);
// HarfBuzz
{
Debug.Profiler.ProfileResourceScope!("hb_ft_font_create_referenced");
_harfBuzzFont = hb_ft_font_create_referenced(_face);
hb_font_set_scale(_harfBuzzFont, (.)fontSize * 64, (.)fontSize * 64);
}
//TestMSDF(); //TestMSDF();
} }
@@ -185,17 +185,17 @@ namespace GlitchyEngine.Renderer.Text
} }
/// Returns the font that can draw the char /// Returns the font that can draw the char
static internal Font GetDrawingFont(char32 char, Font font) internal Font GetDrawingFont(char32 char)
{ {
uint32 glyphId = FreeType.Get_Char_Index(font._face, char); uint32 glyphId = FreeType.Get_Char_Index(_face, char);
if (glyphId != 0) if (glyphId != 0)
{ {
return font; return this;
} }
else if (font.Fallback != null) else if (Fallback != null)
{ {
return GetDrawingFont(char, font.Fallback); return Fallback.GetDrawingFont(char);
} }
else else
{ {
@@ -193,7 +193,7 @@ namespace GlitchyEngine.Renderer.Text
hb_buffer_set_script(buf, .HB_SCRIPT_LATIN); hb_buffer_set_script(buf, .HB_SCRIPT_LATIN);
hb_buffer_set_language(buf, hb_language_from_string("en".CStr(), -1)); hb_buffer_set_language(buf, hb_language_from_string("en".CStr(), -1));
hb_shape(font._harfBuzzFont, buf, null, 0); hb_shape(currentFont._harfBuzzFont, buf, null, 0);
// 5. Get the glyph and position information. // 5. Get the glyph and position information.
@@ -209,7 +209,7 @@ namespace GlitchyEngine.Renderer.Text
hb_position_t x_advance = glyph_pos[i].x_advance; hb_position_t x_advance = glyph_pos[i].x_advance;
hb_position_t y_advance = glyph_pos[i].y_advance; hb_position_t y_advance = glyph_pos[i].y_advance;
PreparedGlyph glyph = .(font, glyphid, .(penPosition, baseline), fontScale);//, x_advance / 64, y_advance / 64); PreparedGlyph glyph = .(currentFont, glyphid, .(penPosition, baseline), fontScale);//, x_advance / 64, y_advance / 64);
preparedText.Glyphs.Add(glyph); preparedText.Glyphs.Add(glyph);
@@ -277,9 +277,9 @@ namespace GlitchyEngine.Renderer.Text
} }
// Get the font that can draw the char. Use the given font if no fallback is found (will draw the "missing glyph"). // Get the font that can draw the char. Use the given font if no fallback is found (will draw the "missing glyph").
Font charFont = Font.GetDrawingFont(char, font) ?? font; Font charFont = currentFont.GetDrawingFont(char) ?? font;
if (charFont != font) if (charFont != currentFont)
{ {
FlushShapeBuffer(); FlushShapeBuffer();