Repository navigation
<
F956
/div>
Expand file tree
/
Copy pathlib.rs
More file actions
54 lines (49 loc) · 2.59 KB
/
Copy pathlib.rs
File metadata and controls
54 lines (49 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! FilmCraft text engine (layer L1).
//!
//! - [`fonts`]: font database — bundled OFL fonts (Inter, JetBrains Mono, Noto Serif) plus faces
//! discovered by [`fonts::FontSource`]s (system font folders on native platforms; nothing on the
//! web unless the host registers font data), family/style resolution with synthetic bold/italic
//! and per-character fallback.
//! - [`layout`]: shaping (harfrust: kerning, ligatures, complex scripts), bidi, line breaking,
//! paragraph layout, per-character style runs, carets and hit testing; cached.
//! - [`raster`]: our own anti-aliased path rasteriser (linear coverage, so compositing in linear
//! light is correct) and vector shapes.
//! - [`render`]: glyph outlines and the glyph-mask cache (sub-pixel positioned), drawing layouts
//! under any affine transform.
//! - [`mask`]: strokes (outer/centre/inner via a Euclidean distance transform), blur, offsets.
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable))]
pub mod fonts;
pub mod layout;
pub mod mask;
pub mod raster;
pub mod render;
pub mod sfnt;
pub use fonts::{FaceId, Resolved, families, resolve};
pub use layout::{Align, Caps, Glyph, Layout, Line, ParagraphStyle, StyleRun, TextStyle, layout, layout_rich, measure};
pub use mask::StrokeKind;
pub use raster::{Mask, Path, Xform};
#[cfg(test)]
mod perf {
use super::*;
/// A three-line 1080p title: layout + rasterisation must stay far below a frame (≈ 41 ms at
/// 24 fps). Cold = first time (shaping + glyph rasterisation); warm = cached.
#[test]
fn three_line_title_is_fast() {
let text = "FILMCRAFT PRESENTS\nA Night Drive Through the City\nDirected by Nobody in Particular";
let st = TextStyle { size: 96.0, style: "Bold".into(), ..Default::default() };
let ps = ParagraphStyle { align: Align::Center, ..Default::default() };
let t0 = std::time::Instant::now();
let l = layout::layout_uncached(text, &st, &ps);
let (m, _, _) = render::rasterize(&l, &render::at(960.0, 400.0));
let cold = t0.elapsed();
let _ = layout(text, &st, &ps);
let t1 = std::time::Instant::now();
let l2 = layout(text, &st, &ps);
let (m2, _, _) = render::rasterize(&l2, &render::at(960.0, 400.0));
let warm = t1.elapsed();
assert_eq!(m.a.len(), m2.a.len());
eprintln!("3-line 1080p title: cold {cold:?}, warm {warm:?} (mask {}x{})", m.w, m.h);
// generous bound for debug builds on busy CI machines
assert!(warm.as_millis() < 40, "warm {warm:?}");
}
}