pub struct Line {
pub glyph_start: usize,
pub glyph_end: usize,
pub metrics: LineMetrics,
}Expand description
A single laid-out line: a contiguous slice of positioned glyphs plus its metrics.
Fields§
§glyph_start: usizeIndex of the first glyph of this line in LayoutResult::glyphs.
glyph_end: usizeIndex past the last glyph of this line in LayoutResult::glyphs.
metrics: LineMetricsVertical and width metrics for the line.
Implementations§
Source§impl Line
impl Line
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of glyphs in the line.
Examples found in repository?
examples/word_aware_layout.rs (line 86)
54fn main() {
55 let text = "The quick brown fox jumps";
56 let run = shaped_run_from_text(text, 12.0);
57
58 // Wrap at 120px — narrow enough that the paragraph spans several lines.
59 let constraints = LayoutConstraints {
60 max_width: 120.0,
61 font_size: 16.0,
62 };
63
64 let mut engine = LayoutEngine::new();
65 let result = engine
66 .layout(text, &[run], &constraints, TextAlignment::Left, None)
67 .expect("layout is currently infallible for well-formed input");
68
69 println!(
70 "laid out {} glyph(s) into {} line(s); paragraph size = {:.1} x {:.1}px",
71 result.glyphs.len(),
72 result.lines.len(),
73 result.metrics.total_width,
74 result.metrics.total_height,
75 );
76 assert!(
77 result.lines.len() > 1,
78 "narrow max_width should force wraps"
79 );
80
81 for (i, line) in result.lines.iter().enumerate() {
82 let glyphs = &result.glyphs[line.glyph_start..line.glyph_end];
83 let first_x = glyphs.first().map(|g| g.pos.0).unwrap_or(0.0);
84 println!(
85 " line {i}: {} glyph(s), starts at x={first_x:.1}, width={:.1}px",
86 line.len(),
87 line.metrics.width,
88 );
89 // Every wrapped line must restart at the left edge.
90 assert!((first_x - 0.0).abs() < 1e-3);
91 }
92
93 // Hand-off to a rasterizer / SDF atlas: the unique (glyph_id, px_size)
94 // pairs actually used by this layout, in first-occurrence order.
95 let glyph_set = result.unique_glyphs_for_atlas();
96 println!(
97 "{} unique glyph(s) needed for rasterization",
98 glyph_set.len()
99 );
100 assert!(!glyph_set.is_empty());
101}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Line
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnsafeUnpin for Line
impl UnwindSafe for Line
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more