From ea9d0d41331e7cd9de72d7ab0fc5b732f4f995ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=82=BA=E4=BB=80=E9=BA=BC?= Date: Sat, 4 Sep 2021 11:27:28 +0800 Subject: [PATCH] Add ttc file textension. --- .../UserInterface/FontSelectionDialog.cs | 1 + .../Skinning/Fonts/FontInfo.cs | 2 ++ .../Skinning/Fonts/FontManager.cs | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/FontSelectionDialog.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/FontSelectionDialog.cs index c47648c35..d6759b7ff 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/FontSelectionDialog.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/FontSelectionDialog.cs @@ -348,6 +348,7 @@ private void load(OsuColour colour) FontFormat.Internal => colour.Gray7, FontFormat.Fnt => colour.Pink, FontFormat.Ttf => colour.Blue, + FontFormat.Ttc => colour.BlueDark, _ => throw new ArgumentOutOfRangeException(nameof(fontFormat)) }; diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs index 257fcab50..0bff037e1 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs @@ -44,5 +44,7 @@ public enum FontFormat Fnt, Ttf, + + Ttc, } } diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs index 6dc740807..875cb4300 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs @@ -25,7 +25,7 @@ public class FontManager : Component private Storage storage => host.Storage.GetStorageForDirectory(FONT_BASE_PATH); - private readonly FontFormat[] supportedFormat = { FontFormat.Fnt, FontFormat.Ttf }; + private readonly FontFormat[] supportedFormat = { FontFormat.Fnt, FontFormat.Ttf, FontFormat.Ttc }; public readonly BindableList Fonts = new(); @@ -187,6 +187,7 @@ public IResourceStore GetGlyphStore(FontInfo fontInfo) { FontFormat.Fnt => getFntGlyphStore(storage, fontName), FontFormat.Ttf => getTtfGlyphStore(storage, fontName), + FontFormat.Ttc => getTtcGlyphStore(storage, fontName), FontFormat.Internal or _ => throw new ArgumentOutOfRangeException(nameof(fontFormat)) }; } @@ -215,11 +216,25 @@ private TtfGlyphStore getTtfGlyphStore(Storage storage, string fontName) return new TtfGlyphStore(new ResourceStore(resources), $"{fontName}"); } + private TtfGlyphStore getTtcGlyphStore(Storage storage, string fontName) + { + var path = Path.Combine(getPathByFontType(FontFormat.Ttc), fontName); + var pathWithExtension = Path.ChangeExtension(path, getExtensionByFontType(FontFormat.Ttc)); + + if (!storage.Exists(pathWithExtension)) + return null; + + // because ttc is just a collection of ttf file, so we can use TtfGlyphStore to read it. + var resources = new StorageBackedResourceStore(storage.GetStorageForDirectory(getPathByFontType(FontFormat.Ttc))); + return new TtfGlyphStore(new ResourceStore(resources), $"{fontName}"); + } + private static string getPathByFontType(FontFormat type) => type switch { FontFormat.Fnt => "fnt", FontFormat.Ttf => "ttf", + FontFormat.Ttc => "ttc", FontFormat.Internal or _ => throw new ArgumentOutOfRangeException(nameof(type)) }; @@ -228,6 +243,7 @@ private static string getExtensionByFontType(FontFormat type) => { FontFormat.Fnt => "zipfnt", FontFormat.Ttf => "ttf", + FontFormat.Ttc => "ttc", FontFormat.Internal or _ => throw new ArgumentOutOfRangeException(nameof(type)) }; @@ -236,6 +252,7 @@ private static FontFormat getFontTypeByExtension(string extension) => { ".zipfnt" => FontFormat.Fnt, ".ttf" => FontFormat.Ttf, + ".ttc" => FontFormat.Ttc, _ => throw new FormatException(nameof(extension)), };