Struct layout_2013::inline::Line
source · pub struct Line {
pub range: Range<FragmentIndex>,
pub visual_runs: Option<Vec<(Range<FragmentIndex>, Level)>>,
pub bounds: LogicalRect<Au>,
pub green_zone: LogicalSize<Au>,
pub minimum_metrics: LineMetrics,
pub metrics: LineMetrics,
}
Expand description
Line
s are represented as offsets into the child list, rather than
as an object that “owns” fragments. Choosing a different set of line
breaks requires a new list of offsets, and possibly some splitting and
merging of TextFragments.
A similar list will keep track of the mapping between CSS fragments and the corresponding fragments in the inline flow.
After line breaks are determined, render fragments in the inline flow may overlap visually. For example, in the case of nested inline CSS fragments, outer inlines must be at least as large as the inner inlines, for purposes of drawing noninherited things like backgrounds, borders, outlines.
N.B. roc has an alternative design where the list instead consists of things like “start outer fragment, text, start inner fragment, text, end inner fragment, text, end outer fragment, text”. This seems a little complicated to serve as the starting point, but the current design doesn’t make it hard to try out that alternative.
Line fragments also contain some metadata used during line breaking. The green zone is the area that the line can expand to before it collides with a float or a horizontal wall of the containing block. The block-start inline-start corner of the green zone is the same as that of the line, but the green zone can be taller and wider than the line itself.
Fields§
§range: Range<FragmentIndex>
A range of line indices that describe line breaks.
For example, consider the following HTML and rendered element with linebreaks:
<span>I <span>like truffles, <img></span> yes I do.</span>
+------------+
| I like |
| truffles, |
| +----+ |
| | | |
| +----+ yes |
| I do. |
+------------+
The ranges that describe these lines would be:
[0, 2) | [2, 3) | [3, 5) | [5, 6) |
---|---|---|---|
‘I like’ | ‘truffles,’ | ‘ yes’ | ‘I do.’ |
visual_runs: Option<Vec<(Range<FragmentIndex>, Level)>>
The bidirectional embedding level runs for this line, in visual order.
Can be set to None
if the line is 100% left-to-right.
bounds: LogicalRect<Au>
The bounds are the exact position and extents of the line with respect to the parent box.
For example, for the HTML below…
<div><span>I like truffles, <img></span></div>
…the bounds would be:
+-----------------------------------------------------------+
| ^ |
| | |
| origin.y |
| | |
| v |
|< - origin.x ->+ - - - - - - - - +---------+---- |
| | | | ^ |
| | | <img> | size.block |
| I like truffles, | | v |
| + - - - - - - - - +---------+---- |
| | | |
| |<------ size.inline ------>| |
| |
| |
+-----------------------------------------------------------+
green_zone: LogicalSize<Au>
The green zone is the greatest extent from which a line can extend to before it collides with a float.
+-----------------------+
|::::::::::::::::: |
|:::::::::::::::::FFFFFF|
|============:::::FFFFFF|
|:::::::::::::::::FFFFFF|
|:::::::::::::::::FFFFFF|
|::::::::::::::::: |
| FFFFFFFFF |
| FFFFFFFFF |
| FFFFFFFFF |
| |
+-----------------------+
=== line
::: green zone
FFF float
minimum_metrics: LineMetrics
The minimum metrics for this line, as specified by the style.
metrics: LineMetrics
The actual metrics for this line.
Implementations§
source§impl Line
impl Line
fn new(writing_mode: WritingMode, minimum_metrics: &LineMetrics) -> Line
sourcefn new_metrics_for_fragment(
&self,
new_fragment: &Fragment,
layout_context: &LayoutContext<'_>,
) -> LineMetrics
fn new_metrics_for_fragment( &self, new_fragment: &Fragment, layout_context: &LayoutContext<'_>, ) -> LineMetrics
Returns the new metrics that this line would have if new_fragment
were added to it.
FIXME(pcwalton): this assumes that the tallest fragment in the line determines the line block-size. This might not be the case with some weird text fonts.
sourcefn new_block_size_for_fragment(
&self,
new_fragment: &Fragment,
new_line_metrics: &LineMetrics,
layout_context: &LayoutContext<'_>,
) -> Au
fn new_block_size_for_fragment( &self, new_fragment: &Fragment, new_line_metrics: &LineMetrics, layout_context: &LayoutContext<'_>, ) -> Au
Returns the new block size that this line would have if new_fragment
were added to it.
new_inline_metrics
represents the new inline metrics that this line would have; it can
be computed with new_inline_metrics()
.
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 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
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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