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
impl Paragraph
Sourcepub fn add_run_with_text(&mut self, text: impl Into<String>) -> &mut Run
pub fn add_run_with_text(&mut self, text: impl Into<String>) -> &mut Run
新增一个带文本的 Run,返回其可变引用。
对应 python-pptx 中 paragraph.add_run(text)。
Sourcepub fn add_line_break(&mut self) -> &mut Run
pub fn add_line_break(&mut self) -> &mut Run
追加一个换行符 Run(<a:br/>)。
python-pptx 中由 paragraph.add_run().text = "\n" 触发;在
本库中换行被建模为独立 Run——这样既保留属性语义又简化序列化。
Sourcepub fn clear_runs(&mut self)
pub fn clear_runs(&mut self)
清空段落中的全部 Run(保留段落属性)。
对应 python-pptx 中对 _Paragraph 重新赋值的常见用法。
Sourcepub fn add_field(
&mut self,
field_type: FieldType,
text: impl Into<String>,
) -> &mut Field
pub fn add_field( &mut self, field_type: FieldType, text: impl Into<String>, ) -> &mut Field
新增一个字段(<a:fld>),返回其可变引用。
对标 python-pptx 中通过 paragraph.add_field() 添加幻灯片编号/日期等动态字段。
§参数
field_type:字段类型(如FieldType::SlideNumber);text:占位文本(如"1")。
Sourcepub fn clear_fields(&mut self)
pub fn clear_fields(&mut self)
清空段落中的全部字段。
Sourcepub fn set_text(&mut self, text: impl Into<String>) -> &mut Run
pub fn set_text(&mut self, text: impl Into<String>) -> &mut Run
替换为单段单 Run 的纯文本(保留段落属性)。
与 TextBox::set_text 不同,不按 \n 切分多段;
适合“修改 Run 文本“场景。
Sourcepub fn set_alignment(&mut self, v: Alignment)
pub fn set_alignment(&mut self, v: Alignment)
设置水平对齐。
Sourcepub fn line_spacing(&self) -> Option<Pt>
pub fn line_spacing(&self) -> Option<Pt>
行距(点数,固定值)。与 set_line_spacing_pct 互斥。
Sourcepub fn set_line_spacing(&mut self, v: Pt)
pub fn set_line_spacing(&mut self, v: Pt)
设置行距为固定点数(1 pt = 12700 EMU)。
Sourcepub fn line_spacing_pct(&self) -> Option<f32>
pub fn line_spacing_pct(&self) -> Option<f32>
行距(百分比,1.0 = 100%)。与 set_line_spacing 互斥。
Sourcepub fn set_line_spacing_pct(&mut self, v: f32)
pub fn set_line_spacing_pct(&mut self, v: f32)
设置行距为倍数(1.0 = 100% = 1000,1.5 = 150% = 1500)。
Sourcepub fn space_before(&self) -> Option<Emu>
pub fn space_before(&self) -> Option<Emu>
段前间距(EMU)。
Sourcepub fn set_space_before(&mut self, emu: Emu)
pub fn set_space_before(&mut self, emu: Emu)
设置段前间距。
Sourcepub fn space_after(&self) -> Option<Emu>
pub fn space_after(&self) -> Option<Emu>
段后间距(EMU)。
Sourcepub fn set_space_after(&mut self, emu: Emu)
pub fn set_space_after(&mut self, emu: Emu)
设置段后间距。
Sourcepub fn set_indent(
&mut self,
left: Option<Emu>,
right: Option<Emu>,
first_line: Option<Emu>,
hanging: Option<i32>,
)
pub fn set_indent( &mut self, left: Option<Emu>, right: Option<Emu>, first_line: Option<Emu>, hanging: Option<i32>, )
设置缩进(一次性给 4 个字段)。
Sourcepub fn end_para_rpr(&self) -> Option<&RunProperties>
pub fn end_para_rpr(&self) -> Option<&RunProperties>
取段落末尾属性(<a:endParaRPr>)的不可变引用。
endParaRPr 用于指定段落末尾(最后一个 Run 之后)的默认 Run 属性。
PowerPoint 在用户把光标移到段落末尾时,会用此属性渲染后续输入的文本。
对应 OOXML 元素 <a:endParaRPr>,结构与 <a:rPr> 完全一致。
Sourcepub fn end_para_rpr_mut(&mut self) -> Option<&mut RunProperties>
pub fn end_para_rpr_mut(&mut self) -> Option<&mut RunProperties>
取段落末尾属性的可变引用。
Sourcepub fn set_end_para_rpr(&mut self, rpr: RunProperties)
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());Sourcepub fn clear_end_para_rpr(&mut self)
pub fn clear_end_para_rpr(&mut self)
清除段落末尾属性(删除 <a:endParaRPr>)。