Skip to main content

TextRun

Struct TextRun 

Source
pub struct TextRun {
Show 14 fields pub index: ObjectIndex, pub font: Arc<Font>, pub font_size: f32, pub font_size_h: f32, pub char_space: f32, pub word_space: f32, pub items: Vec<Item>, pub kernings: Vec<f32>, pub position: Point, pub text_matrix: Affine, pub rect: Rect, pub advance: f64, pub marks: ContentMarks, pub type3: BTreeMap<u32, Type3Metrics>,
}
Expand description

A text object with everything the heuristics ask of it.

Built once per object per page and then read many times, because almost every decision in the pipeline needs at least the first and last item.

Fields§

§index: ObjectIndex

Where this object sits in the page’s flattened walk.

§font: Arc<Font>

The font, shared with every other object using the same resource — duplicate suppression compares fonts by this pointer’s identity.

§font_size: f32

The font size. May be negative, and is never rescued.

§font_size_h: f32

|hypot(a, b)| * font_size of the composed matrix: “the horizontal scale of the font in device units”, which every space threshold is measured in.

§char_space: f32

Tc, the character spacing.

§word_space: f32

Tw, the word spacing.

§items: Vec<Item>

One entry per glyph, in content order.

§kernings: Vec<f32>

The adjustment following each glyph, in thousandths of a text-space unit. Same length as items; the last is always zero.

§position: Point

The object’s position in page space.

§text_matrix: Affine

The composed text matrix: the object’s linear transform with its position as the translation.

§rect: Rect

The object’s bounding box in page space, stroke-inflated when the render mode strokes.

§advance: f64

Total advance width in page space: w0 summed over the object’s glyphs (ISO 32000-1 §9.4.3), measured through the same text matrix the bounding box goes through, so the two are comparable against one epsilon.

§9.2.2 keeps the glyph bounding box and the §9.4.3 displacement distinct, and only the displacement says whether the pen moved. A space, and any glyph whose outline is empty, has an empty box and a non-zero w0; a zero-width space has both empty.

§marks: ContentMarks

The marks enclosing the object.

§type3: BTreeMap<u32, Type3Metrics>

What each shown character’s Type 3 glyph procedure declared, empty for every other kind of font. A Type 3 glyph’s box and advance live inside a content stream, so they arrive from the page layer rather than from the font.

Implementations§

Source§

impl TextRun

Source

pub fn count(&self) -> usize

How many glyphs the object shows.

Source

pub fn item(&self, index: usize) -> Option<Item>

One glyph, or None past the end.

Source

pub fn kerning(&self, index: usize) -> f32

The adjustment following a glyph; zero past the end.

Source

pub fn scaled_char_width(&self, code: CharCode) -> f32

The advance width of one character code, already scaled by font_size / 1000.

A vertical CID font reports its (negative) vertical advance instead.

Source

pub fn glyph_width(&self, code: CharCode) -> f32

The advance width of one character code in glyph units.

A Type 3 font whose /Widths said nothing defers to what the glyph procedure’s d0/d1 declared, which is the only place the number exists.

Source

pub fn glyph_bbox(&self, code: CharCode) -> Rect

The bounding box of one character code in glyph units, y-up.

Trait Implementations§

Source§

impl Clone for TextRun

Source§

fn clone(&self) -> TextRun

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 TextRun

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, !>

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.