pub struct Text {
pub content: String,
pub style: TextStyle,
pub url: Option<String>,
pub anchor: Option<String>,
pub link_to: Option<String>,
pub outline_level: Option<u8>,
pub role: Option<ThemeRole>,
pub spans: Option<Box<Vec<Span>>>,
pub hyphenate: Option<HyphenationLanguage>,
pub common: Common,
}Fields§
§content: String§style: TextStyle§url: Option<String>§anchor: Option<String>Registers this element as an internal jump target other Text
elements can point at via .link_to(name) — analogous to an HTML
id. Independent of url/link_to: an element can be a target,
a source, both, or neither.
link_to: Option<String>Internal counterpart to url: jumps to whatever element in this
document called .anchor(name) with the same name, instead of an
external URI. If both url and link_to are set, url wins.
outline_level: Option<u8>Set by .heading1()/.heading2()/.heading3() (1/2/3), or
explicitly via .outline_level(n) for text that should appear in
the PDF bookmark sidebar without being an actual heading preset.
None (the default for plain Text) means “not a bookmark”.
role: Option<ThemeRole>Theme eligibility (Document::theme(..), ADR/issue #16): Some
means “resolve this element’s style from the theme’s matching role
the next time it’s added to a themed Document.” Text::new()
defaults this to Some(ThemeRole::Body); every style-mutating
method below (.size(), .bold(), .color(), …) clears it back
to None since the caller has taken over styling by hand. The
.heading1()/.heading2()/.heading3()/.caption()/.muted()/
.table_header() presets re-set a specific role afterwards.
spans: Option<Box<Vec<Span>>>Set only by Text::rich(..) (issue #11) — a sequence of
independently-styled runs instead of one style for the whole
content. When Some, layout/render use this instead of
content/style (content is still populated, as the spans’
text concatenated, so anything that only reads content — e.g. a
future plain-text export — degrades to unstyled text instead of
seeing nothing). Rich text doesn’t (yet) support
url/anchor/link_to/outline_level/Align::Justify — plain
Text remains the only way to get those.
Boxed, not Option<Vec<Span>> directly: Text is the payload of
Element’s largest variant (in turn embedded in LayoutResult
and every Row/Column’s children: Vec<Element>), and a bare
Vec here would cost every plain Text (the overwhelming
majority, where this field is always None) the full 24 bytes;
Option<Box<Vec<Span>>> costs 8.
hyphenate: Option<HyphenationLanguage>Set by .hyphenate(lang) (issue #13, Stage 2): before wrapping,
each word gets Knuth-Liang break points inserted as soft hyphens
(U+00AD) for lang, on top of Stage 1’s always-on soft-hyphen
support (an author-inserted U+00AD works with or without this).
None (the default) means “only break where the author put a
soft hyphen, if anywhere.” Only consulted for plain Text; a
Text::rich(..) ignores it, same as Align::Justify.
Requires the hyphenation cargo feature — with it disabled this
silently has no effect, since skipping automatic hyphenation only
changes where a line wraps, not what the text says.
common: CommonImplementations§
Source§impl Text
impl Text
pub fn new(content: impl Into<String>) -> Self
Sourcepub fn rich(spans: impl IntoIterator<Item = Span>) -> Self
pub fn rich(spans: impl IntoIterator<Item = Span>) -> Self
A Text made of independently-styled Spans instead of one
uniform style — the paragraph still wraps and paginates as a
single unit, word boundaries and line breaks span across spans
freely, and mixed sizes on the same line share one baseline (see
lightweight-pdf-layout::text::wrap_spans).
pub fn url(self, url: impl Into<String>) -> Self
pub fn anchor(self, name: impl Into<String>) -> Self
pub fn link_to(self, anchor: impl Into<String>) -> Self
pub fn outline_level(self, level: u8) -> Self
Sourcepub fn hyphenate(self, lang: HyphenationLanguage) -> Self
pub fn hyphenate(self, lang: HyphenationLanguage) -> Self
Opts this Text into automatic (Knuth-Liang) hyphenation for
lang — see the hyphenate field’s doc comment for scope and the
hyphenation cargo feature it requires.
Sourcepub fn role(self, role: ThemeRole) -> Self
pub fn role(self, role: ThemeRole) -> Self
Opts a Text into theme resolution under role without going
through one of the named presets — e.g. a custom role-like use
that isn’t .heading1()/.caption()/etc.
pub fn size(self, size: f32) -> Self
pub fn bold(self) -> Self
pub fn italic(self) -> Self
pub fn bold_italic(self) -> Self
pub fn font(self, font: FontKey) -> Self
pub fn color(self, color: Color) -> Self
Sourcepub fn align(self, align: Align) -> Self
pub fn align(self, align: Align) -> Self
Unlike the other style setters, .align() does not clear
role: alignment is a positioning choice independent of which
named style a Text resolves from (.heading1().align(Center)
should stay theme-eligible as a heading, just centered) — see
theme::apply_theme, which resolves every role field except
align and always leaves whatever .align() set alone.
pub fn line_height(self, line_height: f32) -> Self
Sourcepub fn heading1(self) -> Self
pub fn heading1(self) -> Self
Heading presets (Phase 6, plan/02-elementcatalog-and-features.md):
thin wrappers over .size()/.bold(), additionally setting
keep_with_next so a heading never ends up alone at the bottom of
a page without its following content
(plan/05-overflow-and-robustness.md Grundprinzip 9), and
outline_level so the PDF bookmark sidebar can be derived from the
heading hierarchy without a separate API (.outline_level(n)
overrides this for the rare case the derivation doesn’t fit).
pub fn heading2(self) -> Self
pub fn heading3(self) -> Self
Sourcepub fn caption(self) -> Self
pub fn caption(self) -> Self
Theme::caption preset — a smaller, muted-gray label (e.g. under
an image, or a secondary line under a heading).
Sourcepub fn muted(self) -> Self
pub fn muted(self) -> Self
Theme::muted preset — body-sized text in the same muted gray as
.caption(), for de-emphasized inline text rather than a label.
Sourcepub fn table_header(self) -> Self
pub fn table_header(self) -> Self
Theme::table_header preset. Table::header([...]) cells built
from plain strings pick this role up automatically (see
theme::apply_theme); use this directly for a Text header cell
built by hand, or for header-like text outside a Table.
pub fn width(self, width: f32) -> Self
pub fn height(self, height: f32) -> Self
pub fn flex(self, factor: f32) -> Self
pub fn padding(self, padding: f32) -> Self
pub fn corner_radius(self, radius: f32) -> Self
pub fn overflow(self, overflow: Overflow) -> Self
pub fn background(self, color: Color) -> Self
pub fn border(self, border: Border) -> Self
Sourcepub fn keep_with_next(self) -> Self
pub fn keep_with_next(self) -> Self
See plan/05-overflow-and-robustness.md Grundprinzip 9: only
placed on a page if the following sibling also still fits.