Skip to main content

TextState

Struct TextState 

Source
pub struct TextState {
    pub char_spacing: f64,
    pub word_spacing: f64,
    pub h_scaling: f64,
    pub leading: f64,
    pub font_name: String,
    pub font_size: f64,
    pub render_mode: TextRenderMode,
    pub rise: f64,
    /* private fields */
}
Expand description

Text state parameters tracked during content stream interpretation.

These parameters are set by text state operators (Tc, Tw, Tz, TL, Tf, Tr, Ts) and persist across text objects (BT/ET blocks). They are part of the graphics state and are saved/restored by q/Q.

Fields§

§char_spacing: f64

Character spacing (Tc operator). Extra space added after each character glyph.

§word_spacing: f64

Word spacing (Tw operator). Extra space added after each space character (code 32).

§h_scaling: f64

Horizontal scaling (Tz operator). Percentage value where 100 = normal. Stored as percentage (e.g., 100.0 for 100%).

§leading: f64

Text leading (TL operator). Distance between baselines of consecutive text lines.

§font_name: String

Current font name set by Tf operator.

§font_size: f64

Current font size set by Tf operator.

§render_mode: TextRenderMode

Text rendering mode (Tr operator).

§rise: f64

Text rise (Ts operator). Vertical offset for superscript/subscript.

Implementations§

Source§

impl TextState

Source

pub fn new() -> Self

Create a new TextState with default values per PDF spec.

Source

pub fn in_text_object(&self) -> bool

Whether we are currently inside a BT/ET text object.

Source

pub fn text_matrix(&self) -> &Ctm

Get the current text matrix.

Source

pub fn text_matrix_array(&self) -> [f64; 6]

Get the current text matrix as a 6-element array.

Source

pub fn line_matrix(&self) -> &Ctm

Get the current line matrix.

Source

pub fn h_scaling_normalized(&self) -> f64

Get the horizontal scaling as a fraction (1.0 = 100%).

Source

pub fn begin_text(&mut self)

BT operator: begin text object.

Resets the text matrix and line matrix to identity. Sets in_text_object to true.

Source

pub fn end_text(&mut self)

ET operator: end text object.

Sets in_text_object to false. Text matrix and line matrix become undefined (but we keep them for potential inspection).

Source

pub fn set_font(&mut self, font_name: String, font_size: f64)

Tf operator: set text font and size.

Source

pub fn set_char_spacing(&mut self, spacing: f64)

Tc operator: set character spacing.

Source

pub fn set_word_spacing(&mut self, spacing: f64)

Tw operator: set word spacing.

Source

pub fn set_h_scaling(&mut self, scale: f64)

Tz operator: set horizontal scaling (percentage).

Source

pub fn set_leading(&mut self, leading: f64)

TL operator: set text leading.

Source

pub fn set_render_mode(&mut self, mode: TextRenderMode)

Tr operator: set text rendering mode.

Source

pub fn set_rise(&mut self, rise: f64)

Ts operator: set text rise.

Source

pub fn set_text_matrix( &mut self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64, )

Tm operator: set the text matrix and line matrix directly.

Both text matrix and line matrix are set to the given matrix. This replaces (not concatenates) the current text matrix.

Source

pub fn move_text_position(&mut self, tx: f64, ty: f64)

Td operator: move to start of next line, offset from start of current line.

Translates the line matrix by (tx, ty) and sets the text matrix to the new line matrix value.

Source

pub fn move_text_position_and_set_leading(&mut self, tx: f64, ty: f64)

TD operator: move to start of next line and set leading.

Equivalent to: -ty TL then tx ty Td. Sets leading to -ty then moves text position by (tx, ty).

Source

pub fn move_to_next_line(&mut self)

T* operator: move to start of next line.

Equivalent to 0 -TL Td (using current leading value).

Source

pub fn advance_text_position(&mut self, tx: f64)

Advance the text matrix by a horizontal displacement.

Used after rendering a character glyph to move to the next glyph position. The displacement is in text space units, already accounting for font size and horizontal scaling.

Trait Implementations§

Source§

impl Clone for TextState

Source§

fn clone(&self) -> TextState

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TextState

Source§

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

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

impl Default for TextState

Source§

fn default() -> Self

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

impl PartialEq for TextState

Source§

fn eq(&self, other: &TextState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TextState

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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.