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
| Property | Type | Access | Description |
|---|---|---|---|
gradient_shape | GradientShape | Read/Write | Whether the gradient is LINEAR, RECTANGLE, RADIAL, or PATH. |
gradient_direction | GradientDirection | Read/Write | Direction of a linear gradient or radial origin (FROM_CORNER1–FROM_CORNER4, FROM_CENTER). |
linear_gradient_angle | float | Read/Write | Angle in degrees for a linear gradient (e.g. 90.0 = top-to-bottom). |
linear_gradient_scaled | NullableBool | Read/Write | Whether the linear gradient is scaled. |
tile_flip | TileFlip | Read/Write | Tile flip mode for the gradient: NO_FLIP, FLIP_X, FLIP_Y, FLIP_BOTH. |
gradient_stops | GradientStopCollection | Read | The ordered list of color stops. |
GradientStop
A single color-and-position stop in a gradient.
GradientStop Properties
| Property | Type | Access | Description |
|---|---|---|---|
position | float | Read/Write | Position along the gradient from 0.0 (start) to 1.0 (end). |
color | ColorFormat | Read | The ColorFormat for this stop. Set the color via stop.color.color = Color.from_argb(...). |
GradientStopCollection
Manages the GradientStop objects in a GradientFormat.
GradientStopCollection Methods
| Method | Signature | Description |
|---|---|---|
add | (position, color) -> GradientStop | Append a new stop. position is 0.0–1.0; color is a Color, PresetColor, or SchemeColor. |
insert | (index, position, color) -> None | Insert a stop at index. |
remove_at | (index) -> None | Remove the stop at zero-based index. |
clear | () -> None | Remove all stops. |
__getitem__ | [index: int] -> GradientStop | Return stop at index. |
__len__ | () -> int | Number of stops. |
__iter__ | N/A | Iterate over stops. |
GradientDirection Enum
| Member | Description |
|---|---|
NOT_DEFINED | Not defined |
FROM_CORNER1 | From top-left corner |
FROM_CORNER2 | From top-right corner |
FROM_CORNER3 | From bottom-left corner |
FROM_CORNER4 | From bottom-right corner |
FROM_CENTER | Radial from center |
GradientShape Enum
| Member | Description |
|---|---|
NOT_DEFINED | Not defined |
LINEAR | Straight-line gradient |
RECTANGLE | Rectangular path gradient |
RADIAL | Circular radial gradient |
PATH | Shape-path gradient |
PatternFormat
PatternFormat fills a shape with a repeating two-color hatch pattern.
PatternFormat Properties
| Property | Type | Access | Description |
|---|---|---|---|
pattern_style | PatternStyle | Read/Write | The hatch pattern (e.g. HORIZONTAL, DIAGONAL_CROSS, TRELLIS). |
fore_color | ColorFormat | Read | Foreground (hatch lines) color. Modify via .fore_color.color = .... |
back_color | ColorFormat | Read | Background color. Modify via .back_color.color = .... |
PatternStyle Enum (selected members)
| Member | Member | Member | Member |
|---|---|---|---|
NOT_DEFINED | UNKNOWN | PERCENT05 | PERCENT50 |
HORIZONTAL | VERTICAL | CROSS | DIAGONAL_CROSS |
DOWNWARD_DIAGONAL | UPWARD_DIAGONAL | DARK_HORIZONTAL | DARK_VERTICAL |
LIGHT_HORIZONTAL | LIGHT_VERTICAL | SMALL_GRID | LARGE_GRID |
SMALL_CHECKER_BOARD | LARGE_CHECKER_BOARD | TRELLIS | HORIZONTAL_BRICK |
DIAGONAL_BRICK | ZIGZAG | WAVE | SPHERE |
WEAVE | DIVOT | SHINGLE | DOTTED_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)