Skip to main content

ColorFormat

Struct ColorFormat 

Source
pub struct ColorFormat<'a> { /* private fields */ }
Expand description

颜色高阶视图(pptx.dml.color.ColorFormat)。

Color 区别:

  • Color 是“OOXML 模型层“表达,只关心值
  • ColorFormat 是“高阶 API 层“包装,关心“颜色如何被使用“—— 例如字体前景色、字体背景高亮、形状填充、形状边框等,引用同一个 Color 时通过 &mut Color 共享。

§与 python-pptx 的对应

  • pptx.dml.color.ColorFormat ←→ ColorFormat
  • font.color.rgb = RGBColor(...) ←→ color_format.set_rgb(...)

§设计要点

  • 借用 + 透明代理:构造时传入 &mut Color所有写操作直接修改 原值;这与 python-pptx 的 font.color.rgb = X 行为一致—— font.color 是个 proxy,实际写回的是底层 a:srgbClr 元素。
  • 零分配:除读取时的临时 String 外不触发堆分配。
  • 类型安全:所有 setter 接受 Color / RGBColor / SchemeColor / PresetColor 任一;From<impl Into<Color>> 自动转换。

Implementations§

Source§

impl<'a> ColorFormat<'a>

Source

pub fn new(color: &'a mut Color) -> ColorFormat<'a>

构造一个颜色格式视图。

§参数
Source

pub fn with_role(color: &'a mut Color, role: ColorRole) -> ColorFormat<'a>

构造时指定角色。

Source

pub fn role(&self) -> ColorRole

角色(python-pptx ColorFormat.type 的简化版)。

Source

pub fn color_type(&self) -> MsoColorType

当前颜色的“类型“(python-pptx color.type)。

Source

pub fn is_set(&self) -> bool

是否已设置颜色(不等于 Color::None)。

Source

pub fn color(&self) -> Color

取内部颜色克隆。

Source

pub fn rgb(&self) -> Option<RGBColor>

若当前是 RGB,取出 sRGB;否则返回 None

Source

pub fn theme_color(&self) -> Option<MsoThemeColorIndex>

若当前是 theme color,取出 scheme 枚举;否则 None

Source

pub fn brightness(&self) -> f32

亮度调整(python-pptx 风格)。

返回当前颜色按 lumMod / lumOff 调整后的“近似“亮度。 注意:本方法只计算并返回 f32 (0.0..=1.0),修改底层 Color。如需在 XML 中表达亮度调整,请在 Color 上加修饰子元素 (路线图 0.2.0)。

Source

pub fn set(&mut self, c: impl Into<Color>)

直接覆盖为任意 Color。对应 color = some_color

Source

pub fn set_rgb(&mut self, c: impl Into<RGBColor>)

设为 sRGB 颜色(对应 python-pptx color.rgb = RGBColor(r, g, b))。

Source

pub fn set_preset(&mut self, p: PresetColor)

设为预设颜色。

Source

pub fn set_theme(&mut self, t: MsoThemeColorIndex)

设为 schemeClr 主题色。

Source

pub fn clear(&mut self)

重置为未设置。

Trait Implementations§

Source§

impl<'a> Debug for ColorFormat<'a>

Source§

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

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

impl<'a> From<&'a mut Color> for ColorFormat<'a>

Source§

fn from(c: &'a mut Color) -> ColorFormat<'a>

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ColorFormat<'a>

§

impl<'a> Freeze for ColorFormat<'a>

§

impl<'a> RefUnwindSafe for ColorFormat<'a>

§

impl<'a> Send for ColorFormat<'a>

§

impl<'a> Sync for ColorFormat<'a>

§

impl<'a> Unpin for ColorFormat<'a>

§

impl<'a> UnsafeUnpin for ColorFormat<'a>

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