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: f64Character spacing (Tc operator). Extra space added after each character glyph.
word_spacing: f64Word spacing (Tw operator). Extra space added after each space character (code 32).
h_scaling: f64Horizontal scaling (Tz operator). Percentage value where 100 = normal. Stored as percentage (e.g., 100.0 for 100%).
leading: f64Text leading (TL operator). Distance between baselines of consecutive text lines.
font_name: StringCurrent font name set by Tf operator.
font_size: f64Current font size set by Tf operator.
render_mode: TextRenderModeText rendering mode (Tr operator).
rise: f64Text rise (Ts operator). Vertical offset for superscript/subscript.
Implementations§
Source§impl TextState
impl TextState
Sourcepub fn in_text_object(&self) -> bool
pub fn in_text_object(&self) -> bool
Whether we are currently inside a BT/ET text object.
Sourcepub fn text_matrix(&self) -> &Ctm
pub fn text_matrix(&self) -> &Ctm
Get the current text matrix.
Sourcepub fn text_matrix_array(&self) -> [f64; 6]
pub fn text_matrix_array(&self) -> [f64; 6]
Get the current text matrix as a 6-element array.
Sourcepub fn line_matrix(&self) -> &Ctm
pub fn line_matrix(&self) -> &Ctm
Get the current line matrix.
Sourcepub fn h_scaling_normalized(&self) -> f64
pub fn h_scaling_normalized(&self) -> f64
Get the horizontal scaling as a fraction (1.0 = 100%).
Sourcepub fn begin_text(&mut self)
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.
Sourcepub fn end_text(&mut self)
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).
Sourcepub fn set_font(&mut self, font_name: String, font_size: f64)
pub fn set_font(&mut self, font_name: String, font_size: f64)
Tf operator: set text font and size.
Sourcepub fn set_char_spacing(&mut self, spacing: f64)
pub fn set_char_spacing(&mut self, spacing: f64)
Tc operator: set character spacing.
Sourcepub fn set_word_spacing(&mut self, spacing: f64)
pub fn set_word_spacing(&mut self, spacing: f64)
Tw operator: set word spacing.
Sourcepub fn set_h_scaling(&mut self, scale: f64)
pub fn set_h_scaling(&mut self, scale: f64)
Tz operator: set horizontal scaling (percentage).
Sourcepub fn set_leading(&mut self, leading: f64)
pub fn set_leading(&mut self, leading: f64)
TL operator: set text leading.
Sourcepub fn set_render_mode(&mut self, mode: TextRenderMode)
pub fn set_render_mode(&mut self, mode: TextRenderMode)
Tr operator: set text rendering mode.
Sourcepub fn set_text_matrix(
&mut self,
a: f64,
b: f64,
c: f64,
d: f64,
e: f64,
f: f64,
)
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.
Sourcepub fn move_text_position(&mut self, tx: f64, ty: f64)
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.
Sourcepub fn move_text_position_and_set_leading(&mut self, tx: f64, ty: f64)
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).
Sourcepub fn move_to_next_line(&mut self)
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).
Sourcepub fn advance_text_position(&mut self, tx: f64)
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.