86 lines
1.4 KiB
C#
86 lines
1.4 KiB
C#
using System.Text.Json.Serialization;
|
|
using MoonWorks.Math.Float;
|
|
|
|
namespace MoonWorks.Graphics.Font.MSDF;
|
|
|
|
[JsonSerializable(typeof(AtlasData))]
|
|
internal partial class AtlasDataContext : JsonSerializerContext
|
|
{
|
|
}
|
|
|
|
// Reads from an atlas generated by msdf-atlas-gen
|
|
public struct AtlasData
|
|
{
|
|
public Atlas Atlas;
|
|
public Metrics Metrics;
|
|
public Glyph[] Glyphs;
|
|
}
|
|
|
|
public struct Atlas
|
|
{
|
|
public FieldType Type;
|
|
public int DistanceRange;
|
|
public int Size;
|
|
public int Width;
|
|
public int Height;
|
|
public Origin YOrigin;
|
|
}
|
|
|
|
public struct Metrics
|
|
{
|
|
public int EmSize;
|
|
public float LineHeight;
|
|
public float Ascender;
|
|
public float Descender;
|
|
public float UnderlineY;
|
|
public float UnderlineThickness;
|
|
}
|
|
|
|
public struct Glyph
|
|
{
|
|
public uint Unicode;
|
|
public float Advance;
|
|
public Bounds PlaneBounds;
|
|
public Bounds AtlasBounds;
|
|
}
|
|
|
|
public struct Bounds
|
|
{
|
|
public float Left;
|
|
public float Bottom;
|
|
public float Right;
|
|
public float Top;
|
|
}
|
|
|
|
public enum FieldType
|
|
{
|
|
Hardmask,
|
|
Softmask,
|
|
SDF,
|
|
PSDF,
|
|
MSDF,
|
|
MTSDF
|
|
}
|
|
|
|
public enum Origin
|
|
{
|
|
Top,
|
|
Bottom
|
|
}
|
|
|
|
public struct FontVertex : IVertexType
|
|
{
|
|
public Vector3 Position;
|
|
public Vector2 TexCoord;
|
|
public Color Color;
|
|
|
|
private static readonly VertexElementFormat[] vertexElementFormats = new VertexElementFormat[]
|
|
{
|
|
VertexElementFormat.Vector3,
|
|
VertexElementFormat.Vector2,
|
|
VertexElementFormat.Color
|
|
};
|
|
|
|
public static VertexElementFormat[] Formats => vertexElementFormats;
|
|
}
|