[p5.js 2.0+ Bug Report]: SVG importer does not respect preserveAspectRatio="none" for <symbol>/<use>
Most appropriate sub-area of p5.js?
- [ ] Accessibility
- [ ] Color
- [x] Core/Environment/Rendering
- [ ] Data
- [ ] DOM
- [ ] Events
- [ ] Image
- [ ] IO
- [ ] Math
- [ ] Typography
- [ ] Utilities
- [ ] WebGL
- [ ] WebGPU
- [ ] p5.strands
- [ ] Build process
- [ ] Unit testing
- [ ] Internationalization
- [ ] Friendly errors
- [ ] Other (specify if possible)
p5.js version
2.3.2
Web browser and version
No response
Operating system
macOS 15.7.3
Steps to reproduce this
Steps:
- Add the regression test below to the
<defs> and <use> elementssuite intest/unit/svg/svg_import.js. - Run
npm test -- test/unit/svg/svg_import.js. - Observe that the test fails because
node.state.transform.ais1instead of the expected2.
The test uses a 100×100 <symbol> with preserveAspectRatio="none" inside a 200×100 <use> viewport. In this case, the expected transform is non-uniform scaling: 2× horizontally and 1× vertically.
I reproduced this on p5.js 2.3.2 (main at 7f9e0fda5). The SVG importer test suite reports 92 passing tests and this test failing with:
AssertionError: expected 1 to be close to 2 +/- 0.001
Snippet:
test('use respects preserveAspectRatio=none', function () {
const record = createSVG(`
<svg xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="stretch" viewBox="0 0 100 100" preserveAspectRatio="none">
<rect x="0" y="0" width="100" height="100" />
</symbol>
</defs>
<use href="#stretch" width="200" height="100" />
</svg>
`);
const scope = firstChild(record);
const node = scope.children[0];
assert.closeTo(node.state.transform.a, 2, 0.001);
assert.closeTo(node.state.transform.d, 1, 0.001);
});
hey can i take this issue ?
hey can i take this issue ?
Hi @Srinidhi444! Thanks for your interest. I'm currently working on this issue and have already implemented a fix with regression tests in my fork. I'm preparing the pull request now.
I appreciate your willingness to help!