pub struct TextFrame<'a> { /* private fields */ }Expand description
文本框高阶视图(pptx.text.textframe.TextFrame)。
§与 python-pptx 的对应
shape.text_frame←→text_frame_mut().as_text_frame()(薄包装);text_frame.text←→TextFrame::text_getter/TextFrame::set_text;text_frame.paragraphs[0]←→TextFrame::paragraphs;text_frame.add_paragraph()←→TextFrame::add_paragraph;text_frame.word_wrap←→TextFrame::word_wrap/TextFrame::set_word_wrap;text_frame.auto_size←→TextFrame::auto_size/TextFrame::set_auto_size;text_frame.vertical_anchor←→TextFrame::vertical_anchor/TextFrame::set_vertical_anchor;text_frame.margin_left/...←→TextFrame::margin_left/ … /TextFrame::set_margins。
§设计要点
- 借用:构造时传入
&mut TextBody; - 零分配:所有方法均不触发堆分配;
- 互斥语义:
TextFrame::add_paragraph不会自动 trim,已有段落不会被移除。
Implementations§
Source§impl<'a> TextFrame<'a>
impl<'a> TextFrame<'a>
Sourcepub fn paragraphs(&self) -> Iter<'_, Paragraph>
pub fn paragraphs(&self) -> Iter<'_, Paragraph>
不可变段落迭代器。
Sourcepub fn paragraphs_mut(&mut self) -> IterMut<'_, Paragraph>
pub fn paragraphs_mut(&mut self) -> IterMut<'_, Paragraph>
可变段落迭代器。
Sourcepub fn paragraph_mut(&mut self, idx: usize) -> Option<&mut Paragraph>
pub fn paragraph_mut(&mut self, idx: usize) -> Option<&mut Paragraph>
按下标取可变段落。
Sourcepub fn first_paragraph(&self) -> Option<&Paragraph>
pub fn first_paragraph(&self) -> Option<&Paragraph>
首个段落。
Sourcepub fn first_paragraph_mut(&mut self) -> Option<&mut Paragraph>
pub fn first_paragraph_mut(&mut self) -> Option<&mut Paragraph>
首个段落的可变引用。
Sourcepub fn add_paragraph(&mut self) -> &mut Paragraph
pub fn add_paragraph(&mut self) -> &mut Paragraph
新增空段落(python-pptx text_frame.add_paragraph())。
Sourcepub fn add_paragraph_with_text(&mut self, text: &str) -> &mut Paragraph
pub fn add_paragraph_with_text(&mut self, text: &str) -> &mut Paragraph
新增带文本段落(按 \n 切分为多段),返回最后一段的可变引用。
Sourcepub fn remove_paragraph(&mut self, idx: usize) -> Option<Paragraph>
pub fn remove_paragraph(&mut self, idx: usize) -> Option<Paragraph>
按下标移除段落。
Sourcepub fn text_getter(&self) -> String
pub fn text_getter(&self) -> String
整体取文本(段间 \n,与 python-pptx text_frame.text 一致)。
Sourcepub fn auto_size(&self) -> MsoAutoSize
pub fn auto_size(&self) -> MsoAutoSize
自动调整策略。
Sourcepub fn set_auto_size(&mut self, v: MsoAutoSize)
pub fn set_auto_size(&mut self, v: MsoAutoSize)
设置自动调整策略。
Sourcepub fn vertical_anchor(&self) -> Option<MsoAnchor>
pub fn vertical_anchor(&self) -> Option<MsoAnchor>
垂直对齐。
Sourcepub fn set_vertical_anchor(&mut self, v: MsoAnchor)
pub fn set_vertical_anchor(&mut self, v: MsoAnchor)
设置垂直对齐。
Sourcepub fn set_word_wrap(&mut self, v: bool)
pub fn set_word_wrap(&mut self, v: bool)
设置是否自动换行。
Sourcepub fn margin_left(&self) -> Option<Emu>
pub fn margin_left(&self) -> Option<Emu>
左边距。
Sourcepub fn margin_right(&self) -> Option<Emu>
pub fn margin_right(&self) -> Option<Emu>
右边距。
Sourcepub fn margin_top(&self) -> Option<Emu>
pub fn margin_top(&self) -> Option<Emu>
上边距。
Sourcepub fn margin_bottom(&self) -> Option<Emu>
pub fn margin_bottom(&self) -> Option<Emu>
下边距。
Sourcepub fn set_margin_left(&mut self, emu: Emu)
pub fn set_margin_left(&mut self, emu: Emu)
设置单边边距(left)。
Sourcepub fn set_margin_right(&mut self, emu: Emu)
pub fn set_margin_right(&mut self, emu: Emu)
设置单边边距(right)。
Sourcepub fn set_margin_top(&mut self, emu: Emu)
pub fn set_margin_top(&mut self, emu: Emu)
设置单边边距(top)。
Sourcepub fn set_margin_bottom(&mut self, emu: Emu)
pub fn set_margin_bottom(&mut self, emu: Emu)
设置单边边距(bottom)。
Sourcepub fn set_num_cols(&mut self, count: u32)
pub fn set_num_cols(&mut self, count: u32)
设置文本列数(numCol 属性)。
Sourcepub fn col_spacing(&self) -> Option<Emu>
pub fn col_spacing(&self) -> Option<Emu>
列间距(spcCol 属性,EMU)。
Sourcepub fn set_col_spacing(&mut self, emu: Emu)
pub fn set_col_spacing(&mut self, emu: Emu)
设置列间距(spcCol 属性,EMU)。
Sourcepub fn set_columns(&mut self, count: u32, spacing: Option<Emu>)
pub fn set_columns(&mut self, count: u32, spacing: Option<Emu>)
一次性设置多列布局(列数 + 可选列间距)。
对标 python-pptx 中 text_frame 的多列设置。
当 spacing 为 None 时仅设置列数,保留已有列间距。
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more