gpui/text_system/font_introspection.rs
1use super::FontTag;
2
3/// A query can be unsupported, fail (`Err`), or succeed with an empty value.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum FontQuery<T> {
6 /// The backend cannot perform this query; this says nothing about the font.
7 Unsupported,
8 /// The query succeeded, including when no features were found.
9 Supported(T),
10}
11
12/// A feature advertised by the resolved face's GSUB and/or GPOS FeatureList.
13/// Presence does not imply applicability to a script, language, or input text.
14/// This is metadata, not a list of boolean toggles or allowed numeric values.
15#[derive(Clone, Debug, Eq, PartialEq)]
16pub struct OpenTypeFeatureInfo {
17 /// The OpenType feature tag, usable with existing numeric `FontFeatures`.
18 pub tag: FontTag,
19 /// Advertised by the glyph substitution table.
20 pub substitution: bool,
21 /// Advertised by the glyph positioning table.
22 pub positioning: bool,
23}
24
25/// Backend support for font inspection and explicit static axes.
26#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
27pub struct FontCapabilities {
28 /// Can read GSUB/GPOS feature metadata.
29 pub feature_introspection: bool,
30 /// Can read variable-axis ranges on resolved faces.
31 pub axis_introspection: bool,
32 /// Applies arbitrary explicit coordinates consistently to layout and rasterization.
33 pub static_variations: bool,
34}
35
36/// An axis advertised by a resolved face's `fvar` table, in design units.
37#[derive(Clone, Debug, PartialEq)]
38pub struct VariationAxisInfo {
39 /// Four-byte OpenType tag.
40 pub tag: FontTag,
41 /// Minimum supported coordinate.
42 pub min_value: f32,
43 /// Default coordinate when no explicit or implicit setting applies.
44 pub default_value: f32,
45 /// Maximum supported coordinate.
46 pub max_value: f32,
47 /// Whether the font recommends hiding this axis from ordinary inspectors.
48 pub hidden: bool,
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54 #[test]
55 fn unsupported_backend_is_not_an_empty_success() {
56 let text = crate::TextSystem::new(std::sync::Arc::new(crate::NoopTextSystem::new()));
57 assert_eq!(
58 text.opentype_features(crate::FontId(0)).unwrap(),
59 FontQuery::Unsupported
60 );
61 }
62}