Repository navigation
Run linear gradients the way CSS Images gives for "to" keywords and angles - #577
Merged
Merged
Conversation
jakejackson1
force-pushed
the
fix/552-gradient-directions
branch
from
September 29, 2026 08:42
d9102f9 to
0a3c523
Compare
jakejackson1
force-pushed
the
fix/552-gradient-directions
branch
from
September 29, 2026 22:54
0a3c523 to
ec4991f
Compare
…ngles "to bottom" and "to top" were read as the legacy start sides, so they drew upside down, and so did the vertical half of the corner keywords. Angles followed the legacy convention, 0deg pointing right and turning counter-clockwise, so 90deg drew bottom to top. An unprefixed gradient now points up at 0deg and turns clockwise, and reads the turn unit. A "to" keyword names the side the gradient ends at, and a corner runs corner to corner across the box, so the other two corners meet halfway. -moz-, -webkit- and -o- gradients keep the legacy angles, and their side keyword names the side they start from. The -webkit- and -o- prefixes are kept through NormalizeProperties so they can be told apart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
force-pushed
the
fix/552-gradient-directions
branch
from
September 29, 2026 23:45
ec4991f to
5288c87
Compare
jakejackson1
added a commit
that referenced
this pull request
Sep 30, 2026
…er (#583) * Read the border and background shorthands with their parts in any order border and its sides take the width, style and colour in any order, so solid #c00 2mm, 2mm #c00 solid and red 2mm solid draw a border. background takes a colour after url(), a size after the position, and its repeat, attachment and origin and clip boxes in any order. Only the last layer may carry a colour; mPDF still draws only the first layer, over that colour. A shorthand with a part that is none of its parts is dropped, as a browser drops it, so the value it would replace still applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep the -webkit- and -o- prefix of a gradient in the background shorthand Since #577, a -webkit- or -o- gradient is told apart from an unprefixed one by its prefix, and keeps the legacy angles and start side. The background shorthand parser dropped every prefix but -moz-, so `background: -webkit-linear-gradient(left, …)` was read as an unprefixed gradient. It now keeps -moz-, -webkit- and -o-, and still drops any other. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Sep 30, 2026
jakejackson1
added a commit
that referenced
this pull request
Sep 30, 2026
Under CssMode::LEGACY a linear gradient reads its direction as mPDF v7 did, prefixed or not: "left" and "right" name the side it ends at and "top" and "bottom" the side it starts from, with or without "to"; angles run counter-clockwise from pointing right in whole degrees; and turn is not read. The output is byte-identical to the code before #577. The angle is wrapped with fmod() and cut with an explicit cast, so PHP 8.1 raises no deprecation for a fractional angle. Under CssMode::STANDARD gradients run as CSS Images gives, as #577 made them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 30, 2026
Under CssMode::LEGACY a linear gradient reads its direction as mPDF v7 did, prefixed or not: "left" and "right" name the side it ends at and "top" and "bottom" the side it starts from, with or without "to"; angles run counter-clockwise from pointing right in whole degrees; and turn is not read. The output is byte-identical to the code before #577. The angle is wrapped with fmod() and cut with an explicit cast, so PHP 8.1 raises no deprecation for a fractional angle. Under CssMode::STANDARD gradients run as CSS Images gives, as #577 made them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jakejackson1
added a commit
that referenced
this pull request
Sep 30, 2026
) Under CssMode::LEGACY a linear gradient reads its direction as mPDF v7 did, prefixed or not: "left" and "right" name the side it ends at and "top" and "bottom" the side it starts from, with or without "to"; angles run counter-clockwise from pointing right in whole degrees; and turn is not read. The output is byte-identical to the code before #577. The angle is wrapped with fmod() and cut with an explicit cast, so PHP 8.1 raises no deprecation for a fractional angle. Under CssMode::STANDARD gradients run as CSS Images gives, as #577 made them. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
parseMozLinearGradient()read every gradient with the legacy syntax of the old-moz-and-webkit-functions. With a red to blue gradient on a 60 × 30 mm box, measured by rasterising the page:linear-gradient(to bottom, …)linear-gradient(to top, …)linear-gradient(to bottom right, …)linear-gradient(0deg, …)linear-gradient(90deg, …)linear-gradient(180deg, …)linear-gradient(0.25turn, …)turnwas not read and fell back to 0-moz-linear-gradient(left, …)to leftandto rightcame out right only because the legacy reading ofleftwas reversed too.-webkit-and-o-were stripped byNormalizeProperties, so a prefixed gradient could not be told from an unprefixed one.%=, which is deprecated for floats on PHP 8.1+.Part of #552 (Backgrounds, bug 5 in the audit). Part of #520.
Change
In
Gradient::parseMozLinearGradient():Gradient()draws from (90 - angle). So0degpoints up and angles run clockwise.turnis read alongsidedeg,gradandrad, and the angle is wrapped withfmod().to, the keyword names the side the gradient ends at. Without it, as in the legacy syntax and mPDF's documentedlinear-gradient(top, …), the keyword names the side it starts from. That fixes the reversed legacyleftandright.to top rightand the other corners set both ends, corner to corner across the box. In the unit box the shading is drawn in, the other two corners then sit halfway along the axis, as CSS's "magic corners" require. Before,Gradient()squared the box, which gave a different angle on a box that is not square.-moz-,-webkit-and-o-functions keep the legacy angles.NormalizePropertiesnow keeps the-webkit-and-o-prefixes onbackgroundandbackground-imageso they reach the parser.Nothing else is affected:
Gradient()and mPDF's ownbackground-gradientproperty are unchanged.Svgbuilds its own coordinates.gradient-maskon images goes throughparseMozGradient(), so it follows the same rules.Documents that set an unprefixed angle, a
to top/to bottomkeyword or a legacyleft/rightkeyword will look different after this change, and will match what a browser draws. No existing snapshot fixture changed.Not changed here: absolute stop positions on a corner gradient are still measured along the corner-to-corner line rather than the gradient line, and
repeating-radial-gradient()still draws one colour (audit bug 6).Tests
LinearGradientDirectionTestrenders a block for each case and reads the axisGradient()registers:0,-90deg,450deg,turn,gradandrad;tocorner;-moz-and-webkit-keywords and angles;22.5deg.LinearGradientDirectionSnapshotTest(linear-gradient-direction) draws each case under a caption saying where the red and blue should be.With the source change reverted, most of the cases fail. Those that pass on both are ones the old reading already got right, such as
to left,to right,-moz- topand the default direction.Checks
composer test: OK. 4486 tests, 31 skipped for missing optional packages or ungenerated data. The snapshot suite ran with Imagick and Ghostscript.composer cs: clean.$m[1] + 0inGradient.phpis removed.🤖 Generated with Claude Code