Text leading (line spacing)
Hello! I need to add line spacing to the text and I'm trying to do this by adding the lineHeight port to the textPath node metadata. However, I'm getting an error. I would be very grateful for your help. By the way, setting the line spacing is a very useful function.
Error text
java.lang.IllegalArgumentException
at jdk.internal.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at nodebox.function.JavaLibrary$StaticMethodFunction.invoke(JavaLibrary.java:104)
at nodebox.node.NodeContext.invokeFunction(NodeContext.java:342)
at nodebox.node.NodeContext.invokeNode(NodeContext.java:238)
at nodebox.node.NodeContext.invokeNode(NodeContext.java:232)
at nodebox.node.NodeContext.renderNode(NodeContext.java:121)
at nodebox.node.NodeContext.renderChild(NodeContext.java:207)
at nodebox.node.NodeContext.renderNode(NodeContext.java:117)
at nodebox.node.NodeContext.renderNode(NodeContext.java:93)
at nodebox.client.NodeBoxDocument$3.doInBackground(NodeBoxDocument.java:1263)
at nodebox.client.NodeBoxDocument$3.doInBackground(NodeBoxDocument.java:1260)
at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
-
2025-08-10_092123.png
648 KB
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
1 Posted by Alex on 10 Aug, 2025 06:23 AM
Example
Support Staff 2 Posted by john on 10 Aug, 2025 10:06 AM
Alex,
I agree with you that not including an ability to adjust leading (line height) in textpath was an oversight. In fact I once urged Frederik (the creator of Nodebox) to fix this. Sadly Frederik is no longer actively improving Nodebox.
But t don't think trying to modify Nodebox yourself is the best approach. What you are doing is creating your own fork of Nodebox. While adding a simple feature like this may seem fairly easy, such modifications are often trickier than they seem, as you have discovered. To add a feature like this you will need to make multiple changes in different places and make sure you don't introduced any unintended consequences. You have to understand the Nodebox code pretty well to do this successfully.
But even if you pull this off, it will only work for you and your special forked version of Nodebox. If you try to share your projects with anyone else, your modified nodes will break for them (as it did for me with the example file you sent). It also creates a maintenance burden which would become a nightmare if other people start modifying Nodebox.
The good news is that it's possible to add this capability entirely within standard Nodebox. I have done this in various ways over the years.
It is a tricky problem, because the algorithm Nodebox uses to handle line breaks based on width is somewhat mysterious, and after it makes those line breaks the text is a single path which is hard to break apart and adjust. Hard but not impossible.
I currently have several nodes in my library that can give you control over line height: align_labels and kern. Both of these methods have a catch, though: you have to set the line breaks manually.
To do this with align_labels, use the make_strings node to divide your text string into separate strings for each line. I usually use a backslash as a separator. Just add backslashes into your text wherever you want a line break. Then feed that list into the labels port of align_labels and adjust the leading to your heart's content.
My kern node give you even more control. With it, you can control both the kerning between characters, spacing between words, AND leading. Kern takes a single text string, so to break it into separate lines you will need to use my line_break node. You can use the same backslashes you used with align_labels.
NOTE: I just improved the kern node in the current release of my library. So for accurate leading control, use the new version available here:
http://support.nodebox.net/discussions/show-your-work/997-improveme...
The demo shows you how to create multi-line text using this technique.
One of these two methods should give you the control you need for now. Please give one of them a try and report back to me.
It would be nice to just have a textpath node with a line height option as you were trying to do. It wouldn't give you the same level of control as my two nodes, but would allow you to more easily adjust the line breaks for different widths. If you tell me this is what you want, I will see if I can create a new node to do this.
John
Support Staff 3 Posted by john on 12 Aug, 2025 07:32 PM
Alex,
Still there?
FYI, I just added leading controls to my charpath and wordpath nodes. These nodes work exactly like textpath except that they return multiple paths (one for each character or one for each word).
http://support.nodebox.net/discussions/show-your-work/1000-leading-...
By adding a leading control to both nodes, I have essentially done exactly what you were trying to do using standard, unmodified Nodebox. So you can just copy/paste either of these two nodes whenever you would normally use textpath.
Please let me know if that solves your problem and if you have any more questions or comments.
Thanks,
John