Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

feat(ppt): expand PPTX↔SVG converter coverage for pattern fills, geometry, and transforms

hugohe303d9ecbdf38e
diff --git a/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
index b4be3761..317219d4 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/fill_to_svg.py
@@ -193,18 +193,15 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,
return FillResult.inherit()
prst = elem.attrib.get("prst", "")
- if prst in {"ltUpDiag", "ltDnDiag"} and bg_hex is not None:
- if _hex_distance(fg_hex, bg_hex) < 36:
- attrs: dict[str, str] = {"fill": bg_hex}
- if bg_alpha < 1.0:
- attrs["fill-opacity"] = fmt_num(bg_alpha, 4)
- return FillResult(attrs=attrs)
-
- if prst not in {"ltUpDiag", "ltDnDiag"}:
+ geom = _pattern_foreground(prst, fg_hex, fg_alpha)
+ if geom is None:
+ # Unsupported preset → degrade to solid fg color so the shape at
+ # least carries the right tone. Round-trip will lose the texture.
attrs: dict[str, str] = {"fill": fg_hex}
if fg_alpha < 1.0:
attrs["fill-opacity"] = fmt_num(fg_alpha, 4)
return FillResult(attrs=attrs)
+ tile_w, tile_h, fg_svg = geom
if seq is None:
seq = [0]
@@ -216,21 +213,18 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,
f' fill-opacity="{fmt_num(bg_alpha, 4)}"'
if bg_alpha < 1.0 else ""
)
- bg_rect = f'<rect width="8" height="8" fill="{bg_hex}"{bg_opacity}/>'
- fg_opacity = (
- f' stroke-opacity="{fmt_num(fg_alpha, 4)}"'
- if fg_alpha < 1.0 else ""
- )
- path_d = (
- "M -2 8 L 8 -2 M 0 10 L 10 0"
- if prst == "ltUpDiag"
- else "M -2 0 L 8 10 M 0 -2 L 10 8"
- )
+ bg_rect = (
+ f'<rect width="{tile_w}" height="{tile_h}" '
+ f'fill="{bg_hex}"{bg_opacity}/>'
+ )
+ # Tag with data attributes so the reverse exporter can rebuild <a:pattFill>
+ # faithfully (preset + fg/bg colors) instead of inferring from path geometry.
+ bg_attr = f' data-pptx-bg="{bg_hex}"' if bg_hex is not None else ""
pattern_xml = (
f'<pattern id="{pattern_id}" patternUnits="userSpaceOnUse" '
- f'width="8" height="8">{bg_rect}'
- f'<path d="{path_d}" stroke="{fg_hex}"{fg_opacity} '
- f'stroke-width="1" fill="none"/></pattern>'
+ f'width="{tile_w}" height="{tile_h}" '
+ f'data-pptx-pattern="{prst}" data-pptx-fg="{fg_hex}"{bg_attr}>'
+ f'{bg_rect}{fg_svg}</pattern>'
)
return FillResult(
attrs={"fill": f"url(#{pattern_id})"},
@@ -238,6 +232,131 @@ def _resolve_patt_fill(elem: ET.Element, palette: ColorPalette | None,
)
+# ---------------------------------------------------------------------------
+# Per-preset SVG geometry for <a:pattFill prst="...">
+#
+# Each handler returns (tile_w, tile_h, foreground_svg). The caller wraps with
+# the background rect + <pattern> element. None means "unsupported preset" and
+# the caller degrades to a solid fg color.
+# ---------------------------------------------------------------------------
+
+def _pattern_foreground(prst: str, fg: str,
+ fg_alpha: float) -> tuple[int, int, str] | None:
+ stroke_op = (
+ f' stroke-opacity="{fmt_num(fg_alpha, 4)}"'
+ if fg_alpha < 1.0 else ""
+ )
+ fill_op = (
+ f' fill-opacity="{fmt_num(fg_alpha, 4)}"'
+ if fg_alpha < 1.0 else ""
+ )
+
+ # Diagonal stripes — tile size and stroke width pick the visual weight.
+ diag = {
+ "ltUpDiag": (8, 1.0, "up", False),
+ "dkUpDiag": (8, 2.0, "up", False),
+ "wdUpDiag": (16, 1.0, "up", False),
+ "dashUpDiag": (8, 1.0, "up", True),
+ "ltDnDiag": (8, 1.0, "dn", False),
+ "dkDnDiag": (8, 2.0, "dn", False),
+ "wdDnDiag": (16, 1.0, "dn", False),
+ "dashDnDiag": (8, 1.0, "dn", True),
+ }
+ if prst in diag:
+ tile, sw, direction, dashed = diag[prst]
+ dash = ' stroke-dasharray="3 2"' if dashed else ""
+ if direction == "up":
+ d = f"M -2 {tile} L {tile} -2 M 0 {tile + 2} L {tile + 2} 0"
+ else:
+ d = f"M -2 0 L {tile} {tile + 2} M 0 -2 L {tile + 2} {tile}"
+ return tile, tile, (
+ f'<path d="{d}" stroke="{fg}"{stroke_op} '
+ f'stroke-width="{fmt_num(sw)}" fill="none"{dash}/>'
+ )
+
+ # Horizontal / vertical lines.
+ line_specs = {
+ "horz": ("h", 8, 1.0, False),
+ "ltHorz": ("h", 8, 0.5, False),
+ "dkHorz": ("h", 8, 2.0, False),
+ "narHorz": ("h", 4, 1.0, False),
+ "dashHorz": ("h", 8, 1.0, True),
+ "vert": ("v", 8, 1.0, False),
+ "ltVert": ("v", 8, 0.5, False),
+ "dkVert": ("v", 8, 2.0, False),
+ "narVert": ("v", 4, 1.0, False),
+ "dashVert": ("v", 8, 1.0, True),
+ }
+ if prst in line_specs:
+ axis, tile, sw, dashed = line_specs[prst]
+ dash = ' stroke-dasharray="3 2"' if dashed else ""
+ mid = tile / 2.0
+ if axis == "h":
+ line = (
+ f'<line x1="0" y1="{fmt_num(mid)}" '
+ f'x2="{tile}" y2="{fmt_num(mid)}"'
+ )
+ else:
+ line = (
+ f'<line x1="{fmt_num(mid)}" y1="0" '
+ f'x2="{fmt_num(mid)}" y2="{tile}"'
+ )
+ return tile, tile, (
+ f'{line} stroke="{fg}"{stroke_op} '
+ f'stroke-width="{fmt_num(sw)}"{dash}/>'
+ )
+
+ # Grids / crosses.
+ if prst == "cross":
+ return 8, 8, (
+ f'<line x1="0" y1="4" x2="8" y2="4" stroke="{fg}"{stroke_op} stroke-width="1"/>'
+ f'<line x1="4" y1="0" x2="4" y2="8" stroke="{fg}"{stroke_op} stroke-width="1"/>'
+ )
+ if prst == "diagCross":
+ d = (
+ "M -2 8 L 8 -2 M 0 10 L 10 0 "
+ "M -2 0 L 8 10 M 0 -2 L 10 8"
+ )
+ return 8, 8, (
+ f'<path d="{d}" stroke="{fg}"{stroke_op} stroke-width="1" fill="none"/>'
+ )
+ if prst in ("smGrid", "lgGrid"):
+ tile = 4 if prst == "smGrid" else 16
+ # Lines along top + left edges; tiles together produce a uniform grid.
+ return tile, tile, (
+ f'<path d="M 0 0 L {tile} 0 M 0 0 L 0 {tile}" '
+ f'stroke="{fg}"{stroke_op} stroke-width="0.5" fill="none"/>'
+ )
+ if prst == "dotGrid":
+ # Dots at corners → tiling yields a uniform dot grid.
+ return 8, 8, (
+ f'<circle cx="0" cy="0" r="1" fill="{fg}"{fill_op}/>'
+ )
+ if prst == "dotDmnd":
+ return 8, 8, (
+ f'<circle cx="0" cy="0" r="1" fill="{fg}"{fill_op}/>'
+ f'<circle cx="4" cy="4" r="1" fill="{fg}"{fill_op}/>'
+ )
+
+ # Percentage shading — single centered dot whose area matches the target
+ # density. Approximates PowerPoint's stipple without per-tile artwork.
+ if prst.startswith("pct"):
+ try:
+ pct = float(prst[3:])
+ except ValueError:
+ return None
+ pct = max(0.0, min(pct, 100.0))
+ tile = 8
+ radius = math.sqrt(pct / 100.0 * tile * tile / math.pi)
+ radius = max(0.3, min(radius, tile / 2.0))
+ return tile, tile, (
+ f'<circle cx="{tile / 2}" cy="{tile / 2}" '
+ f'r="{fmt_num(radius, 3)}" fill="{fg}"{fill_op}/>'
+ )
+
+ return None
+
+
def _hex_distance(a: str, b: str) -> float:
"""Euclidean distance between two #RRGGBB colors."""
try:
diff --git a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
index a5e288b1..e570f6b5 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/ln_to_svg.py
@@ -53,6 +53,7 @@ def resolve_stroke(
*,
id_prefix: str = "m",
id_seq: list[int] | None = None,
+ style_stroke_default: str | None = None,
) -> StrokeResult:
"""Resolve <a:ln> child of <p:spPr>.
@@ -152,9 +153,10 @@ def resolve_stroke(
end_elem = ln.find(f"a:{which}", NS)
if end_elem is None:
continue
+ marker_color = attrs.get("stroke") or style_stroke_default or "#000000"
marker_id, marker_def = _build_arrow_marker(
end_elem,
- attrs.get("stroke", "#000000"),
+ marker_color,
id_prefix=id_prefix,
seq=id_seq,
reversed_=(which == "headEnd"),
@@ -171,8 +173,10 @@ def resolve_stroke(
# Arrow marker generation
# ---------------------------------------------------------------------------
-# Bucket -> markerWidth/markerHeight ratio (in stroke widths)
-SIZE_BUCKET = {"sm": 1.5, "med": 2.5, "lg": 3.5}
+# Bucket -> markerWidth/markerHeight ratio (in stroke widths).
+# Tuned to roughly match PowerPoint's rendered arrowhead size; the spec is
+# under-defined but PowerPoint draws noticeably larger heads than 1.5–3.5×.
+SIZE_BUCKET = {"sm": 3.0, "med": 5.0, "lg": 7.0}
def _build_arrow_marker(
diff --git a/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py
index 90ce979f..28eb3347 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/prstgeom_to_svg.py
@@ -102,7 +102,8 @@ def convert_prst_geom(
Returns None if the preset has no v1 mapping; the caller can then choose
to render a fallback rect.
"""
- if prst == "line":
+ # Line-style presets accept zero width OR zero height (axis-aligned lines).
+ if prst in ("line", "straightConnector1"):
if xfrm.w == 0 and xfrm.h == 0:
return None
return _line(xfrm, sp_pr)
@@ -310,9 +311,17 @@ def _parallelogram(xfrm: Xfrm, sp_pr) -> GeomResult:
def _trapezoid(xfrm: Xfrm, sp_pr) -> GeomResult:
- """adj = horizontal inset of top edge (default 25%)."""
- adj = _adj_value(sp_pr, "adj", default_pct=0.25)
- inset = adj * xfrm.w
+ """OOXML trapezoid: x1 = ss * adj / 200000 (ss = min(w, h)).
+
+ adj default 25000; maxAdj caps at 50000 * w / ss so the top can't invert.
+ """
+ adj = _adj_int_value(sp_pr, "adj", 25000)
+ ss = min(xfrm.w, xfrm.h)
+ if ss <= 0:
+ return _rect(xfrm, sp_pr)
+ max_adj = 50000.0 * xfrm.w / ss
+ a = max(0.0, min(float(adj), max_adj))
+ inset = ss * a / 200000.0
return _polygon([
(xfrm.x + inset, xfrm.y),
(xfrm.x + xfrm.w - inset, xfrm.y),
@@ -321,6 +330,73 @@ def _trapezoid(xfrm: Xfrm, sp_pr) -> GeomResult:
])
+def _chevron(xfrm: Xfrm, sp_pr) -> GeomResult:
+ """OOXML chevron: dx = ss * adj / 100000 (ss = min(w, h)), default adj=50000.
+
+ Both the right-pointing tip length and the left back-notch depth equal dx,
+ which is what lets a series of chevrons tile flush.
+ """
+ adj = _adj_int_value(sp_pr, "adj", 50000)
+ x, y, w, h = xfrm.x, xfrm.y, xfrm.w, xfrm.h
+ ss = min(w, h)
+ if ss <= 0:
+ return _rect(xfrm, sp_pr)
+ max_adj = 100000.0 * w / ss
+ a = max(0.0, min(float(adj), max_adj))
+ dx = ss * a / 100000.0
+ cy = y + h / 2.0
+ return _polygon([
+ (x, y),
+ (x + w - dx, y),
+ (x + w, cy),
+ (x + w - dx, y + h),
+ (x, y + h),
+ (x + dx, cy),
+ ])
+
+
+def _home_plate(xfrm: Xfrm, sp_pr) -> GeomResult:
+ """OOXML homePlate: tip length = ss * adj / 100000; body fills 0..(w - tip).
+
+ Same dx as chevron so a homePlate→chevron series tiles seamlessly.
+ """
+ adj = _adj_int_value(sp_pr, "adj", 50000)
+ x, y, w, h = xfrm.x, xfrm.y, xfrm.w, xfrm.h
+ ss = min(w, h)
+ if ss <= 0:
+ return _rect(xfrm, sp_pr)
+ max_adj = 100000.0 * w / ss
+ a = max(0.0, min(float(adj), max_adj))
+ dx = ss * a / 100000.0
+ split = w - dx
+ cy = y + h / 2.0
+ return _polygon([
+ (x, y),
+ (x + split, y),
+ (x + w, cy),
+ (x + split, y + h),
+ (x, y + h),
+ ])
+
+
+def _flow_chart_extract(xfrm: Xfrm, _sp_pr) -> GeomResult:
+ """Flowchart "Extract": upward-pointing isoceles triangle."""
+ return _polygon([
+ (xfrm.x + xfrm.w / 2.0, xfrm.y),
+ (xfrm.x + xfrm.w, xfrm.y + xfrm.h),
+ (xfrm.x, xfrm.y + xfrm.h),
+ ])
+
+
+def _flow_chart_merge(xfrm: Xfrm, _sp_pr) -> GeomResult:
+ """Flowchart "Merge": downward-pointing isoceles triangle."""
+ return _polygon([
+ (xfrm.x, xfrm.y),
+ (xfrm.x + xfrm.w, xfrm.y),
+ (xfrm.x + xfrm.w / 2.0, xfrm.y + xfrm.h),
+ ])
+
+
def _regular_polygon(xfrm: Xfrm, n_sides: int, *, rot_deg: float = -90.0) -> GeomResult:
"""Regular polygon inscribed in the bounding box."""
cx = xfrm.x + xfrm.w / 2.0
@@ -540,6 +616,9 @@ _PRESET_HANDLERS = {
"round2SameRect": _round_2_same_rect,
"ellipse": _ellipse,
"line": _line,
+ # Straight connector: same geometry as a `line` preset; head/tail markers
+ # come from <a:ln>.
+ "straightConnector1": _line,
# Polygons
"triangle": _triangle,
@@ -547,6 +626,10 @@ _PRESET_HANDLERS = {
"diamond": _diamond,
"parallelogram": _parallelogram,
"trapezoid": _trapezoid,
+ "chevron": _chevron,
+ "homePlate": _home_plate,
+ "flowChartExtract": _flow_chart_extract,
+ "flowChartMerge": _flow_chart_merge,
"pentagon": _pentagon,
"hexagon": _hexagon,
"heptagon": _heptagon,
diff --git a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
index da884527..7cff3a2d 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/slide_to_svg.py
@@ -390,11 +390,18 @@ def _build_geometry_xml(node: ShapeNode, sp_pr: ET.Element | None,
if geom is None:
return ""
+ # Resolve style defaults early so markers can adopt the theme stroke color
+ # when <a:ln> doesn't carry an explicit solidFill.
+ style_defaults = _resolve_shape_style_defaults(node, ctx)
+
# Fill / stroke / effect
fill = resolve_fill(sp_pr, ctx.palette,
id_prefix="g", id_seq=ctx.grad_seq)
- stroke = resolve_stroke(sp_pr, ctx.palette,
- id_prefix="m", id_seq=ctx.marker_seq)
+ stroke = resolve_stroke(
+ sp_pr, ctx.palette,
+ id_prefix="m", id_seq=ctx.marker_seq,
+ style_stroke_default=style_defaults.get("stroke"),
+ )
filter_id, effect_defs = convert_effects(sp_pr, ctx.palette,
id_prefix="fx",
id_seq=ctx.filter_seq)
@@ -404,7 +411,6 @@ def _build_geometry_xml(node: ShapeNode, sp_pr: ET.Element | None,
ctx.defs.extend(effect_defs)
attrs = {**fill.attrs, **stroke.attrs}
- style_defaults = _resolve_shape_style_defaults(node, ctx)
for key, value in style_defaults.items():
attrs.setdefault(key, value)
if filter_id is not None:
diff --git a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
index 4df59b8f..608febc9 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/txbody_to_svg.py
@@ -853,7 +853,10 @@ def _clip_lines_to_bottom(
cursor_y = top_y
for line in lines:
line_h = _line_height(para, line)
- if cursor_y + line_h > bottom_y:
+ # PowerPoint lets the first line that starts within the box render even
+ # when it slightly exceeds the bottom — only suppress lines whose top
+ # is already at/below the bottom edge.
+ if cursor_y >= bottom_y:
break
visible.append(line)
cursor_y += line_h
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py
index d5236683..5332c79e 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_converter.py
@@ -2,6 +2,7 @@
from __future__ import annotations
+import math
import re
from pathlib import Path
from xml.etree import ElementTree as ET
@@ -57,33 +58,43 @@ def _is_chrome_id(elem_id: str | None) -> bool:
# ---------------------------------------------------------------------------
def parse_transform(transform_str: str) -> tuple[float, float, float, float, float]:
- """Parse SVG transform string, extract translate, scale, and rotate.
-
- Returns:
- (dx, dy, sx, sy, angle_deg) tuple.
+ """Parse an SVG transform list into (dx, dy, sx, sy, angle_deg).
+
+ Composes every translate/scale/rotate/matrix operation rather than picking
+ the first occurrence — needed for idioms like
+ ``translate(cx cy) scale(-1 -1) translate(-cx -cy)`` which encode a flip
+ around a non-origin pivot.
+
+ When the composed matrix has no shear and no rotation, the decomposition is
+ exact (sx/sy may be negative to represent flips). When rotation is present
+ without shear, sx/sy default to the column magnitudes and angle_deg is the
+ rotation. Shear is not representable in this 5-tuple and silently
+ collapses; callers that need exact fidelity should consume the full matrix
+ via ``parse_transform_matrix``.
"""
if not transform_str:
return 0.0, 0.0, 1.0, 1.0, 0.0
- dx, dy = 0.0, 0.0
- sx, sy = 1.0, 1.0
- angle_deg = 0.0
-
- m = re.search(r'translate\(\s*([-\d.]+)[\s,]+([-\d.]+)\s*\)', transform_str)
- if m:
- dx = float(m.group(1))
- dy = float(m.group(2))
-
- m = re.search(r'scale\(\s*([-\d.]+)(?:[\s,]+([-\d.]+))?\s*\)', transform_str)
- if m:
- sx = float(m.group(1))
- sy = float(m.group(2)) if m.group(2) else sx
-
- m = re.search(r'rotate\(\s*([-\d.]+)', transform_str)
- if m:
- angle_deg = float(m.group(1))
-
- return dx, dy, sx, sy, angle_deg
+ a, b, c, d, e, f = parse_transform_matrix(transform_str)
+
+ # No shear / rotation: direct decomposition preserves the original signs of
+ # sx / sy. ctx_x / ctx_y use the simple ``val * sx + tx`` formula, so this
+ # is the only form that survives flip-around-pivot composites without
+ # collapsing them into a rotation that the consumer can't honour.
+ if abs(b) < 1e-9 and abs(c) < 1e-9:
+ sx = a if a != 0 else 1.0
+ sy = d if d != 0 else 1.0
+ return e, f, sx, sy, 0.0
+
+ sx = math.hypot(a, b)
+ sy = math.hypot(c, d)
+ if sx == 0:
+ sx = 1.0
+ if sy == 0:
+ sy = 1.0
+
+ angle_deg = math.degrees(math.atan2(b, a))
+ return e, f, sx, sy, angle_deg
# ---------------------------------------------------------------------------
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml_styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml_styles.py
index a34ae10c..4693afee 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml_styles.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml_styles.py
@@ -121,9 +121,16 @@ def build_fill_xml(
if fill == 'none':
return '<a:noFill/>'
- grad_id = resolve_url_id(fill)
- if grad_id and grad_id in ctx.defs:
- return build_gradient_fill(ctx.defs[grad_id], opacity)
+ ref_id = resolve_url_id(fill)
+ if ref_id and ref_id in ctx.defs:
+ ref_elem = ctx.defs[ref_id]
+ ref_tag = ref_elem.tag.replace(f'{{{SVG_NS}}}', '')
+ if ref_tag == 'pattern':
+ patt_xml = build_pattern_fill(ref_elem, opacity)
+ if patt_xml:
+ return patt_xml
+ return '<a:noFill/>'
+ return build_gradient_fill(ref_elem, opacity)
color = parse_hex_color(fill)
if color:
@@ -132,6 +139,53 @@ def build_fill_xml(
return '<a:noFill/>'
+def build_pattern_fill(
+ pattern_elem: ET.Element,
+ opacity: float | None = None,
+) -> str:
+ """Build <a:pattFill> from an SVG <pattern> emitted by pptx_to_svg.
+
+ Reads the round-trip annotations (data-pptx-pattern / data-pptx-fg /
+ data-pptx-bg) when present. Falls back to inspecting the inner stroke /
+ rect colors when annotations are absent (hand-authored SVG).
+ """
+ prst = pattern_elem.get('data-pptx-pattern') or 'ltUpDiag'
+
+ fg_color = pattern_elem.get('data-pptx-fg')
+ bg_color = pattern_elem.get('data-pptx-bg')
+
+ if not fg_color or not bg_color:
+ # Hand-authored fallback: derive from child elements.
+ for child in pattern_elem:
+ tag = child.tag.replace(f'{{{SVG_NS}}}', '')
+ if tag == 'rect' and not bg_color:
+ bg_color = child.get('fill')
+ elif tag == 'path' and not fg_color:
+ fg_color = child.get('stroke')
+
+ fg_hex = parse_hex_color(fg_color) if fg_color else None
+ bg_hex = parse_hex_color(bg_color) if bg_color else None
+ if not fg_hex:
+ return ''
+
+ alpha_xml = ''
+ if opacity is not None and opacity < 1.0:
+ alpha_xml = f'<a:alpha val="{int(opacity * 100000)}"/>'
+
+ fg_xml = f'<a:srgbClr val="{fg_hex}">{alpha_xml}</a:srgbClr>'
+ if bg_hex:
+ bg_xml = f'<a:srgbClr val="{bg_hex}"/>'
+ else:
+ bg_xml = '<a:srgbClr val="FFFFFF"/>'
+
+ return (
+ f'<a:pattFill prst="{prst}">'
+ f'<a:fgClr>{fg_xml}</a:fgClr>'
+ f'<a:bgClr>{bg_xml}</a:bgClr>'
+ f'</a:pattFill>'
+ )
+
+
# ---------------------------------------------------------------------------
# Marker (arrow-head) support
# ---------------------------------------------------------------------------