GradientFormat / PatternFormat

GradientFormat and PatternFormat — Aspose.Slides FOSS Python API Reference

When a shape’s fill_type is FillType.GRADIENT the fill is controlled by a GradientFormat object (accessed via shape.fill_format.gradient_fill_format). When fill_type is FillType.PATTERN the fill is controlled by a PatternFormat (accessed via shape.fill_format.pattern_fill_format).

Package: aspose.slides_foss


GradientFormat

GradientFormat defines how a gradient transitions between two or more colors across a shape.

GradientFormat Properties

PropertyTypeAccessDescription
gradient_shapeGradientShapeRead/WriteWhether the gradient is LINEAR, RECTANGLE, RADIAL, or PATH.
gradient_directionGradientDirectionRead/WriteDirection of a linear gradient or radial origin (FROM_CORNER1FROM_CORNER4, FROM_CENTER).
linear_gradient_anglefloatRead/WriteAngle in degrees for a linear gradient (e.g. 90.0 = top-to-bottom).
linear_gradient_scaledNullableBoolRead/WriteWhether the linear gradient is scaled.
tile_flipTileFlipRead/WriteTile flip mode for the gradient: NO_FLIP, FLIP_X, FLIP_Y, FLIP_BOTH.
gradient_stopsGradientStopCollectionReadThe ordered list of color stops.

GradientStop

A single color-and-position stop in a gradient.

GradientStop Properties

PropertyTypeAccessDescription
positionfloatRead/WritePosition along the gradient from 0.0 (start) to 1.0 (end).
colorColorFormatReadThe ColorFormat for this stop. Set the color via stop.color.color = Color.from_argb(...).

GradientStopCollection

Manages the GradientStop objects in a GradientFormat.

GradientStopCollection Methods

MethodSignatureDescription
add(position, color) -> GradientStopAppend a new stop. position is 0.01.0; color is a Color, PresetColor, or SchemeColor.
insert(index, position, color) -> NoneInsert a stop at index.
remove_at(index) -> NoneRemove the stop at zero-based index.
clear() -> NoneRemove all stops.
__getitem__[index: int] -> GradientStopReturn stop at index.
__len__() -> intNumber of stops.
__iter__N/AIterate over stops.

GradientDirection Enum

MemberDescription
NOT_DEFINEDNot defined
FROM_CORNER1From top-left corner
FROM_CORNER2From top-right corner
FROM_CORNER3From bottom-left corner
FROM_CORNER4From bottom-right corner
FROM_CENTERRadial from center

GradientShape Enum

MemberDescription
NOT_DEFINEDNot defined
LINEARStraight-line gradient
RECTANGLERectangular path gradient
RADIALCircular radial gradient
PATHShape-path gradient

PatternFormat

PatternFormat fills a shape with a repeating two-color hatch pattern.

PatternFormat Properties

PropertyTypeAccessDescription
pattern_stylePatternStyleRead/WriteThe hatch pattern (e.g. HORIZONTAL, DIAGONAL_CROSS, TRELLIS).
fore_colorColorFormatReadForeground (hatch lines) color. Modify via .fore_color.color = ....
back_colorColorFormatReadBackground color. Modify via .back_color.color = ....

PatternStyle Enum (selected members)

MemberMemberMemberMember
NOT_DEFINEDUNKNOWNPERCENT05PERCENT50
HORIZONTALVERTICALCROSSDIAGONAL_CROSS
DOWNWARD_DIAGONALUPWARD_DIAGONALDARK_HORIZONTALDARK_VERTICAL
LIGHT_HORIZONTALLIGHT_VERTICALSMALL_GRIDLARGE_GRID
SMALL_CHECKER_BOARDLARGE_CHECKER_BOARDTRELLISHORIZONTAL_BRICK
DIAGONAL_BRICKZIGZAGWAVESPHERE
WEAVEDIVOTSHINGLEDOTTED_GRID

(46 members total in PatternStyle.py.)


Code Examples

Apply a Two-Stop Linear Gradient

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, GradientShape, GradientDirection
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, 400, 200)

    ff = shape.fill_format
    ff.fill_type = FillType.GRADIENT
    gf = ff.gradient_fill_format
    gf.gradient_shape = GradientShape.LINEAR
    gf.linear_gradient_angle = 90.0   # top to bottom

    stops = gf.gradient_stops
    stops.clear()
    stops.add(0.0, Color.from_argb(255, 0, 80, 200))    # top: blue
    stops.add(1.0, Color.from_argb(255, 200, 230, 255)) # bottom: light blue

    prs.save("gradient.pptx", SaveFormat.PPTX)

Radial Gradient from Center

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, GradientShape, GradientDirection
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.ELLIPSE, 100, 100, 300, 300)

    ff = shape.fill_format
    ff.fill_type = FillType.GRADIENT
    gf = ff.gradient_fill_format
    gf.gradient_shape = GradientShape.RADIAL
    gf.gradient_direction = GradientDirection.FROM_CENTER

    stops = gf.gradient_stops
    stops.clear()
    stops.add(0.0, Color.from_argb(255, 255, 255, 200))  # center: pale yellow
    stops.add(1.0, Color.from_argb(255, 200, 80, 0))     # edge: orange

    prs.save("radial-gradient.pptx", SaveFormat.PPTX)

Apply a Pattern Fill

import aspose.slides_foss as slides
from aspose.slides_foss import ShapeType, FillType, PatternStyle
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)

    ff = shape.fill_format
    ff.fill_type = FillType.PATTERN
    pf = ff.pattern_fill_format
    pf.pattern_style = PatternStyle.DIAGONAL_BRICK
    pf.fore_color.color = Color.from_argb(255, 80, 80, 80)
    pf.back_color.color = Color.from_argb(255, 240, 240, 240)

    prs.save("pattern-fill.pptx", SaveFormat.PPTX)

See Also