Skip to content

userSpaceOnUse/objectBoundingBox#4283

Open
jsjgdh wants to merge 2 commits into
GraphiteEditor:masterfrom
jsjgdh:svg-gradient-units-import-export
Open

userSpaceOnUse/objectBoundingBox#4283
jsjgdh wants to merge 2 commits into
GraphiteEditor:masterfrom
jsjgdh:svg-gradient-units-import-export

Conversation

@jsjgdh

@jsjgdh jsjgdh commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Request

This feature depends on Yohei's ongoing refactor and should be merged after that work is completed.

@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 introduces support for preserving and rendering SVG gradientUnits (userSpaceOnUse and objectBoundingBox) during import and export. It adds a GradientUnits enum, extracts the units from the raw SVG XML during import, propagates the property through the node graph, and utilizes it during rendering to correctly set the gradientUnits attribute and adjust the gradient transform. The feedback recommends optimizing the import process by avoiding redundant XML parsing of the same SVG string across multiple functions, and suggests renaming the _bounds variable to bounds since it is now actively used.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +556 to +563
fn extract_svg_gradient_units(svg: &str) -> HashMap<String, GradientUnits> {
let mut result = HashMap::new();
let mut gradient_nodes = HashMap::new();

let doc = match usvg::roxmltree::Document::parse(svg) {
Ok(doc) => doc,
Err(_) => return result,
};

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.

medium

Redundant XML Parsing

Both extract_graphite_gradient_stops and extract_svg_gradient_units parse the same raw SVG XML string independently using usvg::roxmltree::Document::parse. For large SVG files, parsing the XML tree multiple times introduces unnecessary CPU and memory overhead.

Consider refactoring these functions to accept a shared reference to the parsed roxmltree::Document, or combining them into a single pass over the XML descendants to extract both gradient stops and units simultaneously.


let placement = gradient_placement(document_transform, gradient_type);
let gradient_transform = format_transform_matrix(element_transform_inverse * placement);
let (gradient_units, gradient_transform) = svg_gradient_transform(element_transform_inverse * placement, _bounds, gradient_units);

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.

medium

Used Variable with Underscore Prefix

The _bounds variable is now used in the call to svg_gradient_transform. By Rust convention, variables prefixed with an underscore should remain unused. Since it is now used, consider renaming _bounds to bounds in the function signature of RenderExt::render for List<GradientStops> to improve code clarity and adhere to standard style guidelines.

@jsjgdh

jsjgdh commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@cubic-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 25, 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.

All reported issues were addressed across 10 files

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread node-graph/libraries/vector-types/src/gradient.rs Outdated
Comment thread node-graph/libraries/graphic-types/src/graphic.rs Outdated
Comment thread node-graph/libraries/rendering/src/render_ext.rs Outdated
@jsjgdh jsjgdh force-pushed the svg-gradient-units-import-export branch from 3a673d1 to 3ae1a44 Compare July 8, 2026 10:12
@jsjgdh jsjgdh marked this pull request as ready for review July 8, 2026 10:12
@jsjgdh jsjgdh force-pushed the svg-gradient-units-import-export branch from 3ae1a44 to e4ab060 Compare July 8, 2026 10:13

@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.

Review completed against the latest diff

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

@jsjgdh jsjgdh force-pushed the svg-gradient-units-import-export branch from e4ab060 to d27f647 Compare July 15, 2026 14:35
@jsjgdh jsjgdh force-pushed the svg-gradient-units-import-export branch from d27f647 to 754f5e9 Compare July 15, 2026 15:42
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