Skip to main content

FillFormat

Struct FillFormat 

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

填充高阶视图(pptx.dml.fill.FillFormat)。

§与 python-pptx 的对应

  • pptx.dml.fill.FillFormat ←→ FillFormat
  • shape.fill.solid() + shape.fill.fore_color.rgb = ... ←→ fill_format.solid().set_rgb(...)

§设计要点

  • 借用 + 透明代理:构造时传入 &mut Fill;所有写都走底层;
  • 零分配:颜色写入走 ColorFormat 的借用;
  • 类型安全:通过 super::simpletypes::MsoFillType 表达“当前填充类型“。

Implementations§

Source§

impl<'a> FillFormat<'a>

Source

pub fn new(fill: &'a mut Fill) -> FillFormat<'a>

构造一个 fill 视图。

Source

pub fn fill(&self) -> &Fill

底层 fill 不可变引用。

Source

pub fn fill_mut(&mut self) -> &mut Fill

底层 fill 可变引用。

Source

pub fn fill_type(&self) -> MsoFillType

当前填充类型(python-pptx fill.type)。

Source

pub fn solid(&mut self) -> ColorFormat<'_>

切到实色模式并返回 ColorFormat 代理。

对应 python-pptx 中 fill.solid() 后再 fill.fore_color.rgb = ...。 调用本方法会把 Fill 切到 Solid(Color::None),后续 set_rgb / set_theme 等会原地更新 Color

Source

pub fn set_none(&mut self)

切到无填充

对应 python-pptx 中 fill.background()。但通常我们用 FillFormat::clear 更直白。

Source

pub fn set_picture(&mut self, rid: impl Into<String>, mode: BlipFillMode)

切到图片填充。

§参数
  • rid:图片关系 id(形如 rIdImg1)。
  • mode:填充模式(拉伸/平铺/无)。使用 BlipFillMode::Stretch 为默认拉伸。
Source

pub fn clear(&mut self)

重置(继承主题默认)。

Source

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

便捷:直接设成 sRGB 实色。

Source

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

便捷:直接设成主题色实色。

Source

pub fn gradient(&mut self) -> &mut GradientFill

切到渐变模式并返回 &mut GradientFill 供进一步配置。

对应 python-pptx 中 fill.gradient()。调用本方法会把 Fill 切到 Gradient(GradientFill { stops: vec![], gradient_type: Linear(0), .. }), 调用方随后通过返回的引用添加光轨、设置角度等。

§示例
use ooxml_core::oxml::sppr::{Fill, GradientStop, GradientType};
use ooxml_core::units::RGBColor;
use ooxml_core::oxml::color::Color;

let mut fill = Fill::Inherit;
let mut fmt = FillFormat::new(&mut fill);
let g = fmt.gradient();
g.stops.push(GradientStop { pos: 0, color: Color::RGB(RGBColor::new(0xFF, 0x00, 0x00)) });
g.stops.push(GradientStop { pos: 100000, color: Color::RGB(RGBColor::new(0x00, 0x00, 0xFF)) });
g.gradient_type = GradientType::Linear(2_700_000); // 向下
Source

pub fn set_gradient_linear(&mut self, stops: Vec<GradientStop>, angle: i32)

便捷:直接设成线性渐变

§参数
  • stops:光轨列表(至少 2 个)。
  • angle:角度(1/60000 度,0 = 向右,5400000 = 向下)。
Source

pub fn set_gradient_path( &mut self, stops: Vec<GradientStop>, path: GradientPath, )

便捷:直接设成路径渐变

§参数
  • stops:光轨列表。
  • path:路径形状(Circle / Rect / Shape)。
Source

pub fn pattern(&mut self) -> &mut PatternFill

切到图案模式并返回 &mut PatternFill 供进一步配置。

调用本方法会把 Fill 切到 Pattern(PatternFill::default()), 调用方随后通过返回的引用设置 prst / fg_color / bg_color。

Source

pub fn set_pattern(&mut self, prst: impl Into<String>, fg: Color, bg: Color)

便捷:直接设成图案填充。

§参数
  • prst:预置图案类型(如 "pct5" / "horz" / "vert" / "cross")。
  • fg:前景色。
  • bg:背景色。

Trait Implementations§

Source§

impl<'a> Debug for FillFormat<'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 Fill> for FillFormat<'a>

Source§

fn from(f: &'a mut Fill) -> FillFormat<'a>

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

impl<'a> Freeze for FillFormat<'a>

§

impl<'a> RefUnwindSafe for FillFormat<'a>

§

impl<'a> Send for FillFormat<'a>

§

impl<'a> Sync for FillFormat<'a>

§

impl<'a> Unpin for FillFormat<'a>

§

impl<'a> UnsafeUnpin for FillFormat<'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