fix(usvg): inherit gradientTransform and patternTransform via href - #1135
Open
killerdevildog wants to merge 1 commit into
Open
killerdevildog wants to merge 1 commit into
killerdevildog wants to merge 1 commit into
Conversation
A gradient or pattern that references another one through `href`/`xlink:href` did not inherit its `gradientTransform` or `patternTransform`. Stops, coordinates, units and `spreadMethod` were inherited, but the transform was silently dropped. For example, `<linearGradient id="lg2" xlink:href="#lg1"/>`, where `lg1` has `gradientTransform="rotate(90 0.5 0.5)"`, rendered left-to-right instead of top-to-bottom, and a referencing pattern lost its rotation. This is a regression from 9101f30 ("Add support for the `transform-origin` attribute"), which replaced `resolve_attr(node, AId::GradientTransform).attribute(..)` with `node.resolve_transform(..)`. `resolve_transform` only reads the attribute from the element itself, so the `GradientTransform` entries in `resolve_lg_attr` and `resolve_rg_attr` became unused. SVG 2 lists `gradientTransform` among the attributes copied from a template `linearGradient` or `radialGradient`, and `patternTransform` among those copied from a template `pattern` (https://www.w3.org/TR/SVG2/pservers.html). SVG 1.1 likewise states that attributes defined on the referenced element but not on this element are inherited. Resolve the element that defines the transform with `resolve_attr` before calling `resolve_transform`, in `convert_linear`, `convert_radial` and `convert_pattern`. A transform set on the element itself still takes precedence over the referenced one. Signed-off-by: killerdevildog <quaylynrimer11@gmail.com> Signed-off-by: killerdevildog <software.quaylynrimer@gmail.com>
Contributor
|
Fix looks good to me but we should have a test added to avoid this issue regressing in the future. |
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.
Fixes #1134.
A gradient or pattern that references another one through
hrefdid not inherit itsgradientTransformorpatternTransform. For example,<linearGradient id="lg2" xlink:href="#lg1"/>, wherelg1hasgradientTransform="rotate(90 0.5 0.5)", rendered left to right instead of top to bottom.This regressed in 9101f30 (first released in v0.37.0), which replaced
resolve_attr(node, AId::GradientTransform).attribute(..)withnode.resolve_transform(..)to supporttransform-origin.resolve_transformonly reads the element itself, so thehreflookup was lost and theGradientTransformentries inresolve_lg_attrandresolve_rg_attrbecame unused. Resolving the defining element withresolve_attrfirst restores inheritance and keepstransform-originsupport. A transform set on the element itself still takes precedence. When the transform is inherited,transform-originis read from the same element that defines the transform.This PR changes only
crates/usvg/src/parser/paint_server.rs.Validation: the reproducer from #1134 fails before the change and passes afterward; resvg's output now matches rsvg-convert 2.58 to within 1/255 per color channel (before the change it differed by up to 255). Local paired cases covering linear, radial and pattern templates, a radial gradient using a linear template, a two-level
hrefchain, and an element that overrides the inherited transform each render pixel-identically to the same transform set directly on the element.cargo test --release -p resvg -p usvgpasses (1731 integration tests, no reference image changes) andcargo fmt --checkis clean. The local regression tests are not included in this PR. Tested on Linux only.