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): close the color modifier contract

hugohe38c6322dc1ef4
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 55794c34..4b945cd2 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -772,6 +772,26 @@ percentage-literal, or out-of-range channels, extra attributes, namespace
aliases, and interleaved text stop import instead of receiving zero defaults or
being clamped into another color. This route is `Native-normalized` because the
SVG retains the displayed sRGB color rather than the source color-space model.
+Imported base colors apply only the following DrawingML modifier subset, in
+document order:
+
+| Modifier | Registered integer contract |
+|---|---|
+| `tint`, `shade`, `alpha` | `0..100000` fixed percentage |
+| `alphaMod`, `hueMod` | `0..2147483647` positive percentage |
+| `alphaOff` | `-100000..100000` fixed offset |
+| `lumMod`, `lumOff`, `satMod`, `satOff` | signed 32-bit percentage |
+| `hueOff` | signed 32-bit angle in 1/60000 degree |
+| `comp`, `gray`, `inv` | empty flag element |
+
+Value modifiers are exact DrawingML-namespace leaves with only a required
+integer `val`; flag modifiers are empty leaves with no attributes. Missing,
+malformed, percentage-literal, or out-of-range values, extra attributes, nested
+payload, foreign-namespace aliases, and unsupported transforms such as
+`gamma`, `invGamma`, or direct RGB-channel transforms stop import. They are
+never ignored or treated as zero. Luminance, saturation, hue, and alpha results
+retain the existing registered normalization and saturation behavior after each
+modifier.
---
diff --git a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
index a3df44d3..8c3b6436 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/color_resolver.py
@@ -1,8 +1,8 @@
"""DrawingML color resolution.
Resolves any of the 6 OOXML color types (srgbClr, schemeClr, sysClr, prstClr,
-hslClr, scrgbClr) plus modifiers (tint/shade/lumMod/lumOff/satMod/satOff/
-hueMod/hueOff/alpha) into an (#RRGGBB, alpha) pair.
+hslClr, scrgbClr) plus the registered luminance, saturation, hue, alpha,
+grayscale, complement, and inverse modifiers into an (#RRGGBB, alpha) pair.
Theme palette is resolved from the slide master's a:clrMap and theme1.xml's
a:clrScheme.
@@ -14,7 +14,7 @@ import colorsys
import re
from xml.etree import ElementTree as ET
-from .emu_units import NS, percent_to_ratio
+from .emu_units import NS
from .ooxml_loader import PartRef
@@ -103,6 +103,21 @@ SCHEME_ALIASES = {
}
_SRGB_HEX_RE = re.compile(r"[0-9A-Fa-f]{6}")
_OOXML_INTEGER_RE = re.compile(r"[+-]?[0-9]+")
+_OOXML_INT_MIN = -(2**31)
+_OOXML_INT_MAX = 2**31 - 1
+_COLOR_MODIFIER_PERCENT_RANGES = {
+ "alpha": (0, 100000),
+ "alphaMod": (0, _OOXML_INT_MAX),
+ "alphaOff": (-100000, 100000),
+ "hueMod": (0, _OOXML_INT_MAX),
+ "lumMod": (_OOXML_INT_MIN, _OOXML_INT_MAX),
+ "lumOff": (_OOXML_INT_MIN, _OOXML_INT_MAX),
+ "satMod": (_OOXML_INT_MIN, _OOXML_INT_MAX),
+ "satOff": (_OOXML_INT_MIN, _OOXML_INT_MAX),
+ "shade": (0, 100000),
+ "tint": (0, 100000),
+}
+_COLOR_MODIFIER_FLAG_NAMES = frozenset({"comp", "gray", "inv"})
_SCHEME_COLOR_VALUES = {
"bg1",
"tx1",
@@ -471,10 +486,42 @@ def _bounded_integer_attribute(
return value
+def _parse_color_modifier(child: ET.Element) -> tuple[str, int | None]:
+ """Parse one modifier from the closed DrawingML color subset."""
+ tag = child.tag.split("}", 1)[-1]
+ if child.tag != f"{{{NS['a']}}}{tag}":
+ raise ValueError(f"invalid-color-modifier-namespace:{tag}")
+ if tag in _COLOR_MODIFIER_FLAG_NAMES:
+ if child.attrib or list(child) or (child.text or "").strip():
+ raise ValueError(f"invalid-color-modifier-structure:{tag}")
+ return tag, None
+
+ bounds = _COLOR_MODIFIER_PERCENT_RANGES.get(tag)
+ if tag == "hueOff":
+ bounds = (_OOXML_INT_MIN, _OOXML_INT_MAX)
+ elif bounds is None:
+ raise ValueError(f"unsupported-color-modifier:{tag}")
+ if (
+ set(child.attrib) != {"val"}
+ or list(child)
+ or (child.text or "").strip()
+ ):
+ raise ValueError(f"invalid-color-modifier-structure:{tag}")
+ try:
+ value = _bounded_integer_attribute(
+ child,
+ "val",
+ minimum=bounds[0],
+ maximum=bounds[1],
+ label=f"{tag} color modifier",
+ )
+ except ValueError:
+ raise ValueError(f"invalid-{tag}-val:{child.attrib['val']!r}") from None
+ return tag, value
+
+
def _apply_modifiers(hex_color: str, color_elem: ET.Element) -> tuple[str, float]:
- """Apply tint / shade / lumMod / lumOff / satMod / hueMod / alpha modifiers
- in document order. DrawingML stacks these on the color in order.
- """
+ """Apply the registered DrawingML color modifiers in document order."""
r, g, b = _hex_to_rgb01(hex_color)
# Convert to HSL for luminance/saturation ops; convert back when emitting.
h, lum, sat = colorsys.rgb_to_hls(r, g, b)
@@ -483,40 +530,35 @@ def _apply_modifiers(hex_color: str, color_elem: ET.Element) -> tuple[str, float
for child in list(color_elem):
if not isinstance(child.tag, str):
continue
- tag = child.tag.split("}", 1)[-1]
- val_ratio = percent_to_ratio(child.attrib.get("val"), default=0.0)
+ tag, value = _parse_color_modifier(child)
if tag == "tint":
# Tint blends toward white. r' = r + (1-r)*(1-val) is the common
# interpretation; OOXML actually defines tint on luminance.
# Use luminance-based tint per ECMA-376.
- lum = lum * val_ratio + (1.0 - val_ratio)
+ ratio = value / 100000.0
+ lum = lum * ratio + (1.0 - ratio)
elif tag == "shade":
# Shade blends toward black on luminance.
- lum = lum * val_ratio
+ lum = lum * (value / 100000.0)
elif tag == "lumMod":
- lum = lum * val_ratio
+ lum = lum * (value / 100000.0)
elif tag == "lumOff":
- lum = lum + val_ratio
+ lum = lum + (value / 100000.0)
elif tag == "satMod":
- sat = sat * val_ratio
+ sat = sat * (value / 100000.0)
elif tag == "satOff":
- sat = sat + val_ratio
+ sat = sat + (value / 100000.0)
elif tag == "hueMod":
- h = (h * val_ratio) % 1.0
+ h = (h * (value / 100000.0)) % 1.0
elif tag == "hueOff":
- # hueOff is in 1/60000 deg
- try:
- deg = float(child.attrib.get("val", "0")) / 60000.0
- except ValueError:
- deg = 0.0
- h = (h + deg / 360.0) % 1.0
+ h = (h + value / 21_600_000.0) % 1.0
elif tag == "alpha":
- alpha = max(0.0, min(1.0, val_ratio))
+ alpha = value / 100000.0
elif tag == "alphaMod":
- alpha = max(0.0, min(1.0, alpha * val_ratio))
+ alpha = max(0.0, min(1.0, alpha * (value / 100000.0)))
elif tag == "alphaOff":
- alpha = max(0.0, min(1.0, alpha + val_ratio))
+ alpha = max(0.0, min(1.0, alpha + (value / 100000.0)))
elif tag == "gray":
# Convert to grayscale based on luminance.
sat = 0.0
diff --git a/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py b/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py
index ef53dd40..4b8c998d 100644
--- a/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py
+++ b/skills/ppt-master/scripts/pptx_to_svg/effect_to_svg.py
@@ -21,26 +21,9 @@ from .emu_units import NS, emu_to_px, fmt_num, format_ooxml_alpha
_OOXML_INTEGER_RE = re.compile(r"[+-]?\d+")
_OOXML_HEX_COLOR_RE = re.compile(r"[0-9A-Fa-f]{6}")
-_OOXML_INT_MIN = -(2**31)
-_OOXML_INT_MAX = 2**31 - 1
_DRAWINGML_NAMESPACE = NS["a"]
_DRAWINGML_TAG_PREFIX = f"{{{_DRAWINGML_NAMESPACE}}}"
_EFFECT_CONTAINER_NAMES = frozenset({"effectLst", "effectDag"})
-# Modulation/offset transforms use DrawingML percentage types, not all fixed
-# percentages; values above 100% such as satMod=175000 are valid.
-_COLOR_MODIFIER_PERCENT_RANGES = {
- "alpha": (0, 100000),
- "alphaMod": (0, _OOXML_INT_MAX),
- "alphaOff": (-100000, 100000),
- "hueMod": (0, _OOXML_INT_MAX),
- "lumMod": (_OOXML_INT_MIN, _OOXML_INT_MAX),
- "lumOff": (_OOXML_INT_MIN, _OOXML_INT_MAX),
- "satMod": (_OOXML_INT_MIN, _OOXML_INT_MAX),
- "satOff": (_OOXML_INT_MIN, _OOXML_INT_MAX),
- "shade": (0, 100000),
- "tint": (0, 100000),
-}
-_COLOR_MODIFIER_FLAG_NAMES = frozenset({"comp", "gray", "inv"})
@dataclass(frozen=True)
@@ -233,28 +216,6 @@ def _validate_color(
elif not (color.get("val") or "").strip():
raise ValueError(f"invalid-color:{color_name}")
- for modifier in color:
- if not isinstance(modifier.tag, str):
- continue
- modifier_name = _local_name(modifier)
- if not modifier.tag.startswith(_DRAWINGML_TAG_PREFIX):
- raise ValueError(
- f"invalid-color-modifier-namespace:{modifier_name}"
- )
- bounds = _COLOR_MODIFIER_PERCENT_RANGES.get(modifier_name)
- if bounds is not None:
- _required_integer(modifier, "val", *bounds)
- elif modifier_name == "hueOff":
- _required_integer(
- modifier,
- "val",
- _OOXML_INT_MIN,
- _OOXML_INT_MAX,
- )
- elif modifier_name not in _COLOR_MODIFIER_FLAG_NAMES:
- raise ValueError(f"unsupported-color-modifier:{modifier_name}")
-
-
def _required_integer(
elem: ET.Element,
attr: str,
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index 9ce199c9..aaa2e9c2 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -3251,6 +3251,86 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
</a:scrgbClr>''')
self.assertEqual(resolve_color(valid, None), ('#BCBCBC', 0.5))
+ def test_native_color_modifiers_use_closed_structure_and_ranges(self):
+ invalid_modifiers = (
+ ('<a:tint/>', 'invalid-color-modifier-structure:tint'),
+ ('<a:alpha val="bad"/>', 'invalid-alpha-val'),
+ ('<a:alpha val="100001"/>', 'invalid-alpha-val'),
+ ('<a:alphaMod val="-1"/>', 'invalid-alphaMod-val'),
+ ('<a:alphaOff val="-100001"/>', 'invalid-alphaOff-val'),
+ ('<a:tint val="50%"/>', 'invalid-tint-val'),
+ ('<a:lumMod val="2147483648"/>', 'invalid-lumMod-val'),
+ ('<a:hueOff val="-2147483649"/>', 'invalid-hueOff-val'),
+ (
+ '<a:shade val="50000" future="x"/>',
+ 'invalid-color-modifier-structure:shade',
+ ),
+ (
+ '<a:satMod val="50000"><a:future/></a:satMod>',
+ 'invalid-color-modifier-structure:satMod',
+ ),
+ (
+ '<a:comp val="50000"/>',
+ 'invalid-color-modifier-structure:comp',
+ ),
+ (
+ '<a:gray>payload</a:gray>',
+ 'invalid-color-modifier-structure:gray',
+ ),
+ (
+ '<future:tint xmlns:future="urn:future" val="50000"/>',
+ 'invalid-color-modifier-namespace:tint',
+ ),
+ ('<a:gamma/>', 'unsupported-color-modifier:gamma'),
+ ('<a:red val="50000"/>', 'unsupported-color-modifier:red'),
+ )
+ namespace = (
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"'
+ )
+ for modifier, expected in invalid_modifiers:
+ with self.subTest(modifier=modifier):
+ color = ET.fromstring(
+ f'<a:srgbClr {namespace} val="336699">'
+ f'{modifier}</a:srgbClr>'
+ )
+ with self.assertRaisesRegex(ValueError, expected):
+ resolve_color(color, None)
+
+ valid_modifiers = (
+ '<a:tint val="50000"/>',
+ '<a:shade val="50000"/>',
+ '<a:lumMod val="175000"/>',
+ '<a:lumOff val="-25000"/>',
+ '<a:satMod val="175000"/>',
+ '<a:satOff val="-25000"/>',
+ '<a:hueMod val="200000"/>',
+ '<a:hueOff val="-5400000"/>',
+ '<a:alpha val="50000"/>',
+ '<a:alphaMod val="200000"/>',
+ '<a:alphaOff val="-50000"/>',
+ '<a:gray/>',
+ '<a:comp/>',
+ '<a:inv/>',
+ )
+ for modifier in valid_modifiers:
+ with self.subTest(valid_modifier=modifier):
+ color = ET.fromstring(
+ f'<a:srgbClr {namespace} val="336699">'
+ f'{modifier}</a:srgbClr>'
+ )
+ resolved, alpha = resolve_color(color, None)
+ self.assertRegex(resolved, r'^#[0-9A-F]{6}$')
+ self.assertGreaterEqual(alpha, 0.0)
+ self.assertLessEqual(alpha, 1.0)
+
+ ordered_alpha = ET.fromstring(f'''
+<a:srgbClr {namespace} val="336699">
+ <a:alpha val="50000"/>
+ <a:alphaMod val="200000"/>
+ <a:alphaOff val="-25000"/>
+</a:srgbClr>''')
+ self.assertEqual(resolve_color(ordered_alpha, None)[1], 0.75)
+
def test_native_gradient_stop_position_round_trips(self):
for position in (0, 1, 7, 13, 33333, 99999, 100000):
with self.subTest(position=position):