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 color
  • portion_format.fill_format.solid_fill_color — text color
  • gradient_stop.color — color at a gradient stop

ColorFormat Properties

PropertyTypeAccessDescription
color_typeColorTypeRead/WriteThe active color mode (RGB, SCHEME, PRESET, SYSTEM, HSL, RGB_PERCENTAGE, NOT_DEFINED).
colorColorRead/WriteThe resolved RGB color. Setting this value switches color_type to RGB and clears all transformations.
preset_colorPresetColorRead/WriteA named CSS/Office preset color (e.g. PresetColor.ROYAL_BLUE). Setting this switches color_type to PRESET.
scheme_colorSchemeColorRead/WriteA theme/scheme color token (e.g. SchemeColor.ACCENT1). Setting this switches color_type to SCHEME.
rintRead/WriteRed component (0–255). Operates on the current RGB color.
gintRead/WriteGreen component (0–255).
bintRead/WriteBlue component (0–255).
float_rfloatRead/WriteRed component as a normalized float (0.0–1.0).
float_gfloatRead/WriteGreen component as a normalized float (0.0–1.0).
float_bfloatRead/WriteBlue component as a normalized float (0.0–1.0).

ColorType Enum

ColorType controls which color representation is active.

MemberDescription
NOT_DEFINEDNo color defined
RGBStandard 24-bit RGB hex color
RGB_PERCENTAGEHigh-definition RGB percentages
HSLHue-Saturation-Lightness
SCHEMETheme / scheme color token
SYSTEMSystem color (e.g. window text)
PRESETNamed CSS/Office preset color

PresetColor Enum

Over 140 named colors drawn from the CSS named-color list. A representative selection:

MemberMemberMemberMember
NOT_DEFINEDALICE_BLUEAQUAAZURE
BLACKBLUEBROWNCORAL
CRIMSONCYANDARK_BLUEDARK_GREEN
DEEP_PINKFIREBRICKGOLDGRAY
GREENHOT_PINKINDIGOLAVENDER
LIMEMAGENTAMAROONNAVY
OLIVEORANGEORCHIDPINK
PURPLEREDROYAL_BLUESALMON
SILVERSKY_BLUESTEEL_BLUETEAL
TOMATOTURQUOISEVIOLETWHITE
YELLOWYELLOW_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.

MemberDescription
NOT_DEFINEDNo scheme color
BACKGROUND1Theme background 1 (maps to OOXML bg1)
TEXT1Theme text 1 (tx1)
BACKGROUND2Theme background 2 (bg2)
TEXT2Theme text 2 (tx2)
ACCENT1ACCENT6Theme accent colors 1–6
HYPERLINKTheme hyperlink color (hlink)
FOLLOWED_HYPERLINKFollowed hyperlink color (folHlink)
DARK1 / LIGHT1Alternative dark/light tokens
DARK2 / LIGHT2Alternative dark/light tokens
STYLE_COLORStyle-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}")

See Also