ColorFormat — Aspose.Slides FOSS Python API Reference
ColorFormat represents a color applied to a fill, line stroke, or text run in a
presentation. It supports four color modes: direct RGB, preset named color,
theme/scheme color, and system color.
Package: aspose.slides_foss
Typical access paths:
shape.fill_format.solid_fill_color— solid fill colorportion_format.fill_format.solid_fill_color— text colorgradient_stop.color— color at a gradient stop
ColorFormat Properties
| Property | Type | Access | Description |
|---|---|---|---|
color_type | ColorType | Read/Write | The active color mode (RGB, SCHEME, PRESET, SYSTEM, HSL, RGB_PERCENTAGE, NOT_DEFINED). |
color | Color | Read/Write | The resolved RGB color. Setting this value switches color_type to RGB and clears all transformations. |
preset_color | PresetColor | Read/Write | A named CSS/Office preset color (e.g. PresetColor.ROYAL_BLUE). Setting this switches color_type to PRESET. |
scheme_color | SchemeColor | Read/Write | A theme/scheme color token (e.g. SchemeColor.ACCENT1). Setting this switches color_type to SCHEME. |
r | int | Read/Write | Red component (0–255). Operates on the current RGB color. |
g | int | Read/Write | Green component (0–255). |
b | int | Read/Write | Blue component (0–255). |
float_r | float | Read/Write | Red component as a normalized float (0.0–1.0). |
float_g | float | Read/Write | Green component as a normalized float (0.0–1.0). |
float_b | float | Read/Write | Blue component as a normalized float (0.0–1.0). |
ColorType Enum
ColorType controls which color representation is active.
| Member | Description |
|---|---|
NOT_DEFINED | No color defined |
RGB | Standard 24-bit RGB hex color |
RGB_PERCENTAGE | High-definition RGB percentages |
HSL | Hue-Saturation-Lightness |
SCHEME | Theme / scheme color token |
SYSTEM | System color (e.g. window text) |
PRESET | Named CSS/Office preset color |
PresetColor Enum
Over 140 named colors drawn from the CSS named-color list. A representative selection:
| Member | Member | Member | Member |
|---|---|---|---|
NOT_DEFINED | ALICE_BLUE | AQUA | AZURE |
BLACK | BLUE | BROWN | CORAL |
CRIMSON | CYAN | DARK_BLUE | DARK_GREEN |
DEEP_PINK | FIREBRICK | GOLD | GRAY |
GREEN | HOT_PINK | INDIGO | LAVENDER |
LIME | MAGENTA | MAROON | NAVY |
OLIVE | ORANGE | ORCHID | PINK |
PURPLE | RED | ROYAL_BLUE | SALMON |
SILVER | SKY_BLUE | STEEL_BLUE | TEAL |
TOMATO | TURQUOISE | VIOLET | WHITE |
YELLOW | YELLOW_GREEN |
(All 141 members are defined in PresetColor.py.)
SchemeColor Enum
Theme tokens that resolve at render time to the presentation’s active color scheme.
| Member | Description |
|---|---|
NOT_DEFINED | No scheme color |
BACKGROUND1 | Theme background 1 (maps to OOXML bg1) |
TEXT1 | Theme text 1 (tx1) |
BACKGROUND2 | Theme background 2 (bg2) |
TEXT2 | Theme text 2 (tx2) |
ACCENT1 – ACCENT6 | Theme accent colors 1–6 |
HYPERLINK | Theme hyperlink color (hlink) |
FOLLOWED_HYPERLINK | Followed hyperlink color (folHlink) |
DARK1 / LIGHT1 | Alternative dark/light tokens |
DARK2 / LIGHT2 | Alternative dark/light tokens |
STYLE_COLOR | Style-level color token |
Code Examples
Set a Solid RGB Fill on a Shape
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType
from aspose.slides_foss.drawing import Color
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 150)
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.color = Color.from_argb(255, 0, 102, 204)
prs.save("rgb-fill.pptx", SaveFormat.PPTX)Use a Preset Color
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, PresetColor
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.ELLIPSE, 50, 50, 200, 200)
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.preset_color = PresetColor.TOMATO
prs.save("preset-color.pptx", SaveFormat.PPTX)Apply a Theme (Scheme) Color
import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, SchemeColor
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
slide = prs.slides[0]
shape = slide.shapes.add_auto_shape(ShapeType.RECTANGLE, 50, 50, 300, 100)
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.scheme_color = SchemeColor.ACCENT1
prs.save("scheme-color.pptx", SaveFormat.PPTX)Inspect the Color of a Shape Fill
import aspose.slides_foss as slides
from aspose.slides_foss import ColorType
with slides.Presentation("deck.pptx") as prs:
shape = prs.slides[0].shapes[0]
cf = shape.fill_format.solid_fill_color
print(f"Color type: {cf.color_type}")
if cf.color_type == ColorType.RGB:
c = cf.color
print(f"RGB: ({c.r}, {c.g}, {c.b}) alpha={c.a}")
elif cf.color_type == ColorType.SCHEME:
print(f"Scheme color: {cf.scheme_color}")
elif cf.color_type == ColorType.PRESET:
print(f"Preset color: {cf.preset_color}")