package alibaba:fontkit; interface commons { record font-key { weight: option, italic: option, stretch: option, family: string, } } interface fontkit-interface { use commons.{font-key}; record name { id: u16, name: string, language-id: u16 } record font-info { style-names: list, names: list, path: option, key: font-key, } record line-metrics { position: s16, thickness: s16, } resource text-metrics { constructor(value: string); duplicate: func() -> text-metrics; width: func(font-size: f32, letter-spacing: f32) -> f32; height: func(font-size: f32, line-height: option) -> f32; ascender: func(font-size: f32) -> f32; line-gap: func() -> f32; units: func() -> f32; slice: func(start: u32, count: u32) -> text-metrics; value: func() -> string; is-rtl: func() -> bool; append: func(other: text-metrics); count: func() -> u32; /// replace this metrics with another, allowing fallback logic replace: func(other: text-metrics, fallback: bool); split-by-width: func(font-size: f32, letter-spacing: f32, width: f32) -> text-metrics; chars: func() -> list; } resource glyph-bitmap { width: func() -> u32; height: func() -> u32; bitmap: func() -> list; x-min: func() -> f32; y-max: func() -> f32; stroke-x: func() -> f32; stroke-y: func() -> f32; stroke-bitmap: func() -> option, u32>>; advanced-x: func() -> f32; ascender: func() -> f32; descender: func() -> f32; } /// Instance of a single font resource font { /// Check if the font has valid data for a character has-glyph: func(c: char) -> bool; /// Output the svg path string of a glyph glyph-path-string: func(c: char) -> option; /// Return the font buffer buffer: func() -> list; /// Return the path if this font is added from searching a path path: func() -> string; /// Return the key of this font key: func() -> font-key; /// Measure text using this font measure: func(text: string) -> result; ascender: func() -> s16; descender: func() -> s16; units-per-em: func() -> u16; bitmap: func(c: char, font-size: f32, stroke-width: f32) -> option; underline-metrics: func() -> option; variation: func() -> option>>; } /// Stores font buffer and provides font-querying APIs resource font-kit { constructor(); /// Register a font (or several fonts in case of ttc), return the keys of added fonts. /// The file type is extracted from the buffer by checking magic numbers add-font-from-buffer: func(buffer: list) -> list; /// Search and add fonts from a path add-search-path: func(path: string); /// Query font using a key, this API returns valid result only if a single result is found query: func(key: font-key) -> option; /// Using exact-match method to directly obtain a font, skipping the querying logic exact-match: func(key: font-key) -> option; /// Get all registered fonts' keys font-keys: func() -> list; /// Get detailed info of all fonts registered fonts-info: func() -> list; /// Get number of registered fonts len: func() -> u32; /// Remove a font matching the given key remove: func(key: font-key); /// Measure a text with some fallback logic measure: func(key: font-key, text: string) -> option; } str-width-to-number: func(width: string) -> u16; number-width-to-str: func(width: u16) -> string; } world fontkit { export fontkit-interface; }