Roblox-File-Format/Utility/FontUtility.cs
CloneTrooper1019 de8df15d3f Large scale refactor to add class support!
Instance classes are now strongly typed with real property fields that
are derived from the JSON API Dump! This required a lot of reworking
across the board:

- Classes and Enums are auto-generated in the 'Generated' folder now.
This is done using a custom built-in plugin, which can be found in
the Plugins folder of this project.
- Property objects are now tied to .NET's reflection system. Reading
and writing from them will try to redirect into a field of the
Instance they are bound to.
- Property types that were loosely defined now have proper data types
(such as Color3uint8, Content, ProtectedString, SharedString, etc)
- Fixed an error with the CFrame directional vectors.
- The binary PRNT chunk now writes instances in child->parent order.
- Enums are now generated correctly, with up-to-date values.
- INST chunks are now referred to as 'Classes' instead of 'Types'.
- Unary operator added to Vector2 and Vector3.
- CollectionService tags can now be manipulated per-instance using
the Instance.Tags member.
- The Instance.Archivable property now works correctly.
- XML files now save/load metadata correctly.
- Cleaned up the property tokens directory.

I probably missed a few things, but that's a general overview of
everything that changed.
2019-06-30 17:01:19 -05:00

67 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RobloxFiles.Enums;
namespace RobloxFiles.Utility
{
public static class FontUtility
{
public static IReadOnlyDictionary<int, FontSize> FontSizes = new Dictionary<int, FontSize>()
{
{ 8, FontSize.Size8 },
{ 9, FontSize.Size9 },
{ 10, FontSize.Size10 },
{ 11, FontSize.Size11 },
{ 12, FontSize.Size12 },
{ 14, FontSize.Size14 },
{ 18, FontSize.Size18 },
{ 24, FontSize.Size24 },
{ 28, FontSize.Size28 },
{ 32, FontSize.Size32 },
{ 36, FontSize.Size36 },
{ 42, FontSize.Size42 },
{ 48, FontSize.Size48 },
{ 60, FontSize.Size60 },
{ 96, FontSize.Size96 },
};
private static Dictionary<int, FontSize> IntToFontSize = new Dictionary<int, FontSize>();
public static FontSize GetFontSize(int fontSize)
{
if (fontSize > 60)
return FontSize.Size96;
if (FontSizes.ContainsKey(fontSize))
return FontSizes[fontSize];
FontSize closest = FontSizes
.Where(pair => pair.Key <= fontSize)
.Select(pair => pair.Value)
.Last();
return closest;
}
public static FontSize GetFontSize(float size)
{
int fontSize = (int)size;
return GetFontSize(fontSize);
}
public static int GetFontSize(FontSize fontSize)
{
int value = FontSizes
.Where(pair => pair.Value == fontSize)
.Select(pair => pair.Key)
.First();
return value;
}
}
}