Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite Font gracious fallback #14199

Merged
merged 1 commit into from Nov 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions OpenRA.Game/Graphics/SpriteFont.cs
Expand Up @@ -84,11 +84,12 @@ public void DrawText(string text, float2 location, Color c)
}

var g = glyphs[Pair.New(s, c)];
Game.Renderer.RgbaSpriteRenderer.DrawSprite(g.Sprite,
new float2(
(int)Math.Round(p.X * deviceScale + g.Offset.X, 0) / deviceScale,
p.Y + g.Offset.Y / deviceScale),
g.Sprite.Size / deviceScale);
if (g.Sprite != null)
Game.Renderer.RgbaSpriteRenderer.DrawSprite(g.Sprite,
new float2(
(int)Math.Round(p.X * deviceScale + g.Offset.X, 0) / deviceScale,
p.Y + g.Offset.Y / deviceScale),
g.Sprite.Size / deviceScale);

p += new float2(g.Advance / deviceScale, 0);
}
Expand Down Expand Up @@ -136,7 +137,20 @@ public int2 Measure(string text)

GlyphInfo CreateGlyph(Pair<char, Color> c)
{
face.LoadChar(c.First, LoadFlags.Default, LoadTarget.Normal);
try
{
face.LoadChar(c.First, LoadFlags.Default, LoadTarget.Normal);
}
catch (FreeTypeException)
{
return new GlyphInfo
{
Sprite = null,
Advance = 0,
Offset = int2.Zero
};
}

face.Glyph.RenderGlyph(RenderMode.Normal);

var size = new Size((int)face.Glyph.Metrics.Width, (int)face.Glyph.Metrics.Height);
Expand Down