pub struct TextSpans { /* private fields */ }Expand description
An encoded list of spans, ready to travel.
Shared rather than copied, for the same reason a draw list is: the same list redrawn every frame compares equal and produces no mutation at all.
Implementations§
Source§impl TextSpans
impl TextSpans
pub fn new(spans: impl IntoIterator<Item = TextSpan>) -> Self
Sourcepub fn new_with_fonts(
spans: impl IntoIterator<Item = (TextSpan, FontRefs)>,
) -> Self
pub fn new_with_fonts( spans: impl IntoIterator<Item = (TextSpan, FontRefs)>, ) -> Self
Runs, each with the fonts it is set in where the text has no role.
An empty list leaves that run in the text’s own font. A run of text that has a role is always in the theme’s font, whatever it names here.
Sourcepub fn new_with_features(
spans: impl IntoIterator<Item = (TextSpan, impl AsRef<[FontFeature]>)>,
) -> Self
pub fn new_with_features( spans: impl IntoIterator<Item = (TextSpan, impl AsRef<[FontFeature]>)>, ) -> Self
Runs, each with the OpenType features it is set with, such as
FontFeature::TABULAR_NUMS on the one run that is a number.
An empty list leaves that run with the features of the text it is in. A run that
names features takes the text’s as well, and where both name a tag the run’s value
is the one used. Unlike a font, features are taken by a run with a role and by a
run of text that has one: they pick a form of the font and leave the font alone.
At most MAX_FONT_FEATURES (16) are taken for one run; a longer list is still
sent, so the Renderer can say what is wrong with it.
Sourcepub fn from_bytes(bytes: impl Into<Rc<[u8]>>) -> Self
pub fn from_bytes(bytes: impl Into<Rc<[u8]>>) -> Self
Adopts an already encoded list, which is what the protocol vectors carry.
Sourcepub fn with_font_table(self, table: impl Into<Rc<[u8]>>) -> Self
pub fn with_font_table(self, table: impl Into<Rc<[u8]>>) -> Self
The same runs with an already encoded font table beside them.
Sourcepub fn with_feature_table(self, table: impl Into<Rc<[u8]>>) -> Self
pub fn with_feature_table(self, table: impl Into<Rc<[u8]>>) -> Self
The same runs with an already encoded font feature table beside them, as
encode_feature_table lays one out. An empty table is no table.
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn font_table(&self) -> &[u8] ⓘ
pub fn font_table(&self) -> &[u8] ⓘ
The SpanFonts blob: a count, then one entry per run that names fonts, then the
font lists themselves. Every offset in it counts from the start of the blob.
Sourcepub fn feature_table(&self) -> &[u8] ⓘ
pub fn feature_table(&self) -> &[u8] ⓘ
The SpanFontFeatures blob: a count, then one entry per run that names features,
then the feature records themselves. Every offset in it counts from the start of
the blob. Empty where no run names a feature, and then nothing is sent.
pub fn is_empty(&self) -> bool
Sourcepub fn font_entry_count(&self) -> usize
pub fn font_entry_count(&self) -> usize
How many runs name fonts.
Sourcepub fn span_fonts(&self) -> Vec<(u32, Vec<FontRef>)>
pub fn span_fonts(&self) -> Vec<(u32, Vec<FontRef>)>
The fonts each run that names any is set in, by the run’s index.
Sourcepub fn feature_entry_count(&self) -> usize
pub fn feature_entry_count(&self) -> usize
How many runs name font features, as the table’s own count says.
Sourcepub fn span_features(&self) -> Vec<(u32, Vec<FontFeature>)>
pub fn span_features(&self) -> Vec<(u32, Vec<FontFeature>)>
The font features each run that names any is set with, by the run’s index, in the order the table lists them.
Empty where there is no table and where the table cannot be read by the rules the
Renderer holds it to: an entry or a feature list that runs past the end, an offset
that is not a multiple of four, more than MAX_FONT_FEATURES features for one run,
or a run named twice. The Renderer reports such a table and draws the text without
any of it, so nothing is read out of half of one here either.
Sourcepub fn spans(&self) -> impl Iterator<Item = TextSpan> + '_
pub fn spans(&self) -> impl Iterator<Item = TextSpan> + '_
The runs this list holds, decoded again.
Sourcepub fn from_markdown(source: &str) -> (String, Self)
pub fn from_markdown(source: &str) -> (String, Self)
Turns a small, closed subset of markdown into a plain string and its spans.
**bold**, *italic* and `code`, and nothing else. It is a convenience, not
a parser: anything it does not recognise is left in the string exactly as written,
because silently eating a character a reader typed is worse than showing it.
Links are not here. A link needs a handler, and a handler is something the screen has rather than something a string can name.