2019-08-30 12:04:11 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2019-08-30 12:04:11 +08:00
|
|
|
using System.Threading.Tasks;
|
2021-05-10 21:36:20 +08:00
|
|
|
using osu.Framework.Allocation;
|
2019-08-30 12:04:11 +08:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Text;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2021-03-07 07:28:08 +08:00
|
|
|
using osuTK;
|
2019-08-30 12:04:11 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public sealed partial class LegacySpriteText : OsuSpriteText
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
2021-05-10 21:36:20 +08:00
|
|
|
private readonly LegacyFont font;
|
|
|
|
|
|
|
|
private LegacyGlyphStore glyphStore;
|
2019-08-30 12:04:11 +08:00
|
|
|
|
2020-10-19 13:59:03 +08:00
|
|
|
protected override char FixedWidthReferenceCharacter => '5';
|
|
|
|
|
|
|
|
protected override char[] FixedWidthExcludeCharacters => new[] { ',', '.', '%', 'x' };
|
|
|
|
|
2021-05-10 21:36:20 +08:00
|
|
|
public LegacySpriteText(LegacyFont font)
|
2019-08-30 12:04:11 +08:00
|
|
|
{
|
2021-05-10 21:36:20 +08:00
|
|
|
this.font = font;
|
2019-08-30 12:04:11 +08:00
|
|
|
Shadow = false;
|
|
|
|
UseFullGlyphHeight = false;
|
2021-05-10 21:36:20 +08:00
|
|
|
}
|
2019-08-30 12:04:11 +08:00
|
|
|
|
2021-05-10 21:36:20 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ISkinSource skin)
|
|
|
|
{
|
2021-03-07 07:28:08 +08:00
|
|
|
Font = new FontUsage(skin.GetFontPrefix(font), 1, fixedWidth: true);
|
|
|
|
Spacing = new Vector2(-skin.GetFontOverlap(font), 0);
|
|
|
|
|
2019-08-30 12:04:11 +08:00
|
|
|
glyphStore = new LegacyGlyphStore(skin);
|
|
|
|
}
|
|
|
|
|
2020-10-19 13:59:03 +08:00
|
|
|
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
|
2019-08-30 12:04:11 +08:00
|
|
|
|
|
|
|
private class LegacyGlyphStore : ITexturedGlyphLookupStore
|
|
|
|
{
|
|
|
|
private readonly ISkin skin;
|
|
|
|
|
|
|
|
public LegacyGlyphStore(ISkin skin)
|
|
|
|
{
|
|
|
|
this.skin = skin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ITexturedCharacterGlyph Get(string fontName, char character)
|
|
|
|
{
|
2021-10-27 12:04:41 +08:00
|
|
|
string lookup = getLookupName(character);
|
2020-10-15 16:56:37 +08:00
|
|
|
|
|
|
|
var texture = skin.GetTexture($"{fontName}-{lookup}");
|
2019-08-30 12:04:11 +08:00
|
|
|
|
|
|
|
if (texture == null)
|
|
|
|
return null;
|
|
|
|
|
2021-09-05 05:41:34 +08:00
|
|
|
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 1f / texture.ScaleAdjust);
|
2019-08-30 12:04:11 +08:00
|
|
|
}
|
|
|
|
|
2020-10-15 16:56:37 +08:00
|
|
|
private static string getLookupName(char character)
|
|
|
|
{
|
|
|
|
switch (character)
|
|
|
|
{
|
|
|
|
case ',':
|
|
|
|
return "comma";
|
|
|
|
|
|
|
|
case '.':
|
|
|
|
return "dot";
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
return "percent";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return character.ToString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-30 12:04:11 +08:00
|
|
|
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|