-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Missing text position in SVG #9489
Comments
weird |
can you reduce th svg to <5 text elements |
I simplified the svg to the above and see the issue (or at least one of them). It looks like the text element should be able to handle tspan subelements but I don't see where Text.fromElement is handling tspan subelements. It looks like the tspan should be used to place the location of the text. This doesn't appear to be in v5 either, at least looking at the code. https://www.w3.org/TR/SVG11/text.html#TSpanElement I'm also confused on why Text.fromElement is replacing dx and dy with 0 instead of reading what's in the svg. Similar with top and left from options. It looks like the v5 code would read top and left from options and set to 0 if they weren't populated but the v6 code just sets to 0. |
I found this test suite: http://fabricjs.com/test/svg_import/text.html |
tspan in svg import aren't supported, while should be supported in output. |
Supporting TSPAN is on my old TODO list, maybe as soon as 6.0 is out i ll do it. |
duplicate of #1280 |
@asturur I'm willing to help with this. I'm just not sure what the idea would be. When a tspan appears, should that be handled in the same FabricText or do you think there may be cases where we'd be forced to use separate FabricTexts? Or is this something where we can get fancy with styling to solve the problem? Something else I noticed is that the svg text supports arrays for the x value (and other values), so that each letter may be handled in the array (but the code assumes only the single value case). One example provided is rotate, so that you see the first couple of letters in a different rotation than the last ones. The array case is actually what's driving my same vs separate question above. |
The original file is a PDF file, and the SVG obtained through MuPDF API conversion is uncertain whether MuPDF can remove tspan |
@more-strive do you mind sharing an example of using MuPDF API to convert PDF to SVG? |
This is the official command line |
I can expand on this, because i thought about it for long time, but i need time to sit down and write everything. |
So if you have seen the text.fromElement const textContent = (element.textContent || '')
.replace(/^\s+|\s+$|\n+/g, '')
.replace(/\s+/g, ' '); We get the textContent of the Text element and we trash everything that is an html/svg tag. What we would like to do is to parse the childNodes of that text element, divide textNodes from other kind of nodes ( opefully the others are only That would be the basic implementation. There will be issues, like TSPAN used to look like text lines that will be a single line that gets displaced. There are different level of efforts that can bring us to a nicer support and get to mostly complete support with time.
There are also some decisions to take, like style does not support x/y but supports dx/dy so eventually a map between x with dx and y with dy needs to be arranged. I'm sure you can help but i would really do some feature development instead of just ts migrations and api changes, so i m looking forward to start it |
CheckList
Version
6.0.0-beta9
In What environments are you experiencing the problem?
Chrome
Node Version (if applicable)
18.16.0
Link To Reproduction
https://codesandbox.io/p/sandbox/fabric-vanillajs-sandbox-forked-wqznkq?file=%2Fsrc%2Findex.ts%3A11%2C23
Steps To Reproduce
Expected Behavior
Text displayed in the specified position
Actual Behavior
Text in the bottom left corner of the canvas
Error Message & Stack Trace
No response
The text was updated successfully, but these errors were encountered: