Skip to main content

TextFrame

Struct TextFrame 

Source
pub struct TextFrame<'a> { /* private fields */ }
Expand description

文本框高阶视图(pptx.text.textframe.TextFrame)。

§与 python-pptx 的对应

§设计要点

  • 借用:构造时传入 &mut TextBody
  • 零分配:所有方法均不触发堆分配;
  • 互斥语义TextFrame::add_paragraph 不会自动 trim,已有段落不会被移除。

Implementations§

Source§

impl<'a> TextFrame<'a>

Source

pub fn new(body: &'a mut TextBody) -> Self

构造。

Source

pub fn body(&self) -> &TextBody

底层 body 不可变引用。

Source

pub fn body_mut(&mut self) -> &mut TextBody

底层 body 可变引用。

Source

pub fn len(&self) -> usize

段落数。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn paragraphs(&self) -> Iter<'_, Paragraph>

不可变段落迭代器。

Source

pub fn paragraphs_mut(&mut self) -> IterMut<'_, Paragraph>

可变段落迭代器。

Source

pub fn paragraph(&self, idx: usize) -> Option<&Paragraph>

按下标取不可变段落。

Source

pub fn paragraph_mut(&mut self, idx: usize) -> Option<&mut Paragraph>

按下标取可变段落。

Source

pub fn first_paragraph(&self) -> Option<&Paragraph>

首个段落。

Source

pub fn first_paragraph_mut(&mut self) -> Option<&mut Paragraph>

首个段落的可变引用。

Source

pub fn add_paragraph(&mut self) -> &mut Paragraph

新增空段落(python-pptx text_frame.add_paragraph())。

Source

pub fn add_paragraph_with_text(&mut self, text: &str) -> &mut Paragraph

新增带文本段落(按 \n 切分为多段),返回最后一段的可变引用。

Source

pub fn remove_paragraph(&mut self, idx: usize) -> Option<Paragraph>

按下标移除段落。

Source

pub fn clear(&mut self)

清空段落(保留一个空段,对应 python-pptx text_frame.clear())。

Source

pub fn text_getter(&self) -> String

整体取文本(段间 \n,与 python-pptx text_frame.text 一致)。

Source

pub fn set_text(&mut self, text: &str)

整体替换文本(按 \n 切分;旧段落属性会被丢弃)。

Source

pub fn auto_size(&self) -> MsoAutoSize

自动调整策略。

Source

pub fn set_auto_size(&mut self, v: MsoAutoSize)

设置自动调整策略。

Source

pub fn vertical_anchor(&self) -> Option<MsoAnchor>

垂直对齐。

Source

pub fn set_vertical_anchor(&mut self, v: MsoAnchor)

设置垂直对齐。

Source

pub fn word_wrap(&self) -> Option<bool>

是否自动换行(None = 走默认)。

Source

pub fn set_word_wrap(&mut self, v: bool)

设置是否自动换行。

Source

pub fn margin_left(&self) -> Option<Emu>

左边距。

Source

pub fn margin_right(&self) -> Option<Emu>

右边距。

Source

pub fn margin_top(&self) -> Option<Emu>

上边距。

Source

pub fn margin_bottom(&self) -> Option<Emu>

下边距。

Source

pub fn set_margins(&mut self, l: Emu, t: Emu, r: Emu, b: Emu)

一次性设置四向边距。

Source

pub fn set_margin_left(&mut self, emu: Emu)

设置单边边距(left)。

Source

pub fn set_margin_right(&mut self, emu: Emu)

设置单边边距(right)。

Source

pub fn set_margin_top(&mut self, emu: Emu)

设置单边边距(top)。

Source

pub fn set_margin_bottom(&mut self, emu: Emu)

设置单边边距(bottom)。

Source

pub fn num_cols(&self) -> Option<u32>

文本列数(numCol 属性)。

None 表示未设置(默认单列);Some(1) 等同于单列。

Source

pub fn set_num_cols(&mut self, count: u32)

设置文本列数(numCol 属性)。

Source

pub fn col_spacing(&self) -> Option<Emu>

列间距(spcCol 属性,EMU)。

Source

pub fn set_col_spacing(&mut self, emu: Emu)

设置列间距(spcCol 属性,EMU)。

Source

pub fn set_columns(&mut self, count: u32, spacing: Option<Emu>)

一次性设置多列布局(列数 + 可选列间距)。

对标 python-pptx 中 text_frame 的多列设置。 当 spacingNone 时仅设置列数,保留已有列间距。

Trait Implementations§

Source§

impl<'a> Debug for TextFrame<'a>

Source§

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

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

impl<'a> From<&'a mut TextBody> for TextFrame<'a>

Source§

fn from(b: &'a mut TextBody) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for TextFrame<'a>

§

impl<'a> Freeze for TextFrame<'a>

§

impl<'a> RefUnwindSafe for TextFrame<'a>

§

impl<'a> Send for TextFrame<'a>

§

impl<'a> Sync for TextFrame<'a>

§

impl<'a> Unpin for TextFrame<'a>

§

impl<'a> UnsafeUnpin for TextFrame<'a>

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