Skip to content

Comments

[vector_graphics_compiler] support percentage units SVG shape attributes#10577

Merged
auto-submit[bot] merged 13 commits intoflutter:mainfrom
stevenctl:stevenctl/svg-percentages
Feb 18, 2026
Merged

[vector_graphics_compiler] support percentage units SVG shape attributes#10577
auto-submit[bot] merged 13 commits intoflutter:mainfrom
stevenctl:stevenctl/svg-percentages

Conversation

@stevenctl
Copy link
Contributor

@stevenctl stevenctl commented Dec 6, 2025

Adds percentage unit support for SVG shape attributes

SVG shapes like <rect>, <circle>, <ellipse>, and <line> can have percentage values for their position and size attributes (e.g., width="50%", cx="50%"). Previously
these weren't handled correctly. Easy to test with any image like https://placeholdit.com/600x400/dddddd/999999

This adds:

  • Percentage parsing in parseDoubleWithUnits that resolves values against the viewport dimensions
  • Viewport width/height getters on SvgParser
  • Proper percentage reference handling for all basic shape elements
  • Circle radius uses the normalized diagonal per SVG spec

List which issues are fixed by this PR. You must list at least one issue.

I'm not sure if it fixes these issues, as they have no description. I can file a new issue if needed.

flutter/flutter#158844
flutter/flutter#158845

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Signed-off-by: Steven Landow <steven@landow.dev>
@stevenctl stevenctl requested a review from jtmcdole as a code owner December 6, 2025 15:53
@github-actions github-actions bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Dec 6, 2025
Copy link

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

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 adds support for percentage units in SVG shape attributes like rect, circle, ellipse, and line, which is a valuable feature. The changes correctly resolve percentage values against the viewport dimensions, and the circle radius calculation correctly uses the normalized diagonal as per the SVG specification. The addition of new tests to verify this functionality is also great. I've found a minor issue with a misleading comment in the new percentage parsing logic and have suggested a correction to improve clarity. Overall, the changes are well-implemented.

Copy link
Member

@jtmcdole jtmcdole left a comment

Choose a reason for hiding this comment

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

Added a question. Sorry for the delay.

parserState.attribute('cy', def: '0'),
percentageRef: vh,
)!;
// For radius percentage, use the normalized diagonal per SVG spec.
Copy link
Member

Choose a reason for hiding this comment

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

can you link to the spec section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


// Handle percentage values first.
// Check inline to avoid circular import with parsers.dart.
final bool isPercent = rawDouble?.endsWith('%') ?? false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the provided rawDouble guaranteed to be trimmed? It seems like it would be safer to trim before doing this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

final bool isPercent = rawDouble?.endsWith('%') ?? false;
if (isPercent) {
if (percentageRef == null || percentageRef.isInfinite) {
// If no reference dimension is available, treat as 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This says "treat as 0", but it returns null, not 0, so it's not clear to me what this comment means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up changing it and forgot to update the comment.

@@ -2,6 +2,10 @@
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should probably revert the pubspec version change, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Which of the version change exemptions do you believe this change falls under?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nvm misread your guide

@stevenctl
Copy link
Contributor Author

I think this is good to go now

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g
Copy link
Collaborator

@jtmcdole FYI this is still waiting on an engine team approval to land.

@jtmcdole
Copy link
Member

Should this technically have been a minor bump in symver?

MINOR version when you add functionality in a backward compatible manner

@stuartmorgan-g
Copy link
Collaborator

Yeah, probably. There's a lot of grey area in minor vs bugfix when the API itself doesn't change, but this does make more sense as a minor version. I'll adjust it.

@stuartmorgan-g stuartmorgan-g added autosubmit Merge PR when tree becomes green via auto submit App and removed triage-engine Should be looked at in engine triage labels Feb 18, 2026
@auto-submit auto-submit bot merged commit 6e02708 into flutter:main Feb 18, 2026
81 checks passed
@github-actions github-actions bot added the triage-engine Should be looked at in engine triage label Feb 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 19, 2026
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Feb 19, 2026
flutter/packages@59f905c...9da22bf

2026-02-19 mit@google.com [cupertino_ui, material_ui] Fix capitalization
in README section headers (flutter/packages#11058)
2026-02-18 engine-flutter-autoroll@skia.org Manual roll Flutter from
6e4a481 to c023e5b (17 revisions) (flutter/packages#11060)
2026-02-18 steven@landow.dev [vector_graphics_compiler] support
percentage units SVG shape attributes (flutter/packages#10577)
2026-02-18 stuartmorgan@google.com [local_auth] Convert example app to
Swift (flutter/packages#11003)
2026-02-18 stuartmorgan@google.com [ci] Fix syntax error in auto-labeler
(flutter/packages#11052)
2026-02-18 github-admin@google.com Refactor Github Action per
b/485167538 (flutter/packages#11051)
2026-02-18 katelovett@google.com [material_ui] Add material_ui package
(flutter/packages#11043)
2026-02-18 katelovett@google.com [cupertino_ui] Add cupertino_ui package
(flutter/packages#11042)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: vector_graphics triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants