Calculate font size correctly

This commit is contained in:
teinarss
2019-05-02 19:44:15 +02:00
committed by reaperrr
parent 7c71e55b01
commit 2d1c110857
3 changed files with 34 additions and 4 deletions

View File

@@ -133,7 +133,9 @@ namespace OpenRA
public interface IFont : IDisposable
{
FontGlyph CreateGlyph(char c, int size, float deviceScale);
FontGlyph CreateGlyph(char c);
void SetSize(int size, float deviceScale);
int Height { get; }
}
public struct FontGlyph

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Graphics
{
public sealed class SpriteFont : IDisposable
{
public int TopOffset { get; private set; }
readonly int size;
readonly SheetBuilder builder;
readonly Func<string, float> lineWidth;
@@ -37,6 +38,7 @@ namespace OpenRA.Graphics
this.builder = builder;
font = Game.Renderer.CreateFont(data);
font.SetSize(size, deviceScale);
glyphs = new Cache<Pair<char, Color>, GlyphInfo>(CreateGlyph, Pair<char, Color>.EqualityComparer);
@@ -46,12 +48,18 @@ namespace OpenRA.Graphics
if (size <= 24)
PrecacheColor(Color.White, name);
TopOffset = size - font.Height;
}
public void SetScale(float scale)
{
deviceScale = scale;
font.SetSize(size, scale);
glyphs.Clear();
TopOffset = size - font.Height;
}
void PrecacheColor(Color c, string name)
@@ -131,7 +139,7 @@ namespace OpenRA.Graphics
GlyphInfo CreateGlyph(Pair<char, Color> c)
{
var glyph = font.CreateGlyph(c.First, this.size, deviceScale);
var glyph = font.CreateGlyph(c.First);
if (glyph.Data == null)
{