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(text-fill): support native picture fills for editable text

hugohe36d6bf871b7b9
diff --git a/skills/ppt-master/scripts/svg_quality/checker.py b/skills/ppt-master/scripts/svg_quality/checker.py
index a9948f1d..ae3d4b5c 100644
--- a/skills/ppt-master/scripts/svg_quality/checker.py
+++ b/skills/ppt-master/scripts/svg_quality/checker.py
@@ -86,6 +86,7 @@ try:
from svg_to_pptx.drawingml.utils import (
IDENTITY_MATRIX as _IDENTITY_MATRIX,
PROJECT_PAINT_PROPERTIES as _PAINT_PROPERTIES,
+ PROJECT_TEXT_IMAGE_FILL_ATTR as _TEXT_IMAGE_FILL_ATTR,
detect_text_lang as _detect_text_lang,
matrix_multiply as _matrix_multiply,
parse_inline_style as _parse_inline_style,
@@ -103,6 +104,7 @@ try:
except ImportError:
_IDENTITY_MATRIX = None
_PAINT_PROPERTIES = None
+ _TEXT_IMAGE_FILL_ATTR = 'data-pptx-text-image-fill'
_detect_text_lang = None
_matrix_multiply = None
_parse_inline_style = None
@@ -3659,7 +3661,9 @@ class SVGQualityChecker:
svg_to_pptx maps <pattern fill> to native <a:pattFill prst="...">. The
preset name comes from `data-pptx-pattern` (e.g. `lgGrid` / `smGrid` /
- `dkUpDiag`). Two failure modes worth catching pre-export:
+ `dkUpDiag`). Patterns marked with `data-pptx-text-image-fill` instead
+ map to run-level <a:blipFill> and are validated by converter preflight.
+ Two preset-pattern failure modes are worth catching pre-export:
1. Missing annotation → the converter compatibility fallback chooses
`ltUpDiag` (diagonal stripes), which is not an authoring contract.
@@ -3691,6 +3695,8 @@ class SVGQualityChecker:
):
pat_id = pattern.get('id', '<unnamed>')
prst = pattern.get('data-pptx-pattern')
+ if pattern.get(_TEXT_IMAGE_FILL_ATTR) is not None:
+ continue
if pat_id in referenced_patterns and not prst:
result['warnings'].append(
f"Fidelity warning: <pattern id=\"{pat_id}\"> has no "
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 fed823d9..5181a1d7 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/context.py
@@ -127,6 +127,8 @@ class ConvertContext:
# Canonical BCP-47 content language from spec_lock.md. ``None`` preserves
# the legacy per-run script heuristic for older projects and lockless quick generation.
primary_language: str | None = None
+ # Reuse media relationships when the same image fills multiple text runs.
+ text_image_fill_cache: dict[tuple[str, str], str] = field(default_factory=dict)
def next_id(self) -> int:
"""Allocate the next shape ID."""
@@ -277,6 +279,7 @@ class ConvertContext:
theme_font_spec=self.theme_font_spec,
theme_color_spec=self.theme_color_spec,
primary_language=self.primary_language,
+ text_image_fill_cache=self.text_image_fill_cache,
)
def sync_from_child(self, child_ctx: ConvertContext) -> None:
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 887c531e..7f540b35 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/elements.py
@@ -56,7 +56,7 @@ from .utils import (
ctx_x, ctx_y, ctx_w, ctx_h,
rect_to_dml_xfrm,
combine_opacity, parse_hex_color, parse_svg_color,
- resolve_url_id, get_effective_filter_id,
+ resolve_project_text_image_fill, resolve_url_id, get_effective_filter_id,
parse_inline_style, parse_font_family, is_cjk_char,
detect_text_lang, estimate_text_cluster_widths, font_px_to_hpt,
resolve_text_run_fonts, split_project_text_clusters,
@@ -2463,14 +2463,32 @@ def _build_text_fill_xml(
if fill_raw.strip().lower() in ('none', 'transparent'):
return '<a:noFill/>'
- 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,
- ctx.theme_color_spec,
- "text",
- )
+ paint_id = resolve_url_id(fill_raw)
+ if paint_id and ctx and paint_id in ctx.defs:
+ paint = ctx.defs[paint_id]
+ paint_tag = paint.tag.rsplit('}', 1)[-1]
+ if paint_tag in {'linearGradient', 'radialGradient'}:
+ return build_gradient_fill(
+ paint,
+ opacity,
+ ctx.theme_color_spec,
+ "text",
+ )
+ if paint_tag == 'pattern':
+ mode, image = resolve_project_text_image_fill(paint)
+ source = load_project_image_source(image, ctx.svg_dir)
+ r_id = _register_image_media(
+ ctx,
+ source.img_format,
+ source.img_data,
+ reuse_text_fill=True,
+ )
+ blip_xml = _build_image_blip_xml(r_id, opacity)
+ if mode == 'stretch':
+ fill_mode_xml = '<a:stretch><a:fillRect/></a:stretch>'
+ else:
+ fill_mode_xml = '<a:tile/>'
+ return f'<a:blipFill>{blip_xml}{fill_mode_xml}</a:blipFill>'
parsed_color, color_alpha = parse_svg_color(fill_raw)
fill = parsed_color or fill
@@ -4267,6 +4285,34 @@ def _build_image_blip_xml(r_id: str, opacity: float | None) -> str:
)
+def _register_image_media(
+ ctx: ConvertContext,
+ img_format: str,
+ img_data: bytes,
+ *,
+ reuse_text_fill: bool = False,
+) -> str:
+ """Register image bytes and return a DrawingML relationship id."""
+ cache_key: tuple[str, str] | None = None
+ if reuse_text_fill:
+ cache_key = (img_format, hashlib.sha256(img_data).hexdigest())
+ if cache_key in ctx.text_image_fill_cache:
+ return ctx.text_image_fill_cache[cache_key]
+
+ img_idx = len(ctx.media_files) + 1
+ img_filename = f's{ctx.slide_num}_img{img_idx}.{img_format}'
+ ctx.media_files[img_filename] = img_data
+ r_id = ctx.next_rel_id()
+ ctx.rel_entries.append({
+ 'id': r_id,
+ 'type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
+ 'target': f'../media/{img_filename}',
+ })
+ if cache_key is not None:
+ ctx.text_image_fill_cache[cache_key] = r_id
+ return r_id
+
+
def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
"""Convert SVG <image> to DrawingML picture element.
@@ -4342,16 +4388,7 @@ def convert_image(elem: ET.Element, ctx: ConvertContext) -> ShapeResult | None:
visible_source_fraction=visible_source_fraction,
)
- img_idx = len(ctx.media_files) + 1
- img_filename = f's{ctx.slide_num}_img{img_idx}.{img_format}'
- ctx.media_files[img_filename] = img_data
-
- r_id = ctx.next_rel_id()
- ctx.rel_entries.append({
- 'id': r_id,
- 'type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
- 'target': f'../media/{img_filename}',
- })
+ r_id = _register_image_media(ctx, img_format, img_data)
# Resolve clip-path → DrawingML geometry
clip_geom = _resolve_clip_geometry(elem, ctx, raw_x, raw_y, raw_w, raw_h)
@@ -4965,16 +5002,7 @@ def convert_nested_svg(elem: ET.Element, ctx: ConvertContext) -> ShapeResult:
),
)
- img_idx = len(ctx.media_files) + 1
- img_filename = f's{ctx.slide_num}_img{img_idx}.{img_format}'
- ctx.media_files[img_filename] = img_data
-
- r_id = ctx.next_rel_id()
- ctx.rel_entries.append({
- 'id': r_id,
- 'type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
- 'target': f'../media/{img_filename}',
- })
+ r_id = _register_image_media(ctx, img_format, img_data)
shape_id = _claim_element_shape_id(elem, ctx)
xfrm_attr, off_x, off_y, ext_cx, ext_cy, bounds_emu = _picture_xfrm_from_svg_rect(
diff --git a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
index 447c7a54..8914eaf0 100644
--- a/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
+++ b/skills/ppt-master/scripts/svg_to_pptx/drawingml/utils.py
@@ -227,6 +227,8 @@ PROJECT_DEFINITION_TAGS = frozenset({
'radialGradient',
})
PROJECT_GRADIENT_TAGS = frozenset({'linearGradient', 'radialGradient'})
+PROJECT_TEXT_IMAGE_FILL_ATTR = 'data-pptx-text-image-fill'
+PROJECT_TEXT_IMAGE_FILL_MODES = frozenset({'stretch', 'tile'})
# PPTX angle projection can overshoot a unit box by at most ~0.1036.
PROJECT_LINEAR_GRADIENT_COORDINATE_MIN = -0.105
PROJECT_LINEAR_GRADIENT_COORDINATE_MAX = 1.105
@@ -2157,6 +2159,51 @@ def project_marker_errors(root: ET.Element) -> list[str]:
return sorted(errors)
+def resolve_project_text_image_fill(pattern: ET.Element) -> tuple[str, ET.Element]:
+ """Resolve the controlled one-image pattern used for native text picture fills."""
+ if _svg_element_tag(pattern) != 'pattern':
+ raise ValueError('definition must be an SVG <pattern>')
+
+ mode = pattern.get(PROJECT_TEXT_IMAGE_FILL_ATTR, '')
+ if mode not in PROJECT_TEXT_IMAGE_FILL_MODES:
+ supported = ', '.join(sorted(PROJECT_TEXT_IMAGE_FILL_MODES))
+ raise ValueError(f'{PROJECT_TEXT_IMAGE_FILL_ATTR} must be one of: {supported}')
+ preset_attributes = [
+ name
+ for name in ('data-pptx-pattern', 'data-pptx-fg', 'data-pptx-bg')
+ if pattern.get(name) is not None
+ ]
+ if preset_attributes:
+ raise ValueError(
+ 'text image fill must not combine preset-pattern attributes: '
+ f'{", ".join(preset_attributes)}'
+ )
+ if pattern.get('patternTransform') is not None:
+ raise ValueError('pattern must not use patternTransform')
+
+ children = list(pattern)
+ if len(children) != 1 or children[0].tag != f'{{{SVG_NS}}}image':
+ raise ValueError('pattern must contain exactly one direct SVG <image> child')
+
+ image = children[0]
+ unsupported = [
+ name
+ for name in (
+ 'clip-path',
+ 'filter',
+ 'fill-opacity',
+ 'mask',
+ 'opacity',
+ 'style',
+ 'transform',
+ )
+ if image.get(name) is not None
+ ]
+ if unsupported:
+ raise ValueError(f"pattern image must not use {', '.join(unsupported)}")
+ return mode, image
+
+
def project_paint_reference_errors(root: ET.Element) -> list[str]:
"""Validate local paint-server references and their native contexts."""
definitions, _duplicates = project_definition_index(root)
@@ -2215,7 +2262,11 @@ def project_paint_reference_errors(root: ET.Element) -> list[str]:
elif property_name == 'stroke' and elem_tag_lower in stroke_shape_tags:
allowed_tags = ('lineargradient', 'radialgradient')
elif property_name == 'fill' and elem_tag_lower in {'text', 'tspan'}:
- allowed_tags = ('lineargradient', 'radialgradient')
+ target_tag = (_svg_element_tag(target) or str(target.tag)).lower()
+ if target_tag == 'pattern' and target.get(PROJECT_TEXT_IMAGE_FILL_ATTR) is not None:
+ allowed_tags = ('lineargradient', 'radialgradient', 'pattern')
+ else:
+ allowed_tags = ('lineargradient', 'radialgradient')
elif property_name == 'fill' and elem_tag_lower == 'g':
allowed_tags = (
('lineargradient', 'radialgradient')
@@ -2239,6 +2290,19 @@ def project_paint_reference_errors(root: ET.Element) -> list[str]:
continue
target_tag = (_svg_element_tag(target) or str(target.tag)).lower()
+ is_text_image_fill = (
+ target_tag == 'pattern'
+ and target.get(PROJECT_TEXT_IMAGE_FILL_ATTR) is not None
+ )
+ if is_text_image_fill and not (
+ property_name == 'fill'
+ and elem_tag_lower in {'text', 'tspan'}
+ ):
+ errors.add(
+ f'<{elem_tag}> {property_name}=url(#{reference_id}) uses a '
+ 'text image fill pattern outside <text>/<tspan>'
+ )
+ continue
if target_tag not in allowed_tags:
tag_labels = {
'lineargradient': 'linearGradient',
@@ -2251,6 +2315,16 @@ def project_paint_reference_errors(root: ET.Element) -> list[str]:
f'to <{_svg_element_tag(target) or target.tag}>; expected '
f'{expected}'
)
+ continue
+
+ if property_name == 'fill' and elem_tag_lower in {'text', 'tspan'} and target_tag == 'pattern':
+ try:
+ resolve_project_text_image_fill(target)
+ except ValueError as exc:
+ errors.add(
+ f'<{elem_tag}> fill=url(#{reference_id}) has an invalid '
+ f'text image fill: {exc}'
+ )
return sorted(errors)