Skip to main content

Connector

Struct Connector 

Source
pub struct Connector { /* private fields */ }
Expand description

连接器(直线 / 折线 / 曲线)。

Implementations§

Source§

impl Connector

Source

pub fn from_cxn(c: OxmlCxn) -> Self

从 oxml OxmlCxn 构造包装。

Source

pub fn new(name: impl Into<String>) -> Self

新建一个连接器(默认名为 name,其余字段由调用方填充)。

Source

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_beginSelf::set_end 之后用 Self::recompute_xfrm 重算。

Source

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=.../> + prstGeomprst="line"(或 bent/curved)配合“反转坐标系“实现的。

简化策略:把 begin/end 转成 (offset, extent) 的 bounding box 写入 xfrm, 由 PowerPoint 端按 line 几何反算端点。这样位置信息不丢

Source

pub fn cxn(&self) -> &OxmlCxn

取出 oxml 引用。

Source

pub fn cxn_mut(&mut self) -> &mut OxmlCxn

取出 oxml 可变引用。

Source

pub fn properties(&self) -> &ShapeProperties

形状属性(spPr)不可变引用。

Source

pub fn properties_mut(&mut self) -> &mut ShapeProperties

形状属性(spPr)可变引用(python-pptx 风格,方便 LineFormat::from)。

Source

pub fn begin(&self) -> Option<EmuPoint>

起点坐标(EMU)。

Source

pub fn set_begin(&mut self, p: EmuPoint)

设置起点坐标。

副作用:会自动重算 xfrm 边界盒(除非你显式调用了 Self::set_no_xfrm_recompute 关闭)。这是为了与 OOXML 序列化要求一致—— p:cxnSp 的端点位置在 xfrm 的 off/ext 中体现。

Source

pub fn end(&self) -> Option<EmuPoint>

终点坐标(EMU)。

Source

pub fn set_end(&mut self, p: EmuPoint)

设置终点坐标。自动重算 xfrm。参见 Self::set_begin

Source

pub fn connector_type(&self) -> Option<MsoConnectorType>

连接器类型。

Source

pub fn set_connector_type(&mut self, t: MsoConnectorType)

设置连接器类型。

Source

pub fn begin_connection(&self) -> Option<(u32, u32)>

起点挂接。

Source

pub fn set_begin_connection(&mut self, shape_id: u32, idx: u32)

设置起点挂接。

Source

pub fn end_connection(&self) -> Option<(u32, u32)>

终点挂接。

Source

pub fn set_end_connection(&mut self, shape_id: u32, idx: u32)

设置终点挂接。

Trait Implementations§

Source§

impl Clone for Connector

Source§

fn clone(&self) -> Connector

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 Connector

Source§

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

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

impl Default for Connector

Source§

fn default() -> Connector

Returns the “default value” for a type. Read more
Source§

impl Shape for Connector

Source§

fn id(&self) -> u32

形状唯一 ID(在所属 slide 内)。 Read more
Source§

fn set_id(&mut self, id: u32)

设置 ID。
Source§

fn name(&self) -> &str

形状名。
Source§

fn set_name(&mut self, name: String)

设置形状名。
Source§

fn shape_type(&self) -> &'static str

形状类型(如 "text_box" / "picture" / …)。 Read more
Source§

fn left(&self) -> Emu

左上角 x(EMU)。
Source§

fn set_left(&mut self, emu: Emu)

设置左上角 x。
Source§

fn top(&self) -> Emu

左上角 y(EMU)。
Source§

fn set_top(&mut self, emu: Emu)

设置左上角 y。
Source§

fn width(&self) -> Emu

宽(EMU)。
Source§

fn set_width(&mut self, emu: Emu)

设置宽。
Source§

fn height(&self) -> Emu

高(EMU)。
Source§

fn set_height(&mut self, emu: Emu)

设置高。
Source§

fn rotation(&self) -> f64

旋转角度(度数,正向顺时针)。 Read more
Source§

fn set_rotation(&mut self, deg: f64)

设置旋转角度。

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