pub struct LayoutContext<B: Brush = [u8; 4]> { /* private fields */ }Expand description
Shared scratch space used when constructing text layouts.
This type is designed to be a global resource with only one per-application (or per-thread).
Implementations§
Source§impl<B: Brush> LayoutContext<B>
impl<B: Brush> LayoutContext<B>
pub fn new() -> Self
Sourcepub fn ranged_builder<'a>(
&'a mut self,
fcx: &'a mut FontContext,
text: &'a str,
scale: f32,
quantize: bool,
) -> RangedBuilder<'a, B>
pub fn ranged_builder<'a>( &'a mut self, fcx: &'a mut FontContext, text: &'a str, scale: f32, quantize: bool, ) -> RangedBuilder<'a, B>
Create a ranged style layout builder.
Set quantize as true to have the layout coordinates aligned to pixel boundaries.
That is the easiest way to avoid blurry text and to receive ready-to-paint layout metrics.
For advanced rendering use cases you can set quantize as false and receive
fractional coordinates. This ensures the most accurate results if you want to perform
some post-processing on the coordinates before painting. To avoid blurry text you will
still need to quantize the coordinates just before painting.
Your should round at least the following:
- Glyph run baseline
- Inline box baseline
box.y = (box.y + box.height).round() - box.height
- Selection geometry’s
y0&y1 - Cursor geometry’s
y0&y1
Keep in mind that for the simple f32::round to be effective,
you need to first ensure the coordinates are in physical pixel space.
Sourcepub fn style_run_builder<'a>(
&'a mut self,
fcx: &'a mut FontContext,
text: &'a str,
scale: f32,
quantize: bool,
) -> StyleRunBuilder<'a, B>
pub fn style_run_builder<'a>( &'a mut self, fcx: &'a mut FontContext, text: &'a str, scale: f32, quantize: bool, ) -> StyleRunBuilder<'a, B>
Create a builder for constructing a layout from indexed style runs.
Unlike Self::ranged_builder, this builder expects callers to provide:
- a style table of fully specified
TextStylevalues (viaStyleRunBuilder::push_style) - a complete sequence of contiguous, non-overlapping spans that cover
0..text.len()and reference style indices (viaStyleRunBuilder::push_style_run)
Parley then skips its internal range-splitting logic.
Sourcepub fn tree_builder<'a>(
&'a mut self,
fcx: &'a mut FontContext,
scale: f32,
quantize: bool,
root_style: &TextStyle<'_, '_, B>,
) -> TreeBuilder<'a, B>
pub fn tree_builder<'a>( &'a mut self, fcx: &'a mut FontContext, scale: f32, quantize: bool, root_style: &TextStyle<'_, '_, B>, ) -> TreeBuilder<'a, B>
Create a tree style layout builder.
Set quantize as true to have the layout coordinates aligned to pixel boundaries.
That is the easiest way to avoid blurry text and to receive ready-to-paint layout metrics.
For advanced rendering use cases you can set quantize as false and receive
fractional coordinates. This ensures the most accurate results if you want to perform
some post-processing on the coordinates before painting. To avoid blurry text you will
still need to quantize the coordinates just before painting.
Your should round at least the following:
- Glyph run baseline
- Inline box baseline
box.y = (box.y + box.height).round() - box.height
- Selection geometry’s
y0&y1 - Cursor geometry’s
y0&y1
Keep in mind that for the simple f32::round to be effective,
you need to first ensure the coordinates are in physical pixel space.