Skip to main content

Text

Struct Text 

Source
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: Common

Implementations§

Source§

impl Text

Source

pub fn new(content: impl Into<String>) -> Self

Source

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).

Source

pub fn url(self, url: impl Into<String>) -> Self

Source

pub fn anchor(self, name: impl Into<String>) -> Self

Source

pub fn outline_level(self, level: u8) -> Self

Source

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.

Source

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.

Source

pub fn size(self, size: f32) -> Self

Source

pub fn bold(self) -> Self

Source

pub fn italic(self) -> Self

Source

pub fn bold_italic(self) -> Self

Source

pub fn font(self, font: FontKey) -> Self

Source

pub fn color(self, color: Color) -> Self

Source

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.

Source

pub fn line_height(self, line_height: f32) -> Self

Source

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).

Source

pub fn heading2(self) -> Self

Source

pub fn heading3(self) -> Self

Source

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).

Source

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.

Source

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.

Source

pub fn width(self, width: f32) -> Self

Source

pub fn height(self, height: f32) -> Self

Source

pub fn flex(self, factor: f32) -> Self

Source

pub fn padding(self, padding: f32) -> Self

Source

pub fn corner_radius(self, radius: f32) -> Self

Source

pub fn overflow(self, overflow: Overflow) -> Self

Source

pub fn background(self, color: Color) -> Self

Source

pub fn border(self, border: Border) -> Self

Source

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.

Trait Implementations§

Source§

impl Clone for Text

Source§

fn clone(&self) -> Text

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Text

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Text

Source§

fn default() -> Text

Returns the “default value” for a type. Read more
Source§

impl From<&str> for Text

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Text

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Text> for Element

Source§

fn from(value: Text) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnsafeUnpin for Text

§

impl UnwindSafe for Text

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.