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 closed line-style contracts
hugohe323a2731c3cc7
diff --git a/docs/powerpoint-svg-mapping.md b/docs/powerpoint-svg-mapping.mdindex 73709928..6cca885d 100644--- a/docs/powerpoint-svg-mapping.md+++ b/docs/powerpoint-svg-mapping.md@@ -146,6 +146,7 @@ Preset-shape selection and its exact atomic fragment contract are documented in| Pattern fill | Annotated project pattern definition | Native `a:pattFill` | `Native-normalized` | Only registered PowerPoint preset patterns are supported || No outline | `stroke="none"` or the registered absence of a line | `a:noFill` under `a:ln` | `Native-stable` | Do not simulate absence with zero-width ambiguous CSS || Solid outline | Registered `stroke` and width | Native `a:ln` | `Native-stable` | Width and paint must use canonical units/grammar |+| Outline scaling under transforms | Exact `vector-effect="none"` or `vector-effect="non-scaling-stroke"` | Choice resolved into native line width | `Native-normalized` | Other values are rejected; generated spelling is exact and lowercase || Dashed or dotted outline | Registered dash array | Preset or custom DrawingML dash | `Native-normalized` | Unsupported dash semantics are rejected || Line cap and join | Registered cap/join values | Native line cap/join properties | `Native-stable` | Only documented values are accepted || Line arrowheads | Registered start/end markers | Native head/tail end properties | `Approximate` for marker size | See the conditional marker contract |diff --git a/docs/zh/powerpoint-svg-mapping.md b/docs/zh/powerpoint-svg-mapping.mdindex 4c7e5bd2..ec30cb64 100644--- a/docs/zh/powerpoint-svg-mapping.md+++ b/docs/zh/powerpoint-svg-mapping.md@@ -146,6 +146,7 @@ preset 形状选择与精确原子片段合同见 [`native-shape-authoring.md`](| 图案填充 | 带注解的项目 pattern 定义 | 原生 `a:pattFill` | `Native-normalized` | 仅支持已登记 PowerPoint 预设 pattern || 无轮廓 | `stroke="none"` 或已登记线缺省 | `a:ln` 内的 `a:noFill` | `Native-stable` | 不得用零线宽模糊 CSS 模拟缺省 || 实线轮廓 | 已登记 `stroke` 与宽度 | 原生 `a:ln` | `Native-stable` | 宽度与 paint 必须使用规范单位/语法 |+| transform 下的轮廓缩放 | 精确的 `vector-effect="none"` 或 `vector-effect="non-scaling-stroke"` | 选择被解析为原生线宽 | `Native-normalized` | 拒绝其他取值;生成拼法必须精确且为小写 || 虚线或点线轮廓 | 已登记 dash array | 预设或自定义 DrawingML dash | `Native-normalized` | 拒绝不支持的 dash 语义 || 线端与连接样式 | 已登记 cap/join 值 | 原生 line cap/join 属性 | `Native-stable` | 仅接受文档化取值 || 线条箭头 | 已登记起点/终点 marker | 原生 head/tail end 属性 | marker 大小为 `Approximate` | 见条件 marker 合同 |diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.mdindex 07943229..5f3d8e95 100644--- a/skills/ppt-master/references/shared-standards.md+++ b/skills/ppt-master/references/shared-standards.md@@ -782,13 +782,29 @@ fidelity.| Surface | Contract / native result ||---|---|| Solid stroke/width/alpha | `Native-stable` editable line |-| `4,4`; `2,2`; `8,4`; `8,4,2,4` | `dash`; `sysDot`; `lgDash`; `lgDashDot` (`Native-normalized`) |-| Other custom dash | Exactly two positive finite unitless numbers (`dash gap`); export scales/quantizes against stroke width; longer arrays reduce to the first pair; `Native-normalized` |+| `4,4`; `6,3`; `2,2`; `8,4`; `8,4,2,4` (comma or space separators) | `dash`; `dash`; `sysDot`; `lgDash`; `lgDashDot` (`Native-normalized`) |+| Canonical custom dash | Exactly two positive finite unitless ordinary decimals (`dash gap`); export scales/quantizes against stroke width; `Native-normalized` |+| Compatible custom dash | Three or more positive finite unitless values are accepted but reduce to the first pair with a Checker recommendation; compatible numeric spellings also warn || `stroke-linecap` | `butt`, `round`, `square`; `Native-stable` || `stroke-linejoin` | `miter`, `round`, `bevel`; `Native-stable` |+| `vector-effect` | Exactly `none` or `non-scaling-stroke`; export resolves the choice into native line width (`Native-normalized`) |+| `stroke-dashoffset` | No general line mapping; allowed only as a direct finite unitless ordinary-decimal attribute on a §6.10 thick-circle shorthand (`px` suffix is compatible input and warns) || Gradient stroke | §6.3; re-import may flatten to first stop || `marker-start` / `marker-end` | §1.1 native line end; type `Native-normalized`, size `Approximate` (`sm/med/lg`) |+The dash grammar is closed: exact lowercase `none`, or at least two finite+unitless numbers separated by whitespace or one comma. Generated SVG uses+ordinary decimal spellings. A leading plus sign, exponent, trailing decimal+point, surrounding whitespace, or longer custom list is compatible input and+produces a non-blocking normalization recommendation. Unknown units, one-value+arrays, empty or repeated comma fields, non-finite values, and negative or zero+entries are errors. The only zero exception is a gap declared directly on the+§6.10 thick-circle element.++Generated cap, join, and `vector-effect` values use the exact lowercase tokens+in the table. Surrounding whitespace is compatible input and produces a+recommendation; every other token is an error.+Match marker fill to the parent stroke. Use markers for connectors and §6.10calculated geometry for a manual diagonal arrowhead. When exact grid spacingmatters, use one multi-subpath path rather than a fixed-density preset pattern:@@ -957,9 +973,11 @@ compound ring.- One circle per segment; `fill="none"`; the circle may use one `rotate` for itsstart angle, and ancestor transforms must be translate-only.-- Exactly two non-preset finite unitless values (`dash gap`); finite unitless `stroke-dashoffset`.+- Exactly two non-preset finite unitless ordinary-decimal values (`dash gap`);+ `stroke-dashoffset` is a direct finite unitless ordinary-decimal attribute.- `0 < stroke-width < 2r`, `stroke-width/r >= 0.15`,- `0 < dash < 2πr`, `gap >= 0`, and `dash + gap >= 2πr`.+ `0 < dash < 2πr`, `gap >= 0`, and `dash + gap >= 2πr - 1` SVG unit. The+ one-unit tolerance exists only for integer-rounded circumference values.- Native construction uses only the first dash and re-imports as a freeform.Its native start is 90° counterclockwise from the SVG preview; use explicitarcs whenever start angle, cap, or radial precision matters.diff --git a/skills/ppt-master/scripts/svg_quality_checker.py b/skills/ppt-master/scripts/svg_quality_checker.pyindex cda4371c..34671510 100644--- a/skills/ppt-master/scripts/svg_quality_checker.py+++ b/skills/ppt-master/scripts/svg_quality_checker.py@@ -61,15 +61,20 @@ try:font_px_to_hpt as _font_px_to_hpt,is_canonical_project_geometry_length as _is_canonical_project_geometry_length,iter_project_geometry_lengths as _iter_project_geometry_lengths,+ iter_project_stroke_styles as _iter_project_stroke_styles,iter_project_transforms as _iter_project_transforms,matrix_multiply as _matrix_multiply,+ noncanonical_stroke_dash_numbers as _noncanonical_stroke_dash_numbers,noncanonical_transform_numbers as _noncanonical_transform_numbers,parse_transform_matrix as _parse_transform_matrix,parse_font_family as _parse_export_font_family,parse_inline_style as _parse_inline_style,parse_project_geometry_length as _parse_project_geometry_length,+ parse_project_stroke_dasharray as _parse_project_stroke_dasharray,+ parse_project_stroke_enum as _parse_project_stroke_enum,parse_svg_color as _parse_export_color,parse_svg_length as _parse_export_length,+ project_stroke_style_errors as _project_stroke_style_errors,project_transform_errors as _project_transform_errors,rect_to_dml_xfrm as _rect_to_dml_xfrm,validate_dml_shape_matrix as _validate_dml_shape_matrix,@@ -82,15 +87,20 @@ except ImportError:_font_px_to_hpt = None_is_canonical_project_geometry_length = None_iter_project_geometry_lengths = None+ _iter_project_stroke_styles = None_iter_project_transforms = None_matrix_multiply = None+ _noncanonical_stroke_dash_numbers = None_noncanonical_transform_numbers = None_parse_transform_matrix = None_parse_export_font_family = None_parse_inline_style = None_parse_project_geometry_length = None+ _parse_project_stroke_dasharray = None+ _parse_project_stroke_enum = None_parse_export_color = None_parse_export_length = None+ _project_stroke_style_errors = None_project_transform_errors = None_rect_to_dml_xfrm = None_validate_dml_shape_matrix = None@@ -1084,13 +1094,16 @@ class SVGQualityChecker:# 2a. Validate direct geometry lengths and stroke widths.self._check_geometry_length_values(root, result)- # 2b. Validate complete path-data and point-list grammar.+ # 2b. Validate line-presentation grammar and mappings.+ self._check_stroke_style_values(root, result)++ # 2c. Validate complete path-data and point-list grammar.self._check_freeform_geometry_values(root, result)- # 2c. Validate complete transform grammar and native mappings.+ # 2d. Validate complete transform grammar and native mappings.self._check_transform_values(root, result)- # 2d. Validate the closed authoring-property surface and+ # 2e. Validate the closed authoring-property surface and# conditional definition interfaces before export.self._check_authoring_property_contract(root, result)self._check_paint_compatibility(root, result)@@ -1099,10 +1112,10 @@ class SVGQualityChecker:self._check_marker_contract(root, result)self._check_clip_path_contract(root, result)- # 2e. Validate the supported shadow/glow filter interface.+ # 2f. Validate the supported shadow/glow filter interface.self._check_filter_effects(root, result)- # 2f. Validate gradient definitions, stops, and coordinates.+ # 2g. Validate gradient definitions, stops, and coordinates.self._check_gradient_interfaces(root, result)# 3. Check font-size values@@ -2175,6 +2188,108 @@ class SVGQualityChecker:f'{attribute}="{normalized}". No change is required for export.')+ def _check_stroke_style_values(+ self,+ root: ET.Element,+ result: Dict,+ ) -> None:+ """Reject invalid line styles and advise project-canonical spellings."""+ helpers = (+ _format_project_geometry_length,+ _is_canonical_project_geometry_length,+ _iter_project_stroke_styles,+ _noncanonical_stroke_dash_numbers,+ _parse_project_geometry_length,+ _parse_project_stroke_dasharray,+ _parse_project_stroke_enum,+ _project_stroke_style_errors,+ )+ if any(helper is None for helper in helpers):+ result['warnings'].append(+ "Unable to import svg_to_pptx line-style validators; native "+ "export will still validate line-presentation syntax."+ )+ return++ result['errors'].extend(_project_stroke_style_errors(root))+ recommendations: Counter[tuple[str, str, str, str]] = Counter()+ examples: Dict[tuple[str, str, str, str], List[str]] = defaultdict(list)++ for elem, attribute, raw, source in _iter_project_stroke_styles(root):+ label = f'{_element_label(elem)} {source}'+ normalized = None+ reason = ''++ if attribute == 'stroke-dasharray':+ try:+ parsed = _parse_project_stroke_dasharray(+ raw,+ allow_zero_gap=True,+ )+ noncanonical = _noncanonical_stroke_dash_numbers(raw)+ except ValueError:+ continue+ if parsed is None:+ if raw != 'none':+ normalized = 'none'+ reason = 'remove surrounding whitespace'+ else:+ preset, values = parsed+ longer_custom = preset is None and len(values) > 2+ if noncanonical or longer_custom or raw != raw.strip():+ kept_values = values[:2] if longer_custom else values+ normalized = ' '.join(+ _format_project_geometry_length(value)+ for value in kept_values+ )+ reasons = []+ if noncanonical:+ reasons.append('use ordinary decimal numbers')+ if longer_custom:+ reasons.append(+ 'make the first-pair export normalization explicit'+ )+ if raw != raw.strip():+ reasons.append('remove surrounding whitespace')+ reason = '; '.join(reasons)+ elif attribute == 'stroke-dashoffset':+ try:+ value = _parse_project_geometry_length(raw, attribute)+ except ValueError:+ continue+ if not _is_canonical_project_geometry_length(raw):+ normalized = _format_project_geometry_length(value)+ reason = 'use the unitless px spelling'+ else:+ try:+ value = _parse_project_stroke_enum(attribute, raw)+ except ValueError:+ continue+ if raw != value:+ normalized = value+ reason = 'remove surrounding whitespace'++ if normalized is None:+ continue+ key = (attribute, raw, normalized, reason)+ recommendations[key] += 1+ if label not in examples[key] and len(examples[key]) < 3:+ examples[key].append(label)++ for (attribute, raw, normalized, reason), count in sorted(+ recommendations.items()+ ):+ shown_examples = ', '.join(+ examples[(attribute, raw, normalized, reason)]+ )+ result['warnings'].append(+ f"Recommendation: line style {attribute}={raw!r} is "+ f"converter-compatible in {count} location(s) "+ f"({shown_examples}); generated SVG should prefer "+ f'{attribute}="{normalized}" to {reason}. No change is '+ "required for export."+ )+def _check_freeform_geometry_values(self,root: ET.Element,diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.pyindex 3518e397..a7809dda 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py@@ -39,6 +39,7 @@ from .utils import (parse_transform_operations,parse_transform_matrix,project_geometry_length_errors,+ project_stroke_style_errors,project_transform_errors,resolve_url_id,supports_full_project_transform,@@ -99,6 +100,22 @@ def _require_project_transforms()+def _require_project_stroke_styles(+ root: ET.Element,+ svg_path: Path | str,+) -> None:+ """Reject invalid project line-style syntax and mappings before conversion."""+ errors = project_stroke_style_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 style(s): '+ f'{preview}{suffix}'+ )++# ---------------------------------------------------------------------------# Transform & layout helpers# ---------------------------------------------------------------------------@@ -1143,6 +1160,7 @@ def convert_svg_to_slide_shapes()_require_project_freeform_geometry(root, svg_path)+ _require_project_stroke_styles(root, svg_path)_require_project_transforms(root, svg_path)viewport_width, viewport_height = _root_viewport_size(root)@@ -1202,6 +1220,7 @@ def convert_svg_to_slide_shapes(print(f' Expanded {expanded_local} local <use href="#..."/> instance(s)')# Recheck compiler-injected icon/use wrappers and cloned definition trees.+ _require_project_stroke_styles(root, svg_path)_require_project_transforms(root, svg_path)# Flatten positional <tspan> (those with x/y/non-zero dy) into independentdiff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.pyindex 3f2bdba1..c9e57d5e 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py@@ -38,7 +38,8 @@ from .utils import (resolve_url_id, get_effective_filter_id,parse_inline_style, parse_font_family, is_cjk_char, estimate_text_width,detect_text_lang, font_px_to_hpt, resolve_text_run_fonts,- is_thick_circle_shorthand,+ is_thick_circle_shorthand, parse_project_geometry_length,+ parse_project_stroke_dasharray,matrix_multiply, parse_transform_matrix, parse_transform_operations,transform_point, _xml_escape,)@@ -1023,9 +1024,10 @@ def _is_donut_circle(elem: ET.Element, ctx: ConvertContext) -> bool:"""Detect if a circle uses stroke-dasharray to simulate an arc segment."""dasharray = _get_attr(elem, 'stroke-dasharray', ctx)stroke = _get_attr(elem, 'stroke', ctx)+ fill = _get_attr(elem, 'fill', ctx)sw = svg_length_size(_get_attr(elem, 'stroke-width', ctx), ctx, 0)r = svg_length_size(elem.get('r'), ctx, 0)- return is_thick_circle_shorthand(dasharray, stroke, sw, r)+ return is_thick_circle_shorthand(dasharray, stroke, fill, sw, r)def convert_circle(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:@@ -1041,9 +1043,22 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:# --- Donut-chart arc segment detection ---if preset_geom is None and _is_donut_circle(elem, ctx):dasharray = _get_attr(elem, 'stroke-dasharray', ctx)- dash_vals = re.split(r'[\s,]+', dasharray.strip())- dash_len = float(dash_vals[0]) if dash_vals else 0- dash_offset = svg_length_size(elem.get('stroke-dashoffset'), ctx, 0)+ parsed_dasharray = parse_project_stroke_dasharray(+ dasharray,+ allow_zero_gap=True,+ )+ if parsed_dasharray is None:+ raise ValueError('Thick-circle arc requires one dash/gap pair')+ _preset, dash_values = parsed_dasharray+ dash_len = dash_values[0]+ raw_dash_offset = elem.get('stroke-dashoffset')+ dash_offset = (+ parse_project_geometry_length(+ raw_dash_offset,+ 'stroke-dashoffset',+ )+ if raw_dash_offset is not None else 0.0+ )stroke_width = svg_length_size(_get_attr(elem, 'stroke-width', ctx), ctx, 1)rotate_deg = 0.0diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.pyindex fcb71f8b..661f2da0 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py@@ -11,10 +11,11 @@ from pptx_shapes import validate_ooxml_line_widthfrom .context import ConvertContextfrom .theme_colors import ThemeColorSpec, color_node_xmlfrom .utils import (- SVG_NS, ANGLE_UNIT, DASH_PRESETS,+ SVG_NS, ANGLE_UNIT,px_to_emu, _f, _get_attr, parse_svg_length,combine_opacity, parse_inline_style, parse_opacity, parse_stop_style,matrix_multiply, parse_svg_color, parse_transform_matrix, resolve_url_id,+ parse_project_stroke_dasharray, parse_project_stroke_enum,)@@ -447,8 +448,13 @@ def _emit_line_end(def _effective_stroke_scale(elem: ET.Element, ctx: ConvertContext) -> float:"""Approximate the effective SVG geometry transform as one line-width scale."""vector_effect = _get_attr(elem, 'vector-effect', ctx)- if vector_effect and vector_effect.strip().lower() == 'non-scaling-stroke':- return 1.0+ if vector_effect:+ vector_effect = parse_project_stroke_enum(+ 'vector-effect',+ vector_effect,+ )+ if vector_effect == 'non-scaling-stroke':+ return 1.0if ctx.use_transform_matrix:matrix = ctx.transform_matrix@@ -488,33 +494,38 @@ def build_stroke_xml(# Dash patterndash_xml = ''dasharray = _get_attr(elem, 'stroke-dasharray', ctx)- if dasharray and dasharray != 'none':- preset = DASH_PRESETS.get(dasharray.strip())- if preset:- dash_xml = f'<a:prstDash val="{preset}"/>'- else:- # Unknown pattern → build custDash proportional to stroke width- try:- parts = re.split(r'[\s,]+', dasharray.strip())- d_raw = float(parts[0])- sp_raw = float(parts[1]) if len(parts) > 1 else d_raw+ if dasharray:+ parsed_dasharray = parse_project_stroke_dasharray(dasharray)+ if parsed_dasharray is not None:+ preset, values = parsed_dasharray+ if preset:+ dash_xml = f'<a:prstDash val="{preset}"/>'+ else:+ # The project contract normalizes compatible longer arrays to+ # their first dash/gap pair before DrawingML quantization.+ d_raw, sp_raw = values[:2]sw = max(source_width, 0.001)- d_pct = int(d_raw / sw * 100000)- sp_pct = int(sp_raw / sw * 100000)- dash_xml = f'<a:custDash><a:ds d="{d_pct}" sp="{sp_pct}"/></a:custDash>'- except (ValueError, IndexError):- dash_xml = '<a:prstDash val="sysDash"/>'+ d_pct = max(1, round(d_raw / sw * 100000))+ sp_pct = max(1, round(sp_raw / sw * 100000))+ dash_xml = (+ '<a:custDash>'+ f'<a:ds d="{d_pct}" sp="{sp_pct}"/>'+ '</a:custDash>'+ )# Line capcap_map = {'round': 'rnd', 'square': 'sq', 'butt': 'flat'}cap_attr = ''linecap = _get_attr(elem, 'stroke-linecap', ctx)- if linecap and linecap in cap_map:+ if linecap:+ linecap = parse_project_stroke_enum('stroke-linecap', linecap)cap_attr = f' cap="{cap_map[linecap]}"'# Line joinjoin_xml = ''linejoin = _get_attr(elem, 'stroke-linejoin', ctx)+ if linejoin:+ linejoin = parse_project_stroke_enum('stroke-linejoin', linejoin)if linejoin == 'round':join_xml = '<a:round/>'elif linejoin == 'bevel':diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.pyindex acc0c0ec..882e2358 100644--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py@@ -1,7 +1,7 @@"""Coordinate, transform, color, and font helpers for DrawingML conversion.-See references/shared-standards.md §2.1 and §6.8 for project geometry and-transform authoring contracts.+See references/shared-standards.md §2.1, §6.6, and §6.8 for project geometry,+line-presentation, and transform authoring contracts."""from __future__ import annotations@@ -136,32 +136,20 @@ _SERIF_LATIN = {'Book Antiqua', 'Cambria', 'SimSun', 'Liberation Serif', 'DejaVu Serif',}-# SVG stroke-dasharray -> DrawingML prstDash+# Parsed SVG stroke-dasharray values -> DrawingML prstDashDASH_PRESETS = {- '4,4': 'dash', '4 4': 'dash',- '6,3': 'dash', '6 3': 'dash',- '2,2': 'sysDot', '2 2': 'sysDot',- '8,4': 'lgDash', '8 4': 'lgDash',- '8,4,2,4': 'lgDashDot', '8 4 2 4': 'lgDashDot',+ (4.0, 4.0): 'dash',+ (6.0, 3.0): 'dash',+ (2.0, 2.0): 'sysDot',+ (8.0, 4.0): 'lgDash',+ (8.0, 4.0, 2.0, 4.0): 'lgDashDot',}---def is_thick_circle_shorthand(- dasharray: str | None,- stroke: str | None,- stroke_width: float,- radius: float,-) -> bool:- """Return whether one circle uses the converter's thick-arc shorthand."""- if not dasharray or dasharray.strip().lower() == 'none':- return False- if not stroke or stroke.strip().lower() == 'none':- return False- if dasharray.strip() in DASH_PRESETS:- return False- if stroke_width <= 0 or radius <= 0:- return False- return stroke_width / radius >= 0.15+PROJECT_STROKE_ENUM_VALUES = {+ 'stroke-linecap': frozenset({'butt', 'round', 'square'}),+ 'stroke-linejoin': frozenset({'bevel', 'miter', 'round'}),+ 'vector-effect': frozenset({'none', 'non-scaling-stroke'}),+}+THICK_CIRCLE_COVERAGE_TOLERANCE = 1.0# ---------------------------------------------------------------------------@@ -208,6 +196,16 @@ _LENGTH_RE = re.compile(r'^\s*([-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?)\s*([A-_CANONICAL_PROJECT_GEOMETRY_LENGTH_RE = re.compile(r'^-?(?:\d+(?:\.\d+)?|\.\d+)$')+_PROJECT_STROKE_DASH_NUMBER_PATTERN = (+ r'[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?'+)+_PROJECT_STROKE_DASH_NUMBER_RE = re.compile(+ _PROJECT_STROKE_DASH_NUMBER_PATTERN+)+_PROJECT_STROKE_DASHARRAY_RE = re.compile(+ rf'\s*{_PROJECT_STROKE_DASH_NUMBER_PATTERN}'+ rf'(?:(?:\s+|\s*,\s*){_PROJECT_STROKE_DASH_NUMBER_PATTERN})+\s*'+)PROJECT_GEOMETRY_LENGTH_ATTRIBUTES = {'svg': frozenset({'x', 'y', 'width', 'height'}),'rect': frozenset({'x', 'y', 'width', 'height', 'rx', 'ry'}),@@ -317,6 +315,117 @@ def format_project_geometry_length(value: float) -> str:return '0' if text in {'', '-0'} else text+def _parse_project_stroke_dasharray(+ raw: str,+ *,+ allow_zero_gap: bool = False,+) -> tuple[str | None, tuple[float, ...], tuple[str, ...]] | None:+ """Parse one project dash array without accepting general SVG lengths."""+ text = raw.strip()+ if text == 'none':+ return None+ if not _PROJECT_STROKE_DASHARRAY_RE.fullmatch(text):+ raise ValueError(+ 'must be "none" or at least two finite unitless numbers separated '+ 'by spaces or single commas'+ )+ tokens = tuple(_PROJECT_STROKE_DASH_NUMBER_RE.findall(text))+ values = tuple(float(token) for token in tokens)+ if not all(math.isfinite(value) for value in values):+ raise ValueError('must contain only finite numbers')+ if values[0] <= 0:+ raise ValueError('dash length must be positive')+ if allow_zero_gap:+ if values[1] < 0:+ raise ValueError('dash gap must be non-negative')+ elif values[1] <= 0:+ raise ValueError('dash gap must be positive')+ if any(value <= 0 for value in values[2:]):+ raise ValueError('additional dash and gap values must be positive')+ return DASH_PRESETS.get(values), values, tokens+++def parse_project_stroke_dasharray(+ raw: str,+ *,+ allow_zero_gap: bool = False,+) -> tuple[str | None, tuple[float, ...]] | None:+ """Return the registered preset and numeric values for one dash array."""+ parsed = _parse_project_stroke_dasharray(+ raw,+ allow_zero_gap=allow_zero_gap,+ )+ if parsed is None:+ return None+ preset, values, _tokens = parsed+ return preset, values+++def noncanonical_stroke_dash_numbers(raw: str) -> tuple[str, ...]:+ """Return compatible dash numbers outside the generated-SVG spelling."""+ parsed = _parse_project_stroke_dasharray(raw, allow_zero_gap=True)+ if parsed is None:+ return ()+ _preset, _values, tokens = parsed+ return tuple(+ token+ for token in tokens+ if not _CANONICAL_PROJECT_GEOMETRY_LENGTH_RE.fullmatch(token)+ )+++def parse_project_stroke_enum(attribute: str, raw: str) -> str:+ """Parse one closed line-presentation enumeration."""+ allowed = PROJECT_STROKE_ENUM_VALUES.get(attribute)+ if allowed is None:+ raise ValueError(f'has no registered project enumeration for {attribute!r}')+ value = raw.strip()+ if value not in allowed:+ choices = ', '.join(sorted(allowed))+ raise ValueError(f'must be one of: {choices}')+ return value+++def is_thick_circle_shorthand(+ dasharray: str | None,+ stroke: str | None,+ fill: str | None,+ stroke_width: float,+ radius: float,+) -> bool:+ """Return whether one circle uses the converter's thick-arc shorthand."""+ if (+ not dasharray+ or not stroke+ or stroke.strip().lower() in {'none', 'transparent'}+ ):+ return False+ if not fill or fill.strip().lower() != 'none':+ return False+ if stroke_width <= 0 or radius <= 0 or stroke_width >= 2 * radius:+ return False+ if stroke_width / radius < 0.15:+ return False+ try:+ parsed = parse_project_stroke_dasharray(+ dasharray,+ allow_zero_gap=True,+ )+ except ValueError:+ return False+ if parsed is None:+ return False+ preset, values = parsed+ if preset is not None or len(values) != 2:+ return False+ dash, gap = values+ circumference = 2 * math.pi * radius+ return (+ dash < circumference+ and dash + gap + THICK_CIRCLE_COVERAGE_TOLERANCE >= circumference+ )++def svg_length_x(val: str | None, ctx: ConvertContext, default: float = 0.0) -> float:return parse_svg_length(val, default, percent_base=ctx.viewport_width)@@ -590,6 +699,7 @@ def _iter_visual_transform_tree(elem: ET.Element) -> Iterator[ET.Element]:_TRANSFORM_ARC_STYLE_ATTRS = (+ 'fill','stroke','stroke-width','stroke-dasharray',@@ -629,6 +739,7 @@ def _is_project_thick_circle(return is_thick_circle_shorthand(arc_styles.get('stroke-dasharray'),arc_styles.get('stroke'),+ arc_styles.get('fill'),stroke_width,radius,)@@ -708,7 +819,10 @@ def _project_thick_circle_ids() -> set[int]:thick_circle_ids: set[int] = set()- def visit(elem: ET.Element, inherited: dict[str, str] | None = None) -> None:+ def visit(+ elem: ET.Element,+ inherited: dict[str, str] | None = None,+ ) -> None:arc_styles = _transform_arc_styles(elem, inherited)if _is_project_thick_circle(elem, arc_styles):thick_circle_ids.add(id(elem))@@ -719,6 +833,62 @@ def _project_thick_circle_ids(return thick_circle_ids+_PROJECT_STROKE_STYLE_ATTRIBUTES = (+ 'stroke-dasharray',+ 'stroke-dashoffset',+ 'stroke-linecap',+ 'stroke-linejoin',+ 'vector-effect',+)+++def iter_project_stroke_styles(+ root: ET.Element,+) -> Iterator[tuple[ET.Element, str, str, str]]:+ """Yield project line-style values with their declaration source."""+ for elem in root.iter():+ for attribute in _PROJECT_STROKE_STYLE_ATTRIBUTES:+ raw = elem.get(attribute)+ if raw is not None:+ yield elem, attribute, raw, 'attribute'+ inline_style = parse_inline_style(elem.get('style'))+ for attribute in _PROJECT_STROKE_STYLE_ATTRIBUTES:+ raw = inline_style.get(attribute)+ if raw is not None:+ yield elem, attribute, raw, 'inline style'+++def project_stroke_style_errors(root: ET.Element) -> list[str]:+ """Return blocking line-style grammar and mapping errors for preflight."""+ thick_circle_ids = _project_thick_circle_ids(root)+ errors: set[str] = set()+ for elem, attribute, raw, source in iter_project_stroke_styles(root):+ label = _transform_element_label(elem)+ try:+ if attribute == 'stroke-dasharray':+ parse_project_stroke_dasharray(+ raw,+ allow_zero_gap=id(elem) in thick_circle_ids,+ )+ elif attribute == 'stroke-dashoffset':+ if source != 'attribute':+ raise ValueError(+ 'is supported only as a direct attribute on a '+ 'thick-circle arc'+ )+ parse_project_geometry_length(raw, attribute)+ if id(elem) not in thick_circle_ids:+ raise ValueError(+ 'is supported only on a circle that satisfies the '+ 'thick-circle arc contract'+ )+ else:+ parse_project_stroke_enum(attribute, raw)+ except ValueError as exc:+ errors.add(f'{label} {source} {attribute}={raw!r}: {exc}')+ return sorted(errors)++def _contains_thick_circle(elem: ET.Element, thick_circle_ids: set[int]) -> bool:return any(id(descendant) in thick_circle_ids