Skip to main content

Line

Struct Line 

Source
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: usize

Index of the first glyph of this line in LayoutResult::glyphs.

§glyph_end: usize

Index past the last glyph of this line in LayoutResult::glyphs.

§metrics: LineMetrics

Vertical and width metrics for the line.

Implementations§

Source§

impl Line

Source

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}
Source

pub fn is_empty(&self) -> bool

Returns true if the line has no glyphs.

Trait Implementations§

Source§

impl Clone for Line

Source§

fn clone(&self) -> Line

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Line

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.