ducpy.builders.style_builders

Helper functions for creating element styles with a user-friendly API. Each ELEMENT_CONTENT_PREFERENCE has its own dedicated method.

Functions

_create_default_tiling_properties(...)

Create default tiling properties.

_create_default_hatch_style(...)

Create default hatch style.

_create_default_image_filter(...)

Create default image filter.

create_solid_content(...)

Create solid color content.

create_fill_content(...)

Create fill content (solid color or gradient).

create_image_content(...)

Create image content with various fit modes.

create_hatch_content(...)

Create hatch pattern content.

create_background(...)

Create element background from content.

create_stroke(→ ducpy.classes.ElementsClass.ElementStroke)

Create element stroke from content.

create_simple_styles(...)

Create element styles from pre-built backgrounds and strokes.

create_fill_style(...)

Create a fill style with the given content (solid, image, hatch, etc).

create_stroke_style(...)

Create a stroke style with the given content and width.

create_fill_and_stroke_style(...)

Create a style with both fill and stroke using the provided contents.

create_solid_style(color[, opacity])

Create solid content for use with create_fill_style or create_stroke_style.

create_hatch_style(pattern[, opacity])

Create hatch content for use with create_fill_style or create_stroke_style.

create_text_style(...)

Create a text style for table cells or other text elements.

create_paragraph_formatting(...)

Create paragraph formatting settings.

create_stack_format_properties(...)

Create stack format properties for stacked text.

create_stack_format(...)

Create stack format for fractions and special text.

create_doc_style(→ ducpy.classes.ElementsClass.DucDocStyle)

Create document style.

create_text_column(...)

Create a text column definition.

create_column_layout(...)

Create column layout for multi-column text.

create_margins(→ ducpy.classes.ElementsClass.Margins)

Create margin settings.

create_table_cell_style(...)

Create table cell style.

create_table_style(...)

Create table style.

Module Contents

ducpy.builders.style_builders._create_default_tiling_properties() ducpy.classes.ElementsClass.TilingProperties

Create default tiling properties.

ducpy.builders.style_builders._create_default_hatch_style() ducpy.classes.ElementsClass.DucHatchStyle

Create default hatch style.

ducpy.builders.style_builders._create_default_image_filter() ducpy.classes.ElementsClass.DucImageFilter

Create default image filter.

ducpy.builders.style_builders.create_solid_content(color: str, opacity: float = 1.0, visible: bool = True) ducpy.classes.ElementsClass.ElementContentBase

Create solid color content.

Args:

color: Hex color string (e.g., “#FF0000”) opacity: Content opacity (0.0 to 1.0) visible: Whether content is visible

Returns:

ElementContentBase: Solid color content

ducpy.builders.style_builders.create_fill_content(color: str, opacity: float = 1.0, visible: bool = True) ducpy.classes.ElementsClass.ElementContentBase

Create fill content (solid color or gradient).

Args:

color: Hex color string or gradient definition opacity: Content opacity (0.0 to 1.0) visible: Whether content is visible

Returns:

ElementContentBase: Fill content

ducpy.builders.style_builders.create_image_content(image_src: str, opacity: float = 1.0, visible: bool = True, fit_mode: str | None = None) ducpy.classes.ElementsClass.ElementContentBase

Create image content with various fit modes.

Args:

image_src: Can be a fileId, url, or frame element’s content @el/${elementId} opacity: Content opacity (0.0 to 1.0) visible: Whether content is visible fit_mode: How image fits (FIT, TILE, STRETCH) - string for now

Returns:

ElementContentBase: Image content

ducpy.builders.style_builders.create_hatch_content(pattern: str, opacity: float = 1.0, visible: bool = True) ducpy.classes.ElementsClass.ElementContentBase

Create hatch pattern content.

Args:

pattern: Hatch pattern definition opacity: Content opacity (0.0 to 1.0) visible: Whether content is visible

Returns:

ElementContentBase: Hatch content

ducpy.builders.style_builders.create_background(content: ducpy.classes.ElementsClass.ElementContentBase) ducpy.classes.ElementsClass.ElementBackground

Create element background from content.

Args:

content: Content created by create_solid_content, create_image_content, etc.

Returns:

ElementBackground: Background with the specified content

ducpy.builders.style_builders.create_stroke(content: ducpy.classes.ElementsClass.ElementContentBase, width: float, placement: ducpy.Duc.STROKE_PLACEMENT.STROKE_PLACEMENT = STROKE_PLACEMENT.INSIDE, style: ducpy.classes.ElementsClass.StrokeStyle | None = None, sides: ducpy.classes.ElementsClass.StrokeSides | None = None) ducpy.classes.ElementsClass.ElementStroke

Create element stroke from content.

Args:

content: Content created by create_solid_content, etc. width: Stroke width placement: Where to place the stroke (INSIDE, CENTER, OUTSIDE) style: Custom stroke style (defaults to solid) sides: Custom stroke sides (defaults to all sides)

Returns:

ElementStroke: Stroke with the specified content and properties

ducpy.builders.style_builders.create_simple_styles(roundness: float = 0.0, opacity: float = 1.0, backgrounds: List[ducpy.classes.ElementsClass.ElementBackground] | None = None, strokes: List[ducpy.classes.ElementsClass.ElementStroke] | None = None, blending: ducpy.Duc.BLENDING.BLENDING | None = None) ducpy.classes.ElementsClass.DucElementStylesBase

Create element styles from pre-built backgrounds and strokes.

Args:

roundness: Corner roundness for rectangles opacity: Element opacity (0.0 to 1.0) backgrounds: List of backgrounds created with create_background() strokes: List of strokes created with create_stroke() blending: Blending mode

Returns:

DucElementStylesBase: Configured styles

ducpy.builders.style_builders.create_fill_style(content, roundness: float = 0.0, opacity: float = 1.0) ducpy.classes.ElementsClass.DucElementStylesBase

Create a fill style with the given content (solid, image, hatch, etc).

ducpy.builders.style_builders.create_stroke_style(content, width: float = 1.0, placement: ducpy.Duc.STROKE_PLACEMENT.STROKE_PLACEMENT = STROKE_PLACEMENT.INSIDE, opacity: float = 1.0) ducpy.classes.ElementsClass.DucElementStylesBase

Create a stroke style with the given content and width.

ducpy.builders.style_builders.create_fill_and_stroke_style(fill_content: ducpy.classes.ElementsClass.ElementContentBase, stroke_content: ducpy.classes.ElementsClass.ElementContentBase, stroke_width: float = 1.0, roundness: float = 0.0, opacity: float = 1.0, placement: ducpy.Duc.STROKE_PLACEMENT.STROKE_PLACEMENT = STROKE_PLACEMENT.INSIDE) ducpy.classes.ElementsClass.DucElementStylesBase

Create a style with both fill and stroke using the provided contents.

ducpy.builders.style_builders.create_solid_style(color: str, opacity: float = 1.0)

Create solid content for use with create_fill_style or create_stroke_style.

ducpy.builders.style_builders.create_hatch_style(pattern: str, opacity: float = 1.0)

Create hatch content for use with create_fill_style or create_stroke_style.

ducpy.builders.style_builders.create_text_style(base_style: ducpy.classes.ElementsClass.DucElementStylesBase | None = None, font_family: str = 'Arial', font_size: float = 12, is_ltr: bool = True, text_align: ducpy.Duc.TEXT_ALIGN.TEXT_ALIGN | None = None, vertical_align: ducpy.Duc.VERTICAL_ALIGN.VERTICAL_ALIGN | None = None, line_height: float = 1.0, line_spacing_value: float = 1.0, line_spacing_type: ducpy.Duc.LINE_SPACING_TYPE.LINE_SPACING_TYPE | None = None, oblique_angle: float = 0.0, width_factor: float = 1.0, is_upside_down: bool = False, is_backwards: bool = False, paper_text_height: float | None = None) ducpy.classes.ElementsClass.DucTextStyle

Create a text style for table cells or other text elements.

Args:

base_style: Base element style font_family: Font family name font_size: Font size is_ltr: Left-to-right text direction text_align: Horizontal text alignment vertical_align: Vertical text alignment line_height: Line height multiplier line_spacing_value: Line spacing value line_spacing_type: Line spacing type oblique_angle: Text oblique angle width_factor: Text width factor is_upside_down: Whether text is upside down is_backwards: Whether text is backwards paper_text_height: Paper text height

ducpy.builders.style_builders.create_paragraph_formatting(first_line_indent: float = 0.0, hanging_indent: float = 0.0, left_indent: float = 0.0, right_indent: float = 0.0, space_before: float = 0.0, space_after: float = 0.0, tab_stops: List[float] | None = None) ducpy.classes.ElementsClass.ParagraphFormatting

Create paragraph formatting settings.

ducpy.builders.style_builders.create_stack_format_properties(upper_scale: float = 0.7, lower_scale: float = 0.7, alignment: ducpy.Duc.STACKED_TEXT_ALIGN.STACKED_TEXT_ALIGN | None = None) ducpy.classes.ElementsClass.StackFormatProperties

Create stack format properties for stacked text.

ducpy.builders.style_builders.create_stack_format(auto_stack: bool = True, stack_chars: List[str] | None = None, properties: ducpy.classes.ElementsClass.StackFormatProperties | None = None) ducpy.classes.ElementsClass.StackFormat

Create stack format for fractions and special text.

ducpy.builders.style_builders.create_doc_style(text_style: ducpy.classes.ElementsClass.DucTextStyle | None = None, paragraph: ducpy.classes.ElementsClass.ParagraphFormatting | None = None, stack_format: ducpy.classes.ElementsClass.StackFormat | None = None) ducpy.classes.ElementsClass.DucDocStyle

Create document style.

ducpy.builders.style_builders.create_text_column(width: float, gutter: float = 0.0) ducpy.classes.ElementsClass.TextColumn

Create a text column definition.

ducpy.builders.style_builders.create_column_layout(definitions: List[ducpy.classes.ElementsClass.TextColumn] | None = None, auto_height: bool = True, column_type: ducpy.Duc.COLUMN_TYPE.COLUMN_TYPE | None = None) ducpy.classes.ElementsClass.ColumnLayout

Create column layout for multi-column text.

ducpy.builders.style_builders.create_margins(top: float = 0.0, right: float = 0.0, bottom: float = 0.0, left: float = 0.0) ducpy.classes.ElementsClass.Margins

Create margin settings.

ducpy.builders.style_builders.create_table_cell_style(base_style: ducpy.classes.ElementsClass.DucElementStylesBase | None = None, text_style: ducpy.classes.ElementsClass.DucTextStyle | None = None, margins: ducpy.classes.ElementsClass.Margins | None = None, alignment: ducpy.classes.ElementsClass.TABLE_CELL_ALIGNMENT | None = None) ducpy.classes.ElementsClass.DucTableCellStyle

Create table cell style.

ducpy.builders.style_builders.create_table_style(base_style: ducpy.classes.ElementsClass.DucElementStylesBase | None = None, header_row_style: ducpy.classes.ElementsClass.DucTableCellStyle | None = None, data_row_style: ducpy.classes.ElementsClass.DucTableCellStyle | None = None, data_column_style: ducpy.classes.ElementsClass.DucTableCellStyle | None = None, flow_direction: ducpy.classes.ElementsClass.TABLE_FLOW_DIRECTION | None = None) ducpy.classes.ElementsClass.DucTableStyle

Create table style.