Skip to main content

DiagramEntry

Struct DiagramEntry 

Source
pub struct DiagramEntry {
    pub data_partname: PartName,
    pub layout_partname: PartName,
    pub quick_style_partname: PartName,
    pub colors_partname: PartName,
    pub data_xml: String,
    pub layout_xml: String,
    pub quick_style_xml: String,
    pub colors_xml: String,
    pub data_rid: String,
    pub layout_rid: String,
    pub quick_style_rid: String,
    pub colors_rid: String,
}
Expand description

SmartArt(diagram)条目:保存到 /ppt/diagrams/ 下的 4 个 part 元数据(TODO-037)。

对应 python-pptx 中 SlideShapes.add_shape(...) 隐式管理的 SmartArt parts。 在 OOXML 中,一个 SmartArt 图形由 4 个独立 part 组成:

part路径关系类型dgm:relIds 属性
data/ppt/diagrams/dataN.xml.../diagramDatar:dm
layout/ppt/diagrams/layoutN.xml.../diagramLayoutr:lo
quickStyle/ppt/diagrams/quickStylesN.xml.../diagramQuickStyler:qs
colors/ppt/diagrams/colorsN.xml.../diagramColorsr:cs

被 slide 的 <p:graphicFrame><a:graphicData uri="...diagram"><dgm:relIds .../> 引用。

§Round-trip 策略

当前实现采用完整 round-trip:读路径保留 4 个 part 的原始 XML 字符串, 写路径直接写入保留的 XML(不重新序列化)。这样保证:

  • 任何 SmartArt 模板/布局/颜色变体都能正确保留;
  • 不依赖完整的 diagram schema 实现(避免数千行代码)。

§与 ChartEntry / OleEntry 的差异

  • ChartEntry 持有强类型 Chart 模型,写出时调用 chart.to_xml()
  • OleEntry 持有二进制 blob;
  • DiagramEntry 持有 4 份 XML 字符串,直接写入 zip(不经过序列化)。

Fields§

§data_partname: PartName

data part 路径,例如 /ppt/diagrams/data1.xml

§layout_partname: PartName

layout part 路径,例如 /ppt/diagrams/layout1.xml

§quick_style_partname: PartName

quickStyle part 路径,例如 /ppt/diagrams/quickStyles1.xml

§colors_partname: PartName

colors part 路径,例如 /ppt/diagrams/colors1.xml

§data_xml: String

原始 data XML 字符串(<dgm:dataModel>...</dgm:dataModel>)。

§layout_xml: String

原始 layout XML 字符串(<dgm:layoutDef>...</dgm:layoutDef>)。

§quick_style_xml: String

原始 quickStyle XML 字符串(<dgm:styleData>...</dgm:styleData>)。

§colors_xml: String

原始 colors XML 字符串(<dgm:colorsDef>...</dgm:colorsDef>)。

§data_rid: String

在 slide xml 中引用 data part 的关系 id(形如 rIdDgmData1)。

对应 <dgm:relIds r:dm="rIdDgmData1"/>

§layout_rid: String

在 slide xml 中引用 layout part 的关系 id(形如 rIdDgmLayout1)。

对应 <dgm:relIds r:lo="rIdDgmLayout1"/>

§quick_style_rid: String

在 slide xml 中引用 quickStyle part 的关系 id(形如 rIdDgmQs1)。

对应 <dgm:relIds r:qs="rIdDgmQs1"/>

§colors_rid: String

在 slide xml 中引用 colors part 的关系 id(形如 rIdDgmColors1)。

对应 <dgm:relIds r:cs="rIdDgmColors1"/>

Implementations§

Source§

impl DiagramEntry

Source

pub fn data_model(&self) -> Result<DataModel>

按需解析 data part 为强类型 crate::oxml::diagram::DataModel(TODO-037)。

DiagramEntry 默认以 String blob 持有原始 XML,保证 byte-exact round-trip。 当调用方需要结构化访问 SmartArt 节点(如查询节点文本、遍历父子关系)时, 调用本方法触发按需解析。

§返回值
§示例
let data_model = entry.data_model().expect("parse data part");
for pt in &data_model.points {
    println!("node {}: {:?}", pt.model_id, pt.text);
}
Source

pub fn layout_def(&self) -> Result<LayoutDef>

按需解析 layout part 为强类型 crate::oxml::diagram::LayoutDef

返回元数据(uniqueId / title / desc / catLst)+ layoutNode 子树原始 XML。

Source

pub fn quick_style_def(&self) -> Result<QuickStyleDef>

按需解析 quickStyle part 为强类型 crate::oxml::diagram::QuickStyleDef

返回 styleLbl 列表(仅 name + 原始 XML)。

Source

pub fn colors_def(&self) -> Result<ColorsDef>

按需解析 colors part 为强类型 crate::oxml::diagram::ColorsDef

返回元数据 + styleClrLbl 列表(仅 name + 原始 XML)。

Source

pub fn set_data_model(&mut self, data_model: &DataModel)

把修改后的 crate::oxml::diagram::DataModel 写回 data_xml 字段(TODO-037 文本节点编辑)。

典型用法:调用方先通过 DiagramEntry::data_model 解析得到 DataModel, 修改节点文本(如 set_point_text),再调用本方法把修改写回 data_xml, 后续 Presentation::save 会把更新后的 data_xml 写入 zip。

§参数
  • data_model:修改后的 DataModel 实例。
§示例
let mut dm = entry.data_model().expect("parse");
dm.set_point_text(1, "新文本");
entry.set_data_model(&dm);
Source

pub fn set_point_text( &mut self, model_id: u32, new_text: impl Into<String>, ) -> Result<bool>

便捷方法:直接修改指定 model_id 节点的文本并写回 data_xml

内部流程:解析 data_xml → 修改节点文本 → 序列化回 data_xml。

§参数
  • model_id:目标节点 ID;
  • new_text:新的文本内容。
§返回值
  • Ok(true):找到节点并成功修改;
  • Ok(false):未找到指定 model_id 的节点;
  • Err:data_xml 解析失败(畸形 XML)。

Trait Implementations§

Source§

impl Clone for DiagramEntry

Source§

fn clone(&self) -> DiagramEntry

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 DiagramEntry

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