Skip to content

Commit b26bf0e

Browse files
authored
Fix gradient regressions, OoO support for use/gradients (#30)
* Fix gradient regressions, OoO support for use/gradients - Defer resolution to build and assert resolution doesn't happen during parsing. - Fix regressions introduced in the last commit around userSpaceOnUse with transforms for linear gradients, and regressions around radial gradients in general. - Tests Things that are still wrong: - I noticed while working on flutter_svg's "devil" SVG test that blends are not being accurately applied to individual paths. I'll try to address that in a separate PR. - userSpaceOnUse gradients with transforms are not being applied correctly. This has been an issue in this repo forever, not a regression. Gotta figure out how to properly transform the gradient to the transformed path coordinate space. See https://github.com/dnfield/flutter_svg/pull/54/files#r216222991 and the test files added in that PR, which do not compile correctly today. * fix inheritence for gradient properties
1 parent 78761ee commit b26bf0e

File tree

9 files changed

+459
-457
lines changed

9 files changed

+459
-457
lines changed

packages/vector_graphics_compiler/lib/src/paint.dart

Lines changed: 161 additions & 213 deletions
Large diffs are not rendered by default.

packages/vector_graphics_compiler/lib/src/svg/node.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,37 @@ class PathNode extends AttributedNode {
307307
}
308308
}
309309
}
310+
311+
/// A node that refers to another node, and uses [resolver] at [build] time
312+
/// to materialize the referenced node into the tree.
313+
class DeferredNode extends AttributedNode {
314+
/// Creates a new deferred node with [attributes] that will call [resolver]
315+
/// with [refId] at [build] time.
316+
DeferredNode(
317+
SvgAttributes attributes, {
318+
required this.refId,
319+
required this.resolver,
320+
}) : super(attributes);
321+
322+
/// The reference id to pass to [resolver].
323+
final String refId;
324+
325+
/// The callback that materializes an [AttributedNode] for [refId] at [build]
326+
/// time.
327+
final Resolver<AttributedNode> resolver;
328+
@override
329+
AttributedNode applyAttributes(SvgAttributes newAttributes) {
330+
return DeferredNode(
331+
attributes.applyParent(newAttributes),
332+
refId: refId,
333+
resolver: resolver,
334+
);
335+
}
336+
337+
@override
338+
void build(DrawCommandBuilder builder, AffineMatrix transform) {
339+
final AttributedNode concreteRef =
340+
resolver(refId).applyAttributes(attributes);
341+
concreteRef.build(builder, transform);
342+
}
343+
}

0 commit comments

Comments
 (0)