# One font, two sizes [SOLVED]

In a gui (DirectGui) I would want to have text at different sizes, and still keep the text ‘crisp’.

I’m doing something like this:

        self.BigFont = loader.loadFont('font/font1.ttf')
self.BigFont.setPixelsPerUnit(24)
self.BigFont.setMinfilter(Texture.FTNearest )
self.BigFont.setMagfilter(Texture.FTNearest )
self.SmallFont.setPixelsPerUnit(16)
self.SmallFont.setMinfilter(Texture.FTNearest )
self.SmallFont.setMagfilter(Texture.FTNearest )

But the pixel-per-unit value for both fonts ends up as 16
Also when I loaded the font some time before (in a different class) then I get an error:

Assertion failed: get_num_pages() == 0 at line 75 of c:\buildslave\release_sdk_w
in32\build\panda3d\panda\src\text\dynamicTextFont.I
Traceback (most recent call last):
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 61, in eventLoop
self.doEvents()
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 55, in doEvents
processFunc(self.eventQueue.dequeueEvent())
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 122, in processE
vent
messenger.send(eventName, paramList)
File "C:\Panda3D-1.8.1\direct\showbase\Messenger.py", line 397, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File "C:\Panda3D-1.8.1\direct\showbase\Messenger.py", line 482, in __dispatch
method (*(extraArgs + sentArgs))
File "main.py", line 435, in save_and_run
File "C:\scratch\game.py", line 220, in __init__
self.common['hud']=HUD(self.common)
File "C:\scratch\hud.py", line 25, in __init__
self.BigFont.setPixelsPerUnit(24)
AssertionError: get_num_pages() == 0 at line 75 of c:\buildslave\release_sdk_win
32\build\panda3d\panda\src\text\dynamicTextFont.I
Traceback (most recent call last):
File "main.py", line 453, in <module>
run()
File "C:\Panda3D-1.8.1\direct\showbase\ShowBase.py", line 2921, in run
self.step()
self.mgr.poll()
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 61, in eventLoop
self.doEvents()
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 55, in doEvents
processFunc(self.eventQueue.dequeueEvent())
File "C:\Panda3D-1.8.1\direct\showbase\EventManager.py", line 122, in processE
vent
messenger.send(eventName, paramList)
File "C:\Panda3D-1.8.1\direct\showbase\Messenger.py", line 397, in send
self.__dispatch(acceptorDict, event, sentArgs, foundWatch)
File "C:\Panda3D-1.8.1\direct\showbase\Messenger.py", line 482, in __dispatch
method (*(extraArgs + sentArgs))
File "main.py", line 435, in save_and_run
File "C:\scratch\game.py", line 220, in __init__
self.common['hud']=HUD(self.common)
File "C:\scratch\hud.py", line 25, in __init__
self.BigFont.setPixelsPerUnit(24)
AssertionError: get_num_pages() == 0 at line 75 of c:\buildslave\release_sdk_win
32\build\panda3d\panda\src\text\dynamicTextFont.I

Is this a bug? Is there any better way to avoid this then to keep many copies of the same font file with different names?

The source code for that assertion is:

  // If this assertion fails, you didn't call clear() first.  RTFM.
nassertr(get_num_pages() == 0, false);

Ok. font.clear() got rid of the assertion.
I had a look at the reference and I found a makeCopy() function, using that I can have two font with different sizes loaded from one font file.

        self.BigFont = loader.loadFont('font/font.ttf')
self.BigFont.setPixelsPerUnit(24)
self.BigFont.setMinfilter(Texture.FTNearest )
self.BigFont.setMagfilter(Texture.FTNearest )
self.SmallFont=self.BigFont.makeCopy()
self.SmallFont.setPixelsPerUnit(16)