calculate textsize for fixed width
Where it is quite esay to do in nodebox 3 I have difficulties
making the same behavior work in Nodebox 1:
I want text blocks to have different font sizes, so that they align
vertically. See the attached photo. My current code does it quite
good bot not perfect, it depends on the text input. Does anyone
know a better attempt to do this?
txt="Hello Width!"
desired_width=300
fontsize(100)
w_draft=textwidth(txt)
fz=100*desired_width/w_draft
fontsize(fz)
print textwidth(txt)
text(txt, 100, 100)
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 ugajin on 25 Aug, 2014 05:30 PM
see: http://nodebox.net/code/index.php/Reference
2 Posted by dreerr on 25 Aug, 2014 07:38 PM
There is no specific command for that, as I want to scale the text to full width, not make a textarea
3 Posted by ugajin on 25 Aug, 2014 08:28 PM
Take another look.
4 Posted by dreerr on 25 Aug, 2014 09:49 PM
Thanks for your help, or let's say clues (^^^)
I was able to do it with BezierPath, file size is the only downside :)
´´´
width=500
last_y=0
for txt in ['Hi', 'Hello', 'Width!']:
path = textpath(txt,0,0) path.fit(0, last_y, width) last_y = last_y + path.bounds.size.height drawpath(path) ´´´
5 Posted by dreerr on 25 Aug, 2014 09:52 PM
Support Staff 6 Posted by Frederik De Ble... on 26 Aug, 2014 08:43 AM
Indeed, The "fit" approach is also how NodeBox 3 does it.
I've also tried your approach, and it seems to work fine, only the commas and question marks at the end throw things off. Here's my version and the result: