diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs index 316fdea7b..6a19909a7 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterfaceV2/FontSelector.cs @@ -326,6 +326,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/IO/Stores/TtfGlyphStore.cs b/osu.Game.Rulesets.Karaoke/IO/Stores/TtfGlyphStore.cs index 6c06f3333..d92eee348 100644 --- a/osu.Game.Rulesets.Karaoke/IO/Stores/TtfGlyphStore.cs +++ b/osu.Game.Rulesets.Karaoke/IO/Stores/TtfGlyphStore.cs @@ -56,6 +56,7 @@ public TtfGlyphStore(ResourceStore store, string assetName = null) Store = new ResourceStore(store); Store.AddExtension("ttf"); + Store.AddExtension("ttc"); AssetName = assetName; @@ -73,8 +74,8 @@ public Task LoadFontAsync() => fontLoadTask ??= Task.Factory.StartNew(() => using (var s = Store.GetStream($@"{AssetName}")) { var fonts = new FontCollection(); - var fontFamily = fonts.Add(s); - font = new Font(fontFamily, 1); + var fontFamily = fonts.AddCollection(s, out var description).ToArray(); + font = new Font(fontFamily[0], 1); } completionSource.SetResult(font); diff --git a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs index 1a4ffd771..373b5eb41 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 1cb7c0002..7eaf1ff7b 100644 --- a/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs +++ b/osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs @@ -26,7 +26,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(); @@ -188,6 +188,7 @@ private void removeFontFromList(string path, FontFormat fontFormat) { FontFormat.Fnt => getFntGlyphStore(fontName), FontFormat.Ttf => getTtfGlyphStore(fontName), + FontFormat.Ttc => getTtcGlyphStore(fontName), FontFormat.Internal or _ => throw new ArgumentOutOfRangeException(nameof(fontFormat)) }; } @@ -216,11 +217,25 @@ private void removeFontFromList(string path, FontFormat fontFormat) return new TtfGlyphStore(new ResourceStore(resources), $"{fontName}"); } + private TtfGlyphStore? getTtcGlyphStore(string fontName) + { + string path = Path.Combine(getPathByFontType(FontFormat.Ttc), fontName); + string? 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)) }; @@ -229,6 +244,7 @@ private static string getExtensionByFontType(FontFormat type) => { FontFormat.Fnt => "zipfnt", FontFormat.Ttf => "ttf", + FontFormat.Ttc => "ttc", FontFormat.Internal or _ => throw new ArgumentOutOfRangeException(nameof(type)) }; @@ -237,6 +253,7 @@ private static FontFormat getFontTypeByExtension(string extension) => { ".zipfnt" => FontFormat.Fnt, ".ttf" => FontFormat.Ttf, + ".ttc" => FontFormat.Ttc, _ => throw new FormatException(nameof(extension)), };