Skip to main content

Paragraph

Struct Paragraph 

Source
pub struct Paragraph {
    pub properties: ParagraphProperties,
    pub runs: Vec<Run>,
    pub fields: Vec<Field>,
    pub end_properties: Option<RunProperties>,
}
Expand description

段落中的“结束段落“Run(</a:p> 之前可附带 a:endParaRPr)。

Fields§

§properties: ParagraphProperties

段落属性。

§runs: Vec<Run>

段落中的 Run 序列(按出现顺序)。

§fields: Vec<Field>

段落中的字段序列(<a:fld>)。

字段在 Run 之后序列化。OOXML 允许 <a:r><a:fld> 交错出现, 但本实现简化为 runs 先于 fields 输出。

§end_properties: Option<RunProperties>

段落末尾的属性(a:endParaRPr)。

Implementations§

Source§

impl Paragraph

Source

pub fn new() -> Paragraph

新建一个空段落。

Source

pub fn write_xml(&self, w: &mut XmlWriter)

写 XML。

Source

pub fn add_run(&mut self) -> &mut Run

新增一个空 Run,返回其可变引用。

对应 python-pptx 中 paragraph.add_run()

Source

pub fn add_run_with_text(&mut self, text: impl Into<String>) -> &mut Run

新增一个带文本的 Run,返回其可变引用。

对应 python-pptx 中 paragraph.add_run(text)

Source

pub fn add_line_break(&mut self) -> &mut Run

追加一个换行符 Run<a:br/>)。

python-pptx 中由 paragraph.add_run().text = "\n" 触发;在 本库中换行被建模为独立 Run——这样既保留属性语义又简化序列化。

Source

pub fn clear_runs(&mut self)

清空段落中的全部 Run(保留段落属性)。

对应 python-pptx 中对 _Paragraph 重新赋值的常见用法。

Source

pub fn add_field( &mut self, field_type: FieldType, text: impl Into<String>, ) -> &mut Field

新增一个字段(<a:fld>),返回其可变引用。

对标 python-pptx 中通过 paragraph.add_field() 添加幻灯片编号/日期等动态字段。

§参数
Source

pub fn clear_fields(&mut self)

清空段落中的全部字段。

Source

pub fn set_text(&mut self, text: impl Into<String>) -> &mut Run

替换为单段单 Run 的纯文本(保留段落属性)。

TextBox::set_text 不同,\n 切分多段; 适合“修改 Run 文本“场景。

Source

pub fn text(&self) -> String

取段落全部 Run 文本拼接(不含 \n)。

Source

pub fn alignment(&self) -> Option<Alignment>

水平对齐(便捷访问)。

Source

pub fn set_alignment(&mut self, v: Alignment)

设置水平对齐。

Source

pub fn level(&self) -> u8

段落级别(0-8)。

Source

pub fn set_level(&mut self, lvl: u8)

设置段落级别。

Source

pub fn line_spacing(&self) -> Option<Pt>

行距(点数,固定值)。与 set_line_spacing_pct 互斥。

Source

pub fn set_line_spacing(&mut self, v: Pt)

设置行距为固定点数(1 pt = 12700 EMU)。

Source

pub fn line_spacing_pct(&self) -> Option<f32>

行距(百分比,1.0 = 100%)。与 set_line_spacing 互斥。

Source

pub fn set_line_spacing_pct(&mut self, v: f32)

设置行距为倍数(1.0 = 100% = 1000,1.5 = 150% = 1500)。

Source

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

段前间距(EMU)。

Source

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

设置段前间距。

Source

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

段后间距(EMU)。

Source

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

设置段后间距。

Source

pub fn indent(&self) -> Indent

缩进便捷访问。

Source

pub fn set_indent( &mut self, left: Option<Emu>, right: Option<Emu>, first_line: Option<Emu>, hanging: Option<i32>, )

设置缩进(一次性给 4 个字段)。

Source

pub fn end_para_rpr(&self) -> Option<&RunProperties>

取段落末尾属性(<a:endParaRPr>)的不可变引用。

endParaRPr 用于指定段落末尾(最后一个 Run 之后)的默认 Run 属性。 PowerPoint 在用户把光标移到段落末尾时,会用此属性渲染后续输入的文本。

对应 OOXML 元素 <a:endParaRPr>,结构与 <a:rPr> 完全一致。

Source

pub fn end_para_rpr_mut(&mut self) -> Option<&mut RunProperties>

取段落末尾属性的可变引用。

Source

pub fn set_end_para_rpr(&mut self, rpr: RunProperties)

设置段落末尾属性(<a:endParaRPr>)。

若段落已有 endParaRPr,会被覆盖。

§示例
let mut p = Paragraph::new();
let mut rpr = RunProperties::default();
rpr.size = Some(Pt(24.0));
rpr.latin_font = Some("Calibri".to_string());
p.set_end_para_rpr(rpr);
assert!(p.end_para_rpr().is_some());
Source

pub fn clear_end_para_rpr(&mut self)

清除段落末尾属性(删除 <a:endParaRPr>)。

Trait Implementations§

Source§

impl Clone for Paragraph

Source§

fn clone(&self) -> Paragraph

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 Paragraph

Source§

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

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

impl Default for Paragraph

Source§

fn default() -> Paragraph

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V