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

feat(svg-to-pptx): inherit project theme colors

hugohe32dade05048df
diff --git a/skills/ppt-master/SKILL.md b/skills/ppt-master/SKILL.md
index 9f028785..d700c40b 100644
--- a/skills/ppt-master/SKILL.md
+++ b/skills/ppt-master/SKILL.md
@@ -704,7 +704,12 @@ python3 ${SKILL_DIR}/scripts/svg_to_pptx.py <project_path>
> `spec_lock.md` typography contract, baseline also installs `title_family` as
> the PowerPoint theme major font and `body_family` / `font_family` as the minor
> font; matching SVG runs use theme tokens so later theme edits can cascade
-> without changing initial rendering. Add
+> without changing initial rendering. Baseline/template export likewise maps
+> the locked background, text, primary/accent, and border roles into the
+> PowerPoint color scheme. Exact matching SVG/native-object colors use
+> context-safe theme tokens; unrelated local colors, inverse white/black, and
+> effects stay concrete, so the first rendering remains the SVG design while
+> later theme edits can cascade selectively. Add
> `--pptx-structure flat` only for debugging/comparison when all generated
> backgrounds and chrome must remain slide-local and fonts must stay concrete.
diff --git a/skills/ppt-master/references/shared-standards.md b/skills/ppt-master/references/shared-standards.md
index 5d7023d4..37aead77 100644
--- a/skills/ppt-master/references/shared-standards.md
+++ b/skills/ppt-master/references/shared-standards.md
@@ -950,6 +950,39 @@ without changing the SVG geometry or the first export's visual design.
diagnostic slide-local/fixed-font comparison path. A project without a usable
`spec_lock.md` typography section keeps the legacy concrete-font behavior.
+### Theme Color Inheritance (Baseline and Template Export)
+
+Native `baseline` and `template` export also derive the PowerPoint color scheme
+from `spec_lock.md` colors. The canonical mapping is:
+
+| Lock role | PowerPoint scheme slot |
+|---|---|
+| `bg` / `background` / `master_bg` | `lt1` |
+| `secondary_bg` / `bg_secondary` | `lt2` |
+| `text` / `body_text` | `dk1` |
+| `text_secondary` | `dk2` |
+| `primary` | `accent1` |
+| `accent` | `accent2` |
+| `secondary_accent` | `accent3` |
+| `border` | `accent4` |
+| First two additional non-black/non-white roles | `accent5` / `accent6` |
+
+The converter promotes an exact locked HEX to `a:schemeClr` only when its
+usage is compatible with the role: backgrounds prefer background roles, text
+prefers text/accent roles, strokes prefer `border`, and chart series use only
+the primary/accent family. This prevents the same literal HEX from coupling
+unrelated semantics such as a white page background and fixed white inverse
+text. Gradients, patterns, bullets, native tables, and exact native-chart
+series colors follow the same rule. Shadows, effects, unmatched local colors,
+and additional palette roles remain concrete `a:srgbClr` values.
+
+The initial rendering is unchanged because every scheme slot resolves to the
+same locked HEX. A later PowerPoint theme edit can update only the promoted
+roles; it does not rewrite the SVG or local exceptions. `preserve` never
+rewrites the imported source color scheme, `flat` keeps concrete colors for
+diagnostics, and projects without a usable colors section retain legacy fixed
+colors.
+
### Explicit PPTX Master / Layout / Placeholder Metadata (Template Export)
**Trigger**: Set `spec_lock.md` `pptx_structure.mode` to `template`, or pass
diff --git a/skills/ppt-master/scripts/docs/svg-pipeline.md b/skills/ppt-master/scripts/docs/svg-pipeline.md
index d25e6f12..12c9809d 100644
--- a/skills/ppt-master/scripts/docs/svg-pipeline.md
+++ b/skills/ppt-master/scripts/docs/svg-pipeline.md
@@ -64,6 +64,7 @@ Behavior:
- Native mode is strict about unsupported visual SVG elements: if a visual element cannot be represented or safely preserved, export fails with the SVG file, element tag, and position instead of silently dropping content.
- Omitting `--pptx-structure` reads `spec_lock.md` `pptx_structure.mode`, then falls back to `baseline`; an explicit CLI value overrides the lock. Template mode builds reusable PowerPoint layouts only from explicit SVG metadata: root `data-pptx-layout`, direct-child `data-pptx-layer="master|layout"`, optional `data-pptx-layer="slide"` on a full-canvas solid background, and direct-child `data-pptx-placeholder`. It validates the per-page `pptx_layouts` lock plus cross-slide structure consistency and never infers layouts from visual similarity. Direct full-canvas solid rects compile to Master/Layout/Slide `p:bg` by scope; an unmarked one is a Slide override. Chart/table placeholders also require `--native-objects`. Full contract: [`shared-standards.md`](../../references/shared-standards.md#explicit-pptx-master--layout--placeholder-metadata-template-export).
- Baseline/template native export reads `spec_lock.md` typography into the PowerPoint theme: `title_family` becomes the major font and `body_family` / `font_family` becomes the minor font. Matching SVG text emits `+mj-*` / `+mn-*` tokens, while unrelated emphasis/code/brand families stay concrete. Preserve mode keeps the imported source theme; flat mode keeps fixed-font diagnostic output.
+- Baseline/template native export also maps canonical `spec_lock.md` color roles into the PowerPoint color scheme and emits context-safe `schemeClr` tokens for exact matches in SVG fills/text/strokes, gradients/patterns/bullets, native tables, and native-chart accent series. Local colors, inverse white/black, and effects stay concrete. Preserve mode keeps the imported source color scheme; flat mode keeps fixed-color diagnostic output.
- Preserve mode requires both a Strategist-confirmed `template_adherence: strict` and a `create-template` native pair (`native_structure.json` + `source_template.pptx`) declared in `spec_lock.md`. It verifies the source digest, binds each generated page to an imported layout part, retains the source master/layout/theme roster, removes preview-only inherited SVG layers, and restores source placeholder type/index identities. The SVG root still declares `data-pptx-layout`; repeated semantic placeholders may disambiguate with `data-pptx-placeholder-idx`. `template_adherence: adaptive` keeps export on baseline even when the pair is present.
- Native output uses content-hash media filenames, so identical images are reused and different images cannot overwrite each other by sharing a basename.
- `[Content_Types].xml` is generated from the actual media extensions written into the PPTX. Unknown media extensions fail unless Python's `mimetypes` can identify them.
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
index 79379282..d855ed59 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
@@ -8,6 +8,7 @@ from xml.etree import ElementTree as ET
from dataclasses import dataclass, field
if TYPE_CHECKING:
+ from .theme_colors import ThemeColorSpec
from .theme_fonts import ThemeFontSpec
AffineMatrix = tuple[float, float, float, float, float, float]
@@ -73,6 +74,9 @@ class ConvertContext:
# Optional project theme contract. Matching SVG title/body families emit
# DrawingML +mj/+mn tokens instead of fixed typeface names.
theme_font_spec: ThemeFontSpec | None = None
+ # Optional project theme-color contract. Exact locked colors are promoted
+ # to context-safe DrawingML scheme slots while local colors stay concrete.
+ theme_color_spec: ThemeColorSpec | None = None
def next_id(self) -> int:
"""Allocate the next shape ID."""
@@ -185,6 +189,7 @@ class ConvertContext:
image_quality=self.image_quality,
trace_events=self.trace_events,
theme_font_spec=self.theme_font_spec,
+ theme_color_spec=self.theme_color_spec,
)
def sync_from_child(self, child_ctx: ConvertContext) -> None:
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 654b6fb5..aa2baf1b 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/converter.py
@@ -11,6 +11,7 @@ from xml.etree import ElementTree as ET
from resource_paths import icon_search_dirs_for_svg
from .context import ConvertContext, ShapeResult
+from .theme_colors import ThemeColorSpec
from .theme_fonts import ThemeFontSpec
from .utils import (
SVG_NS, EMU_PER_PX,
@@ -414,7 +415,12 @@ def _background_xml_from_rect(
ctx: ConvertContext,
) -> str:
"""Build native ``p:bg`` XML from a full-slide SVG background rect."""
- fill_xml = build_fill_xml(elem, ctx, get_fill_opacity(elem, ctx))
+ fill_xml = build_fill_xml(
+ elem,
+ ctx,
+ get_fill_opacity(elem, ctx),
+ usage="background",
+ )
if not fill_xml or '<a:noFill' in fill_xml:
return ''
return f'<p:bg><p:bgPr>{fill_xml}<a:effectLst/></p:bgPr></p:bg>'
@@ -577,6 +583,7 @@ def convert_svg_to_slide_shapes(
image_quality: int = 85,
native_objects: bool = False,
theme_font_spec: ThemeFontSpec | None = None,
+ theme_color_spec: ThemeColorSpec | None = None,
trace_out: list[dict[str, Any]] | None = None,
) -> tuple[
str,
@@ -606,6 +613,9 @@ def convert_svg_to_slide_shapes(
markers to native PowerPoint objects. Default off.
theme_font_spec: Optional major/minor theme-font contract. Matching SVG
families emit DrawingML theme tokens instead of fixed typefaces.
+ theme_color_spec: Optional context-aware theme-color contract. Exact
+ locked colors emit DrawingML scheme tokens while local colors stay
+ fixed.
trace_out: Optional list populated with one per-slide trace dictionary.
Returns:
@@ -684,6 +694,7 @@ def convert_svg_to_slide_shapes(
native_objects_enabled=native_objects,
trace_events=trace_events,
theme_font_spec=theme_font_spec,
+ theme_color_spec=theme_color_spec,
)
shapes: list[str] = []
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
index 131478ad..b19d0834 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -14,6 +14,7 @@ from xml.etree import ElementTree as ET
from resource_paths import resolve_external_image_reference
from .context import ConvertContext, ShapeResult
+from .theme_colors import color_node_xml
from .theme_fonts import theme_font_tokens
from .utils import (
SVG_NS, XLINK_NS, ANGLE_UNIT, FONT_PX_TO_HUNDREDTHS_PT, DASH_PRESETS,
@@ -556,10 +557,18 @@ def convert_circle(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
op = get_fill_opacity(elem, ctx)
grad_id = resolve_url_id(stroke_val) if stroke_val else None
if grad_id and grad_id in ctx.defs:
- fill = build_gradient_fill(ctx.defs[grad_id], op)
+ fill = build_gradient_fill(
+ ctx.defs[grad_id],
+ op,
+ ctx.theme_color_spec,
+ "fill",
+ )
elif stroke_val:
color = parse_hex_color(stroke_val)
- fill = build_solid_fill(color, op) if color else '<a:noFill/>'
+ fill = (
+ build_solid_fill(color, op, ctx.theme_color_spec, "fill")
+ if color else '<a:noFill/>'
+ )
else:
fill = '<a:noFill/>'
@@ -1210,12 +1219,18 @@ def _bullet_indent_px(bullet: dict[str, Any], font_size: float) -> float:
return -_bullet_margin_px(bullet, font_size)
-def _build_bullet_xml(bullet: dict[str, Any] | None) -> str:
+def _build_bullet_xml(
+ bullet: dict[str, Any] | None,
+ ctx: ConvertContext | None,
+) -> str:
if not bullet:
return ''
fill = bullet.get('fill')
if isinstance(fill, str) and re.fullmatch(r'[0-9A-Fa-f]{6}', fill):
- color_xml = f'<a:buClr><a:srgbClr val="{fill.upper()}"/></a:buClr>'
+ theme_spec = ctx.theme_color_spec if ctx is not None else None
+ color_xml = (
+ f'<a:buClr>{color_node_xml(fill, theme_spec, "text")}</a:buClr>'
+ )
else:
color_xml = '<a:buClrTx/>'
return (
@@ -1230,13 +1245,14 @@ def _paragraph_pr_xml(
font_size: float,
body_xml: str = '',
bullet: dict[str, Any] | None = None,
+ ctx: ConvertContext | None = None,
) -> str:
attrs = f'algn="{algn}"'
if bullet:
margin = px_to_emu(_bullet_margin_px(bullet, font_size))
indent = px_to_emu(_bullet_indent_px(bullet, font_size))
attrs += f' marL="{margin}" indent="{indent}"'
- return f'<a:pPr {attrs}>{body_xml}{_build_bullet_xml(bullet)}</a:pPr>'
+ return f'<a:pPr {attrs}>{body_xml}{_build_bullet_xml(bullet, ctx)}</a:pPr>'
def _estimate_bullet_line_width(runs: list[dict[str, Any]]) -> float:
@@ -1388,15 +1404,28 @@ def _build_text_fill_xml(
grad_id = resolve_url_id(fill_raw)
if grad_id and ctx and grad_id in ctx.defs:
- return build_gradient_fill(ctx.defs[grad_id], opacity)
+ return build_gradient_fill(
+ ctx.defs[grad_id],
+ opacity,
+ ctx.theme_color_spec,
+ "text",
+ )
alpha_xml = ''
if opacity is not None and opacity < 1.0:
alpha_xml = f'<a:alphaMod val="{int(opacity * 100000)}"/>'
- return f'<a:solidFill><a:srgbClr val="{fill}">{alpha_xml}</a:srgbClr></a:solidFill>'
+ theme_spec = ctx.theme_color_spec if ctx is not None else None
+ return (
+ '<a:solidFill>'
+ f'{color_node_xml(fill, theme_spec, "text", alpha_xml)}'
+ '</a:solidFill>'
+ )
-def _build_text_outline_xml(run: dict[str, Any]) -> str:
+def _build_text_outline_xml(
+ run: dict[str, Any],
+ ctx: ConvertContext | None,
+) -> str:
"""Build DrawingML outline XML for a text run from SVG stroke attributes."""
stroke_raw = run.get('stroke_raw')
if not stroke_raw or stroke_raw.strip().lower() in ('none', 'transparent'):
@@ -1412,9 +1441,12 @@ def _build_text_outline_xml(run: dict[str, Any]) -> str:
if stroke_opacity is not None and stroke_opacity < 1.0:
alpha_xml = f'<a:alphaMod val="{int(stroke_opacity * 100000)}"/>'
+ theme_spec = ctx.theme_color_spec if ctx is not None else None
return (
f'<a:ln w="{px_to_emu(stroke_width)}">'
- f'<a:solidFill><a:srgbClr val="{color}">{alpha_xml}</a:srgbClr></a:solidFill>'
+ '<a:solidFill>'
+ f'{color_node_xml(color, theme_spec, "stroke", alpha_xml)}'
+ '</a:solidFill>'
'</a:ln>'
)
@@ -1457,7 +1489,7 @@ def _build_run_xml(
lang = detect_text_lang(text)
fill_xml = _build_text_fill_xml(fill, fill_raw, opacity, ctx)
- outline_xml = _build_text_outline_xml(run)
+ outline_xml = _build_text_outline_xml(run, ctx)
space_attr = ' xml:space="preserve"' if text != text.strip() or ' ' in text else ''
@@ -1715,6 +1747,7 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
font_size=float(line[0].get('font_size', font_size)) if line else font_size,
body_xml=f'{ln_spc_xml}{spc_bef_xml}',
bullet=bullet,
+ ctx=ctx,
)
paragraph_xml_chunks.append(
f'<a:p>\n{p_pr_xml}\n{runs_inner}\n</a:p>'
@@ -1726,6 +1759,7 @@ def convert_text(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
algn=algn,
font_size=float(runs[0].get('font_size', font_size)) if runs else font_size,
bullet=single_bullet,
+ ctx=ctx,
)
paragraphs_xml = f'<a:p>\n{p_pr_xml}\n{runs_xml}\n</a:p>'
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
index f6280c36..554e52cb 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/styles.py
@@ -7,6 +7,7 @@ import re
from xml.etree import ElementTree as ET
from .context import ConvertContext
+from .theme_colors import ThemeColorSpec, color_node_xml
from .utils import (
SVG_NS, ANGLE_UNIT, DASH_PRESETS,
px_to_emu, _f, _get_attr, parse_svg_length,
@@ -14,17 +15,28 @@ from .utils import (
)
-def build_solid_fill(color: str, opacity: float | None = None) -> str:
+def build_solid_fill(
+ color: str,
+ opacity: float | None = None,
+ theme_color_spec: ThemeColorSpec | None = None,
+ usage: str = "fill",
+) -> str:
"""Build <a:solidFill> XML."""
alpha = ''
if opacity is not None and opacity < 1.0:
alpha = f'<a:alpha val="{int(opacity * 100000)}"/>'
- return f'<a:solidFill><a:srgbClr val="{color}">{alpha}</a:srgbClr></a:solidFill>'
+ return (
+ '<a:solidFill>'
+ f'{color_node_xml(color, theme_color_spec, usage, alpha)}'
+ '</a:solidFill>'
+ )
def build_gradient_fill(
grad_elem: ET.Element,
opacity: float | None = None,
+ theme_color_spec: ThemeColorSpec | None = None,
+ usage: str = "fill",
) -> str:
"""Build <a:gradFill> from SVG linearGradient or radialGradient element."""
tag = grad_elem.tag.replace(f'{{{SVG_NS}}}', '')
@@ -67,7 +79,9 @@ def build_gradient_fill(
alpha_xml = f'<a:alpha val="{int(effective_opacity * 100000)}"/>'
stops_xml.append(
- f'<a:gs pos="{pos}"><a:srgbClr val="{color}">{alpha_xml}</a:srgbClr></a:gs>'
+ f'<a:gs pos="{pos}">'
+ f'{color_node_xml(color, theme_color_spec, usage, alpha_xml)}'
+ '</a:gs>'
)
if not stops_xml:
@@ -112,6 +126,7 @@ def build_fill_xml(
elem: ET.Element,
ctx: ConvertContext,
opacity: float | None = None,
+ usage: str = "fill",
) -> str:
"""Build fill XML for a shape element, with inherited style support."""
fill = _get_attr(elem, 'fill', ctx)
@@ -126,15 +141,25 @@ def build_fill_xml(
ref_elem = ctx.defs[ref_id]
ref_tag = ref_elem.tag.replace(f'{{{SVG_NS}}}', '')
if ref_tag == 'pattern':
- patt_xml = build_pattern_fill(ref_elem, opacity)
+ patt_xml = build_pattern_fill(
+ ref_elem,
+ opacity,
+ ctx.theme_color_spec,
+ usage,
+ )
if patt_xml:
return patt_xml
return '<a:noFill/>'
- return build_gradient_fill(ref_elem, opacity)
+ return build_gradient_fill(
+ ref_elem,
+ opacity,
+ ctx.theme_color_spec,
+ usage,
+ )
color = parse_hex_color(fill)
if color:
- return build_solid_fill(color, opacity)
+ return build_solid_fill(color, opacity, ctx.theme_color_spec, usage)
return '<a:noFill/>'
@@ -142,6 +167,8 @@ def build_fill_xml(
def build_pattern_fill(
pattern_elem: ET.Element,
opacity: float | None = None,
+ theme_color_spec: ThemeColorSpec | None = None,
+ usage: str = "fill",
) -> str:
"""Build <a:pattFill> from an SVG <pattern> emitted by pptx_to_svg.
@@ -172,11 +199,11 @@ def build_pattern_fill(
if opacity is not None and opacity < 1.0:
alpha_xml = f'<a:alpha val="{int(opacity * 100000)}"/>'
- fg_xml = f'<a:srgbClr val="{fg_hex}">{alpha_xml}</a:srgbClr>'
+ fg_xml = color_node_xml(fg_hex, theme_color_spec, usage, alpha_xml)
if bg_hex:
- bg_xml = f'<a:srgbClr val="{bg_hex}"/>'
+ bg_xml = color_node_xml(bg_hex, theme_color_spec, usage)
else:
- bg_xml = '<a:srgbClr val="FFFFFF"/>'
+ bg_xml = color_node_xml('FFFFFF', theme_color_spec, usage)
return (
f'<a:pattFill prst="{prst}">'
@@ -396,7 +423,12 @@ def build_stroke_xml(
# Gradient stroke
grad_id = resolve_url_id(stroke)
if grad_id and grad_id in ctx.defs:
- grad_fill = build_gradient_fill(ctx.defs[grad_id], opacity)
+ grad_fill = build_gradient_fill(
+ ctx.defs[grad_id],
+ opacity,
+ ctx.theme_color_spec,
+ "stroke",
+ )
return f'<a:ln w="{width_emu}"{cap_attr}>{grad_fill}{dash_xml}{join_xml}{line_ends}</a:ln>'
# Solid color stroke
@@ -408,8 +440,9 @@ def build_stroke_xml(
if opacity is not None and opacity < 1.0:
alpha_xml = f'<a:alpha val="{int(opacity * 100000)}"/>'
+ color_xml = color_node_xml(color, ctx.theme_color_spec, "stroke", alpha_xml)
return f'''<a:ln w="{width_emu}"{cap_attr}>
-<a:solidFill><a:srgbClr val="{color}">{alpha_xml}</a:srgbClr></a:solidFill>{dash_xml}{join_xml}{line_ends}
+<a:solidFill>{color_xml}</a:solidFill>{dash_xml}{join_xml}{line_ends}
</a:ln>'''
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py
new file mode 100644
index 00000000..ebdb66cc
--- /dev/null
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/theme_colors.py
@@ -0,0 +1,276 @@
+"""Theme-color contracts shared by SVG conversion and PPTX package assembly."""
+
+from __future__ import annotations
+
+import re
+from dataclasses import dataclass
+from pathlib import Path
+from xml.etree import ElementTree as ET
+
+from .utils import parse_hex_color
+
+
+DML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"
+_LOCK_ROW_RE = re.compile(r"^-\s+([A-Za-z0-9_]+)\s*:\s*(.+?)\s*$")
+_SRGB_PAIR_RE = re.compile(
+ r"<a:srgbClr\b(?P<attrs>[^>]*)>(?P<body>.*?)</a:srgbClr>",
+ re.DOTALL,
+)
+_SRGB_EMPTY_RE = re.compile(r"<a:srgbClr\b(?P<attrs>[^>]*)/>")
+_VAL_RE = re.compile(r'\bval="(?P<color>[0-9A-Fa-f]{6})"')
+
+_OFFICE_DEFAULTS = {
+ "dk1": "000000",
+ "lt1": "FFFFFF",
+ "dk2": "1F497D",
+ "lt2": "EEECE1",
+ "accent1": "4F81BD",
+ "accent2": "C0504D",
+ "accent3": "9BBB59",
+ "accent4": "8064A2",
+ "accent5": "4BACC6",
+ "accent6": "F79646",
+ "hlink": "0000FF",
+ "folHlink": "800080",
+}
+_ROLE_SLOTS = {
+ "bg": "lt1",
+ "background": "lt1",
+ "master_bg": "lt1",
+ "secondary_bg": "lt2",
+ "bg_secondary": "lt2",
+ "text": "dk1",
+ "body_text": "dk1",
+ "text_secondary": "dk2",
+ "primary": "accent1",
+ "accent": "accent2",
+ "secondary_accent": "accent3",
+ "border": "accent4",
+}
+_USAGE_ROLE_ORDER = {
+ "background": (
+ "bg", "background", "master_bg", "secondary_bg", "bg_secondary",
+ "primary", "accent", "secondary_accent",
+ ),
+ "fill": (
+ "primary", "accent", "secondary_accent", "bg", "background",
+ "master_bg", "secondary_bg", "bg_secondary", "text", "body_text",
+ "text_secondary", "border",
+ ),
+ "text": (
+ "text", "body_text", "text_secondary", "primary", "accent",
+ "secondary_accent",
+ ),
+ "stroke": (
+ "border", "primary", "accent", "secondary_accent", "text",
+ "body_text", "text_secondary",
+ ),
+ "chart": ("primary", "accent", "secondary_accent"),
+}
+_BACKGROUND_ROLE_TOKENS = (
+ "bg", "background", "surface", "paper", "card", "panel", "tint",
+)
+_TEXT_ROLE_TOKENS = ("text", "ink", "muted")
+_STROKE_ROLE_TOKENS = ("border", "grid", "line", "stroke")
+_BACKGROUND_USAGES = frozenset({"background", "fill"})
+_TEXT_USAGES = frozenset({"text"})
+_STROKE_USAGES = frozenset({"stroke", "fill"})
+_SEMANTIC_USAGES = frozenset({"fill", "text", "stroke"})
+
+
+class ThemeColorError(RuntimeError):
+ """Raised when a project theme-color contract cannot be loaded or applied."""
+
+
+@dataclass(frozen=True)
+class ThemeColorSpec:
+ """PowerPoint color scheme derived from one project's color lock."""
+
+ slots: dict[str, str]
+ roles: dict[str, str]
+ role_slots: dict[str, str]
+ extra_roles: tuple[str, ...] = ()
+
+ def scheme_for(self, color: str, usage: str) -> str | None:
+ """Resolve one concrete color to a safe scheme slot for its usage."""
+ normalized = parse_hex_color(color)
+ if normalized is None:
+ return None
+ for role in _USAGE_ROLE_ORDER.get(usage, ()):
+ if self.roles.get(role) == normalized:
+ slot = self.role_slots[role]
+ if self.slots.get(slot) == normalized:
+ return slot
+ for role in self.extra_roles:
+ if usage in _extra_role_usages(role) and self.roles.get(role) == normalized:
+ slot = self.role_slots[role]
+ if self.slots.get(slot) == normalized:
+ return slot
+ return None
+
+
+def _extra_role_usages(role: str) -> frozenset[str]:
+ """Limit extra theme slots to contexts implied by their lock role name."""
+ normalized = role.lower()
+ if any(token in normalized for token in _BACKGROUND_ROLE_TOKENS):
+ return _BACKGROUND_USAGES
+ if any(token in normalized for token in _TEXT_ROLE_TOKENS):
+ return _TEXT_USAGES
+ if any(token in normalized for token in _STROKE_ROLE_TOKENS):
+ return _STROKE_USAGES
+ return _SEMANTIC_USAGES
+
+
+def _color_rows(lock_path: Path) -> dict[str, str]:
+ rows: dict[str, str] = {}
+ current_section: str | None = None
+ try:
+ lines = lock_path.read_text(encoding="utf-8").splitlines()
+ except OSError as exc:
+ raise ThemeColorError(f"Cannot read {lock_path}: {exc}") from exc
+ for raw_line in lines:
+ line = raw_line.strip()
+ if line.startswith("## "):
+ current_section = line[3:].strip()
+ continue
+ if current_section != "colors":
+ continue
+ match = _LOCK_ROW_RE.fullmatch(line)
+ if not match:
+ continue
+ color = parse_hex_color(match.group(2))
+ if color is not None:
+ rows[match.group(1)] = color
+ return rows
+
+
+def _first_color(roles: dict[str, str], *keys: str, default: str) -> str:
+ return next((roles[key] for key in keys if key in roles), default)
+
+
+def load_theme_color_spec(project_path: Path) -> ThemeColorSpec | None:
+ """Load a PowerPoint color scheme from ``spec_lock.md`` color rows."""
+ lock_path = project_path / "spec_lock.md"
+ if not lock_path.is_file():
+ return None
+ roles = _color_rows(lock_path)
+ if not roles:
+ return None
+
+ extra_roles = tuple(
+ key
+ for key, color in roles.items()
+ if key not in _ROLE_SLOTS and color not in {"000000", "FFFFFF"}
+ )[:2]
+ extra_slots = dict(zip(extra_roles, ("accent5", "accent6")))
+ role_slots = {**_ROLE_SLOTS, **extra_slots}
+
+ slots = dict(_OFFICE_DEFAULTS)
+ slots.update({
+ "lt1": _first_color(
+ roles,
+ "bg", "background", "master_bg",
+ default=slots["lt1"],
+ ),
+ "dk1": _first_color(
+ roles,
+ "text", "body_text", "primary",
+ default=slots["dk1"],
+ ),
+ "lt2": _first_color(
+ roles,
+ "secondary_bg", "bg_secondary", "bg", "background", "master_bg",
+ default=slots["lt2"],
+ ),
+ "dk2": _first_color(roles, "text_secondary", "text", default=slots["dk2"]),
+ "accent1": _first_color(roles, "primary", "accent", default=slots["accent1"]),
+ "accent2": _first_color(
+ roles,
+ "accent", "secondary_accent", "primary",
+ default=slots["accent2"],
+ ),
+ "accent3": _first_color(roles, "secondary_accent", "accent", default=slots["accent3"]),
+ "accent4": _first_color(roles, "border", "primary", default=slots["accent4"]),
+ "hlink": _first_color(roles, "accent", "primary", default=slots["hlink"]),
+ "folHlink": _first_color(roles, "secondary_accent", "accent", default=slots["folHlink"]),
+ })
+ for role, slot in extra_slots.items():
+ slots[slot] = roles[role]
+ return ThemeColorSpec(
+ slots=slots,
+ roles=roles,
+ role_slots=role_slots,
+ extra_roles=extra_roles,
+ )
+
+
+def color_node_xml(
+ color: str,
+ spec: ThemeColorSpec | None,
+ usage: str,
+ inner_xml: str = "",
+) -> str:
+ """Build an srgbClr or schemeClr node while preserving child transforms."""
+ normalized = parse_hex_color(color) or color.strip().lstrip("#").upper()
+ scheme = spec.scheme_for(normalized, usage) if spec is not None else None
+ if scheme:
+ return f'<a:schemeClr val="{scheme}">{inner_xml}</a:schemeClr>'
+ return f'<a:srgbClr val="{normalized}">{inner_xml}</a:srgbClr>'
+
+
+def _set_scheme_color(parent: ET.Element, slot: str, color: str) -> None:
+ target = parent.find(f"{{{DML_NS}}}{slot}")
+ if target is None:
+ target = ET.SubElement(parent, f"{{{DML_NS}}}{slot}")
+ for child in list(target):
+ target.remove(child)
+ ET.SubElement(target, f"{{{DML_NS}}}srgbClr", {"val": color})
+
+
+def apply_theme_color_spec(extract_dir: Path, spec: ThemeColorSpec) -> None:
+ """Install the locked color scheme into every existing PPTX theme part."""
+ theme_dir = extract_dir / "ppt" / "theme"
+ theme_paths = sorted(theme_dir.glob("theme*.xml"))
+ if not theme_paths:
+ raise ThemeColorError(f"PPTX package has no theme part under {theme_dir}")
+
+ ET.register_namespace("a", DML_NS)
+ for theme_path in theme_paths:
+ try:
+ tree = ET.parse(theme_path)
+ except (OSError, ET.ParseError) as exc:
+ raise ThemeColorError(f"Cannot parse {theme_path}: {exc}") from exc
+ color_scheme = tree.getroot().find(f".//{{{DML_NS}}}clrScheme")
+ if color_scheme is None:
+ raise ThemeColorError(f"Theme has no clrScheme: {theme_path}")
+ color_scheme.set("name", "PPT Master")
+ for slot, color in spec.slots.items():
+ _set_scheme_color(color_scheme, slot, color)
+ tree.write(theme_path, encoding="utf-8", xml_declaration=True)
+
+
+def rewrite_chart_accent_colors(data: bytes, spec: ThemeColorSpec | None) -> bytes:
+ """Promote exact locked accent colors inside native chart XML."""
+ if spec is None or b"<a:srgbClr" not in data:
+ return data
+ try:
+ text = data.decode("utf-8")
+ except UnicodeDecodeError:
+ return data
+
+ def replacement(match: re.Match[str], *, paired: bool) -> str:
+ attrs = match.group("attrs")
+ value_match = _VAL_RE.search(attrs)
+ if value_match is None:
+ return match.group(0)
+ scheme = spec.scheme_for(value_match.group("color"), "chart")
+ if scheme is None:
+ return match.group(0)
+ new_attrs = _VAL_RE.sub(f'val="{scheme}"', attrs, count=1)
+ if paired:
+ return f'<a:schemeClr{new_attrs}>{match.group("body")}</a:schemeClr>'
+ return f'<a:schemeClr{new_attrs}/>'
+
+ text = _SRGB_PAIR_RE.sub(lambda match: replacement(match, paired=True), text)
+ text = _SRGB_EMPTY_RE.sub(lambda match: replacement(match, paired=False), text)
+ return text.encode("utf-8")
diff --git a/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py b/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
index eab4cc10..f655fb35 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/native_objects/table.py
@@ -6,6 +6,7 @@ from typing import Any
from xml.etree import ElementTree as ET
from ..drawingml.context import ConvertContext, ShapeResult
+from ..drawingml.theme_colors import ThemeColorSpec, color_node_xml
from ..drawingml.utils import _xml_escape
from .chart_style import _font_face_xml
from .marker_common import (
@@ -31,11 +32,12 @@ def _table_text_run(
bold: bool | None,
font_size: int | None,
font_face: str | None,
+ theme_color_spec: ThemeColorSpec | None,
) -> str:
size_attr = f' sz="{font_size}"' if font_size is not None else ""
bold_attr = f' b="{_bool_attr(bold)}"' if bold is not None else ""
color_xml = (
- f'<a:solidFill><a:srgbClr val="{color}"/></a:solidFill>'
+ f'<a:solidFill>{color_node_xml(color, theme_color_spec, "text")}</a:solidFill>'
if color else ""
)
space_attr = ' xml:space="preserve"' if text != text.strip() else ""
@@ -358,14 +360,18 @@ def _table_border_width(cell_data: dict[str, Any], style: dict[str, Any]) -> flo
return _number(1 if width_raw is None else width_raw, "table border_width")
-def _table_border_xml(cell_data: dict[str, Any], style: dict[str, Any]) -> str:
+def _table_border_xml(
+ cell_data: dict[str, Any],
+ style: dict[str, Any],
+ theme_color_spec: ThemeColorSpec | None,
+) -> str:
color_raw = cell_data.get("border_color", cell_data.get("borderColor", style.get("border_color")))
width = _table_border_width(cell_data, style)
if width <= 0:
return ""
color = _clean_hex(color_raw, "#D9DEE7")
line = (
- f'<a:solidFill><a:srgbClr val="{color}"/></a:solidFill>'
+ f'<a:solidFill>{color_node_xml(color, theme_color_spec, "stroke")}</a:solidFill>'
'<a:prstDash val="solid"/>'
)
line_width = _powerpoint_line_width_emu(width, "table border_width")
@@ -469,16 +475,30 @@ def _build_native_table(elem: ET.Element, ctx: ConvertContext, payload: dict[str
if not preserve_source_style or anchor_keys.intersection(cell_data) or anchor_keys.intersection(style):
anchor_attr = f' anchor="{_table_anchor(cell_data, style)}"'
tc_pr_attrs = f'{anchor_attr}{_table_padding_attrs(cell_data, style)}'
- border_xml = _table_border_xml(cell_data, style)
+ border_xml = _table_border_xml(
+ cell_data,
+ style,
+ ctx.theme_color_spec,
+ )
fill_xml = (
- f'<a:solidFill><a:srgbClr val="{fill}"/></a:solidFill>'
+ '<a:solidFill>'
+ f'{color_node_xml(fill, ctx.theme_color_spec, "fill")}'
+ '</a:solidFill>'
if fill else ""
)
+ text_run_xml = _table_text_run(
+ text,
+ color=color,
+ bold=bold,
+ font_size=cell_font_size,
+ font_face=font_face,
+ theme_color_spec=ctx.theme_color_spec,
+ )
cells_xml.append(
"<a:tc>"
"<a:txBody><a:bodyPr/><a:lstStyle/>"
f"<a:p>{paragraph_props}"
- f"{_table_text_run(text, color=color, bold=bold, font_size=cell_font_size, font_face=font_face)}"
+ f"{text_run_xml}"
"</a:p></a:txBody>"
f'<a:tcPr{tc_pr_attrs}>{border_xml}{fill_xml}</a:tcPr>'
"</a:tc>"
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
index 9a18e123..e4d10ac9 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/builder.py
@@ -27,6 +27,11 @@ from pptx import Presentation
from pptx.util import Emu
from ..drawingml.converter import convert_svg_to_slide_shapes
+from ..drawingml.theme_colors import (
+ ThemeColorSpec,
+ apply_theme_color_spec,
+ rewrite_chart_accent_colors,
+)
from ..drawingml.theme_fonts import (
ThemeFontSpec,
apply_theme_font_spec,
@@ -2867,6 +2872,7 @@ def create_pptx_with_native_svg(
pptx_structure: str = "baseline",
native_structure_contract: NativeStructureContract | None = None,
theme_font_spec: ThemeFontSpec | None = None,
+ theme_color_spec: ThemeColorSpec | None = None,
) -> bool:
"""Create a PPTX file with native SVG.
@@ -2912,6 +2918,9 @@ def create_pptx_with_native_svg(
``preserve`` mode.
theme_font_spec: Locked project major/minor fonts for baseline/template
theme inheritance. Preserve and flat modes ignore this value.
+ theme_color_spec: Locked project color scheme for context-aware
+ baseline/template theme inheritance. Preserve and flat modes
+ ignore this value.
Returns:
Whether all slides were successfully created.
@@ -3062,6 +3071,13 @@ def create_pptx_with_native_svg(
)
if active_theme_font_spec is not None:
apply_theme_font_spec(extract_dir, active_theme_font_spec)
+ active_theme_color_spec = (
+ theme_color_spec
+ if use_native_shapes and pptx_structure in {"baseline", "template"}
+ else None
+ )
+ if active_theme_color_spec is not None:
+ apply_theme_color_spec(extract_dir, active_theme_color_spec)
structure = _read_slide_layout_targets(extract_dir, len(svg_files))
media_dir = extract_dir / 'ppt' / 'media'
@@ -3126,6 +3142,7 @@ def create_pptx_with_native_svg(
image_quality=image_quality,
native_objects=native_objects,
theme_font_spec=active_theme_font_spec,
+ theme_color_spec=active_theme_color_spec,
trace_out=conversion_trace
if conversion_trace is not None
else structure_trace,
@@ -3226,6 +3243,14 @@ def create_pptx_with_native_svg(
# object converters, e.g. chart XML, chart rels, and
# embedded workbooks.
for part_name, part_data in package_files_dict.items():
+ if (
+ part_name.startswith('ppt/charts/')
+ and part_name.endswith('.xml')
+ ):
+ part_data = rewrite_chart_accent_colors(
+ part_data,
+ active_theme_color_spec,
+ )
package_path = extract_dir / part_name
package_path.parent.mkdir(parents=True, exist_ok=True)
with open(package_path, 'wb') as f:
diff --git a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
index b01521eb..35ec1ed4 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/pptx_package/cli.py
@@ -29,6 +29,7 @@ if __package__ in {None, ''}:
from .dimensions import CANVAS_FORMATS, get_project_info, get_viewbox_dimensions
from .discovery import find_svg_files, find_notes_files
from .builder import create_pptx_with_native_svg
+from ..drawingml.theme_colors import ThemeColorError, load_theme_color_spec
from ..drawingml.theme_fonts import ThemeFontError, load_theme_font_spec
from .narration import NARRATION_EXTENSIONS, find_narration_files, probe_audio_duration
from .slide_xml import TRANSITIONS
@@ -363,10 +364,12 @@ Recorded narration:
print(f"Error: {exc}", file=sys.stderr)
return 1
theme_font_spec = None
+ theme_color_spec = None
if pptx_structure in {'baseline', 'template'}:
try:
theme_font_spec = load_theme_font_spec(project_path)
- except ThemeFontError as exc:
+ theme_color_spec = load_theme_color_spec(project_path)
+ except (ThemeFontError, ThemeColorError) as exc:
print(f"Error: {exc}", file=sys.stderr)
return 1
if args.image_max_dimension < 1:
@@ -752,6 +755,7 @@ Recorded narration:
pptx_structure=pptx_structure,
native_structure_contract=native_structure_contract,
theme_font_spec=theme_font_spec,
+ theme_color_spec=theme_color_spec,
)
success = True
diff --git a/skills/ppt-master/templates/spec_lock_reference.md b/skills/ppt-master/templates/spec_lock_reference.md
index b88d4ac2..fa5c4b27 100644
--- a/skills/ppt-master/templates/spec_lock_reference.md
+++ b/skills/ppt-master/templates/spec_lock_reference.md
@@ -37,6 +37,8 @@
> Strategist: fill only colors actually used. Add extra rows as needed; delete unused rows rather than leave as `#......`.
>
+> **PowerPoint theme roles.** Native `baseline` / `template` export maps `bg` / `background` / `master_bg` → `lt1`, `secondary_bg` / `bg_secondary` → `lt2`, `text` / `body_text` → `dk1`, `text_secondary` → `dk2`, `primary` → `accent1`, `accent` → `accent2`, `secondary_accent` → `accent3`, and `border` → `accent4`. The first two additional non-black/non-white roles become `accent5` / `accent6`; remaining colors stay fixed. Mapping is usage-aware, so a background HEX is not automatically reused for inverse text. Preserve mode keeps the imported source theme; flat mode keeps concrete colors for diagnostics.
+>
> **`image_rendering` and `image_palette`** — required only when `images` section below contains `ai`-sourced files. Values MUST be valid names from `references/image-renderings/_index.md` and `references/image-palettes/_index.md`, **or** the literal string `custom`. Image_Generator reads these and applies them deck-wide. Omit both rows when the deck has no AI-generated images.
>
> **`custom` escape hatch.** When set to `custom`, add a sibling `*_behavior` row carrying a one-paragraph prose description. Image_Generator splices the prose into the prompt in place of the preset file's fewshot snippet. Tail-case only — see [`image-renderings/_index.md`](../references/image-renderings/_index.md) §1.5 / [`image-palettes/_index.md`](../references/image-palettes/_index.md) §2 for invocation rules.