1mod cache_keys;
2mod cache_tuning;
3mod decorations;
4mod fallback_policy;
5mod font_instance_key;
6mod font_names;
7mod font_stack;
8mod font_trace;
9mod geometry;
10mod line_layout;
11mod measure;
12mod parley_font_db;
13mod parley_shaper;
14mod prepare_layout;
15mod spans;
16mod wrapper;
17mod wrapper_balance;
18mod wrapper_boundaries;
19mod wrapper_paragraphs;
20mod wrapper_ranges;
21mod wrapper_slices;
22
23pub use cache_keys::{
24 TextBlobKey, TextMeasureKey, TextShapeKey, spans_paint_fingerprint, spans_shaping_fingerprint,
25};
26pub use cache_tuning::{
27 measure_shaping_cache_entries, measure_shaping_cache_min_text_len_bytes,
28 released_blob_cache_entries,
29};
30pub use decorations::{
31 TextDecoration, TextDecorationKind, TextDecorationMetricsPx,
32 decoration_metrics_px_for_font_bytes, decorations_for_lines,
33};
34pub use fallback_policy::{CommonFallbackMode, TextFallbackPolicyV1, common_fallback_stack_suffix};
35pub use font_instance_key::{FontFaceKey, variation_key_from_normalized_coords};
36pub use font_names::best_family_name_from_font_bytes;
37pub use font_stack::{GenericFamilyInjectionState, apply_font_families_inner};
38pub use font_trace::{FontTraceFamilyResolved, FontTraceState};
39pub use geometry::{
40 TextLineCluster, TextLineDecorationGeometry, TextLineGeometry, caret_rect_from_lines,
41 caret_stops_for_slice, caret_x_from_stops, hit_test_point_from_lines, hit_test_x_from_stops,
42 selection_rects_from_lines, selection_rects_from_lines_clipped,
43};
44pub use line_layout::TextLineLayout;
45pub use measure::TextMeasureCaches;
46pub use parley_shaper::{
47 FontEnvironmentBlobRef, FontSynthesis, GlyphFontData, ParleyGlyph, ParleyShaper,
48 ParleyShaperFontDbDiagnosticsSnapshot, ShapedCluster, ShapedLineLayout, run_system_font_rescan,
49};
50pub use prepare_layout::{PreparedLayout, PreparedLine, prepare_layout_from_wrapped};
51pub use spans::{
52 ResolvedSpan, paint_span_for_text_range, resolve_spans_for_text, sanitize_spans_for_text,
53};
54pub use wrapper::{WrappedLayout, wrap_with_constraints, wrap_with_constraints_measure_only};
55
56#[inline]
57pub fn effective_text_scale_factor(scale_factor: f32) -> f32 {
58 if scale_factor.is_finite() && scale_factor > 0.0 {
59 scale_factor
60 } else {
61 1.0
62 }
63}
64
65#[derive(Debug, Clone, PartialEq, Eq, Hash)]
66pub struct FontCatalogEntryMetadata {
67 family: String,
68 has_variable_axes: bool,
69 known_variable_axes: Vec<String>,
70 variable_axes: Vec<FontVariableAxisMetadata>,
71 is_monospace_candidate: bool,
72}
73
74#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
75pub struct FontVariableAxisMetadata {
76 tag: String,
77 min_bits: u32,
78 max_bits: u32,
79 default_bits: u32,
80}
81
82impl FontCatalogEntryMetadata {
83 pub fn new(
84 family: String,
85 has_variable_axes: bool,
86 known_variable_axes: Vec<String>,
87 variable_axes: Vec<FontVariableAxisMetadata>,
88 is_monospace_candidate: bool,
89 ) -> Self {
90 Self {
91 family,
92 has_variable_axes,
93 known_variable_axes,
94 variable_axes,
95 is_monospace_candidate,
96 }
97 }
98
99 pub fn family(&self) -> &str {
100 &self.family
101 }
102
103 pub fn has_variable_axes(&self) -> bool {
104 self.has_variable_axes
105 }
106
107 pub fn known_variable_axes(&self) -> &[String] {
108 &self.known_variable_axes
109 }
110
111 pub fn variable_axes(&self) -> &[FontVariableAxisMetadata] {
112 &self.variable_axes
113 }
114
115 pub fn is_monospace_candidate(&self) -> bool {
116 self.is_monospace_candidate
117 }
118
119 pub fn into_parts(
120 self,
121 ) -> (
122 String,
123 bool,
124 Vec<String>,
125 Vec<FontVariableAxisMetadata>,
126 bool,
127 ) {
128 (
129 self.family,
130 self.has_variable_axes,
131 self.known_variable_axes,
132 self.variable_axes,
133 self.is_monospace_candidate,
134 )
135 }
136}
137
138impl FontVariableAxisMetadata {
139 pub fn new(tag: String, min_bits: u32, max_bits: u32, default_bits: u32) -> Self {
140 Self {
141 tag,
142 min_bits,
143 max_bits,
144 default_bits,
145 }
146 }
147
148 pub fn tag(&self) -> &str {
149 &self.tag
150 }
151
152 pub fn min_bits(&self) -> u32 {
153 self.min_bits
154 }
155
156 pub fn max_bits(&self) -> u32 {
157 self.max_bits
158 }
159
160 pub fn default_bits(&self) -> u32 {
161 self.default_bits
162 }
163
164 pub fn into_parts(self) -> (String, u32, u32, u32) {
165 (self.tag, self.min_bits, self.max_bits, self.default_bits)
166 }
167}
168
169#[derive(Debug, Clone)]
170pub struct SystemFontRescanSeed {
171 pub(crate) registered_font_blobs: Vec<parley::fontique::Blob<u8>>,
172}
173
174pub struct SystemFontRescanResult {
175 pub(crate) collection: parley::fontique::Collection,
176 pub(crate) all_font_names: Vec<String>,
177 pub(crate) all_font_catalog_entries: Vec<FontCatalogEntryMetadata>,
178 pub(crate) environment_fingerprint: u64,
179}
180
181const _: () = {
182 fn assert_send<T: Send>() {}
183 fn assert_sync<T: Sync>() {}
184
185 let _ = assert_send::<SystemFontRescanSeed> as fn();
186 let _ = assert_send::<SystemFontRescanResult> as fn();
187 let _ = assert_sync::<SystemFontRescanSeed> as fn();
188 let _ = assert_sync::<SystemFontRescanResult> as fn();
189};
190
191impl std::fmt::Debug for SystemFontRescanResult {
192 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193 f.debug_struct("SystemFontRescanResult")
194 .field("all_font_names_len", &self.all_font_names.len())
195 .field(
196 "all_font_catalog_entries_len",
197 &self.all_font_catalog_entries.len(),
198 )
199 .field("environment_fingerprint", &self.environment_fingerprint)
200 .finish_non_exhaustive()
201 }
202}
203
204impl SystemFontRescanSeed {
205 pub fn run(self) -> SystemFontRescanResult {
206 parley_shaper::run_system_font_rescan(self)
207 }
208}