Skip to content

Fix text with shape inside and cleaning of PR #74 - #75

Open
jackestar wants to merge 8 commits into
Klowner:masterfrom
jackestar:fix-text-shape-inside
Open

Fix text with shape inside and cleaning of PR #74#75
jackestar wants to merge 8 commits into
Klowner:masterfrom
jackestar:fix-text-shape-inside

Conversation

@jackestar

Copy link
Copy Markdown

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.

erik.vullings-tno and others added 8 commits January 4, 2026 13:43
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)
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
@Klowner

Klowner commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Thank you very much for cleaning this up into something I would actually be willing to merge 😁

@vmario89

Copy link
Copy Markdown
Contributor

great PR. and it looks like the other PRs are inside ths PR too?

looks very good. however, some example does not properly apply with the new code, but works with old code:

grafik

test file:
Zeichnung

with the #PR75 the text jumps around. did not before:
grafik

had no time to dig deeper, but at least wanted to try out for now

@jackestar

Copy link
Copy Markdown
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...

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.

3 participants