Skip to content

Add focal point, focal radius#4139

Draft
jsjgdh wants to merge 3 commits into
GraphiteEditor:masterfrom
jsjgdh:Graident_SVG
Draft

Add focal point, focal radius#4139
jsjgdh wants to merge 3 commits into
GraphiteEditor:masterfrom
jsjgdh:Graident_SVG

Conversation

@jsjgdh

@jsjgdh jsjgdh commented May 12, 2026

Copy link
Copy Markdown
Contributor

Enhance gradient functionality with new features:

  • Focal point & radius for radial gradients — allows off-center starts and elliptical falloffs, matching the SVG fx/fy/fr attributes
  • SVG import/export fidelity — radial gradients now correctly round-trip with focal data, named CSS colors and short hex codes are parsed on import, percentage-based stop offsets are supported, and href-based stop inheritance is handled
  • Rendering improvements — updated peniko radial positioning.

@jsjgdh

jsjgdh commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@cubic-dev

@cubic-dev-ai

cubic-dev-ai Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev

@jsjgdh I have started the AI code review. It will take a few minutes to complete.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances gradient support by introducing focal points, focal radii, and gradient units to the Gradient structure. It improves SVG import capabilities by adding support for percentage-based offsets, 3-digit hex colors, and named CSS colors via the svgtypes crate. Additionally, it implements a mechanism for gradient stops to inherit from other gradients using href. Feedback focuses on making the href resolution more robust to handle multi-level or out-of-order references and simplifying the color parsing logic to better utilize the svgtypes library and correctly handle alpha multiplication.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 10 files

Confidence score: 4/5

  • This PR looks generally safe to merge, but there is a moderate, user-visible rendering issue in editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs where parsed color alpha is dropped.
  • The most significant impact is that stop-colors using embedded alpha (for example rgba(...), hsla(...), or 8-digit hex) may render with incorrect opacity, which can change gradient appearance.
  • Given the single mid-severity finding (5/10) with good confidence, this is a limited-risk fix area rather than a likely broad regression.
  • Pay close attention to editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs - preserve and propagate c.alpha when converting parsed colors.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs">

<violation number="1" location="editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs:625">
P2: `svgtypes::Color::from_str` already parses alpha for formats like `rgba(...)`, `hsla(...)`, and 8-digit hex, but the alpha component (`c.alpha`) is discarded here. This means any stop-color with an embedded alpha channel will lose it. Furthermore, per SVG2, the final opacity should be `(c.alpha / 255) * stop_opacity` — a product of the color's alpha and the `stop-opacity` attribute — but `parse_stop_color` currently uses `alpha.unwrap_or(opacity)`, choosing one or the other instead of multiplying them.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@jsjgdh jsjgdh changed the title Improvement Add focal point, focal radius, and gradient units support to gradients May 13, 2026
@jsjgdh

jsjgdh commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@cubic-dev

@cubic-dev-ai

cubic-dev-ai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev

@jsjgdh I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 11 files

Confidence score: 3/5

  • In node-graph/libraries/rendering/src/render_ext.rs, the gradientUnits write condition appears inverted, so UserSpaceOnUse is skipped and SVG renderers can fall back to the default coordinate space, producing visibly incorrect gradients for affected exports — fix the condition (and ideally add a regression test for UserSpaceOnUse) before merging.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/libraries/rendering/src/render_ext.rs">

<violation number="1" location="node-graph/libraries/rendering/src/render_ext.rs:57">
P1: `gradientUnits` emission condition is inverted: `UserSpaceOnUse` (non-default) is omitted, causing SVG consumers to misinterpret the gradient coordinate space</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

format!(r#" spreadMethod="{}""#, self.spread_method.svg_name())
};

let gradient_units = if self.gradient_units == GradientUnits::UserSpaceOnUse {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: gradientUnits emission condition is inverted: UserSpaceOnUse (non-default) is omitted, causing SVG consumers to misinterpret the gradient coordinate space

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/libraries/rendering/src/render_ext.rs, line 57:

<comment>`gradientUnits` emission condition is inverted: `UserSpaceOnUse` (non-default) is omitted, causing SVG consumers to misinterpret the gradient coordinate space</comment>

<file context>
@@ -54,21 +54,39 @@ impl RenderExt for Gradient {
 			format!(r#" spreadMethod="{}""#, self.spread_method.svg_name())
 		};
 
+		let gradient_units = if self.gradient_units == GradientUnits::UserSpaceOnUse {
+			String::new()
+		} else {
</file context>

Comment thread node-graph/libraries/rendering/src/renderer.rs Outdated
@Keavon Keavon force-pushed the master branch 2 times, most recently from 4b7a823 to 847b8e9 Compare May 17, 2026 14:37
@timon-schelling timon-schelling force-pushed the master branch 2 times, most recently from 15fcaac to d5f0140 Compare May 17, 2026 15:37
@jsjgdh jsjgdh changed the title Add focal point, focal radius, and gradient units support to gradients Add focal point, focal radius Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant