TextNode and card boundaries

Hi,

My 2 boxes do not overlap, but I don’t understand why, can anyone helps ?

from panda3d.core import *
import direct.directbase.DirectStart
from direct.gui.DirectGui import *

screenScale = 0.1
btext = "my text string"

text = TextNode('node name')
text.setText(btext)
text.setTextColor(0,0,0,1)
text.setCardColor(1,0,0,0.2)
text.setCardAsMargin(0, 0, 0, 0)

textNodePath = aspect2d.attachNewNode(text)
textNodePath.setScale(screenScale)
textNodePath.setPos(0,0,0)
textNodePath.reparentTo(aspect2d)


middle_cm = CardMaker('logo')
middle_cm.setFrame((0, text.getWidth(), 0, text.getHeight()))
middle_cm.setColor(0,0,1,0.3)

middle_card = aspect2d.attachNewNode(middle_cm.generate())
middle_card.setTransparency(1)
middle_card.setScale(screenScale)
middle_card.setPos(0,0,0)
middle_card.reparentTo(aspect2d)

# Run 
base.run()

Thanks !

To start with, if I’m not much mistaken, a TextNode is set up such that a z-coordinate of “0” corresponds to the baseline of the text–the line on which its letters rest, excluding any bits that hang down (such as the tail of a “g” or a “y”). Thus, when you set up your CardMaker’s frame to have a lowest extent of “0”, it starts at the baseline, rather than the bottom-most extent of the text.

Furthermore, I think that the height returned by “getHeight()” gives the total height of the text–including bits that hang down. And since the text has such bits, the total height is greater than the distance from its baseline to the top of the text.

As a result, your card ends up starting from the baseline, and rising up further than the top of the text.

Thanks, It makes sense.

Finally I found that text.get_left/get_right,get_bottom,get_top() give me the exact size of the textnode card and I will go with that. I tried with getTightBounds too but it gaves me the size of… something else :sweat_smile:.

Ciao !

1 Like