pub struct Typesetter { /* private fields */ }Expand description
Estado compartido del motor de texto. Una instancia por proceso es lo
recomendado: FontContext cachea la base de fuentes y LayoutContext
reutiliza allocaciones entre layouts.
Implementations§
Source§impl Typesetter
impl Typesetter
pub fn new() -> Self
Sourcepub fn font_context_mut(&mut self) -> &mut FontContext
pub fn font_context_mut(&mut self) -> &mut FontContext
Acceso al FontContext por si se necesita registrar fuentes extra
o cambiar la stack de fallback. Invalida el caché de shaping: tocar
el set de fuentes o el fallback puede cambiar el resultado de cualquier
layout, así que descartamos lo cacheado (operación rara, de setup).
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Estadísticas del caché de shaping (hits/misses acumulados + entradas vivas). Para benchmark/evidencia; no afecta el render.
Sourcepub fn layout(
&mut self,
text: &str,
size_px: f32,
max_width: Option<f32>,
alignment: Alignment,
line_height: f32,
italic: bool,
font_family: Option<&str>,
weight: f32,
underline: bool,
strikethrough: bool,
letter_spacing: f32,
word_spacing: f32,
) -> Layout<()>
pub fn layout( &mut self, text: &str, size_px: f32, max_width: Option<f32>, alignment: Alignment, line_height: f32, italic: bool, font_family: Option<&str>, weight: f32, underline: bool, strikethrough: bool, letter_spacing: f32, word_spacing: f32, ) -> Layout<()>
Construye y resuelve un parley::Layout. Aplica font_size,
line_height (multiplicador del font_size), max_width (line
break), alignment y weight (peso de fuente CSS: 400 normal,
700 bold). italic=true selecciona la variante italic/oblique de
la fuente activa (vía parley::FontStyle). underline/strikethrough
activan la decoración global del bloque — parley deja la metadata
(offset + grosor) en cada Run y el pintado (draw_layout_*) emite
el rect correspondiente sobre la línea base.
API pública 12-arg (sin overflow-wrap): la usan showreels, canvas,
hit-testing de selección, etc. Delega en Self::layout_inner con
overflow_wrap = false (la palabra larga desborda, comportamiento
histórico). El quiebre dentro de palabra entra sólo por layout_clamped
(camino del compositor), para no propagar el flag a todos los callers.
Sourcepub fn layout_clamped(
&mut self,
text: &str,
size_px: f32,
max_width: Option<f32>,
alignment: Alignment,
line_height: f32,
italic: bool,
font_family: Option<&str>,
weight: f32,
max_lines: Option<usize>,
ellipsis: bool,
underline: bool,
strikethrough: bool,
letter_spacing: f32,
word_spacing: f32,
overflow_wrap: bool,
) -> Layout<()>
pub fn layout_clamped( &mut self, text: &str, size_px: f32, max_width: Option<f32>, alignment: Alignment, line_height: f32, italic: bool, font_family: Option<&str>, weight: f32, max_lines: Option<usize>, ellipsis: bool, underline: bool, strikethrough: bool, letter_spacing: f32, word_spacing: f32, overflow_wrap: bool, ) -> Layout<()>
Como Self::layout pero clampado a max_lines líneas (CSS
-webkit-line-clamp / Flutter maxLines). Si el texto envuelto cabe en
max_lines o menos, devuelve el layout completo. Si excede:
ellipsis = true→ la última línea visible termina en…(se recortan graphemes del final hasta que el bloque vuelve a caber enmax_lines).ellipsis = false→ se corta sin glifo (queda el prefijo que cupo).
max_lines = None o Some(0) ⇒ sin límite (idéntico a layout). El
clamp sólo recorta cuando hay envoltura, así que requiere un max_width
definido para tener efecto (un label en una caja dimensionada — el caso
típico). Reusa layout internamente: 0 costo extra cuando no trunca.
Sourcepub fn layout_runs(
&mut self,
text: &str,
size_px: f32,
default_color: Color,
runs: &[(usize, usize, Color)],
alignment: Alignment,
line_height: f32,
weight: f32,
underline: bool,
strikethrough: bool,
) -> Layout<RunBrush>
pub fn layout_runs( &mut self, text: &str, size_px: f32, default_color: Color, runs: &[(usize, usize, Color)], alignment: Alignment, line_height: f32, weight: f32, underline: bool, strikethrough: bool, ) -> Layout<RunBrush>
Construye un layout multicolor en una sola pasada de shaping:
default_color cubre todo el texto y cada (start_byte, end_byte, color) lo sobreescribe en su rango (offsets en bytes, no chars —
la convención de parley). Pensado para syntax highlighting: shapear
la línea entera una vez con un color por token, en vez de un layout
por token. Sin wrap (max_width = None); el caller posiciona la línea.
Sourcepub fn layout_spans(
&mut self,
text: &str,
size_px: f32,
default_color: Color,
weight: f32,
line_height: f32,
italic: bool,
font_family: Option<&str>,
underline: bool,
strikethrough: bool,
spans: &[TextSpan],
max_width: Option<f32>,
alignment: Alignment,
) -> Layout<RunBrush>
pub fn layout_spans( &mut self, text: &str, size_px: f32, default_color: Color, weight: f32, line_height: f32, italic: bool, font_family: Option<&str>, underline: bool, strikethrough: bool, spans: &[TextSpan], max_width: Option<f32>, alignment: Alignment, ) -> Layout<RunBrush>
Construye un layout RichText: defaults a nivel bloque + un
arreglo de TextSpan que sobreescriben tamaño/peso/italic/familia/
color/decoración por rango de bytes. A diferencia de
Self::layout_runs (sólo color, sin wrap), este camino:
- permite
max_width(envuelve a párrafo); - aplica los siete
StylePropertypor rango; - usa el mismo
runs_cx(RunBrush), así puede convivir con el pintado multicolor.
Sin caché en v1 (a diferencia de layout/layout_clamped): el
RichText típico cambia frame-a-frame (cursor de editor, hover de
link), y la clave de caché de un span-set arbitrario es pesada.
Reusa todo el shaping interno de parley, que ya es rápido para
párrafos de la magnitud de una UI.