Repository navigation
Paint: radial-gradient text fill and stroke - #5
Merged
Merged
Conversation
A radial-gradient (repeating too) paints background-clip:text and --rt-text-stroke-image instead of leaving the text invisible. Every form draws as a circle reaching the farthest corner of the painted box, centred at its at-position (%, px, keywords; the centre when absent), over the box a linear gradient uses at that site. On a path one circle spans the declarer's glyphs as laid out. Linear output is unchanged.
…clarers A stop before the centre opens the circle with the colour CSS shows there (`red -100%, blue 100%` starts half way), mixed in premultiplied sRGB for hex, named, rgb() and hsl() colours. A prelude that opens with a math function (`calc(20px + 10px) at 20% 80%`) is read as size and position, not as a stop. A gradient name inside a quoted string or url() is no longer a call, so it neither paints nor overrides a real layer. On a path one circle spans every glyph of its declaring element, a descendant that paints its own included; each circle is read once per draw, and a shadow mask builds no radial gradient. Linear output is unchanged.
…s CSS does A missing (none) rgb() channel or alpha takes the other stop's value when the centre colour is mixed, and channels written with calc()/min()/max()/ clamp() are evaluated instead of falling back to clamping the stop.
# Conflicts: # src/paint-state.ts
Contributor
|
Looks like colors drift from what Chrome is rendering. render-tag should follow CSS, then we should adopt from polotno side to make it consistent across the packages/exporters. |
Ellipses (the default) and every extent keyword or length now draw as CSS does instead of one farthest-corner circle. An ellipse is placed through its gradient's setTransform on a vector adapter that has one, painted as a device-resolution pattern on a raster canvas, else drawn as the circle of its horizontal radius. A repeating radial tiles out to the farthest corner.
…e too A repeating radial whose percentage stops collapse onto a zero-size shape paints their average, as Chrome does; any other zero-size shape its last stop. A path's --rt-text-stroke-image keeps such a solid paint instead of falling back to the stroke colour.
The first gradient layer paints, linear or radial; a linear layer no longer beats a radial one above it, and a prefixed -webkit-radial-gradient (another grammar) paints nothing. `at` reads edge offsets (`right 10px bottom 20px`), math functions and any length, and an invalid position paints nothing as in Chrome. Font and viewport lengths in a gradient resolve on the declaring element, as text-shadow's do, so `circle 2em` and `red 1em` match Chrome; a stop position takes any length or math function, and a single stop paints. An ellipse's pattern image reaches 128px past its box instead of half the box's height (a 1000x2700 block: 34.6ms to 9.6ms a draw in Chromium), is released when the draw ends, and costs one gradient, not two. A vector adapter gets the circle at the ellipse's centre, with `setTransform` mapping it onto the ellipse. On a path each glyph carries its declarer's box from layout, so a layout that went through JSON paints the same. Detection reuses the layer splitter and the validator's prelude rule; the url() blanking and the mask shortcut are gone.
An adapter written before radial gradients threw a TypeError on radial text; it painted nothing before.
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.
Text with a
radial-gradientfill or stroke (background-clip: text,--rt-text-stroke-image) now paints. Before, it was left invisible. polotno's radial gradients (polotno-project/polotno#109) need this for text.What draws
circleorellipse(the default);closest-side,closest-corner,farthest-side,farthest-corner(the default) or lengths, with%of the box for an ellipse;atposition: lengths,%, keywords, or edge offsets such asright 10px bottom 20px; the centre when there is none.circle 50%,at 10px left) paints nothing, as in CSS.text-shadow's do. Sizes, positions and stop positions take any length orcalc()/min()/max()/clamp(). This also applies to linear gradients.-webkit-radial-gradient(another grammar) paints nothing. A single-stop gradient paints.createCanvaswhere given). The image reaches 128px past its box and is released when the draw ends.setTransform(matrix)on that gradient when the adapter's gradients have one (SVGgradientTransform, a PDF pattern matrix). Without it the adapter keeps that circle. The method is render-tag's own extension; the README's "PDF and other vector adapters" section documents it.%stops collapse.red -100%, blue 100%starts half way. The colours are mixed in premultiplied sRGB for hex, named, rgb() and hsl() colours, withnoneand math-function channels as CSS Color 4 specifies.Known deviations
in <colorspace>is ignored: colours mix in sRGB.Tests
tests/node/radial-gradient.test.tscovers sizes and shapes, positions, invalid grammar, units, zero-size shapes, the ellipse paint (adaptersetTransform, the raster pattern against canvas's own scaled ellipse, its image size and release, a rotated path frame), stops, the centre mix, layer order, and the paint sites.tests/gradient-parity.test.tscompares linear and radial cases against each engine's native rendering on a 600×120 box, including positions, units, single stops and layer order.rgb(none 0 0)in WebKit; the zero-size forms in WebKit, and the average-colour ones in Firefox.npm test(node + chromium) 2823 passed;test:webkit300 passed;test:firefox294 passed.bench:cross-browser: layout consistency unchanged in every lane.Draft until
setTransformon their radial gradients.