Custom Fonts From The File Pool
Hi all,
I need to use a custom font for my experiment which I want to place in the File Pool so the experiment is portable and I don't need to ask the IT Department to get involved! However OpenSesame won't use any font I place in the File Pool.
I have made sure the font is TTF and have used the syntax from here, namely:
draw textline 0.0 0.0 "This will be inconsolata" font_family="inconsolata"
But still no joy. The font works fine when I install it and select it from the Font Selection Dialogue, so I know the font itself is fine, so it must be OpenSesame or my code! I have tried the same thing on both Windows and Mac, and have installed the latest version of OS to no avail.
The code in question is below, with a screenshot attached showing the File Pool contents.
draw textline center=1 color=Black font_bold=no font_family="Open" font_italic=no font_size=50 html=yes show_if=always text="Test using file pool font" x=0 y=-128 z_index=0
Any assistance would be really appreciated, I need to start running my experiment ASAP and this is the last thing in the way! 😥
Thanks all, Rich
Comments
Hi Rich,
Thanks for bringing this to our attention. It's a bug that was introduced with the new text-rendering system in OpenSesame 3.2. We'll fix this in an upcoming maintenance release. But for now, you can register your font (from the file pool) with a script like the one below. This script needs to be put in the prepare phase of an
inline_scriptitem at the start of the experiment.from qtpy.QtGui import QFontDatabase from openexp._canvas._richtext import richtext font = 'test' # The name of the font in the pool, without .ttf # Register the font with OpenSesame fdb = QFontDatabase() font_id = fdb.addApplicationFont(pool[font + '.ttf']) print('font_id = {}'.format(font_id)) font_families = fdb.applicationFontFamilies(font_id) print('font_families = {}'.format(font_families)) richtext.font_substitutions.append((font_families[0], font))Hope this helps!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastian, thank you for your help.
I put that code in but the experiment crashes now, throwing a python error.
If I comment out all lines from "fdb = ..." downwards then the experiment runs. But as soon as "fdb = ..." is allowed to run, python crashes.
It's the same on Windows and Mac. Any idea how to get round this?
Many thanks,
Rich
I would also be interested in solving this issue.
Thank you,
Emma
Hi @Emma and @Richie ,
If this crashes, then I suggest to, as a temporary workaround, either install the fonts on the systems that you will use, or render the text as bitmaps. That's not ideal, but it should be doable. And, as I said above, for the next maintenance release this issue should be fixed!
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!