pub struct Connector { /* private fields */ }Expand description
连接器(直线 / 折线 / 曲线)。
Implementations§
Source§impl Connector
impl Connector
Sourcepub fn new_with_type(
name: impl Into<String>,
connector_type: MsoConnectorType,
) -> Self
pub fn new_with_type( name: impl Into<String>, connector_type: MsoConnectorType, ) -> Self
新建一个指定类型的连接器。
对应 python-pptx 中 Connector(connector_type, begin_x, begin_y, end_x, end_y)
的“类型“部分。几何由 connector_type 决定。
§修订历史
早期版本不会自动计算 xfrm(bounding box),导致 begin/end 在序列化时 被丢弃 / 位置跑到 (0, 0)。现已自动根据 begin/end 计算 xfrm:
- off_x = min(begin_x, end_x)
- off_y = min(begin_y, end_y)
- ext_cx = |end_x - begin_x|
- ext_cy = |end_y - begin_y|
§注意
若 begin/end 还未设置,xfrm 保持为 0/0/0/0;可在调用 Self::set_begin
与 Self::set_end 之后用 Self::recompute_xfrm 重算。
Sourcepub fn recompute_xfrm(&mut self)
pub fn recompute_xfrm(&mut self)
重新计算 xfrm 边界盒(基于 begin/end)。
若 begin/end 都没设置,xfrm 会被重置为 0/0/0/0。
§OOXML 语义
p:spPr/a:xfrm 表达“此连接器在 slide 上的占位矩形“;a:off 是
该矩形的左上角,a:ext 是宽高。p:cxnSp 本身没有 begin/end 元素,
端点是用 <a:xfrm> 内嵌 <a:off x=0 y=0/><a:ext cx=... cy=.../> +
prstGeom 的 prst="line"(或 bent/curved)配合“反转坐标系“实现的。
简化策略:把 begin/end 转成 (offset, extent) 的 bounding box 写入 xfrm, 由 PowerPoint 端按 line 几何反算端点。这样位置信息不丢。
Sourcepub fn properties(&self) -> &ShapeProperties
pub fn properties(&self) -> &ShapeProperties
形状属性(spPr)不可变引用。
Sourcepub fn properties_mut(&mut self) -> &mut ShapeProperties
pub fn properties_mut(&mut self) -> &mut ShapeProperties
形状属性(spPr)可变引用(python-pptx 风格,方便 LineFormat::from)。
Sourcepub fn set_begin(&mut self, p: EmuPoint)
pub fn set_begin(&mut self, p: EmuPoint)
设置起点坐标。
副作用:会自动重算 xfrm 边界盒(除非你显式调用了
Self::set_no_xfrm_recompute 关闭)。这是为了与 OOXML 序列化要求一致——
p:cxnSp 的端点位置在 xfrm 的 off/ext 中体现。
Sourcepub fn set_end(&mut self, p: EmuPoint)
pub fn set_end(&mut self, p: EmuPoint)
设置终点坐标。自动重算 xfrm。参见 Self::set_begin。
Sourcepub fn connector_type(&self) -> Option<MsoConnectorType>
pub fn connector_type(&self) -> Option<MsoConnectorType>
连接器类型。
Sourcepub fn set_connector_type(&mut self, t: MsoConnectorType)
pub fn set_connector_type(&mut self, t: MsoConnectorType)
设置连接器类型。
Sourcepub fn begin_connection(&self) -> Option<(u32, u32)>
pub fn begin_connection(&self) -> Option<(u32, u32)>
起点挂接。
Sourcepub fn set_begin_connection(&mut self, shape_id: u32, idx: u32)
pub fn set_begin_connection(&mut self, shape_id: u32, idx: u32)
设置起点挂接。
Sourcepub fn end_connection(&self) -> Option<(u32, u32)>
pub fn end_connection(&self) -> Option<(u32, u32)>
终点挂接。
Sourcepub fn set_end_connection(&mut self, shape_id: u32, idx: u32)
pub fn set_end_connection(&mut self, shape_id: u32, idx: u32)
设置终点挂接。