1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 14:13:18 +08:00

Specify font size in a saner way

This commit is contained in:
Dean Herbert 2019-08-21 14:31:19 +09:00
parent 73bb540c23
commit 444f2b9387

View File

@ -135,7 +135,7 @@ namespace osu.Game.Skinning
case "Play/osu/number-text": case "Play/osu/number-text":
return !hasFont(Configuration.HitCircleFont) return !hasFont(Configuration.HitCircleFont)
? null ? null
: new LegacySpriteText(Textures, Configuration.HitCircleFont) : new LegacySpriteText(this, Configuration.HitCircleFont)
{ {
Scale = new Vector2(0.96f), Scale = new Vector2(0.96f),
// Spacing value was reverse-engineered from the ratio of the rendered sprite size in the visual inspector vs the actual texture size // Spacing value was reverse-engineered from the ratio of the rendered sprite size in the visual inspector vs the actual texture size
@ -282,45 +282,38 @@ namespace osu.Game.Skinning
{ {
private readonly LegacyGlyphStore glyphStore; private readonly LegacyGlyphStore glyphStore;
public LegacySpriteText(TextureStore textures, string font) public LegacySpriteText(ISkin skin, string font)
{ {
Shadow = false; Shadow = false;
UseFullGlyphHeight = false; UseFullGlyphHeight = false;
Font = new FontUsage(font, 16); Font = new FontUsage(font, OsuFont.DEFAULT_FONT_SIZE);
glyphStore = new LegacyGlyphStore(textures); glyphStore = new LegacyGlyphStore(skin);
} }
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore); protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
private class LegacyGlyphStore : ITexturedGlyphLookupStore private class LegacyGlyphStore : ITexturedGlyphLookupStore
{ {
private readonly TextureStore textures; private readonly ISkin skin;
public LegacyGlyphStore(TextureStore textures) public LegacyGlyphStore(ISkin skin)
{ {
this.textures = textures; this.skin = skin;
} }
public ITexturedCharacterGlyph Get(string fontName, char character) public ITexturedCharacterGlyph Get(string fontName, char character)
{ {
string textureName = $"{fontName}-{character}"; var texture = skin.GetTexture($"{fontName}-{character}");
// Approximate value that brings character sizing roughly in-line with stable
float ratio = 36;
var texture = textures.Get($"{textureName}@2x");
if (texture == null)
{
ratio = 18;
texture = textures.Get(textureName);
}
if (texture != null) if (texture != null)
texture.ScaleAdjust = ratio; // Approximate value that brings character sizing roughly in-line with stable
texture.ScaleAdjust *= 18;
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture?.Width ?? 0, null), texture, 1f / ratio); if (texture == null)
return null;
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture?.Width ?? 0, null), texture, 1f / texture.ScaleAdjust);
} }
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character)); public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));