Форматирование фигур PowerPoint в Python
Введение
Форматируйте формы в PowerPoint, изменяя их контуры, заливки и эффекты. Aspose.Slides for Python via .NET позволяет управлять этими настройками программно, включая прозрачность, вращение и 3D‑форматирование.

Aspose.Slides for Python via .NET предоставляет классы и свойства, которые позволяют форматировать формы, используя те же параметры, что доступны в PowerPoint.
Форматирование линий
Use Shape.line_format to control a shape’s outline. This example creates an unfilled rectangle with a blue, dashed outline. LineFormat.style selects a thick‑thin compound line, while LineFormat.width sets its width to 7 points and LineFormat.dash_style selects the dash pattern.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
shape.fill_format.fill_type = slides.FillType.NO_FILL
shape.line_format.style = slides.LineStyle.THICK_THIN
shape.line_format.width = 7
shape.line_format.dash_style = slides.LineDashStyle.DASH
shape.line_format.fill_format.fill_type = slides.FillType.SOLID
shape.line_format.fill_format.solid_fill_color.color = draw.Color.blue
presentation.save("formatted_lines.pptx", slides.export.SaveFormat.PPTX)
Результат:

Настройка пользовательских шаблонов пунктирных линий
Use LineFormat.custom_dash_pattern when predefined line styles do not provide the dash lengths and gaps you need, for example for branded outlines or technical diagrams. Assigning a pattern automatically sets LineFormat.dash_style to LineDashStyle.CUSTOM.
List entries alternate between dash and gap lengths, starting with a dash. Each value is a multiple of the line width: [4, 2] at a width of 3 points produces a 12‑point dash followed by a 6‑point gap. Use pairs of finite, nonnegative values to define complete dash‑and‑gap segments. The example uses positive values to keep every dash and gap visible.
This example creates five blue lines with the same length and flat caps. The first three compare patterns at a width of 3 points. The fourth repeats the first pattern at twice the width, doubling both the dash and gap lengths. The fifth switches from a custom pattern to a solid line.
import aspose.slides as slides
with slides.Presentation() as presentation:
presentation.slide_size.set_size(600, 300, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
patterns = [
[4, 2],
[1, 2],
[6, 2, 1, 2],
[4, 2],
[4, 2]
]
for i, pattern in enumerate(patterns):
line = slide.shapes.add_auto_shape(slides.ShapeType.LINE, 50, 50 + i * 50, 500, 0)
line.line_format.width = 6 if i == 3 else 3
line.line_format.fill_format.fill_type = slides.FillType.SOLID
line.line_format.fill_format.solid_fill_color.preset_color = slides.PresetColor.DARK_BLUE
line.line_format.cap_style = slides.LineCapStyle.FLAT
line.line_format.begin_arrowhead_style = slides.LineArrowheadStyle.NONE
line.line_format.end_arrowhead_style = slides.LineArrowheadStyle.NONE
line.line_format.custom_dash_pattern = pattern
# Вернуть последнюю линию к сплошному стилю.
slide.shapes[4].line_format.dash_style = slides.LineDashStyle.SOLID
presentation.save("custom_dash_patterns.pptx", slides.export.SaveFormat.PPTX)
To return to a predefined dashed style instead, assign LineDashStyle.DASH to LineFormat.dash_style. The selected style controls the line’s appearance.
Результат в PowerPoint сверху вниз: {4, 2}, 3 pt; {1, 2}, 3 pt; {6, 2, 1, 2}, 3 pt; {4, 2}, 6 pt; and Solid, 3 pt.

Установка концов линии
Use LineFormat.cap_style to set the ends of an open line. The LineCapStyle enumeration provides three explicit cap styles:
FLAT: Обводка останавливается на конечной точке.ROUND: Полукруглая кромка выходит за конечную точку на половину толщины линии.SQUARE: Квадратная кромка выходит за конечную точку на половину толщины линии.
The enumeration also includes NOT_DEFINED, which means that no cap style is explicitly assigned.
Caps are different from arrowheads, which add symbols to line ends, and joins, which control corners between line segments. This example disables arrowheads through LineFormat.begin_arrowhead_style and LineFormat.end_arrowhead_style so that only the cap shapes are compared.
The following example creates three otherwise identical horizontal lines, 20 points wide. From top to bottom, they use flat, round, and square caps. Their endpoints have the same horizontal coordinates; the round and square caps extend 10 points beyond each endpoint.
import aspose.slides as slides
with slides.Presentation() as presentation:
presentation.slide_size.set_size(500, 240, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
cap_styles = [slides.LineCapStyle.FLAT, slides.LineCapStyle.ROUND, slides.LineCapStyle.SQUARE]
for i, cap_style in enumerate(cap_styles):
line = slide.shapes.add_auto_shape(slides.ShapeType.LINE, 100, 50 + i * 70, 300, 0)
line.line_format.width = 20
line.line_format.fill_format.fill_type = slides.FillType.SOLID
line.line_format.fill_format.solid_fill_color.preset_color = slides.PresetColor.DARK_BLUE
line.line_format.dash_style = slides.LineDashStyle.SOLID
line.line_format.cap_style = cap_style
line.line_format.begin_arrowhead_style = slides.LineArrowheadStyle.NONE
line.line_format.end_arrowhead_style = slides.LineArrowheadStyle.NONE
presentation.save("line_caps.pptx", slides.export.SaveFormat.PPTX)
Результат в PowerPoint сверху вниз: Flat, Round и Square.

Применение эффектов наброска к линиям фигур
A sketch effect makes a shape line look hand‑drawn. Use Shape.line_format to access the line settings, LineFormat.sketch_format to access the sketch settings, and SketchFormat.sketch_type to select a value from the LineSketchType enumeration.
The following Python code shows how to apply a LineSketchType.CURVED effect, read the explicitly assigned value, and remove the effect with LineSketchType.NONE:
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 200, 100)
sketch_format = shape.line_format.sketch_format
sketch_format.sketch_type = slides.LineSketchType.CURVED
explicit_sketch_type = sketch_format.sketch_type
print(f"Explicit sketch type: {explicit_sketch_type}")
sketch_format.sketch_type = slides.LineSketchType.NONE
The value returned by SketchFormat.sketch_type represents the setting assigned directly to the shape. If the line formatting can be inherited from a theme, master slide, or layout slide, use LineFormat.get_effective, access ILineFormatEffectiveData.sketch_format, and read ISketchFormatEffectiveData.sketch_type. The effective value reflects the formatting that is actually applied after inheritance is resolved. This example requires an existing presentation with at least one shape on its first slide and prints both values:
import aspose.slides as slides
with slides.Presentation("presentation.pptx") as presentation:
shape = presentation.slides[0].shapes[0]
line_format = shape.line_format
explicit_sketch_type = line_format.sketch_format.sketch_type
effective_line_format = line_format.get_effective()
effective_sketch_type = effective_line_format.sketch_format.sketch_type
print(f"Explicit sketch type: {explicit_sketch_type}")
print(f"Effective sketch type: {effective_sketch_type}")
Форматирование стилей соединений
Here are the three join type options:
- Round
- Miter
- Bevel
The join style controls how two outline segments meet at a corner. Use Round for rounded corners, Miter for sharp corners, or Bevel for flattened corners.

This example creates three black rectangles with blue outlines 15 points wide. It sets LineFormat.join_style to the miter, bevel, and round values of LineJoinStyle, respectively, to compare how the corners are drawn.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
miter_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 20, 150, 75)
bevel_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 210, 20, 150, 75)
round_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 20, 135, 150, 75)
miter_shape.fill_format.fill_type = slides.FillType.SOLID
miter_shape.fill_format.solid_fill_color.color = draw.Color.black
bevel_shape.fill_format.fill_type = slides.FillType.SOLID
bevel_shape.fill_format.solid_fill_color.color = draw.Color.black
round_shape.fill_format.fill_type = slides.FillType.SOLID
round_shape.fill_format.solid_fill_color.color = draw.Color.black
miter_shape.line_format.width = 15
bevel_shape.line_format.width = 15
round_shape.line_format.width = 15
miter_shape.line_format.fill_format.fill_type = slides.FillType.SOLID
miter_shape.line_format.fill_format.solid_fill_color.color = draw.Color.blue
bevel_shape.line_format.fill_format.fill_type = slides.FillType.SOLID
bevel_shape.line_format.fill_format.solid_fill_color.color = draw.Color.blue
round_shape.line_format.fill_format.fill_type = slides.FillType.SOLID
round_shape.line_format.fill_format.solid_fill_color.color = draw.Color.blue
miter_shape.line_format.join_style = slides.LineJoinStyle.MITER
bevel_shape.line_format.join_style = slides.LineJoinStyle.BEVEL
round_shape.line_format.join_style = slides.LineJoinStyle.ROUND
miter_shape.text_frame.text = "Miter Join Style"
bevel_shape.text_frame.text = "Bevel Join Style"
round_shape.text_frame.text = "Round Join Style"
presentation.save("join_styles.pptx", slides.export.SaveFormat.PPTX)
Ограничение стыков Miter при острых углах
Use LineFormat.miter_limit with LineFormat.join_style set to LineJoinStyle.MITER to limit how far a sharp corner can extend.
The limit is a ratio of the distance between the inner and outer corners of the join to the line width. For example, a value of 8 permits a miter length of up to eight times the line width; it is not a measurement in points. If the corner would exceed the limit, PowerPoint uses a beveled join at that corner. A larger limit allows sharper points. The setting affects miter joins only, and changing it has no visible effect when the corner remains within both limits.
This example creates two identical, unfilled triangles with outlines 20 points wide. The left triangle uses a limit of 2, and the right uses 8. Each triangle is 80 points wide and 160 points high, giving its top corner a miter‑length‑to‑line‑width ratio of approximately 4.12. Consequently, PowerPoint bevels the left apex and preserves the right apex.
import aspose.slides as slides
with slides.Presentation() as presentation:
presentation.slide_size.set_size(500, 320, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
miter_limits = [2.0, 8.0]
for i, miter_limit in enumerate(miter_limits):
triangle = slide.shapes.add_auto_shape(slides.ShapeType.TRIANGLE, 90 + i * 240, 110, 80, 160)
triangle.fill_format.fill_type = slides.FillType.NO_FILL
triangle.line_format.width = 20
triangle.line_format.fill_format.fill_type = slides.FillType.SOLID
triangle.line_format.fill_format.solid_fill_color.preset_color = slides.PresetColor.DARK_BLUE
triangle.line_format.join_style = slides.LineJoinStyle.MITER
triangle.line_format.miter_limit = miter_limit
presentation.save("miter_limits.pptx", slides.export.SaveFormat.PPTX)
Результат в PowerPoint: Miter limit 2 слева и miter limit 8 справа.

Градиентная заливка
A gradient fill blends colors across a shape. This example fills an ellipse with a linear gradient at a 45‑degree angle from red to purple using FillFormat.gradient_format. The GradientStopCollection.add method places the color stops at 0 and 1, the beginning and end of the gradient. Clearing the existing stops ensures that only these two colors are used.
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.ELLIPSE, 50, 50, 150, 75)
shape.fill_format.fill_type = slides.FillType.GRADIENT
shape.fill_format.gradient_format.gradient_shape = slides.GradientShape.LINEAR
shape.fill_format.gradient_format.linear_gradient_angle = 45
shape.fill_format.gradient_format.gradient_stops.clear()
shape.fill_format.gradient_format.gradient_stops.add(1.0, slides.PresetColor.PURPLE)
shape.fill_format.gradient_format.gradient_stops.add(0.0, slides.PresetColor.RED)
presentation.save("gradient_fill.pptx", slides.export.SaveFormat.PPTX)
Результат:

If a gradient looks different in an exported image than it does in PowerPoint, see Choose a Gradient Rendering Style. You can select a rendering style without changing the gradient fill stored in the presentation.
Установка угла линейного градиента
Use GradientFormat.linear_gradient_angle to control the orientation of a GradientShape.LINEAR fill. The angle is measured in degrees and increases clockwise: 0 runs from left to right, 90 from top to bottom, 180 from right to left, and 270 from bottom to top. Fractional angles are supported. Finite angles outside [0, 360) are normalized to one revolution; for example, -45 becomes 315 and 360 becomes 0.
This example creates six rectangles with identical red, green, and blue stops at positions 0, 0.5, and 1. Scaling is disabled so that the angle can be compared independently of the rectangles' proportions. The angles, from left to right, are 0, 45, and 90 in the first row, and 135, 180, and 270 in the second row.
import aspose.slides as slides
with slides.Presentation() as presentation:
presentation.slide_size.set_size(720, 400, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
angles = [0, 45, 90, 135, 180, 270]
for i, angle in enumerate(angles):
x = 30 + (i % 3) * 230
y = 30 + (i // 3) * 190
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, x, y, 200, 150)
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
shape.fill_format.fill_type = slides.FillType.GRADIENT
gradient = shape.fill_format.gradient_format
gradient.gradient_shape = slides.GradientShape.LINEAR
gradient.gradient_stops.clear()
gradient.gradient_stops.add(0.0, slides.PresetColor.RED)
gradient.gradient_stops.add(0.5, slides.PresetColor.LIME)
gradient.gradient_stops.add(1.0, slides.PresetColor.BLUE)
gradient.linear_gradient_scaled = slides.NullableBool.FALSE
gradient.linear_gradient_angle = angle
presentation.save("linear_gradient_angles.pptx", slides.export.SaveFormat.PPTX)
Результат в PowerPoint:

Масштабирование линейного градиента фигурой
GradientFormat.linear_gradient_scaled accepts a NullableBool value. Set it explicitly to FALSE to keep the geometric gradient angle as the shape’s proportions change, or to TRUE to scale the gradient with the shape’s width and height. With scaling enabled, the visible angle can differ from the assigned angle on a non‑square shape.
The following example uses a 45‑degree angle and the same color stops as the angle comparison. The left column uses FALSE; the right column uses TRUE. Each column contains a wide rectangle above a tall rectangle. Both start with the same wide dimensions; changing the second rectangle’s width and height demonstrates how the fill responds to resizing without changing its gradient settings.
import aspose.slides as slides
with slides.Presentation() as presentation:
presentation.slide_size.set_size(720, 460, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
scaling_options = [slides.NullableBool.FALSE, slides.NullableBool.TRUE]
for column, scaling in enumerate(scaling_options):
for row in range(2):
x = 30 + column * 360
y = 30 if row == 0 else 150
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, x, y, 300, 90)
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
shape.fill_format.fill_type = slides.FillType.GRADIENT
gradient = shape.fill_format.gradient_format
gradient.gradient_shape = slides.GradientShape.LINEAR
gradient.gradient_stops.clear()
gradient.gradient_stops.add(0.0, slides.PresetColor.RED)
gradient.gradient_stops.add(0.5, slides.PresetColor.LIME)
gradient.gradient_stops.add(1.0, slides.PresetColor.BLUE)
gradient.linear_gradient_angle = 45
gradient.linear_gradient_scaled = scaling
if row == 1:
shape.width = 90
shape.height = 280
presentation.save("linear_gradient_scaling.pptx", slides.export.SaveFormat.PPTX)
Результат в PowerPoint, с отключённым масштабированием слева и включённым справа:

With scaling disabled, the diagonal color bands keep the same orientation in both rectangles. With scaling enabled, the bands stretch with the shape’s proportions. This helps reproduce a template’s gradient when adapting a shape to a different size. On a square, enabling scaling does not change the appearance of this 45‑degree gradient.
Both the angle and scaling settings apply to linear gradients. They do not control GradientShape.RADIAL or GradientShape.RECTANGLE fills.
Комбинирование угла с направлением градиента
GradientFormat.gradient_direction selects a gradient style from the GradientDirection enumeration; it is not a substitute for a numeric angle. For a linear gradient, the corner styles can change the area over which the colors are distributed without changing linear_gradient_angle. Keep the direction unchanged when comparing angles or scaling.
The following example applies the same settings in opposite orders. The two rectangles have the same appearance: assigning the direction before or after the angle does not change the result.
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
for i in range(2):
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 30 + i * 140, 320, 100)
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
shape.fill_format.fill_type = slides.FillType.GRADIENT
gradient = shape.fill_format.gradient_format
gradient.gradient_shape = slides.GradientShape.LINEAR
gradient.gradient_stops.clear()
gradient.gradient_stops.add(0.0, slides.PresetColor.RED)
gradient.gradient_stops.add(0.5, slides.PresetColor.LIME)
gradient.gradient_stops.add(1.0, slides.PresetColor.BLUE)
gradient.linear_gradient_scaled = slides.NullableBool.TRUE
if i == 0:
gradient.gradient_direction = slides.GradientDirection.FROM_CORNER1
gradient.linear_gradient_angle = 30
else:
gradient.linear_gradient_angle = 30
gradient.gradient_direction = slides.GradientDirection.FROM_CORNER1
presentation.save("linear_gradient_direction.pptx", slides.export.SaveFormat.PPTX)
Заливка шаблоном
A pattern fill applies a two‑color design, such as dots, stripes, or checks. This example uses PatternFormat.pattern_style to select a trellis pattern. PatternFormat.back_color supplies the light gray background, and PatternFormat.fore_color supplies the yellow pattern color.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
shape.fill_format.fill_type = slides.FillType.PATTERN
shape.fill_format.pattern_format.pattern_style = slides.PatternStyle.TRELLIS
shape.fill_format.pattern_format.back_color.color = draw.Color.light_gray
shape.fill_format.pattern_format.fore_color.color = draw.Color.yellow
presentation.save("pattern_fill.pptx", slides.export.SaveFormat.PPTX)
Результат:

Заливка изображением
A picture fill uses an image inside a shape. This example requires a local image and uses Images.from_file to load it into the presentation’s image collection. Setting PictureFillFormat.picture_fill_mode to the tiled mode repeats the image within the rectangle. The source image used here is shown below:

import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 255, 130)
shape.fill_format.fill_type = slides.FillType.PICTURE
shape.fill_format.picture_fill_format.picture_fill_mode = slides.PictureFillMode.TILE
with slides.Images.from_file("lotus.png") as image:
presentation_image = presentation.images.add_image(image)
shape.fill_format.picture_fill_format.picture.image = presentation_image
presentation.save("picture_fill.pptx", slides.export.SaveFormat.PPTX)
Результат:

Мозаика изображения как текстуры
If you want to set a tiled picture as a texture and customize the tiling behavior, you can use the following properties of the PictureFillFormat class:
- picture_fill_mode: Устанавливает режим заливки изображением —
TILEилиSTRETCH. - tile_alignment: Задает выравнивание плиток внутри фигуры.
- tile_flip: Управляет тем, будет ли плитка отражена по горизонтали, вертикали или в обеих направлениях.
- tile_offset_x: Устанавливает горизонтальное смещение плитки (в пунктах) от начала фигуры.
- tile_offset_y: Устанавливает вертикальное смещение плитки (в пунктах) от начала фигуры.
- tile_scale_x: Определяет горизонтальный масштаб плитки в процентах.
- tile_scale_y: Определяет вертикальный масштаб плитки в процентах.
This example requires a local image and configures PictureFillFormat to repeat it at 50% of its original size. Offsets of −32 points shift the tiles horizontally and vertically; bottom‑right alignment and flipping in both directions determine how the repeated texture is arranged.
import aspose.slides as slides
with slides.Presentation() as presentation:
first_slide = presentation.slides[0]
shape = first_slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 190, 95)
shape.fill_format.fill_type = slides.FillType.PICTURE
with slides.Images.from_file("lotus.png") as source_image:
presentation_image = presentation.images.add_image(source_image)
picture_fill_format = shape.fill_format.picture_fill_format
picture_fill_format.picture.image = presentation_image
picture_fill_format.picture_fill_mode = slides.PictureFillMode.TILE
picture_fill_format.tile_offset_x = -32
picture_fill_format.tile_offset_y = -32
picture_fill_format.tile_scale_x = 50
picture_fill_format.tile_scale_y = 50
picture_fill_format.tile_alignment = slides.RectangleAlignment.BOTTOM_RIGHT
picture_fill_format.tile_flip = slides.TileFlip.FLIP_BOTH
presentation.save("tile.pptx", slides.export.SaveFormat.PPTX)
Результат:

Заливка сплошным цветом
A solid fill gives a shape a single, uniform color. This example sets FillFormat.fill_type to the solid fill mode and assigns yellow through FillFormat.solid_fill_color, then saves the rectangle in a presentation.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
shape.fill_format.fill_type = slides.FillType.SOLID
shape.fill_format.solid_fill_color.color = draw.Color.yellow
presentation.save("solid_color_fill.pptx", slides.export.SaveFormat.PPTX)
Результат:

Копирование цветов с сохранением ссылок на тему
Use ColorFormat.copy_from to copy a color definition, including its color type, theme reference, and transformations. This is useful when transferring a fill color between shapes that should continue to follow the presentation theme. The method copies only the color: it does not copy the fill type, outline, or other shape formatting. Set the destination’s FillFormat.fill_type explicitly.
This example creates three rectangles, from left to right: the source, a theme‑aware copy, and a fixed RGB copy. The source uses ColorFormat.scheme_color to reference the first accent color and adds a tint through ColorOperationCollection.add. The RGB copy uses the source’s effective fill color so all three initially look identical. Assigning ColorFormat.color sets a fixed RGB value and clears any existing color transformations.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
presentation.slide_size.set_size(660, 220, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
presentation.master_theme.color_scheme.accent1.color = draw.Color.royal_blue
source = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 30, 40, 180, 140)
theme_copy = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 240, 40, 180, 140)
rgb_copy = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 450, 40, 180, 140)
for shape in (source, theme_copy, rgb_copy):
shape.fill_format.fill_type = slides.FillType.SOLID
shape.line_format.fill_format.fill_type = slides.FillType.NO_FILL
source_color = source.fill_format.solid_fill_color
source_color.scheme_color = slides.SchemeColor.ACCENT1
source_color.color_transform.add(slides.ColorTransformOperation.TINT, 0.75)
theme_copy.fill_format.solid_fill_color.copy_from(source_color)
rgb_copy.fill_format.solid_fill_color.color = source.fill_format.get_effective().solid_fill_color
with slide.get_image(1.0, 1.0) as before:
before.save("color-copy-before.png", slides.ImageFormat.PNG)
# Ссылки на тему следуют новому цвету акцента; фиксированное значение RGB не меняется.
presentation.master_theme.color_scheme.accent1.color = draw.Color.orange_red
with slide.get_image(1.0, 1.0) as after:
after.save("color-copy-after.png", slides.ImageFormat.PNG)
presentation.save("copied_colors.pptx", slides.export.SaveFormat.PPTX)
Before the theme change, all three fills match:

After the theme change, the source and the theme‑aware copy follow the new accent color and retain their tint. The fixed RGB copy remains blue:

The copied definition is independent of the source. Subsequently changing the source’s theme reference, assigning another color, or adding or removing its transformations does not change the destination. A theme change still affects both shapes because each independently refers to the same theme color.
Saving and reopening the PPTX preserves the copied color’s ColorFormat.color_type, theme reference, and ColorFormat.color_transform collection; it does not flatten the definition to RGB.
When copying between different theme contexts, such as presentations with different accent palettes, the copied reference resolves against the destination’s theme. The same reference and transformations can therefore produce a different visible color. See Presentation Theme for more about configuring theme colors.
Использование фона слайда как заливки фигуры
Use AutoShape.use_background_fill when a shape should match the slide background, for example in a presentation template. Set FillFormat.fill_type to FillType.NOT_DEFINED first to remove any explicit fill. With this combination, the shape uses the slide background instead of its style fill. Enabling the flag alone does not remove an existing explicit fill.
This differs from FillType.NO_FILL: background fill covers objects behind the shape with the corresponding area of the slide background, while no fill leaves those objects visible. A gradient remains aligned with the slide rather than restarting inside each shape.
The following example creates a master background inherited by the slide and places a magenta band behind three rectangles. The left rectangle uses the background, the middle rectangle has no fill, and the right rectangle switches from background fill to an explicit orange fill.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
presentation.slide_size.set_size(720, 400, slides.SlideSizeScaleType.DO_NOT_SCALE)
slide = presentation.slides[0]
# Наследовать градиент из шаблона.
slide.background.type = slides.BackgroundType.NOT_DEFINED
slide.layout_slide.background.type = slides.BackgroundType.NOT_DEFINED
background = slide.layout_slide.master_slide.background
background.type = slides.BackgroundType.OWN_BACKGROUND
background.fill_format.fill_type = slides.FillType.GRADIENT
gradient = background.fill_format.gradient_format
gradient.gradient_shape = slides.GradientShape.LINEAR
gradient.linear_gradient_angle = 0
gradient.gradient_stops.clear()
gradient.gradient_stops.add(0, draw.Color.dark_blue)
gradient.gradient_stops.add(1, draw.Color.light_sky_blue)
# Добавить этот объект первым, чтобы он оказался за прямоугольниками.
band = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 25, 150, 670, 100)
band.fill_format.fill_type = slides.FillType.SOLID
band.fill_format.solid_fill_color.color = draw.Color.magenta
band.line_format.fill_format.fill_type = slides.FillType.NO_FILL
background_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 100, 160, 200)
background_shape.fill_format.fill_type = slides.FillType.NOT_DEFINED
background_shape.use_background_fill = True
no_fill_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 280, 100, 160, 200)
no_fill_shape.fill_format.fill_type = slides.FillType.NO_FILL
explicit_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 510, 100, 160, 200)
explicit_shape.fill_format.fill_type = slides.FillType.NOT_DEFINED
explicit_shape.use_background_fill = True
# Отключить заливку фоном перед применением явной заливки.
explicit_shape.use_background_fill = False
explicit_shape.fill_format.fill_type = slides.FillType.SOLID
explicit_shape.fill_format.solid_fill_color.color = draw.Color.orange
presentation.save("background_fill.pptx", slides.export.SaveFormat.PPTX)
Результат слева направо: background fill, no fill, and explicit fill. The magenta band is hidden by the left and right rectangles but remains visible through the middle rectangle.

The same behavior applies to a background defined directly on the slide or inherited from a layout. The shape uses the slide’s resolved background; the example leaves both the slide and layout backgrounds undefined so the master supplies it.
Установка прозрачности
For a solid fill, the color’s alpha component controls opacity: 0 is fully transparent and 255 is fully opaque. This example uses an alpha value of 128 for a yellow rectangle, making it approximately 50% transparent so the rectangle underneath remains visible. The color is assigned through FillFormat.solid_fill_color.
import aspose.slides as slides
import aspose.pydrawing as draw
alpha = 128
with slides.Presentation() as presentation:
slide = presentation.slides[0]
solid_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
transparent_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 80, 80, 150, 75)
transparent_shape.fill_format.fill_type = slides.FillType.SOLID
transparent_shape.fill_format.solid_fill_color.color = draw.Color.from_argb(alpha, draw.Color.yellow)
presentation.save("shape_transparency.pptx", slides.export.SaveFormat.PPTX)
Результат:

Вращение фигур
Use Shape.rotation to rotate a shape in the slide plane. The angle is measured in degrees; this example rotates a rectangle 5 degrees clockwise and saves the presentation.
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
shape.rotation = 5
presentation.save("shape_rotation.pptx", slides.export.SaveFormat.PPTX)
Результат:

Добавление 3D-скошенных эффектов
Use Shape.three_d_format to give a shape depth and beveled edges. This example creates a green ellipse with an orange outline, sets ThreeDFormat.depth to 4 points, and applies a circular top bevel with a width and height of 6 points through ThreeDFormat.bevel_top. A front‑facing orthographic camera and three‑point lighting make the bevel visible.
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.ELLIPSE, 50, 50, 100, 100)
shape.fill_format.fill_type = slides.FillType.SOLID
shape.fill_format.solid_fill_color.color = draw.Color.green
shape.line_format.fill_format.fill_type = slides.FillType.SOLID
shape.line_format.fill_format.solid_fill_color.color = draw.Color.orange
shape.line_format.width = 2.0
shape.three_d_format.depth = 4
shape.three_d_format.bevel_top.bevel_type = slides.BevelPresetType.CIRCLE
shape.three_d_format.bevel_top.height = 6
shape.three_d_format.bevel_top.width = 6
shape.three_d_format.camera.camera_type = slides.CameraPresetType.ORTHOGRAPHIC_FRONT
shape.three_d_format.light_rig.light_type = slides.LightRigPresetType.THREE_PT
shape.three_d_format.light_rig.direction = slides.LightingDirection.TOP
presentation.save("3D_bevel_effect.pptx", slides.export.SaveFormat.PPTX)
Результат:

Добавление 3D-вращения
A shape’s 3D view is controlled by its camera settings. This example uses Camera.set_rotation with latitude, longitude, and revolution angles of 40, 35, and 20 degrees, respectively. It selects an isometric camera through Camera.camera_type and balanced lighting through LightRig.light_type, then saves the formatted rectangle.
import aspose.slides as slides
with slides.Presentation() as presentation:
slide = presentation.slides[0]
auto_shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 150, 75)
auto_shape.text_frame.text = "Hello, Aspose!"
auto_shape.three_d_format.camera.camera_type = slides.CameraPresetType.ISOMETRIC_LEFT_UP
auto_shape.three_d_format.camera.set_rotation(40, 35, 20)
auto_shape.three_d_format.light_rig.light_type = slides.LightRigPresetType.BALANCED
presentation.save("3D_rotation_effect.pptx", slides.export.SaveFormat.PPTX)
Результат:

Управление черно‑белой отрисовкой фигур
The Shape.black_white_mode property specifies how an individual shape is rendered when a presentation is viewed or processed in black‑and‑white mode. It does not enable black‑and‑white display by itself, and it does not change the shape’s fill, line, or other formatting in normal color mode.
Use a value from the BlackWhiteMode enumeration to select the desired behavior. For example, AUTOMATIC lets the rendering application choose the conversion, GRAY and LIGHT_GRAY use gray coloring, BLACK_WHITE uses only black and white, BLACK and WHITE force a single color, COLOR preserves normal coloring, and HIDDEN omits the shape in black‑and‑white mode. NOT_DEFINED means that no shape‑level mode is assigned.
This example creates an orange rectangle and sets Shape.black_white_mode to gray. The saved shape retains its orange fill for normal color display and requests gray coloring from applications that honor black‑and‑white display settings:
import aspose.slides as slides
import aspose.pydrawing as draw
with slides.Presentation() as presentation:
slide = presentation.slides[0]
shape = slide.shapes.add_auto_shape(slides.ShapeType.RECTANGLE, 50, 50, 200, 100)
shape.fill_format.fill_type = slides.FillType.SOLID
shape.fill_format.solid_fill_color.color = draw.Color.orange
shape.black_white_mode = slides.BlackWhiteMode.GRAY
presentation.save("shape_black_white_mode.pptx", slides.export.SaveFormat.PPTX)
In normal color mode, the rectangle retains its orange fill. In a black‑and‑white display workflow, it uses gray coloring because its mode is set to GRAY. This lets you preserve a full‑color slide while defining a distinct appearance for printing, previewing, or other workflows that honor the presentation’s black‑and‑white display settings.
Сброс форматирования
Use Slide.reset to restore the position, size, and formatting of slide placeholders from their corresponding layout placeholders. This example requires an existing presentation with layout‑linked placeholders and resets every slide before saving. Shapes without corresponding layout placeholders are not reset.
import aspose.slides as slides
with slides.Presentation("sample.pptx") as presentation:
for slide in presentation.slides:
slide.reset()
presentation.save("reset_formatting.pptx", slides.export.SaveFormat.PPTX)
ЧаВо
Влияет ли форматирование фигур на конечный размер файла презентации?
Цвета, стили линий и настройки эффектов обычно добавляют небольшое количество данных по сравнению с встроенными изображениями и медиа. Заливки изображениями могут увеличивать размер файла, потому‑что их изображения хранятся в презентации.
Как обнаружить фигуры на слайде с одинаковым форматированием, чтобы их сгруппировать?
Сравните у каждой фигуры ключевые свойства форматирования — заливку, линейные и эффектные параметры. Если все соответствующие значения совпадают, рассматривайте их стили как одинаковые и логически группируйте такие фигуры, что упрощает последующее управление стилями.
Можно ли сохранить набор пользовательских стилей фигур в отдельный файл для повторного использования в других презентациях?
Да. Сохраните образцы фигур с нужными стилями в шаблоне презентации или файле шаблона .POTX. При создании новой презентации откройте шаблон, клонируйте нужные стилизованные фигуры и применяйте их форматирование там, где требуется.