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
TextPath bbox width varies #684
Comments
It varies the same either I set |
and the |
The problem may be solved by computing the tspan's bbox().w at the very beginning while adding it to the text path and then passing it to the offset computing function. But the problem remains, because if we leave everything as is and then get the tspan's bbox().w instead of text bbox().w, it will be varying too |
Hey @uyouthe I may have a solution for you, I don't know if it will work with what you are trying to do but hear me out. What you could do is to get the reverse of the path you use for the text path. You can get it using a software like Inkscape or something else. With that, you could put your text at the end using something like this:
And if you want to put it at the start, then you would do something like this:
I think it is the easiest way to accomplish what you want. Trying to calculate the offset so that the text is at the end of the path seem to me as it would be difficult (I seriously have no idea how to do it). The only real issue with my solution is getting the reverse of the path. Unfortunately, I hope this help you out, I'm definitely not the expert on textpath of the team. Maybe @Fuzzyma will give you a better solution. |
Forget my previous post, what I'm proposing won't work as it will also reverse the text. I will need to think more on this! |
Wow... turn out this is actually pretty easy to do. You just need to set the |
@uyouthe I get a notification mail whenever the svg.js tag is mentioned on stackoverflow. I searched for anything like this. Couldnt find a question from you. Of course the bbox varies when you move the text at the path. When the path is a circle, the text is drawn along this circle which means the bbox is a square. The text itself is always "longer" than text you draw along a path. Depending on what your path looks like, the text has another bbox. I think @RmiTtro has a good solution here |
There's no problem to calculate the offset, it was the easiest part. Reverse path will not work because I'm building a uml tool and my path (line between two diagram blocks) is cubic-bezier and it's being drawn dynamically. Of course when the text bends, bbox width may vary slightly, but the problem remains: for specific path the same text looking the same way and doesn't bend at all because the path is straight, but text bbox width value jumps around for about 15 units or more |
Can you please put that in a fiddle so we can see it and play with it? |
It may be the text path glitch that needs some research but for now I have found the workaround. This bug is so hard to spot but if sometimes someone will try to fix it, feel free to contact me |
I tried to fiddle it before replying here today, but it doesn't show up. It seems to happen just in my specific situation, with svg.draggy.js and path redraw on drag. And it's also strange that text bbox().x is always 0. Maybe I'm using something wrong, because the bug happens only with the one single path, reverse it vertically or horizontally and bug doesn't show itself. Anyway, thank you! |
Closing this for now |
Posting here because stack overflow is silent about everything related to svg.js.
I got the code adding the textpath (it's not clean, sorry):
And then I need to compute the
startOffset
value for attaching my text to either start or end of the line, but I don't need the relative value in %, I need the exactly value. I also need to add some padding and it's done just like that:I also change the path function, but the
path.length()
is behaving absolutely correct. The problem is textbbox().w
:So the text bbox is changing so much, but the text are the same, the path length may be the same, everything is the same but bbox. What I supposed to do?
The text was updated successfully, but these errors were encountered: