Fix text with shape inside and cleaning of PR #74 - #75
Open
jackestar wants to merge 8 commits into
Open
Conversation
This commit introduces a number of improvements and bug fixes to the applytransforms extension. Features: - Apply transformations to text and tspan elements, including font size scaling. - Improved handling of circles and ellipses, with warnings only for complex transformations. - Basic handling for clipPath and linearGradient elements. Fixes: - Corrected the scaling logic for rectangles. - Improved stroke width scaling to handle both style and direct attributes. - Fixed a ValueError in the scaleMultiple function. - Added tests for the new functionality and updated the test suite.
This commit fixes critical bugs where circles and ellipses with transforms were becoming invisible or lost during transformation, especially when using gradient fills. Changes: - Fixed type errors: All coordinate (cx, cy) and radius (r, rx, ry) values are now properly converted to strings as required by SVG specification - Circle to ellipse conversion: Circles with non-uniform scaling are now correctly converted to ellipses with proper rx/ry attributes - Automatic gradient transformation: Implemented proper transformation of radial and linear gradients with userSpaceOnUse coordinates: * Added transformGradient() method to detect and transform gradient refs * Added transformRadialGradient() to transform cx, cy, fx, fy, r coords * Added transformLinearGradient() to transform x1, y1, x2, y2 coords * Gradients now follow their shapes during transformation * Existing gradientTransform attributes are properly applied * CSS style attribute checked first (correct precedence over fill attr) - Added test case for circles with gradient fills in groups - Updated README with detailed changelog Fixes issue where shapes with gradient fills would appear at wrong positions or become invisible after applying transforms. Co-authored-by: Claude (Anthropic)
IDE/MCP thing deleted
added hypothesis to the dev requirements removed unneeded test run_test.py (the result dont match with inkscape anyway) from PR Klowner#74 restore original test and removed additional test (don't work) from PR Klowner#74
Owner
|
Thank you very much for cleaning this up into something I would actually be willing to merge 😁 |
Contributor
Author
|
Yes, it still has bugs; sometimes it breaks with files that were working. I still need to implement object translation/transformation properly, embedded images, and it still breaks with some text and other edge cases... it's still something I'm working on (personally, I find it useful). Honestly, that code needs to be rewritten from scratch along with the creation of test files... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fix text with shape inside and cleaning of PR #74
First, I want to apologize in advance, as my English is not perfect.
I would like to clarify that I have not yet performed extensive testing (I will be working with this version and conducting daily usage tests). I am testing on Arch Linux , Python 3.14.3, and Inkscape 1.4.3 (0d15f75042, 2025-12-25). The original pytest works, but it needs to be updated...
Okay...When a text element uses shape-inside, Inkscape seems to ignore x and y coordinates on the and elements. Instead, it dynamically generates the text position, line breaks, and bounding box strictly based on that hidden linked shape. The original ApplyTransform script was grabbing the transformation matrix (the scaling and moving values) from your grouped text, doing the math to update the 's x, y, and font-size values, and then deleting the transform attribute.
However, because the script didn't know about shape-inside, it left the hidden bounding shape completely untransformed. When you opened the file in Inkscape, Inkscape saw that the transform attribute was gone, ignored your newly calculated x/y text coordinates, and forcefully snapped the text back inside the original, un-moved, un-scaled hidden shape.
This results (at least in my case) in a text box of an unwanted size, with the text positioned elsewhere.
All of this—in addition to the corrections from PR #74—still requires review regarding certain edge cases (which is why I mentioned the need to update the tests). PR #74 was the one that worked best for me up to this point, but it was too "vibes-coded" and didn't resolve the text-related issue (which I am fixing in this PR). At the very least, I hope this PR proves useful to those curious enough to dig through the pull requests of a this project.