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

fix(pptx-to-svg): constrain gradient tile rectangles

hugohe334463de80d74
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index b31c384a..295a2974 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -774,6 +774,10 @@ Project SVG has no gradient-tile flip mapping. Imported `a:gradFill@flip` may
therefore be omitted for the documented Office `none` baseline or be exactly
`none`; `x`, `y`, `xy`, malformed, and unknown values stop import instead of
becoming an ordinary unflipped gradient.
+An imported `a:tileRect` may be absent or occur once as an empty/full-area
+relative rectangle. Explicit `l/t/r/b` values use strict DrawingML percentage
+syntax and must resolve to zero. Duplicate or malformed rectangles and non-zero
+tile offsets stop import because project SVG has no gradient tiling model.
The quality checker and exporter preflight both validate definition location,
references, gradient structure, and paint context from the same closed contract.
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 b1c6449d..f5e32a45 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
@@ -15,6 +15,7 @@ from __future__ import annotations
import math
import re
from dataclasses import dataclass, field
+from decimal import Decimal
from xml.etree import ElementTree as ET
from .color_resolver import ColorPalette, find_color_elem, resolve_color
@@ -29,7 +30,12 @@ from .emu_units import (
_OOXML_INTEGER_RE = re.compile(r"[+-]?[0-9]+")
+_OOXML_PERCENT_LITERAL_RE = re.compile(
+ r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)%"
+)
_OOXML_FULL_CIRCLE = 360 * ANGLE_UNIT
+_OOXML_PERCENTAGE_MIN = Decimal(-(2**31)) / Decimal(PERCENT_UNIT)
+_OOXML_PERCENTAGE_MAX = Decimal(2**31 - 1) / Decimal(PERCENT_UNIT)
@dataclass
@@ -121,6 +127,7 @@ def _resolve_grad_fill(elem: ET.Element, palette: ColorPalette | None,
"""Convert <a:gradFill> to an SVG linearGradient or radialGradient."""
_validate_gradient_rotation(elem)
_validate_gradient_flip(elem)
+ _validate_gradient_tile_rect(elem)
if seq is None:
seq = [0]
seq[0] += 1
@@ -281,6 +288,48 @@ def _validate_gradient_flip(gradient: ET.Element) -> None:
raise ValueError(f"Unsupported DrawingML gradient flip: {flip!r}")
+def _validate_gradient_tile_rect(gradient: ET.Element) -> None:
+ """Accept only the full-area gradient tile rectangle."""
+ tile_rects = gradient.findall("a:tileRect", NS)
+ if len(tile_rects) > 1:
+ raise ValueError(
+ "DrawingML gradient fill must contain at most one tileRect"
+ )
+ if not tile_rects:
+ return
+ tile_rect = tile_rects[0]
+ if (
+ set(tile_rect.attrib) - {"l", "t", "r", "b"}
+ or list(tile_rect)
+ or (tile_rect.text or "").strip()
+ ):
+ raise ValueError("Invalid DrawingML gradient tileRect structure")
+ for edge, raw in tile_rect.attrib.items():
+ value = _parse_ooxml_percentage(
+ raw,
+ label=f"gradient tileRect {edge}",
+ )
+ if value != 0:
+ raise ValueError(
+ "Non-zero DrawingML gradient tileRect is not representable "
+ "by the project SVG gradient mapping"
+ )
+
+
+def _parse_ooxml_percentage(raw: str, *, label: str) -> Decimal:
+ """Parse one DrawingML ST_Percentage as an exact normalized ratio."""
+ token = raw.strip()
+ if _OOXML_INTEGER_RE.fullmatch(token) is not None:
+ value = Decimal(token) / Decimal(PERCENT_UNIT)
+ elif _OOXML_PERCENT_LITERAL_RE.fullmatch(token) is not None:
+ value = Decimal(token[:-1]) / Decimal(100)
+ else:
+ raise ValueError(f"Invalid DrawingML {label}: {raw!r}")
+ if not _OOXML_PERCENTAGE_MIN <= value <= _OOXML_PERCENTAGE_MAX:
+ raise ValueError(f"Invalid DrawingML {label}: {raw!r}")
+ return value
+
+
def _parse_ooxml_boolean(
raw: str | None,
*,
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index de361ee2..b926a280 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -3102,6 +3102,63 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
):
resolve_flip(flip)
+ def test_native_gradient_tile_rect_must_cover_full_area(self):
+ def resolve_tile_rect(tile_rect: str):
+ sp_pr = ET.fromstring(f'''
+<p:spPr xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
+ <a:gradFill>
+ <a:gsLst>
+ <a:gs pos="0"><a:srgbClr val="112233"/></a:gs>
+ </a:gsLst>
+ {tile_rect}
+ </a:gradFill>
+</p:spPr>''')
+ return resolve_fill(sp_pr, None)
+
+ valid_rects = (
+ '',
+ '<a:tileRect/>',
+ '<a:tileRect l="0" t="+0" r="-0" b="0.0%"/>',
+ )
+ for tile_rect in valid_rects:
+ with self.subTest(valid_tile_rect=tile_rect):
+ self.assertTrue(resolve_tile_rect(tile_rect).defs)
+
+ for tile_rect in (
+ '<a:tileRect l="1"/>',
+ '<a:tileRect t="-1"/>',
+ '<a:tileRect r="1%"/>',
+ ):
+ with self.subTest(nonzero_tile_rect=tile_rect):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Non-zero DrawingML gradient tileRect',
+ ):
+ resolve_tile_rect(tile_rect)
+
+ for raw in ('', 'NaN', '1e2', '0px', '2147483648'):
+ with self.subTest(invalid_tile_rect_value=raw):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'Invalid DrawingML gradient tileRect l',
+ ):
+ resolve_tile_rect(f'<a:tileRect l="{raw}"/>')
+
+ invalid_structures = (
+ '<a:tileRect/><a:tileRect/>',
+ '<a:tileRect future="0"/>',
+ '<a:tileRect><a:ext/></a:tileRect>',
+ '<a:tileRect>payload</a:tileRect>',
+ )
+ for tile_rect in invalid_structures:
+ with self.subTest(invalid_tile_rect=tile_rect):
+ with self.assertRaisesRegex(
+ ValueError,
+ 'tileRect',
+ ):
+ resolve_tile_rect(tile_rect)
+
def test_compound_native_line_is_rejected_on_import(self):
for compound in ('dbl', 'thickThin', 'thinThick', 'tri'):
with self.subTest(compound=compound):