Skip to content

Commit

Permalink
Add ttc file textension.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy840119 committed Sep 4, 2021
1 parent 62c23f6 commit ea9d0d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
};

Expand Down
2 changes: 2 additions & 0 deletions osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public enum FontFormat
Fnt,

Ttf,

Ttc,
}
}
19 changes: 18 additions & 1 deletion osu.Game.Rulesets.Karaoke/Skinning/Fonts/FontManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FontInfo> Fonts = new();

Expand Down Expand Up @@ -187,6 +187,7 @@ public IResourceStore<TextureUpload> 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))
};
}
Expand Down Expand Up @@ -215,11 +216,25 @@ private TtfGlyphStore getTtfGlyphStore(Storage storage, string fontName)
return new TtfGlyphStore(new ResourceStore<byte[]>(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<byte[]>(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))
};

Expand All @@ -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))
};

Expand All @@ -236,6 +252,7 @@ private static FontFormat getFontTypeByExtension(string extension) =>
{
".zipfnt" => FontFormat.Fnt,
".ttf" => FontFormat.Ttf,
".ttc" => FontFormat.Ttc,
_ => throw new FormatException(nameof(extension)),
};

Expand Down

0 comments on commit ea9d0d4

Please sign in to comment.