Skip to main content

TextObject

Struct TextObject 

Source
pub struct TextObject {
    pub x: f64,
    pub y: f64,
    pub font: String,
    pub size: f64,
    pub weight: u32,
    pub italic: bool,
    pub color: u32,
    pub text: String,
    pub width: Option<f64>,
    pub height: Option<f64>,
}
Expand description

带位置、字体和内容的文本对象。

Fields§

§x: f64

距左边缘的 X 位置(mm)。

§y: f64

距顶部的 Y 位置(mm)。

§font: String

字体族名称(如 “SimSun”、“SimHei”)。

§size: f64

字号(pt)。

§weight: u32

字重: 400 = 正常, 700 = 粗体。

§italic: bool

是否斜体。

§color: u32

文本颜色(RGB 十六进制,如 0x000000 为黑色)。

§text: String

实际文本内容。

§width: Option<f64>

可选的文本宽度覆盖(mm)。 如果为 None,写入器将根据字符数估算。

§height: Option<f64>

可选的文本高度覆盖(mm)。 如果为 None,写入器将使用字号。

Implementations§

Source§

impl TextObject

Source

pub fn new(x: f64, y: f64, text: impl Into<String>) -> Self

使用默认样式创建新的文本对象。

Source

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

设置字体族。

Source

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

设置字号(pt)。

Source

pub fn bold(self) -> Self

设置粗体。

Source

pub fn italic(self) -> Self

设置斜体。

Source

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

设置文本颜色(RGB 十六进制)。

Trait Implementations§

Source§

impl Clone for TextObject

Source§

fn clone(&self) -> TextObject

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 TextObject

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.