Add SVG mix-blend-mode support + fix gradient rendering#140
Merged
nicolaasuni merged 1 commit intotecnickcom:mainfrom Feb 25, 2026
Merged
Add SVG mix-blend-mode support + fix gradient rendering#140nicolaasuni merged 1 commit intotecnickcom:mainfrom
nicolaasuni merged 1 commit intotecnickcom:mainfrom
Conversation
881cd1a to
8fd246d
Compare
- Parse mix-blend-mode CSS property from SVG style attributes and map all 16 CSS blend modes to PDF /BM operator equivalents via getAlpha()\n- Normalize gradient stop colors to hex RGB to prevent CMYK/RGB color space mismatch when mixing named and hex colors in gradient stops\n- Add prescanSVGGradients() to collect gradient definitions before the main render pass, fixing forward references in Figma SVG exports\n- Move blend mode detection before gradient early return so /BM applies to gradient-filled elements too\n- Preserve and combine opacity/fill-opacity/stroke-opacity when mix-blend-mode is enabled (avoid alpha clobbering from repeated ExtGState writes)\n- Add regression tests for blend mode + opacity combinations and keep prescan callbacks PHPMD/PHPStan clean\n- Add visual smoke test
8fd246d to
aa94d2f
Compare
Contributor
Author
|
Follow-up fix pushed: preserves effective SVG opacity when Also added regression tests for blend mode + opacity combinations and cleaned up Validated locally:
|
Member
|
Thank you for your contribution. |
Member
|
I had to remove the SvgBlendModeTest.php as it is failing. |
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.
Summary
Add SVG
mix-blend-modesupport and fix gradient rendering when exporting SVG → PDF.Closes #139.
mix-blend-modesupport: Parse the CSS property from SVG style attributes and map all 16 CSS blend modes to their PDF/BMoperator equivalents via the existinggetAlpha()infrastructure.white,red, etc.) resolve to CMYK while hex colors (#FFFFFF,#00C147) resolve to RGB. When mixed in gradient stops, the PDF gradient breaks silently. All stop colors are now normalized to hex RGB.<defs>at the end of the SVG. The single-pass parser couldn't resolve forward gradient references. A lightweightprescanSVGGradients()pre-parse now collects all gradient definitions before the main render pass.parseSVGStyleFill()so/BMapplies to gradient-filled elements too.Test Input
Original SVG used for reproduction (exported from Figma):
BlendModeTest.svgChanges
src/SVG.php— all source changes (blend mode parsing, stop color fix, prescan method)test/SvgBlendModeTest.php— 26 integration tests covering all blend modes, inheritance, gradient combinationstest/visual/BlendModeTest.svg+test/visual/blend-mode-smoke.php— visual smoke test with real Figma exportTest plan
vendor/bin/phpunit --no-coverage)🤖 Generated with Claude Code