1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

lineheight: set solid

Posted by andrea on Apr 19, 2008

(I'm sorry for the bombing but I need to understand...)

I think I'm missing something with lineheight()
If I set it to 1 I guess I should set solid. But ascenders and descenders don't touch. I'm having a set solid with a 0.78 value (approx).
e.g.

font("Century", 40)
lineheight(0.78)
text("gggggggggggggggg llllllllllllllllllllllllll!!", 0,51, 370 )
What am I missing?

Many thanks
-a-


 
Posted by Mark M on Apr 20, 2008

Andrea,

I think what you are missing is the height is calculated as a multiple of the 'natural line height' of the font. This comes from apple's text engine and is the height from tallest character to the lowest descender. Most fonts are going to have caps with accents that will be higher than ascenders--think of the 'A' with a ring above it used in Danish. It's a little complicated to figure out how to do what you want in anything other than a case by case method, I think, but here are some Appkit methods that are easy to use in nodebox that might help a bit.

from AppKit import *
 
helv = NSFont.fontWithName_size_("Helvetica", 32)
defaultHeight = helv.defaultLineHeightForFont()
capHeight =  helv.capHeight()
descender =  helv.descender()
xheight = helv.xHeight()
print helv.leading()
 
font("Helvetica", 32)
 
lineheight((xheight)/defaultHeight)
text("xxxx\nxxxx", 0,54, 281 )
 
lineheight((capHeight)/defaultHeight)
text("MMMM\nMMMM", 0,104, 281 )
 
lineheight((capHeight-descender)/defaultHeight)
text("jjjjjj\nMMMM", 0,167, 292 )
I don't know if this forum software takes unicode so this last line might by messed up, but it's not important--you get the idea:
lineheight(1)
text(u"jjjjjjjjjjjÅÅÅ", 30,243, 95 )
Good luck, hopes this helps a bit.



Posted by andrea on Apr 21, 2008

Uh, thanks a lot, Mark.
Perfect, I understood the problem.
But it would be nice to have documentation (or at least some hints) about the module you used.

Best

-a-



Posted by Mark M on Apr 21, 2008

Hi Andrea,

The Appkit library comes with the Mac. It isn't a nodebox module per se--anymore than any other python library is.

Despite that, there is a really good intro on using it with Nodebox that will get you started here:

http://www.nodebox.net/code/index.php/PyObjC

It is very powerful because it gives you access to most of the apple API, and because of this, there is a bit of learning curve.



Posted by andrea on Apr 21, 2008

Ah, didn't take a look to that page...

many thanks

-a-