Skip to content

fix: respect preserveAspectRatio meet alignment in SVG use - #9292

Merged
davepagurek merged 2 commits into
processing:mainfrom
Danyccsf:fix-svg-preserve-aspect-ratio-alignment
Oct 15, 2026
Merged

davepagurek merged 2 commits into
processing:mainfrom
Danyccsf:fix-svg-preserve-aspect-ratio-alignment

Conversation

@Danyccsf

Copy link
Copy Markdown
Contributor

Description

Fixes #9287.

The SVG importer previously centered <symbol> content referenced by <use>, regardless of the specified preserveAspectRatio alignment.

This PR implements all nine meet alignment combinations (xMin, xMid, xMax × YMin, YMid, YMax) while preserving the existing behavior for preserveAspectRatio="none" and the default xMidYMid meet.

Changes

  • Parse horizontal and vertical alignment values from preserveAspectRatio.
  • Calculate translation offsets based on the specified alignment while maintaining uniform scaling.
  • Account for nonzero viewBox origins.
  • Add unit tests covering all nine alignments in horizontal and vertical viewports.
  • Add an SVG fixture and visual regression test.

Testing

  • SVG unit tests: 114 passed.
  • Visual regression test: passed.
  • npm run lint: 0 errors, 18 warnings in existing code.
  • Git whitespace checks: passed.

Scope

This PR focuses on meet alignment behavior. Support for slice is outside the scope of this change and can be addressed separately.

@p5-bot

p5-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: a160273

Previous deployments

This is an automated message.

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

Looks great, thanks for completing our support of this property!

// Default SVG alignment is xMidYMid meet.
const alignment = preserveAspectRatio?.trim().split(/\s+/)[0] || "xMidYMid";

const alignX = alignment.startsWith("xMin") ? 0

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.

Nice!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, Dave! I appreciate your review and feedback. It was a great opportunity to build on the previous SVG importer fix and improve the alignment support in p5.js!

@davepagurek
davepagurek merged commit 63e3b9e into processing:main Oct 15, 2026
4 of 5 checks passed
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.

[p5.js 2.0+ Bug Report]: SVG importer ignores xMinYMin meet alignment for <symbol>/<use>

2 participants