mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Fixed fallback font rendering
This commit is contained in:
@@ -141,6 +141,14 @@ namespace GlitchyEngine.Renderer.Text
|
||||
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);
|
||||
_geometryScaler = _fontSize / unitsPerEm;
|
||||
|
||||
@@ -155,14 +163,6 @@ namespace GlitchyEngine.Renderer.Text
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -185,17 +185,17 @@ namespace GlitchyEngine.Renderer.Text
|
||||
}
|
||||
|
||||
/// 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)
|
||||
{
|
||||
return font;
|
||||
return this;
|
||||
}
|
||||
else if (font.Fallback != null)
|
||||
else if (Fallback != null)
|
||||
{
|
||||
return GetDrawingFont(char, font.Fallback);
|
||||
return Fallback.GetDrawingFont(char);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -193,7 +193,7 @@ namespace GlitchyEngine.Renderer.Text
|
||||
hb_buffer_set_script(buf, .HB_SCRIPT_LATIN);
|
||||
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.
|
||||
@@ -209,7 +209,7 @@ namespace GlitchyEngine.Renderer.Text
|
||||
hb_position_t x_advance = glyph_pos[i].x_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);
|
||||
|
||||
@@ -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").
|
||||
Font charFont = Font.GetDrawingFont(char, font) ?? font;
|
||||
Font charFont = currentFont.GetDrawingFont(char) ?? font;
|
||||
|
||||
if (charFont != font)
|
||||
if (charFont != currentFont)
|
||||
{
|
||||
FlushShapeBuffer();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user