Skip to content
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

Is it possible to add text in path ? #215

Open
lightgmco opened this issue Apr 6, 2023 · 7 comments
Open

Is it possible to add text in path ? #215

lightgmco opened this issue Apr 6, 2023 · 7 comments

Comments

@lightgmco
Copy link

I'm looking for a method to re-draw hundreds of text as fast as I can.

@tdewolff
Copy link
Owner

tdewolff commented Apr 6, 2023

Ok, so what's the problem?

@lightgmco
Copy link
Author

I need to transform a flight map with thousands of lines and texts and little triangles frequently, so I saved all the lines by a path, so it's faster to transform the map,but text can't be included?
If It's impossible to include the text in a path, is it possible to create a specified textPath collection for fast redraw?
I just want to try.

@tdewolff
Copy link
Owner

tdewolff commented Apr 6, 2023

You can convert a text line to a path using FontFace.ToPath("text"). If you want transform a text box, you can use the Text.RenderAsPath(targetRenderer, matrix, resolution)

@lightgmco
Copy link
Author

That's great!So I can merge text in the path!Even js can't achieve that.
By the way ,which way is right to merge a path with another one?
path1=path1.Join(path2)?
path1=path1.Append(path2)?

@tdewolff
Copy link
Owner

tdewolff commented Apr 6, 2023

Append will simply merge two separate paths into two subpaths. Join will join both paths by a line, this will leave only one subpath. Remember that using Append or Join will give different results when paths overlap then when drawing paths separately! Some parts may cancel out, but if you have no overlapping paths there should be no issue.

@lightgmco
Copy link
Author

lightgmco commented Apr 6, 2023

Append sounds safe.
But if I have some lines in path1,now I want to append a circle with a center(x,y).I tried:
path1.MoveTo(x,y)
path1=path1.Append(canvas.circle(2))
This way didn't work,I lost those circles.Why?

@tdewolff
Copy link
Owner

tdewolff commented Apr 6, 2023

Because canvas.Circle creates a path that starts at MoveTo(r,0), so appending or joining both would result in MoveTo(x,y) MoveTo(r,0) ArcTo(-r,0) ArcTo(r,0) which remove the first redundant MoveTo command. You need to translate the circle: canvas.Circle(2).Translate(x,y)

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

No branches or pull requests

2 participants