Skip to content

Add template-aware text colors and code font auto-scaling#171

Merged
jongalloway merged 3 commits into
mainfrom
feature/template-aware-text-colors-and-code-scaling
May 11, 2026
Merged

Add template-aware text colors and code font auto-scaling#171
jongalloway merged 3 commits into
mainfrom
feature/template-aware-text-colors-and-code-scaling

Conversation

@jongalloway
Copy link
Copy Markdown
Owner

@jongalloway jongalloway commented May 11, 2026

  • Inspect the review comments and affected renderer logic
  • Run existing tests to establish the current baseline for the affected area
  • Apply the requested fixes in the renderer with minimal changes
  • Run targeted validation for the updated code paths
  • Reply to addressed review comments with the fixing commit hash
  • Run final validation and summarize the result

- Build theme from template color scheme (lt1/dk1) to pick readable
  text color based on background luminance
- Detect low-contrast placeholder text in layouts and override with
  scheme-appropriate color
- Resolve scheme color references (bg1, tx1, dk1, lt1, etc.) through
  the template's color scheme
- Scale code font to 75% of template body text size (capped at 32pt)
- Scale code font to fill available frame height per line count
- Supports solidFill backgrounds via both srgbClr and schemeClr
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves template-driven rendering in MarpToPptx so output better matches (and remains readable with) dark PowerPoint templates, while also making code blocks scale more appropriately with template typography.

Changes:

  • Derive effective text colors from the template theme color scheme (dk1/lt1) and slide background luminance when --template style rendering is enabled.
  • Detect low-contrast placeholder default text colors from layout lstStyle and apply a per-run solid fill override when needed.
  • Auto-scale code font size based on template body text defaults and available frame height, with a maximum cap.
Show a summary per file
File Description
src/MarpToPptx.Pptx/Rendering/OpenXmlPptxRenderer.cs Adds template-aware theme/color resolution and implements code font scaling logic for template-based rendering.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 3

Comment on lines +1022 to +1026
var bodyFontSizePt = bodySzAttr.Value / 100.0; // hundredths to points
var scaledCodeSize = Math.Round(bodyFontSizePt * 0.75, 1);
var clampedSize = Math.Clamp(scaledCodeSize, baseCode.FontSize, MaxCodeFontSize);

return clampedSize > baseCode.FontSize
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d328e7d.

if (ph is null) continue;

var matches = placeholder.Type is { } t
? ph.Type?.Value == t
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d328e7d.

var optimalSize = availableHeight / (lineCount * lineHeight);

// Clamp: never shrink below theme default, never exceed max.
var clampedSize = Math.Clamp(Math.Round(optimalSize, 1), style.FontSize, MaxCodeFontSize);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d328e7d.

@jongalloway jongalloway merged commit eea0d5a into main May 11, 2026
5 checks passed
@jongalloway jongalloway deleted the feature/template-aware-text-colors-and-code-scaling branch May 11, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants