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(svg-to-pptx): enforce the line-end marker contract

hugohe3f007245f9430
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index a9c6d072..ced6b0ee 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -174,8 +174,9 @@ when the referenced marker fits this native-arrow contract:
The converter maps the three shapes to DrawingML triangle, diamond, and oval
line ends. Prefer `<polygon>` for triangle/diamond markers because the vertex
-count is unambiguous. Other marker shapes do not have a native mapping and are
-dropped with a warning.
+count is unambiguous. Checker and exporter preflight consume this same contract;
+other marker shapes have no native mapping and block export instead of being
+silently dropped.
---
diff --git a/skills/ppt-master/scripts/svg_quality_checker.py b/skills/ppt-master/scripts/svg_quality_checker.py
index 96a5f94c..6ea171c9 100644
--- a/skills/ppt-master/scripts/svg_quality_checker.py
+++ b/skills/ppt-master/scripts/svg_quality_checker.py
@@ -114,6 +114,7 @@ try:
project_filter_errors as _project_filter_errors,
project_gradient_errors as _project_gradient_errors,
project_image_aspect_ratio_errors as _project_image_aspect_ratio_errors,
+ project_marker_errors as _project_marker_errors,
project_opacity_errors as _project_opacity_errors,
project_paint_errors as _project_paint_errors,
project_paint_reference_errors as _project_paint_reference_errors,
@@ -164,6 +165,7 @@ except ImportError:
_project_filter_errors = None
_project_gradient_errors = None
_project_image_aspect_ratio_errors = None
+ _project_marker_errors = None
_project_opacity_errors = None
_project_paint_errors = None
_project_paint_reference_errors = None
@@ -472,18 +474,6 @@ _BAKE_REQUIRED_VISUAL_PROPERTIES = frozenset({
'isolation',
'mix-blend-mode',
})
-_NUMBER_TOKEN = r'[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?'
-_POINT_TOKEN = rf'{_NUMBER_TOKEN}(?:\s*,\s*|\s+){_NUMBER_TOKEN}'
-_MARKER_TRIANGLE_PATH_RE = re.compile(
- rf'^\s*M\s*{_POINT_TOKEN}(?:\s*L\s*{_POINT_TOKEN}){{2}}\s*Z\s*$',
- re.IGNORECASE,
-)
-_MARKER_DIAMOND_PATH_RE = re.compile(
- rf'^\s*M\s*{_POINT_TOKEN}(?:\s*L\s*{_POINT_TOKEN}){{3}}\s*Z\s*$',
- re.IGNORECASE,
-)
-
-
def _compact_preset_ancestor_paint(
root: ET.Element,
) -> list[tuple[str, tuple[str, ...]]]:
@@ -978,20 +968,6 @@ def _element_label(elem: ET.Element) -> str:
return f'<{tag} id="{elem_id}">' if elem_id else f'<{tag}>'
-def _marker_polygon_vertex_count(raw: str) -> int | None:
- """Return the number of finite polygon vertices, or ``None``."""
- tokens = [token for token in re.split(r'[\s,]+', raw.strip()) if token]
- if not tokens or len(tokens) % 2:
- return None
- try:
- values = [float(token) for token in tokens]
- except ValueError:
- return None
- if not all(math.isfinite(value) for value in values):
- return None
- return len(values) // 2
-
-
def _effective_presentation_value(
elem: ET.Element,
name: str,
@@ -1868,136 +1844,13 @@ class SVGQualityChecker:
result: Dict,
) -> None:
"""Validate marker references against the native line-end contract."""
- definitions, _duplicates = _direct_defs_index(root)
- parent_by_id = {
- id(child): parent
- for parent in root.iter()
- for child in list(parent)
- }
- issues: set[str] = set()
- checked_markers: set[str] = set()
-
- for elem in root.iter():
- for attr in ('marker-start', 'marker-end'):
- raw_ref = elem.get(attr)
- if raw_ref is None or raw_ref.strip().lower() == 'none':
- continue
- label = _element_label(elem)
- tag = _local_name(elem).lower()
- if tag not in {'line', 'path'}:
- issues.add(
- f"{label} {attr} is allowed only on <line> or <path>"
- )
- match = re.fullmatch(r'url\(#([^)]+)\)', raw_ref.strip())
- if match is None:
- issues.add(
- f"{label} {attr} must be an exact local url(#id) reference; "
- f"got {raw_ref!r}"
- )
- continue
- marker_id = match.group(1)
- marker = definitions.get(marker_id)
- if marker is None or _local_name(marker) != 'marker':
- issues.add(
- f"{label} {attr}=url(#{marker_id}) has no matching direct "
- f"<defs><marker id=\"{marker_id}\"> definition"
- )
- continue
-
- visual_children = [
- child for child in list(marker)
- if _local_name(child) not in _NON_VISUAL_SVG_TAGS
- ]
- shape = visual_children[0] if len(visual_children) == 1 else None
- if marker_id not in checked_markers:
- checked_markers.add(marker_id)
- marker_label = f'<marker id="{marker_id}">'
- if marker.get('orient') not in {
- 'auto',
- 'auto-start-reverse',
- }:
- issues.add(
- f'{marker_label} requires orient="auto" or '
- 'orient="auto-start-reverse"'
- )
- marker_units = marker.get('markerUnits', 'strokeWidth')
- if marker_units not in {'strokeWidth', 'userSpaceOnUse'}:
- issues.add(
- f"{marker_label} has unsupported markerUnits={marker_units!r}"
- )
- for size_attr in ('markerWidth', 'markerHeight'):
- raw_size = marker.get(size_attr)
- if raw_size is None:
- continue
- try:
- size = float(raw_size)
- except ValueError:
- size = math.nan
- if not math.isfinite(size) or size <= 0:
- issues.add(
- f"{marker_label} {size_attr} must be a positive "
- f"finite number; got {raw_size!r}"
- )
- if shape is None:
- issues.add(
- f"{marker_label} must contain exactly one direct "
- "triangle/diamond path or polygon, circle, or ellipse"
- )
- else:
- shape_tag = _local_name(shape).lower()
- if shape.get('transform'):
- issues.add(
- f"{marker_label} child <{shape_tag}> cannot use transform"
- )
- if shape_tag == 'path':
- path_data = shape.get('d', '')
- if not (
- _MARKER_TRIANGLE_PATH_RE.fullmatch(path_data)
- or _MARKER_DIAMOND_PATH_RE.fullmatch(path_data)
- ):
- issues.add(
- f"{marker_label} path must be a closed 3- or "
- "4-vertex path with one explicit M/L command "
- "per vertex"
- )
- elif shape_tag == 'polygon':
- vertex_count = _marker_polygon_vertex_count(
- shape.get('points', '')
- )
- if vertex_count not in {3, 4}:
- issues.add(
- f"{marker_label} polygon must contain exactly "
- "3 or 4 finite vertices"
- )
- elif shape_tag not in {'circle', 'ellipse'}:
- issues.add(
- f"{marker_label} child <{shape_tag}> has no native "
- "line-end mapping"
- )
-
- if shape is None or _parse_export_color is None:
- continue
- stroke_value = _effective_presentation_value(
- elem, 'stroke', parent_by_id,
- )
- marker_fill = _effective_presentation_value(
- shape, 'fill', parent_by_id,
- ) or '#000000'
- stroke_color, _stroke_alpha = _parse_export_color(stroke_value or '')
- fill_color, _fill_alpha = _parse_export_color(marker_fill)
- if stroke_color is None or fill_color is None:
- issues.add(
- f"{label} {attr} marker fill and line stroke must both be "
- "supported solid colors"
- )
- elif stroke_color != fill_color:
- issues.add(
- f"{label} {attr}=url(#{marker_id}) marker fill "
- f"{marker_fill!r} does not match effective line stroke "
- f"{stroke_value!r}"
- )
-
- result['errors'].extend(sorted(issues))
+ if _project_marker_errors is None:
+ result['warnings'].append(
+ 'Unable to import the shared marker validator; native export '
+ 'will still validate line-end markers.'
+ )
+ return
+ result['errors'].extend(_project_marker_errors(root))
def _check_clip_path_contract(
self,
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 4435785e..3bc9be2e 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
@@ -52,6 +52,7 @@ from .utils import (
project_geometry_length_errors,
project_gradient_errors,
project_image_aspect_ratio_errors,
+ project_marker_errors,
project_opacity_errors,
project_paint_errors,
project_paint_reference_errors,
@@ -307,6 +308,22 @@ def _require_project_paint_references(
)
+def _require_project_line_end_markers(
+ root: ET.Element,
+ svg_path: Path | str,
+) -> None:
+ """Reject markers outside the native line-end contract."""
+ errors = project_marker_errors(root)
+ if not errors:
+ return
+ preview = '; '.join(errors[:8])
+ suffix = '' if len(errors) <= 8 else f'; +{len(errors) - 8} more'
+ raise SvgNativeConversionError(
+ f'{Path(svg_path).name}: invalid project line-end marker(s): '
+ f'{preview}{suffix}'
+ )
+
+
def _require_project_gradients(
root: ET.Element,
svg_path: Path | str,
@@ -1448,6 +1465,7 @@ def convert_svg_to_slide_shapes(
_require_project_paints(root, svg_path)
_require_project_definitions(root, svg_path)
_require_project_paint_references(root, svg_path)
+ _require_project_line_end_markers(root, svg_path)
_require_project_gradients(root, svg_path)
_require_project_effect_status(root, svg_path)
_require_project_filters(root, svg_path)
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index 3cef7d2d..b7343c55 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -213,6 +213,23 @@ PROJECT_FILTER_EFFECT_PRIMITIVES = frozenset({
'feGaussianBlur',
})
PROJECT_FILTER_PUBLIC_TARGETS = frozenset({'rect', 'circle', 'path', 'text'})
+_PROJECT_MARKER_NUMBER_TOKEN = (
+ r'[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?'
+)
+_PROJECT_MARKER_POINT_TOKEN = (
+ rf'{_PROJECT_MARKER_NUMBER_TOKEN}'
+ rf'(?:\s*,\s*|\s+){_PROJECT_MARKER_NUMBER_TOKEN}'
+)
+_PROJECT_MARKER_TRIANGLE_PATH_RE = re.compile(
+ rf'^\s*M\s*{_PROJECT_MARKER_POINT_TOKEN}'
+ rf'(?:\s*L\s*{_PROJECT_MARKER_POINT_TOKEN}){{2}}\s*Z\s*$',
+ re.IGNORECASE,
+)
+_PROJECT_MARKER_DIAMOND_PATH_RE = re.compile(
+ rf'^\s*M\s*{_PROJECT_MARKER_POINT_TOKEN}'
+ rf'(?:\s*L\s*{_PROJECT_MARKER_POINT_TOKEN}){{3}}\s*Z\s*$',
+ re.IGNORECASE,
+)
PROJECT_NON_VISUAL_DEFINITION_CHILD_TAGS = frozenset({
'defs',
'desc',
@@ -1733,6 +1750,192 @@ def project_definition_errors(root: ET.Element) -> list[str]:
return sorted(errors)
+def _project_marker_polygon_vertex_count(raw: str) -> int | None:
+ """Return the number of finite marker polygon vertices, or ``None``."""
+ tokens = [token for token in re.split(r'[\s,]+', raw.strip()) if token]
+ if not tokens or len(tokens) % 2:
+ return None
+ try:
+ values = [float(token) for token in tokens]
+ except ValueError:
+ return None
+ if not all(math.isfinite(value) for value in values):
+ return None
+ return len(values) // 2
+
+
+def _project_effective_presentation_value(
+ elem: ET.Element,
+ name: str,
+ parent_by_id: dict[int, ET.Element],
+) -> str | None:
+ """Resolve one inherited presentation value for project validation."""
+ current: ET.Element | None = elem
+ while current is not None:
+ style_values = parse_inline_style(current.get('style'))
+ if name in style_values:
+ return style_values[name]
+ direct = current.get(name)
+ if direct is not None:
+ return direct
+ current = parent_by_id.get(id(current))
+ return None
+
+
+def project_marker_errors(root: ET.Element) -> list[str]:
+ """Validate SVG line-end markers against the native arrow contract."""
+ definitions, _duplicates = project_definition_index(root)
+ parent_by_id = {
+ id(child): parent
+ for parent in root.iter()
+ for child in list(parent)
+ }
+ errors: set[str] = set()
+ checked_markers: set[str] = set()
+
+ for elem in root.iter():
+ for attribute_name in ('marker-start', 'marker-end'):
+ raw_reference = elem.get(attribute_name)
+ if (
+ raw_reference is None
+ or raw_reference.strip().lower() == 'none'
+ ):
+ continue
+
+ label = _transform_element_label(elem)
+ tag = (_svg_element_tag(elem) or '').lower()
+ if tag not in {'line', 'path'}:
+ errors.add(
+ f'{label} {attribute_name} is allowed only on <line> '
+ 'or <path>'
+ )
+
+ match = re.fullmatch(r'url\(#([^)]+)\)', raw_reference.strip())
+ if match is None:
+ errors.add(
+ f'{label} {attribute_name} must be an exact local '
+ f'url(#id) reference; got {raw_reference!r}'
+ )
+ continue
+
+ marker_id = match.group(1)
+ marker = definitions.get(marker_id)
+ if marker is None or _svg_element_tag(marker) != 'marker':
+ errors.add(
+ f'{label} {attribute_name}=url(#{marker_id}) has no '
+ f'matching direct <defs><marker id="{marker_id}"> '
+ 'definition'
+ )
+ continue
+
+ visual_children = [
+ child
+ for child in list(marker)
+ if _svg_element_tag(child)
+ not in PROJECT_NON_VISUAL_DEFINITION_CHILD_TAGS
+ ]
+ shape = visual_children[0] if len(visual_children) == 1 else None
+ if marker_id not in checked_markers:
+ checked_markers.add(marker_id)
+ marker_label = f'<marker id="{marker_id}">'
+ if marker.get('orient') not in {
+ 'auto',
+ 'auto-start-reverse',
+ }:
+ errors.add(
+ f'{marker_label} requires orient="auto" or '
+ 'orient="auto-start-reverse"'
+ )
+ marker_units = marker.get('markerUnits', 'strokeWidth')
+ if marker_units not in {'strokeWidth', 'userSpaceOnUse'}:
+ errors.add(
+ f'{marker_label} has unsupported '
+ f'markerUnits={marker_units!r}'
+ )
+ for size_attribute in ('markerWidth', 'markerHeight'):
+ raw_size = marker.get(size_attribute)
+ if raw_size is None:
+ continue
+ try:
+ size = float(raw_size)
+ except ValueError:
+ size = math.nan
+ if not math.isfinite(size) or size <= 0:
+ errors.add(
+ f'{marker_label} {size_attribute} must be a '
+ f'positive finite number; got {raw_size!r}'
+ )
+
+ if shape is None:
+ errors.add(
+ f'{marker_label} must contain exactly one direct '
+ 'triangle/diamond path or polygon, circle, or ellipse'
+ )
+ else:
+ shape_tag = (_svg_element_tag(shape) or '').lower()
+ if shape.get('transform'):
+ errors.add(
+ f'{marker_label} child <{shape_tag}> cannot use '
+ 'transform'
+ )
+ if shape_tag == 'path':
+ path_data = shape.get('d', '')
+ if not (
+ _PROJECT_MARKER_TRIANGLE_PATH_RE.fullmatch(path_data)
+ or _PROJECT_MARKER_DIAMOND_PATH_RE.fullmatch(path_data)
+ ):
+ errors.add(
+ f'{marker_label} path must be a closed 3- or '
+ '4-vertex path with one explicit M/L command '
+ 'per vertex'
+ )
+ elif shape_tag == 'polygon':
+ vertex_count = _project_marker_polygon_vertex_count(
+ shape.get('points', '')
+ )
+ if vertex_count not in {3, 4}:
+ errors.add(
+ f'{marker_label} polygon must contain exactly '
+ '3 or 4 finite vertices'
+ )
+ elif shape_tag not in {'circle', 'ellipse'}:
+ errors.add(
+ f'{marker_label} child <{shape_tag}> has no native '
+ 'line-end mapping'
+ )
+
+ if shape is None:
+ continue
+ stroke_value = _project_effective_presentation_value(
+ elem,
+ 'stroke',
+ parent_by_id,
+ )
+ marker_fill = (
+ _project_effective_presentation_value(
+ shape,
+ 'fill',
+ parent_by_id,
+ )
+ or '#000000'
+ )
+ stroke_color, _stroke_alpha = parse_svg_color(stroke_value or '')
+ fill_color, _fill_alpha = parse_svg_color(marker_fill)
+ if stroke_color is None or fill_color is None:
+ errors.add(
+ f'{label} {attribute_name} marker fill and line stroke '
+ 'must both be supported solid colors'
+ )
+ elif stroke_color != fill_color:
+ errors.add(
+ f'{label} {attribute_name}=url(#{marker_id}) marker fill '
+ f'{marker_fill!r} does not match effective line stroke '
+ f'{stroke_value!r}'
+ )
+
+ return sorted(errors)
+
+
def project_paint_reference_errors(root: ET.Element) -> list[str]:
"""Validate local paint-server references and their native contexts."""
definitions, _duplicates = project_definition_index(root)
diff --git a/skills/ppt-master/scripts/test_svg_quality_checker.py b/skills/ppt-master/scripts/test_svg_quality_checker.py
index b7ce620c..862d3436 100644
--- a/skills/ppt-master/scripts/test_svg_quality_checker.py
+++ b/skills/ppt-master/scripts/test_svg_quality_checker.py
@@ -2568,6 +2568,22 @@ class SVGQualityCheckerCompatibilityTests(unittest.TestCase):
slide_xml,
)
+ def test_invalid_line_end_marker_blocks_checker_and_exporter(self):
+ self._assert_checker_and_exporter_reject(
+ '''<svg xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 1280 720">
+ <defs>
+ <marker id="broken" orient="0">
+ <path d="M 0 0 L 10 5 L 0 10" fill="#112233"/>
+ </marker>
+ </defs>
+ <line x1="80" y1="80" x2="300" y2="80" stroke="#112233"
+ marker-end="url(#broken)"/>
+</svg>''',
+ '<marker id="broken"> requires orient="auto"',
+ 'invalid project line-end marker',
+ )
+
def test_invalid_filter_contract_blocks_checker_and_exporter(self):
self._assert_checker_and_exporter_reject(
'''<svg xmlns="http://www.w3.org/2000/svg"