Add template-aware text colors and code font auto-scaling#171
Merged
jongalloway merged 3 commits intoMay 11, 2026
Conversation
- 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
Contributor
There was a problem hiding this comment.
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
--templatestyle rendering is enabled. - Detect low-contrast placeholder default text colors from layout
lstStyleand 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 |
| if (ph is null) continue; | ||
|
|
||
| var matches = placeholder.Type is { } t | ||
| ? ph.Type?.Value == t |
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.