diff --git a/modern_graphics/base.py b/modern_graphics/base.py index dc30f76..bba5dc7 100644 --- a/modern_graphics/base.py +++ b/modern_graphics/base.py @@ -13,11 +13,12 @@ class BaseGenerator: """Base class for Modern Graphics generators""" - def __init__(self, title: str, template: Optional[StyleTemplate] = None, attribution: Optional[Attribution] = None, use_svg_js: bool = False): + def __init__(self, title: str, template: Optional[StyleTemplate] = None, attribution: Optional[Attribution] = None, use_svg_js: bool = False, use_pretext: bool = False): self.title = title self.template = template or DEFAULT_TEMPLATE self.attribution = attribution or Attribution() self.use_svg_js = use_svg_js + self.use_pretext = use_pretext def _generate_attribution_html(self) -> str: """Generate attribution label HTML (pill style, optional context).""" @@ -114,7 +115,13 @@ def _wrap_html(self, content: str, styles: str) -> str: if self.use_svg_js: from .svg_utils import generate_svg_js_cdn_script svg_js_script = generate_svg_js_cdn_script() - + + # Include Pretext for SVG text rendering if enabled + pretext_scripts = "" + if self.use_pretext: + from .pretext_utils import generate_pretext_bootstrap_script + pretext_scripts = generate_pretext_bootstrap_script() + return f"""
@@ -130,6 +137,7 @@ def _wrap_html(self, content: str, styles: str) -> str: {content} +{pretext_scripts} """ diff --git a/modern_graphics/cli.py b/modern_graphics/cli.py index 376ba16..cbdafb2 100644 --- a/modern_graphics/cli.py +++ b/modern_graphics/cli.py @@ -141,6 +141,7 @@ def main(): create_expert.add_argument('--export-preset', choices=list_export_presets(), help='Channel preset for PNG export (linkedin|x|substack-hero)') create_expert.add_argument('--crop-mode', choices=['none', 'safe', 'tight'], default=CREATE_DEFAULTS.crop_mode, help=f'PNG crop mode (default: {CREATE_DEFAULTS.crop_mode})') create_expert.add_argument('--padding-mode', choices=['none', 'minimal', 'comfortable'], default=CREATE_DEFAULTS.padding_mode, help=f'PNG padding mode (default: {CREATE_DEFAULTS.padding_mode})') + create_expert.add_argument('--text-render', choices=['css', 'pretext'], default='css', help='Text rendering mode: css (default) or pretext (SVG text via Pretext)') # Themes browser subparsers.add_parser('themes', help='List available color themes with descriptions') diff --git a/modern_graphics/cli_create.py b/modern_graphics/cli_create.py index 7b791f1..575bfa2 100644 --- a/modern_graphics/cli_create.py +++ b/modern_graphics/cli_create.py @@ -298,9 +298,11 @@ def handle_create(args) -> int: if getattr(args, 'png', False) and output_path.suffix != '.png': output_path = output_path.with_suffix('.png') + use_pretext = getattr(args, 'text_render', 'css') == 'pretext' generator = ModernGraphicsGenerator( getattr(args, 'title', 'Modern Graphic'), attribution=attribution, + use_pretext=use_pretext, ) density = normalize_density(getattr(args, "density", "clarity")) color_scheme = get_scheme(getattr(args, 'theme', None)) if getattr(args, 'theme', None) else None diff --git a/modern_graphics/color_scheme.py b/modern_graphics/color_scheme.py index 4008645..413ec88 100644 --- a/modern_graphics/color_scheme.py +++ b/modern_graphics/color_scheme.py @@ -185,7 +185,10 @@ def get_css_overrides(self) -> str: """Generate CSS overrides for all graphics types""" css = f""" /* Color Scheme: {self.name} */ - + + /* Pretext SVG text: inherit color from parent CSS */ + .pretext-slot text, .pretext-slot tspan {{ fill: currentColor; }} + /* Base styles */ body {{ font-family: {self.font_family}; diff --git a/modern_graphics/diagrams/modern_hero.py b/modern_graphics/diagrams/modern_hero.py index 85083ae..b9ea038 100644 --- a/modern_graphics/diagrams/modern_hero.py +++ b/modern_graphics/diagrams/modern_hero.py @@ -378,13 +378,48 @@ def generate_modern_hero( stats_html = _render_stats(stats) cta_html = f"