// Generated API outline. Implementation bodies omitted. #nullable enable using G16 = ushort; using RGBA = uint; using System.ComponentModel; using System.Diagnostics; using nfloat = System.Runtime.InteropServices.NFloat; namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System.Linq; using System.Text; using System; public class CMapTable { public CMapTable(ReadOnlySpan data); public int? GetGlyphIndex(int unicode); public int? GetGlyphIndex(Rune rune); /// Creates a Windows Unicode cmap for the retained Unicode scalar values. public static byte[] CreateSubset(IReadOnlyList mappings); public readonly record struct GlyphMapping(Rune Character, ushort GlyphId); } public sealed class KernTable { public readonly Dictionary<(ushort Left, ushort Right), short> Pairs; public CMapTable CMap { get; } public KernTable(ReadOnlySpan data, CMapTable cmap); public short GetKerningAdjustment(ushort left, ushort right); public TrueTypeFont.ValueRecord this[Rune left, Rune right] { get; } /// Creates a horizontal format-0 kern table from the retained pairs. public static byte[] CreateSubset(IEnumerable pairs); public readonly record struct Pair(ushort Left, ushort Right, short Value); } } namespace Xui.Runtime.Software.Font { using System.Collections.Generic; using System.IO; using System.Linq; using System; using Xui.Core.Canvas; public class Catalog { public Catalog(params IEnumerable[] sources); /// Creates a catalog backed by descriptor-first, lazily loaded font resources. public Catalog(IFontSource fontSource); public virtual IEnumerable Fonts(); public virtual ReadOnlyMemory LoadFromUri(Uri uri); /// /// Loads embedded font data from a URI in the format: embedded://Assembly.Name/Folder/File.ttf /// /// The embedded URI, e.g. embedded://Xui.Core.Fonts/Inter/Inter-Bold.ttf /// A byte array containing the font file contents. /// Thrown when the resource or assembly cannot be found. public static ReadOnlyMemory LoadEmbedded(Uri uri); public IEnumerable AStar(FontFace font); public TextMetrics MeasureText(in Core.Canvas.Font font, string text, TextAlign textAlign = TextAlign.Left, TextBaseline textBaseline = TextBaseline.Alphabetic); public TrueTypeFont? FontForFace(in FontFace face); } } namespace Xui.Runtime.Software.Font { using System.Collections.Generic; using System; using Xui.Core.Canvas; public readonly struct FontFace { /// /// A struct comparer for that avoids boxing and uses case-insensitive family comparison. /// public static readonly IEqualityComparer Comparer; public string Family { get; } public FontWeight Weight { get; } public FontStyle Style { get; } public FontStretch Stretch { get; } public FontFace(string family, FontWeight weight, FontStyle style, FontStretch stretch); } } namespace Xui.Runtime.Software.Font { using System.Collections.Generic; using System.Text; using System; /// /// The characters and adjacent character pairs rendered with one font face. /// /// /// This deliberately records source characters rather than only glyph IDs. A compact font needs /// a cmap for the SVG text, while pairs allow the subsetter to retain the kerning actually used. /// Complex OpenType shaping is outside the first subset format and will add richer usage records. /// public sealed class FontUsage { public IReadOnlySet Characters { get; } public IReadOnlySet Pairs { get; } public void Add(string text); public readonly record struct RunePair(Rune Left, Rune Right); } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System; /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class ClassDefTable { public sealed class Format1 : ClassDefTable { public Format1(ReadOnlySpan span); /// /// Returns the class ID for the given glyph ID. /// If the glyph is not in the defined range, returns 0 (default class). /// public override ushort this[ushort glyphId] { get; } } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class PairAdjustmentSubtable { /// /// Represents a GPOS LookupType 2 subtable: Pair Adjustment Format 2 (class-based kerning). /// public sealed class Format2 : PairAdjustmentSubtable { public ushort ValueFormat1 { get; } public ushort ValueFormat2 { get; } public ClassDefTable ClassDef1 { get; } public ClassDefTable ClassDef2 { get; } public PairValueRecord[, ] Matrix { get; } public CoverageTable Coverage { get; } public ushort Class1Count { get; } public ushort Class2Count { get; } public Format2(ReadOnlySpan span); public sealed record PairValueRecord(TrueTypeFont.ValueRecord Value1, TrueTypeFont.ValueRecord Value2); public override TrueTypeFont.ValueRecordTuple this[ushort leftGlyph, ushort rightGlyph] { get; } } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class PairAdjustmentSubtable { public static PairAdjustmentSubtable Parse(ReadOnlySpan span); public abstract TrueTypeFont.ValueRecordTuple this[ushort leftGlyph, ushort rightGlyph] { get; } } } public class HeaderTable { public ushort FontRevisionMajor { get; } public ushort FontRevisionMinor { get; } public ushort UnitsPerEm { get; } public DateTime Created { get; } public DateTime Modified { get; } public short XMin { get; } public short YMin { get; } public short XMax { get; } public short YMax { get; } public ushort MacStyle { get; } public ushort LowestRecPPEM { get; } public ushort IndexToLocFormat { get; } public bool IsBold { get; } public bool IsItalic { get; } public bool IsUnderline { get; } public bool IsOutline { get; } public bool IsShadow { get; } public bool IsCondensed { get; } public bool IsExtended { get; } public HeaderTable(ReadOnlySpan data); /// Copies a head table configured for long loca offsets and a new checksum. public static byte[] CreateSubset(ReadOnlySpan source); } public class HorizontalHeaderTable { public short Ascender { get; } public short Descender { get; } public short LineGap { get; } public ushort AdvanceWidthMax { get; } public short MinLeftSideBearing { get; } public short MinRightSideBearing { get; } public short XMaxExtent { get; } public short CaretSlopeRise { get; } public short CaretSlopeRun { get; } public short CaretOffset { get; } public short MetricDataFormat { get; } public ushort NumberOfHMetrics { get; } public HorizontalHeaderTable(ReadOnlySpan data); /// Copies an hhea table for a compact hmtx table with one metric per glyph. public static byte[] CreateSubset(ReadOnlySpan source, ushort numberOfHMetrics); } public class MaxProfileTable { public ushort NumGlyphs { get; } public MaxProfileTable(ReadOnlySpan data); /// Copies a maxp table with the compact glyph count. public static byte[] CreateSubset(ReadOnlySpan source, ushort numGlyphs); } public class OS2Table { public ushort WeightClass { get; } public ushort WidthClass { get; } public short TypoAscender { get; } public short TypoDescender { get; } public short TypoLineGap { get; } public OS2Table(ReadOnlySpan data); } public partial class TrueTypeFont { public record struct ValueRecord(short? XPlacement, short? YPlacement, short? XAdvance, short? YAdvance) { public static ValueRecord Parse(ReadOnlySpan span, ushort format, out int size); } } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System; /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class ClassDefTable { public sealed class Format2 : ClassDefTable { public Format2(ReadOnlySpan span); public override ushort this[ushort glyphId] { get; } } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class ClassDefTable { /// /// Parses a ClassDefTable (Format 1 or 2). /// public static ClassDefTable Parse(ReadOnlySpan span); public abstract ushort this[ushort glyphId] { get; } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// public abstract partial class CoverageTable : IReadOnlyDictionary { public sealed class Format1 : CoverageTable { public Format1(ReadOnlySpan span); public override int Count { get; } public override IEnumerable Keys { get; } public override IEnumerable Values { get; } public override bool ContainsKey(ushort key); public override bool TryGetValue(ushort key, out int value); public override int this[ushort key] { get; } public override IEnumerator> GetEnumerator(); } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// public abstract partial class CoverageTable : IReadOnlyDictionary { public sealed class Format2 : CoverageTable { public Format2(ReadOnlySpan span); public override int Count { get; } public override IEnumerable Keys { get; } public override IEnumerable Values { get; } public override bool ContainsKey(ushort key); public override bool TryGetValue(ushort key, out int value); public override int this[ushort key] { get; } public override IEnumerator> GetEnumerator(); } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// /// /// Represents a GPOS Coverage Table used in subtables to identify glyphs affected. /// public abstract partial class CoverageTable : IReadOnlyDictionary { public static CoverageTable Parse(ReadOnlySpan span); public abstract int Count { get; } public abstract IEnumerable Keys { get; } public abstract IEnumerable Values { get; } public abstract bool ContainsKey(ushort key); public abstract bool TryGetValue(ushort key, out int value); public abstract int this[ushort key] { get; } public abstract IEnumerator> GetEnumerator(); } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public abstract partial class PairAdjustmentSubtable { public class Format1 : PairAdjustmentSubtable { public ushort ValueFormat1 { get; } public ushort ValueFormat2 { get; } public List PairSets { get; } public CoverageTable Coverage { get; } public Format1(ReadOnlySpan span); public sealed record PairSet(List Pairs); public sealed record PairValueRecord(ushort SecondGlyphID, TrueTypeFont.ValueRecord Value1, TrueTypeFont.ValueRecord Value2); public override TrueTypeFont.ValueRecordTuple this[ushort leftGlyph, ushort rightGlyph] { get; } } } } public class GlyfTable { public GlyfTable(ReadOnlyMemory data, LocaTable loca); /// /// Returns a glyph shape by slicing the raw memory using loca table offsets. /// public bool TryGetGlyph(int glyphIndex, out GlyphShape shape); /// Adds every component needed by retained composite glyphs. public void ExpandCompositeDependencies(SortedSet glyphs); /// Creates compact glyf and long-format loca tables for retained glyphs. public Subset CreateSubset(IReadOnlyList glyphs, IReadOnlyDictionary glyphMap); public readonly record struct Subset(byte[] Glyf, byte[] Loca); } public class HorizontalMetricsTable { public HorizontalMetricsTable(ReadOnlySpan data, ushort numberOfHMetrics); public HorizontalMetric GetMetric(int glyphIndex); /// Creates a compact hmtx table with one full metric per retained glyph. public byte[] CreateSubset(IEnumerable glyphIndices); public record struct HorizontalMetric(ushort AdvanceWidth, short LeftSideBearing); } public class LocaTable { public LocaTable(ReadOnlySpan data, int numGlyphs, ushort indexToLocFormat); public (int Offset, int Length) GetGlyphBounds(int glyphIndex); /// Creates a long-format loca table from glyph offsets. public static byte[] CreateLong(IReadOnlyList offsets); } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System; using static Xui.Runtime.Software.Font.GPosTable.LookupTable; /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public sealed class ExtensionPositioningSubtable { public GPosLookupType ExtensionLookupType { get; } public PairAdjustmentSubtable? WrappedPairSubtable { get; } public ExtensionPositioningSubtable(ReadOnlySpan span); public TrueTypeFont.ValueRecordTuple this[ushort leftGlyph, ushort rightGlyph] { get; } } } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System.Collections; using System; /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public sealed class FeatureListTable : IReadOnlyDictionary { public FeatureListTable(ReadOnlySpan span); public FeatureTable this[string key] { get; } public IEnumerable Keys { get; } public IEnumerable Values { get; } public int Count { get; } public bool ContainsKey(string key); public bool TryGetValue(string key, out FeatureTable value); public IEnumerator> GetEnumerator(); } public sealed class FeatureTable { public List LookupIndices { get; } public FeatureTable(ReadOnlySpan span); } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public sealed class LookupListTable : IReadOnlyList { public LookupListTable(ReadOnlySpan span); public LookupTable this[int index] { get; } public int Count { get; } public IEnumerator GetEnumerator(); } public sealed class LookupTable { public GPosLookupType LookupType { get; } public ushort LookupFlag { get; } public List SubTableOffsets { get; } public List? PairAdjustmentSubtables { get; } public List? ExtensionPositioningSubtables { get; } public LookupTable(ReadOnlySpan span); public TrueTypeFont.ValueRecordTuple this[ushort leftGlyph, ushort rightGlyph] { get; } public enum GPosLookupType : ushort { SingleAdjustment = 1, PairAdjustment = 2, CursiveAttachment = 3, MarkToBase = 4, MarkToLigature = 5, MarkToMark = 6, ContextPositioning = 7, ChainedContextPositioning = 8, ExtensionPositioning = 9 } } } /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public sealed class ScriptListTable : IReadOnlyDictionary { public ScriptListTable(ReadOnlySpan span); public ScriptTable this[string key] { get; } public IEnumerable Keys { get; } public IEnumerable Values { get; } public int Count { get; } public bool ContainsKey(string key); public bool TryGetValue(string key, out ScriptTable value); public IEnumerator> GetEnumerator(); } public sealed class ScriptTable : IReadOnlyDictionary { public ScriptTable(ReadOnlySpan span); public LangSysTable this[string key] { get; } public IEnumerable Keys { get; } public IEnumerable Values { get; } public int Count { get; } public bool ContainsKey(string key); public bool TryGetValue(string key, out LangSysTable value); public IEnumerator> GetEnumerator(); } public sealed class LangSysTable { public ushort RequiredFeatureIndex { get; } public List FeatureIndices { get; } public LangSysTable(ReadOnlySpan span); } } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Text; using System; /// /// Parses the 'GPOS' (Glyph Positioning) table from an OpenType font. /// This table handles kerning, mark positioning, and other glyph adjustments. /// public sealed partial class GPosTable { public ushort MajorVersion { get; } public ushort MinorVersion { get; } public ushort ScriptListOffset { get; } public ushort FeatureListOffset { get; } public ushort LookupListOffset { get; } public uint? FeatureVariationsOffset { get; } public ScriptListTable? ScriptList { get; } public FeatureListTable? FeatureList { get; } public LookupListTable? LookupList { get; } public CMapTable CMap { get; } public GPosTable(ReadOnlySpan span, CMapTable cMap); /// /// Gets the kerning adjustment between two characters using GPOS LookupType 2 or ExtensionPositioning. /// Returns a default ValueRecord if no adjustment is defined. /// public TrueTypeFont.ValueRecord this[Rune left, Rune right] { get; } } } namespace Xui.Runtime.Software.Font { public readonly record struct GlyphPosition(int GlyphId, float X, float Y); public readonly record struct TableRecord(string Tag, uint Offset, uint Length, uint Checksum); public partial class TrueTypeFont { public record struct ValueRecordTuple(ValueRecord Left, ValueRecord Right); } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System; using Xui.Core.Canvas; using Xui.Core.Math2D; /// /// A parsed TrueType glyph. This is a lightweight, stack-only view into raw glyph data. /// public ref struct GlyphShape { /// /// Gets the unscaled bounding box of the glyph in font units. /// public GlyphBound Bounds { get; } public GlyphShape(ReadOnlySpan data); public void Visit(IGlyphPathBuilder builder); public struct GlyphBound { public short XMin; public short YMin; public short XMax; public short YMax; public GlyphBound(short xMin, short yMin, short xMax, short yMax); } } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System.Text; using System; public partial class NameTable { /// Copyright notice (Name ID 0) public string? Copyright { get; } /// Font family name (Name ID 1) public string? FamilyName { get; } /// Font subfamily name (e.g. Regular, Bold) (Name ID 2) public string? SubfamilyName { get; } /// Unique font identifier (Name ID 3) public string? UniqueIdentifier { get; } /// Full font name (Name ID 4) public string? FullName { get; } /// Version string (Name ID 5) public string? Version { get; } /// PostScript name (Name ID 6) public string? PostScriptName { get; } /// Trademark notice (Name ID 7) public string? Trademark { get; } /// Manufacturer name (Name ID 8) public string? Manufacturer { get; } /// Designer name (Name ID 9) public string? Designer { get; } /// Description of the font (Name ID 10) public string? Description { get; } /// URL of the vendor (Name ID 11) public string? VendorURL { get; } /// URL of the designer (Name ID 12) public string? DesignerURL { get; } /// License description (Name ID 13) public string? License { get; } /// License info URL (Name ID 14) public string? LicenseURL { get; } /// Preferred family (Name ID 16) — used for name linking and fallback grouping public string? PreferredFamily { get; } /// Preferred subfamily (Name ID 17) — used with PreferredFamily public string? PreferredSubfamily { get; } public IReadOnlyList Names { get; } public NameTable(ReadOnlySpan data); public string? GetNameById(int id); public record struct NameRecord(ushort NameID, string Value); } public class PostTable { public PostTable(ReadOnlySpan data); public string? GetGlyphName(int glyphIndex); /// Creates a post format-3 table, retaining metrics but dropping glyph names. public static byte[] CreateSubset(ReadOnlySpan source); } } namespace Xui.Runtime.Software.Font { using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; using System; using Xui.Core.Canvas; using Xui.Core.Math2D; /// /// Lays out a string of text using a TrueType font. /// Produces positioned glyphs and bounding metrics for rendering and measurement. /// public class TextLayout { public IReadOnlyList Glyphs { get; } /// /// The horizontal and vertical bounding metrics of the laid-out text. /// public readonly LineMetrics LineMetrics; public TextLayout(TrueTypeFont font, string text); public TextLayout(TrueTypeFont font, string text, nfloat fontSize, TextAlign textAlign = TextAlign.Left, TextBaseline textBaseline = TextBaseline.Alphabetic); /// /// Visits each glyph path, offset and scaled to its layout position. /// public void Visit(IGlyphPathBuilder builder); public readonly record struct GlyphPosition(int GlyphId, NFloat X, NFloat Y); } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System.Text; using System; using Xui.Core.Canvas; public partial class TrueTypeFont { public readonly ReadOnlyMemory Blob; public readonly Uri? SourceUri; public IReadOnlyDictionary Tables { get; } public HeaderTable? Head { get; } public MaxProfileTable? Maxp { get; } public CMapTable? Cmap { get; } public PostTable? Post { get; } public LocaTable? Loca { get; } public GlyfTable? Glyf { get; } public OS2Table? OS2 { get; } public NameTable? Name { get; } public HorizontalHeaderTable? Hhea { get; } public HorizontalMetricsTable? Hmtx { get; } public KernTable? Kern { get; } public GPosTable? GPos { get; } public FontFace Face { get; } public KerningQuery Kerning { get; } public TrueTypeFont(ReadOnlyMemory blob, Uri? SourceUri = null); public TextMetrics MeasureText(string text, Xui.Core.Canvas.Font font, TextAlign textAlign = TextAlign.Left, TextBaseline textBaseline = TextBaseline.Alphabetic); /// Measures metrics which depend on the text's glyphs and shaping. public LineMetrics MeasureLine(string text, Xui.Core.Canvas.Font font, TextAlign textAlign = TextAlign.Left, TextBaseline textBaseline = TextBaseline.Alphabetic); public FontMetrics Metrics(Xui.Core.Canvas.Font font); public bool TryGetGlyph(int glyphId, out GlyphShape shape); public int? GetGlyphIndex(Rune rune); public string? GetGlyphName(int glyphId); public readonly record struct TableRecord(string Tag, uint Offset, uint Length, uint Checksum); public readonly struct KerningQuery { public KerningQuery(TrueTypeFont font); public ValueRecord this[Rune left, Rune right] { get; } } /// /// Extracts a from minimal parsed font tables. /// /// The containing font naming information. /// The containing weight and width data. /// The used to determine italic style (via macStyle flags). /// A constructed . public static FontFace FontFace(HeaderTable? head, NameTable? name, OS2Table? os2); public static FontFace FontFace(ReadOnlySpan fontData); } } namespace Xui.Runtime.Software.Font { using System.Buffers.Binary; using System.Collections.Generic; using System.Linq; using System; /// Builds a compact TrueType sfnt containing the rendered simple glyphs and kerning pairs. public static class TrueTypeFontSubset { /// /// Creates a deterministic TrueType subset. The initial format supports BMP characters and /// simple and composite glyf outlines; its callers must retain the original font for unsupported scripts. /// public static ReadOnlyMemory Create(TrueTypeFont font, FontUsage usage); } }