Font reloading [SOLVED]

When I try to load the same font again - it seems that Panda return link to the first loaded font. For example I try to set different outline (red and green), but I get the same results for both loaded fonts.

font1 = loader.loadFont('arial.ttf', outlineColor = Vec4(1,0,0,1), outlineWidth = 0.5)
font2 = loader.loadFont('arial.ttf', outlineColor = Vec4(0,1,0,1), outlineWidth = 0.5)

TextNode1 = TextNode('text1')
TextNode1.setFont(font1)
TextNode1.setText('111111')

TextNode2 = TextNode('text2')
TextNode2.setFont(font2)
TextNode2.setText('222222')

t1 = render2d.attachNewNode(TextNode1.generate())
t2 = render2d.attachNewNode(TextNode2.generate())

t1.setScale(0.07)
t1.setX(0.5)
t2.setScale(0.07)

This is a feature, because normally you do want it to share the same font object. But when you want to do something unusual like make a specialization of a particular font in one particular color or something, you need to explicitly load a different copy of the font object.

The easiest way to do this is to insert a call to FontPool.releaseFont(‘arial.ttf’) before the second call to loader.loadFont(‘arial.ttf’). Another way is to replace the second call to loadFont() with the call font2 = font1.makeCopy(), and then set the parameters explicitly.

David

It’s work, thanks for the fast reply :slight_smile: