From 015f82d856e1b222fe8dbd7797e42904f25a26cb 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 1/2] Add ttc file textension. --- .../Graphics/UserInterfaceV2/FontSelector.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/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/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)), }; From 2f4c3136769fe761c703f8020e467d187c9f67a5 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:34:58 +0800 Subject: [PATCH 2/2] [temp] use this shit to test ttc format. and notice that ttc might have the issue: 1. ttc is list of fonts, not single font. so might have multiple font family. 2. it might contains the format that cannot be parsed (not pure ttf file.) --- osu.Game.Rulesets.Karaoke/IO/Stores/TtfGlyphStore.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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);