dknowc-dsh 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/package.json +2 -2
- package/skills/dknowc-official-doc-writer/SKILL.md +17 -8
- package/skills/dknowc-official-doc-writer/reference/sample_search_result.md +48 -0
- package/skills/dknowc-official-doc-writer/reference/sample_trace_report.html +75 -0
- package/skills/dknowc-official-doc-writer/reference/search_intro.md +72 -8
- package/skills/dknowc-official-doc-writer/scripts/register.mjs +1 -1
- package/skills/dknowc-ppt-assistant/README.md +54 -0
- package/skills/dknowc-ppt-assistant/SKILL.md +151 -0
- package/skills/dknowc-ppt-assistant/THIRD_PARTY_NOTICES.md +36 -0
- package/skills/dknowc-ppt-assistant/official-docs/output/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/official-docs/search-results/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/projects/.gitkeep +0 -0
- package/skills/dknowc-ppt-assistant/references/content-pack.md +55 -0
- package/skills/dknowc-ppt-assistant/references/material_usage.md +51 -0
- package/skills/dknowc-ppt-assistant/references/sample_effect.html +89 -0
- package/skills/dknowc-ppt-assistant/references/sample_search_result.md +48 -0
- package/skills/dknowc-ppt-assistant/references/search_intro.md +79 -0
- package/skills/dknowc-ppt-assistant/references/style-presets.md +126 -0
- package/skills/dknowc-ppt-assistant/references/svg-authoring.md +81 -0
- package/skills/dknowc-ppt-assistant/references/upstream-docs/svg-pipeline.md +842 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/01_cover.svg +28 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/02_quote.svg +38 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/03_origin.svg +96 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/README.md +15 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/design_spec.md +408 -0
- package/skills/dknowc-ppt-assistant/references/upstream-example/spec_lock.md +78 -0
- package/skills/dknowc-ppt-assistant/scripts/adapt_mcp_result.py +279 -0
- package/skills/dknowc-ppt-assistant/scripts/check_release.py +106 -0
- package/skills/dknowc-ppt-assistant/scripts/compact_svg_coordinates.py +345 -0
- package/skills/dknowc-ppt-assistant/scripts/config.py +707 -0
- package/skills/dknowc-ppt-assistant/scripts/console_encoding.py +33 -0
- package/skills/dknowc-ppt-assistant/scripts/error_helper.py +434 -0
- package/skills/dknowc-ppt-assistant/scripts/finalize_svg.py +507 -0
- package/skills/dknowc-ppt-assistant/scripts/hyperlink_contract.py +399 -0
- package/skills/dknowc-ppt-assistant/scripts/initialize.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/language_tags.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/mcp_direct.py +158 -0
- package/skills/dknowc-ppt-assistant/scripts/native_payloads.py +655 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animation_presets.json +3440 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_animations.py +3965 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_effects.py +143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_opc_validation.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/__init__.py +130 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-APACHE-2.0.txt +202 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/LICENSE-OPEN-XML-SDK-MIT.txt +23 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/NOTICE.md +54 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeDefinitions.xml +19898 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/presetShapeSemantics.json +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/data/shape_type_values.txt +187 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/errors.py +39 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/formula.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/loader.py +364 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/models.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/registry.py +270 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantic_hash.py +456 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/semantics.py +543 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_shapes/xml_safety.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/__init__.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/animation_import.py +287 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chart_to_svg.py +2377 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/chartex_to_svg.py +422 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/color_resolver.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/converter.py +1143 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/custgeom_to_svg.py +165 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/effect_to_svg.py +410 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/emu_units.py +258 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/fill_to_svg.py +816 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/formula_import.py +611 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/hyperlinks.py +93 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/import_diagnostics.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ln_to_svg.py +362 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/normalized_chart_svg.py +1217 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/ooxml_loader.py +506 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/pic_to_svg.py +653 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_authoring.py +894 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_registry_to_svg.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/preset_svg_markup.py +198 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/prstgeom_to_svg.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/shape_walker.py +556 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/slide_to_svg.py +2002 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/tbl_to_svg.py +1841 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/transition_import.py +201 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_to_svg/txbody_to_svg.py +1433 -0
- package/skills/dknowc-ppt-assistant/scripts/pptx_transitions.py +3153 -0
- package/skills/dknowc-ppt-assistant/scripts/preset_shape_svg.py +450 -0
- package/skills/dknowc-ppt-assistant/scripts/project_utils.py +645 -0
- package/skills/dknowc-ppt-assistant/scripts/register_key.mjs +183 -0
- package/skills/dknowc-ppt-assistant/scripts/register_template.py +1327 -0
- package/skills/dknowc-ppt-assistant/scripts/render_trace_html.py +1048 -0
- package/skills/dknowc-ppt-assistant/scripts/resource_paths.py +282 -0
- package/skills/dknowc-ppt-assistant/scripts/shape_boolean_svg.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/slide_roster.py +44 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/__init__.py +12 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/align_embed_images.py +672 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/crop_images.py +370 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_icons.py +564 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/embed_images.py +288 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/fix_image_aspect.py +389 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/flatten_tspan.py +948 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_finalize/svg_rect_to_path.py +346 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/__init__.py +15 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/checker.py +7791 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/cli.py +193 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/svg_contracts.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality/xml_support.py +35 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_quality_checker.py +59 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/__init__.py +37 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/animation_config.py +1622 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/canvas_contract.py +226 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/context.py +291 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/converter.py +1980 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/elements.py +5272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/hyperlinks.py +162 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/paths.py +847 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/styles.py +752 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/text_properties.py +796 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_colors.py +283 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/theme_fonts.py +330 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/drawingml/utils.py +3555 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/geometry_properties.py +140 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/__init__.py +356 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_data.py +1449 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_style.py +886 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chart_xml.py +1495 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/chartex.py +272 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/fallback_hash.py +161 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula.py +243 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_ast.py +592 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_compiler.py +96 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_omml.py +1049 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_parser.py +2181 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_profile.py +739 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/formula_run_properties.py +234 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/inline_formula.py +311 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_attributes.py +182 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_common.py +806 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/marker_status.py +190 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/table.py +1113 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/native_objects/workbook.py +216 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/__init__.py +1 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/builder.py +6273 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/cli.py +2059 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/dimensions.py +189 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/discovery.py +120 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/media.py +160 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/narration.py +696 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/notes.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/slide_xml.py +138 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_structure.py +3457 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/pptx_package/template_validation.py +1536 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/semantic_markers.py +240 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/shape_boolean.py +1355 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/text_outline.py +1121 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/tspan_flattener.py +64 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx/use_expander.py +577 -0
- package/skills/dknowc-ppt-assistant/scripts/svg_to_pptx.py +21 -0
- package/skills/dknowc-ppt-assistant/scripts/trusted_search.py +336 -0
- package/skills/dknowc-ppt-assistant/scripts/update_spec.py +404 -0
- package/skills/dknowc-ppt-assistant/workflows/generate-pptx.md +142 -0
- package/skills/dknowc-ppt-assistant/workflows/routing.md +38 -0
- package/skills/dknowc-trusted-consulting/SKILL.md +21 -5
- package/skills/dknowc-trusted-consulting/reference/consult_intro.md +79 -0
- package/skills/dknowc-trusted-consulting/reference/sample_consult_answer.md +31 -0
- package/skills/dknowc-trusted-consulting/reference/sample_trace_report.html +76 -0
- package/skills/dknowc-trusted-consulting/scripts/register_key.mjs +1 -0
- package/skills/dknowc-trusted-search/SKILL.md +30 -2
- package/skills/dknowc-trusted-search/reference/sample_search_result.md +33 -0
- package/skills/dknowc-trusted-search/reference/sample_trace_report.html +450 -0
- package/skills/dknowc-trusted-search/reference/search_intro.md +79 -0
- package/skills/dknowc-trusted-search/scripts/register_key.mjs +1 -0
- package/src/index.js +7 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""DrawingML <a:custGeom> -> SVG <path d="..."> conversion.
|
|
2
|
+
|
|
3
|
+
Reverse of svg_to_pptx/drawingml/paths.py path_commands_to_drawingml.
|
|
4
|
+
|
|
5
|
+
Path command mapping:
|
|
6
|
+
<a:moveTo> -> M
|
|
7
|
+
<a:lnTo> -> L
|
|
8
|
+
<a:cubicBezTo> -> C
|
|
9
|
+
<a:quadBezTo> -> Q
|
|
10
|
+
<a:arcTo> -> A (DrawingML uses center + sweep angles; we convert
|
|
11
|
+
to SVG endpoint parameterization)
|
|
12
|
+
<a:close/> -> Z
|
|
13
|
+
|
|
14
|
+
DrawingML <a:path w="..." h="..."> defines a shape-local coordinate system.
|
|
15
|
+
Each path resolves guide formulas against that local coordinate system, then
|
|
16
|
+
its coordinates are projected into the shape's absolute SVG frame.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
from dataclasses import dataclass
|
|
22
|
+
from xml.etree import ElementTree as ET
|
|
23
|
+
|
|
24
|
+
from pptx_shapes import FormulaEvaluationError, FormulaEvaluator
|
|
25
|
+
|
|
26
|
+
from .emu_units import NS, Xfrm
|
|
27
|
+
from .preset_registry_to_svg import render_evaluated_path
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(frozen=True)
|
|
31
|
+
class _EvaluatedCommand:
|
|
32
|
+
name: str
|
|
33
|
+
parameters: tuple[float, ...]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def convert_custom_geom(
|
|
37
|
+
cust_geom: ET.Element,
|
|
38
|
+
xfrm: Xfrm,
|
|
39
|
+
) -> str | None:
|
|
40
|
+
"""Evaluate a complete custom geometry and return absolute SVG path data."""
|
|
41
|
+
path_lst = cust_geom.find("a:pathLst", NS)
|
|
42
|
+
if path_lst is None:
|
|
43
|
+
return None
|
|
44
|
+
shape_evaluator = _custom_geometry_evaluator(cust_geom, xfrm.w, xfrm.h)
|
|
45
|
+
paths = [
|
|
46
|
+
_convert_one_path(path_elem, cust_geom, xfrm, shape_evaluator)
|
|
47
|
+
for path_elem in path_lst.findall("a:path", NS)
|
|
48
|
+
]
|
|
49
|
+
rendered = [path for path in paths if path]
|
|
50
|
+
return " ".join(rendered) if rendered else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _custom_geometry_evaluator(
|
|
54
|
+
cust_geom: ET.Element,
|
|
55
|
+
width: float,
|
|
56
|
+
height: float,
|
|
57
|
+
) -> FormulaEvaluator:
|
|
58
|
+
evaluator = FormulaEvaluator(width, height)
|
|
59
|
+
for list_name in ("avLst", "gdLst"):
|
|
60
|
+
guide_list = cust_geom.find(f"a:{list_name}", NS)
|
|
61
|
+
if guide_list is None:
|
|
62
|
+
continue
|
|
63
|
+
for guide in guide_list.findall("a:gd", NS):
|
|
64
|
+
name = guide.attrib.get("name", "").strip()
|
|
65
|
+
formula = guide.attrib.get("fmla", "").strip()
|
|
66
|
+
if not name or not formula:
|
|
67
|
+
raise FormulaEvaluationError(
|
|
68
|
+
f"Custom geometry {list_name} contains an incomplete guide"
|
|
69
|
+
)
|
|
70
|
+
evaluator.bind(name, evaluator.evaluate(formula))
|
|
71
|
+
return evaluator
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _convert_one_path(
|
|
75
|
+
path_elem: ET.Element,
|
|
76
|
+
cust_geom: ET.Element,
|
|
77
|
+
xfrm: Xfrm,
|
|
78
|
+
shape_evaluator: FormulaEvaluator,
|
|
79
|
+
) -> str:
|
|
80
|
+
coordinate_width = _path_extent(
|
|
81
|
+
path_elem.get("w"),
|
|
82
|
+
xfrm.w,
|
|
83
|
+
shape_evaluator,
|
|
84
|
+
)
|
|
85
|
+
coordinate_height = _path_extent(
|
|
86
|
+
path_elem.get("h"),
|
|
87
|
+
xfrm.h,
|
|
88
|
+
shape_evaluator,
|
|
89
|
+
)
|
|
90
|
+
path_evaluator = _custom_geometry_evaluator(
|
|
91
|
+
cust_geom,
|
|
92
|
+
coordinate_width,
|
|
93
|
+
coordinate_height,
|
|
94
|
+
)
|
|
95
|
+
commands = tuple(
|
|
96
|
+
_evaluate_path_command(command, path_evaluator)
|
|
97
|
+
for command in path_elem
|
|
98
|
+
if isinstance(command.tag, str)
|
|
99
|
+
)
|
|
100
|
+
return render_evaluated_path(
|
|
101
|
+
commands,
|
|
102
|
+
x=xfrm.x,
|
|
103
|
+
y=xfrm.y,
|
|
104
|
+
width=xfrm.w,
|
|
105
|
+
height=xfrm.h,
|
|
106
|
+
coordinate_width=coordinate_width,
|
|
107
|
+
coordinate_height=coordinate_height,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def _evaluate_path_command(
|
|
112
|
+
element: ET.Element,
|
|
113
|
+
evaluator: FormulaEvaluator,
|
|
114
|
+
) -> _EvaluatedCommand:
|
|
115
|
+
name = element.tag.rsplit("}", 1)[-1]
|
|
116
|
+
if name == "arcTo":
|
|
117
|
+
values = tuple(
|
|
118
|
+
evaluator.evaluate_value(_required_attr(element, attr))
|
|
119
|
+
for attr in ("wR", "hR", "stAng", "swAng")
|
|
120
|
+
)
|
|
121
|
+
return _EvaluatedCommand(name=name, parameters=values)
|
|
122
|
+
expected_points = {
|
|
123
|
+
"moveTo": 1,
|
|
124
|
+
"lnTo": 1,
|
|
125
|
+
"quadBezTo": 2,
|
|
126
|
+
"cubicBezTo": 3,
|
|
127
|
+
"close": 0,
|
|
128
|
+
}.get(name)
|
|
129
|
+
if expected_points is None:
|
|
130
|
+
raise FormulaEvaluationError(
|
|
131
|
+
f"Unsupported custom geometry path command: {name!r}"
|
|
132
|
+
)
|
|
133
|
+
points = element.findall("a:pt", NS)
|
|
134
|
+
if len(points) != expected_points:
|
|
135
|
+
raise FormulaEvaluationError(
|
|
136
|
+
f"Custom path command {name!r} expects {expected_points} point(s), "
|
|
137
|
+
f"found {len(points)}"
|
|
138
|
+
)
|
|
139
|
+
values = tuple(
|
|
140
|
+
evaluator.evaluate_value(_required_attr(point, coordinate))
|
|
141
|
+
for point in points
|
|
142
|
+
for coordinate in ("x", "y")
|
|
143
|
+
)
|
|
144
|
+
return _EvaluatedCommand(name=name, parameters=values)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _path_extent(
|
|
148
|
+
raw: str | None,
|
|
149
|
+
shape_extent: float,
|
|
150
|
+
evaluator: FormulaEvaluator,
|
|
151
|
+
) -> float:
|
|
152
|
+
if raw is None:
|
|
153
|
+
return shape_extent
|
|
154
|
+
value = evaluator.evaluate_value(raw)
|
|
155
|
+
return shape_extent if value == 0 else value
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _required_attr(element: ET.Element, name: str) -> str:
|
|
159
|
+
value = element.attrib.get(name)
|
|
160
|
+
if value is None or not value.strip():
|
|
161
|
+
raise FormulaEvaluationError(
|
|
162
|
+
f"Custom geometry element {element.tag.rsplit('}', 1)[-1]!r} "
|
|
163
|
+
f"requires attribute {name!r}"
|
|
164
|
+
)
|
|
165
|
+
return value.strip()
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
"""Convert the closed DrawingML effect subset into project SVG filters.
|
|
2
|
+
|
|
3
|
+
One classifiable outer shadow or one glow maps to the public shadow/glow
|
|
4
|
+
contract. Every other source effect receives explicit blocking metadata; the
|
|
5
|
+
importer never relabels it as another native effect or drops it silently.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
import re
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from xml.etree import ElementTree as ET
|
|
14
|
+
|
|
15
|
+
from pptx_effects import unsupported_effect_metadata
|
|
16
|
+
from pptx_shapes.formula import OOXML_COORDINATE_MAX
|
|
17
|
+
|
|
18
|
+
from .color_resolver import COLOR_TAGS, ColorPalette, resolve_color
|
|
19
|
+
from .emu_units import NS, emu_to_px, fmt_num, format_ooxml_alpha
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
_OOXML_INTEGER_RE = re.compile(r"[+-]?\d+")
|
|
23
|
+
_OOXML_HEX_COLOR_RE = re.compile(r"[0-9A-Fa-f]{6}")
|
|
24
|
+
_DRAWINGML_NAMESPACE = NS["a"]
|
|
25
|
+
_DRAWINGML_TAG_PREFIX = f"{{{_DRAWINGML_NAMESPACE}}}"
|
|
26
|
+
_EFFECT_CONTAINER_NAMES = frozenset({"effectLst", "effectDag"})
|
|
27
|
+
_OUTER_SHADOW_ATTRIBUTES = frozenset({
|
|
28
|
+
"algn",
|
|
29
|
+
"blurRad",
|
|
30
|
+
"dir",
|
|
31
|
+
"dist",
|
|
32
|
+
"kx",
|
|
33
|
+
"ky",
|
|
34
|
+
"rotWithShape",
|
|
35
|
+
"sx",
|
|
36
|
+
"sy",
|
|
37
|
+
})
|
|
38
|
+
_OUTER_SHADOW_ALIGNMENTS = frozenset({
|
|
39
|
+
"b",
|
|
40
|
+
"bl",
|
|
41
|
+
"br",
|
|
42
|
+
"ctr",
|
|
43
|
+
"l",
|
|
44
|
+
"r",
|
|
45
|
+
"t",
|
|
46
|
+
"tl",
|
|
47
|
+
"tr",
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@dataclass(frozen=True)
|
|
52
|
+
class EffectResult:
|
|
53
|
+
"""One supported SVG filter or one explicit unsupported-source marker."""
|
|
54
|
+
|
|
55
|
+
filter_id: str | None = None
|
|
56
|
+
defs: tuple[str, ...] = ()
|
|
57
|
+
metadata: tuple[tuple[str, str], ...] = ()
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def unsupported(cls, reason: str) -> "EffectResult":
|
|
61
|
+
return cls(metadata=tuple(unsupported_effect_metadata(reason).items()))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def unsupported_target_effect_metadata(
|
|
65
|
+
sp_pr: ET.Element | None,
|
|
66
|
+
target: str,
|
|
67
|
+
) -> dict[str, str]:
|
|
68
|
+
"""Mark source effects that cannot attach to this SVG target type."""
|
|
69
|
+
if sp_pr is None:
|
|
70
|
+
return {}
|
|
71
|
+
effect_names: list[str] = []
|
|
72
|
+
for container in sp_pr:
|
|
73
|
+
if (
|
|
74
|
+
not isinstance(container.tag, str)
|
|
75
|
+
or _local_name(container) not in _EFFECT_CONTAINER_NAMES
|
|
76
|
+
):
|
|
77
|
+
continue
|
|
78
|
+
container_name = _local_name(container)
|
|
79
|
+
if container_name == "effectDag":
|
|
80
|
+
effect_names.append(container_name)
|
|
81
|
+
continue
|
|
82
|
+
effect_names.extend(
|
|
83
|
+
_local_name(child)
|
|
84
|
+
for child in container
|
|
85
|
+
if isinstance(child.tag, str)
|
|
86
|
+
)
|
|
87
|
+
if not effect_names:
|
|
88
|
+
return {}
|
|
89
|
+
return unsupported_effect_metadata(
|
|
90
|
+
f"unsupported-effect-target:{target}:" + ",".join(effect_names)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def convert_effects(
|
|
95
|
+
sp_pr: ET.Element | None,
|
|
96
|
+
palette: ColorPalette | None,
|
|
97
|
+
*,
|
|
98
|
+
id_prefix: str = "fx",
|
|
99
|
+
id_seq: list[int] | None = None,
|
|
100
|
+
target_rotation_degrees: float = 0.0,
|
|
101
|
+
) -> EffectResult:
|
|
102
|
+
"""Return one supported filter or blocking metadata for source effects."""
|
|
103
|
+
if sp_pr is None:
|
|
104
|
+
return EffectResult()
|
|
105
|
+
containers = [
|
|
106
|
+
child
|
|
107
|
+
for child in sp_pr
|
|
108
|
+
if isinstance(child.tag, str)
|
|
109
|
+
and _local_name(child) in _EFFECT_CONTAINER_NAMES
|
|
110
|
+
]
|
|
111
|
+
if not containers:
|
|
112
|
+
return EffectResult()
|
|
113
|
+
container_names = [_local_name(child) for child in containers]
|
|
114
|
+
if len(containers) != 1:
|
|
115
|
+
return EffectResult.unsupported(
|
|
116
|
+
"multiple-effect-containers:" + ",".join(container_names)
|
|
117
|
+
)
|
|
118
|
+
container = containers[0]
|
|
119
|
+
container_name = container_names[0]
|
|
120
|
+
if not container.tag.startswith(_DRAWINGML_TAG_PREFIX):
|
|
121
|
+
return EffectResult.unsupported(
|
|
122
|
+
f"invalid-effect-container-namespace:{container_name}"
|
|
123
|
+
)
|
|
124
|
+
if container_name == "effectDag":
|
|
125
|
+
return EffectResult.unsupported("unsupported-effect-container:effectDag")
|
|
126
|
+
effects = [
|
|
127
|
+
child
|
|
128
|
+
for child in container
|
|
129
|
+
if isinstance(child.tag, str)
|
|
130
|
+
]
|
|
131
|
+
if not effects:
|
|
132
|
+
return EffectResult()
|
|
133
|
+
names = [child.tag.split("}", 1)[-1] for child in effects]
|
|
134
|
+
if len(effects) != 1:
|
|
135
|
+
return EffectResult.unsupported(
|
|
136
|
+
"multiple-effects:" + ",".join(names)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
effect = effects[0]
|
|
140
|
+
effect_name = names[0]
|
|
141
|
+
if not effect.tag.startswith(_DRAWINGML_TAG_PREFIX):
|
|
142
|
+
return EffectResult.unsupported(
|
|
143
|
+
f"invalid-effect-namespace:{effect_name}"
|
|
144
|
+
)
|
|
145
|
+
try:
|
|
146
|
+
if effect_name == "outerShdw":
|
|
147
|
+
unsupported_attributes = _unsupported_outer_shadow_attributes(
|
|
148
|
+
effect,
|
|
149
|
+
target_rotation_degrees=target_rotation_degrees,
|
|
150
|
+
)
|
|
151
|
+
if unsupported_attributes:
|
|
152
|
+
return EffectResult.unsupported(
|
|
153
|
+
"unsupported-effect-attributes:outerShdw:"
|
|
154
|
+
+ ",".join(unsupported_attributes)
|
|
155
|
+
)
|
|
156
|
+
primitives = _outer_shadow(effect, palette)
|
|
157
|
+
elif effect_name == "glow":
|
|
158
|
+
primitives = _glow(effect, palette)
|
|
159
|
+
else:
|
|
160
|
+
return EffectResult.unsupported(
|
|
161
|
+
f"unsupported-effect:{effect_name}"
|
|
162
|
+
)
|
|
163
|
+
except (OverflowError, TypeError, ValueError) as exc:
|
|
164
|
+
return EffectResult.unsupported(
|
|
165
|
+
f"invalid-effect:{effect_name}:{exc}"
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
if id_seq is None:
|
|
169
|
+
id_seq = [0]
|
|
170
|
+
id_seq[0] += 1
|
|
171
|
+
filter_id = f"{id_prefix}{id_seq[0]}"
|
|
172
|
+
|
|
173
|
+
# Filter region needs to extend beyond the bounding box to render shadows
|
|
174
|
+
# and glows; choose generous defaults.
|
|
175
|
+
filter_x = "-25%"
|
|
176
|
+
filter_y = "-25%"
|
|
177
|
+
filter_w = "150%"
|
|
178
|
+
filter_h = "150%"
|
|
179
|
+
|
|
180
|
+
defs_xml = (
|
|
181
|
+
f'<filter id="{filter_id}" x="{filter_x}" y="{filter_y}" '
|
|
182
|
+
f'width="{filter_w}" height="{filter_h}">'
|
|
183
|
+
+ primitives
|
|
184
|
+
+ "</filter>"
|
|
185
|
+
)
|
|
186
|
+
return EffectResult(filter_id=filter_id, defs=(defs_xml,))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _color_alpha(elem: ET.Element, palette: ColorPalette | None) -> tuple[str, float]:
|
|
190
|
+
direct_children = [
|
|
191
|
+
child
|
|
192
|
+
for child in elem
|
|
193
|
+
if isinstance(child.tag, str)
|
|
194
|
+
]
|
|
195
|
+
colors = [
|
|
196
|
+
child
|
|
197
|
+
for child in direct_children
|
|
198
|
+
if _local_name(child) in COLOR_TAGS
|
|
199
|
+
]
|
|
200
|
+
if len(colors) != 1:
|
|
201
|
+
reason = "missing-color" if not colors else "multiple-colors"
|
|
202
|
+
raise ValueError(reason)
|
|
203
|
+
if len(direct_children) != 1:
|
|
204
|
+
extras = [
|
|
205
|
+
_local_name(child)
|
|
206
|
+
for child in direct_children
|
|
207
|
+
if child is not colors[0]
|
|
208
|
+
]
|
|
209
|
+
raise ValueError("unexpected-effect-child:" + ",".join(extras))
|
|
210
|
+
color = colors[0]
|
|
211
|
+
if not color.tag.startswith(_DRAWINGML_TAG_PREFIX):
|
|
212
|
+
raise ValueError(f"invalid-color-namespace:{_local_name(color)}")
|
|
213
|
+
_validate_color(color, palette)
|
|
214
|
+
hex_, alpha = resolve_color(color, palette)
|
|
215
|
+
if hex_ is None:
|
|
216
|
+
raise ValueError(f"unresolvable-color:{_local_name(color)}")
|
|
217
|
+
return hex_, alpha
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _validate_color(
|
|
221
|
+
color: ET.Element,
|
|
222
|
+
palette: ColorPalette | None,
|
|
223
|
+
) -> None:
|
|
224
|
+
"""Validate the color subset resolved into one SVG filter paint."""
|
|
225
|
+
color_name = _local_name(color)
|
|
226
|
+
if color_name == "srgbClr":
|
|
227
|
+
raw = color.get("val", "")
|
|
228
|
+
if _OOXML_HEX_COLOR_RE.fullmatch(raw) is None:
|
|
229
|
+
raise ValueError(f"invalid-color:{color_name}")
|
|
230
|
+
elif color_name == "schemeClr":
|
|
231
|
+
raw = (color.get("val") or "").strip()
|
|
232
|
+
resolved = palette.resolve_scheme(raw) if palette is not None else None
|
|
233
|
+
if resolved is None or _OOXML_HEX_COLOR_RE.fullmatch(resolved) is None:
|
|
234
|
+
raise ValueError(f"unresolvable-color:{color_name}")
|
|
235
|
+
elif color_name == "sysClr":
|
|
236
|
+
if not (color.get("val") or "").strip():
|
|
237
|
+
raise ValueError(f"invalid-color:{color_name}")
|
|
238
|
+
raw = color.get("lastClr") or ""
|
|
239
|
+
if _OOXML_HEX_COLOR_RE.fullmatch(raw) is None:
|
|
240
|
+
raise ValueError(f"unresolvable-color:{color_name}")
|
|
241
|
+
elif color_name == "hslClr":
|
|
242
|
+
_required_integer(color, "hue", 0, 21_599_999)
|
|
243
|
+
_required_integer(color, "sat", 0, 100000)
|
|
244
|
+
_required_integer(color, "lum", 0, 100000)
|
|
245
|
+
elif color_name == "scrgbClr":
|
|
246
|
+
for attr in ("r", "g", "b"):
|
|
247
|
+
_required_integer(color, attr, 0, 100000)
|
|
248
|
+
elif not (color.get("val") or "").strip():
|
|
249
|
+
raise ValueError(f"invalid-color:{color_name}")
|
|
250
|
+
|
|
251
|
+
def _required_integer(
|
|
252
|
+
elem: ET.Element,
|
|
253
|
+
attr: str,
|
|
254
|
+
minimum: int,
|
|
255
|
+
maximum: int,
|
|
256
|
+
) -> int:
|
|
257
|
+
raw = elem.get(attr)
|
|
258
|
+
if raw is None:
|
|
259
|
+
raise ValueError(f"missing-{_local_name(elem)}-{attr}")
|
|
260
|
+
token = raw.strip()
|
|
261
|
+
if _OOXML_INTEGER_RE.fullmatch(token) is None:
|
|
262
|
+
raise ValueError(f"invalid-{_local_name(elem)}-{attr}")
|
|
263
|
+
value = int(token)
|
|
264
|
+
if not minimum <= value <= maximum:
|
|
265
|
+
raise ValueError(f"invalid-{_local_name(elem)}-{attr}")
|
|
266
|
+
return value
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _local_name(elem: ET.Element) -> str:
|
|
270
|
+
return elem.tag.rsplit("}", 1)[-1]
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def _effect_integer(
|
|
274
|
+
elem: ET.Element,
|
|
275
|
+
attr: str,
|
|
276
|
+
*,
|
|
277
|
+
default: int = 0,
|
|
278
|
+
non_negative: bool = False,
|
|
279
|
+
maximum: int | None = None,
|
|
280
|
+
) -> int:
|
|
281
|
+
raw = elem.get(attr)
|
|
282
|
+
if raw is None:
|
|
283
|
+
value = default
|
|
284
|
+
else:
|
|
285
|
+
token = raw.strip()
|
|
286
|
+
if _OOXML_INTEGER_RE.fullmatch(token) is None:
|
|
287
|
+
raise ValueError(f"{attr}={raw!r}")
|
|
288
|
+
value = int(token)
|
|
289
|
+
if (
|
|
290
|
+
(non_negative and value < 0)
|
|
291
|
+
or (maximum is not None and value > maximum)
|
|
292
|
+
):
|
|
293
|
+
raise ValueError(f"{attr}={raw!r}")
|
|
294
|
+
return value
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _unsupported_outer_shadow_attributes(
|
|
298
|
+
elem: ET.Element,
|
|
299
|
+
*,
|
|
300
|
+
target_rotation_degrees: float,
|
|
301
|
+
) -> tuple[str, ...]:
|
|
302
|
+
"""Return source shadow attributes the local SVG filter cannot preserve."""
|
|
303
|
+
unsupported = set(elem.attrib) - _OUTER_SHADOW_ATTRIBUTES
|
|
304
|
+
neutral_transforms = (
|
|
305
|
+
("sx", 100000),
|
|
306
|
+
("sy", 100000),
|
|
307
|
+
("kx", 0),
|
|
308
|
+
("ky", 0),
|
|
309
|
+
)
|
|
310
|
+
for attr, neutral in neutral_transforms:
|
|
311
|
+
if attr in elem.attrib and _effect_integer(elem, attr) != neutral:
|
|
312
|
+
unsupported.add(attr)
|
|
313
|
+
|
|
314
|
+
raw_alignment = elem.get("algn")
|
|
315
|
+
if (
|
|
316
|
+
raw_alignment is not None
|
|
317
|
+
and raw_alignment.strip() not in _OUTER_SHADOW_ALIGNMENTS
|
|
318
|
+
):
|
|
319
|
+
raise ValueError(f"algn={raw_alignment!r}")
|
|
320
|
+
|
|
321
|
+
raw_rotates = elem.get("rotWithShape")
|
|
322
|
+
if raw_rotates is None:
|
|
323
|
+
rotates_with_shape = True
|
|
324
|
+
else:
|
|
325
|
+
token = raw_rotates.strip()
|
|
326
|
+
if token in {"1", "true"}:
|
|
327
|
+
rotates_with_shape = True
|
|
328
|
+
elif token in {"0", "false"}:
|
|
329
|
+
rotates_with_shape = False
|
|
330
|
+
else:
|
|
331
|
+
raise ValueError(f"rotWithShape={raw_rotates!r}")
|
|
332
|
+
target_is_rotated = not math.isclose(
|
|
333
|
+
math.remainder(target_rotation_degrees, 360.0),
|
|
334
|
+
0.0,
|
|
335
|
+
abs_tol=1e-9,
|
|
336
|
+
)
|
|
337
|
+
if rotates_with_shape and target_is_rotated:
|
|
338
|
+
# CT_OuterShadowEffect defaults rotWithShape to true, while the local
|
|
339
|
+
# SVG-to-PPTX mapping writes false. Blocking the visible distinction
|
|
340
|
+
# prevents the next export from changing the source shadow direction.
|
|
341
|
+
unsupported.add("rotWithShape")
|
|
342
|
+
|
|
343
|
+
return tuple(sorted(unsupported))
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
def _direction_offset(elem: ET.Element) -> tuple[float, float]:
|
|
347
|
+
"""Read dir / dist into (dx, dy) px."""
|
|
348
|
+
direction_units = _effect_integer(
|
|
349
|
+
elem,
|
|
350
|
+
"dir",
|
|
351
|
+
non_negative=True,
|
|
352
|
+
maximum=21_599_999,
|
|
353
|
+
)
|
|
354
|
+
dist_emu = _effect_integer(
|
|
355
|
+
elem,
|
|
356
|
+
"dist",
|
|
357
|
+
non_negative=True,
|
|
358
|
+
maximum=OOXML_COORDINATE_MAX,
|
|
359
|
+
)
|
|
360
|
+
direction_deg = direction_units / 60000.0
|
|
361
|
+
dist_px = emu_to_px(dist_emu)
|
|
362
|
+
rad = math.radians(direction_deg)
|
|
363
|
+
return dist_px * math.cos(rad), dist_px * math.sin(rad)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _blur_radius(elem: ET.Element, attr: str) -> float:
|
|
367
|
+
return emu_to_px(_effect_integer(
|
|
368
|
+
elem,
|
|
369
|
+
attr,
|
|
370
|
+
non_negative=True,
|
|
371
|
+
maximum=OOXML_COORDINATE_MAX,
|
|
372
|
+
))
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def _outer_shadow(
|
|
376
|
+
elem: ET.Element,
|
|
377
|
+
palette: ColorPalette | None,
|
|
378
|
+
) -> str:
|
|
379
|
+
dx, dy = _direction_offset(elem)
|
|
380
|
+
blur = _blur_radius(elem, "blurRad")
|
|
381
|
+
dx_token = fmt_num(dx, 8)
|
|
382
|
+
dy_token = fmt_num(dy, 8)
|
|
383
|
+
if abs(float(dx_token)) <= 0.01 and abs(float(dy_token)) <= 0.01:
|
|
384
|
+
raise ValueError("offset-is-not-classifiable")
|
|
385
|
+
color, alpha = _color_alpha(elem, palette)
|
|
386
|
+
# std deviation ~= blur radius / 2 (rough; PowerPoint shadows are larger)
|
|
387
|
+
std = blur / 2.0
|
|
388
|
+
# Use feDropShadow for compactness — it's well-supported in modern browsers.
|
|
389
|
+
return (
|
|
390
|
+
f'<feDropShadow dx="{dx_token}" dy="{dy_token}" '
|
|
391
|
+
f'stdDeviation="{fmt_num(std, 8)}" '
|
|
392
|
+
f'flood-color="{color}" '
|
|
393
|
+
f'flood-opacity="{format_ooxml_alpha(alpha)}"/>'
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _glow(elem: ET.Element, palette: ColorPalette | None) -> str:
|
|
398
|
+
if elem.get("rad") is None:
|
|
399
|
+
raise ValueError("missing-rad")
|
|
400
|
+
rad = _blur_radius(elem, "rad")
|
|
401
|
+
color, alpha = _color_alpha(elem, palette)
|
|
402
|
+
# svg_to_pptx maps stdDeviation directly back to a:glow@rad.
|
|
403
|
+
std = rad
|
|
404
|
+
return (
|
|
405
|
+
f'<feGaussianBlur in="SourceAlpha" stdDeviation="{fmt_num(std, 8)}" result="blurred"/>'
|
|
406
|
+
f'<feFlood flood-color="{color}" '
|
|
407
|
+
f'flood-opacity="{format_ooxml_alpha(alpha)}" result="flood"/>'
|
|
408
|
+
f'<feComposite in="flood" in2="blurred" operator="in" result="glow"/>'
|
|
409
|
+
f'<feMerge><feMergeNode in="glow"/><feMergeNode in="SourceGraphic"/></feMerge>'
|
|
410
|
+
)
|