Hello,
I am running an experiment on version 1.84.2 of PsychoPy.
I wish to display text in the Aharoni font. However, this works only on one computer but not on others (yet, I am able to display other fonts, such as Arial, in those computers). In all computers I am using win 10, and in those in which displaying this font does not work, the font does seem to exist in other programs such as Power Point or Word.
How can I add a font?
Thanks,
Ofir
My guess is that the font is installed on one computer but not the others. Thereâs two solutions:
-
Install the font on all systems. Google how to do it for your operating system.
-
You can add the font file (probably âaharoni.ttfâ) to your experiment folder and then specify that as the font in your
TextStim
.my_text = visual.TextStim(win, text='Look, this is the Aharoni font!', font='aharoni.ttf')
Hi,
I found a solution after doing some research. It seems that non-system font files must be registered for once before you can specify them in a textâs Font field (Builder) or .font
property.
You can use a temporary TextStim object at the beginning of the experiment just for registering font files:
font_files = ['NotoSansSC-Regular.otf', 'NotoSerifSC-Regular.otf']
font_main = 'Noto Sans SC'
_ = visual.TextStim(win=win, font=font_main, fontFiles=font_files)
del _
After this, you can set the font of your texts to âNoto Sans SCâ or âNoto Serif SCâ (the names of the two Simplified Chinese fonts). PsychoPy will recognize the font name and you donât need to pass the fontFiles
argument again.
new_text = visual.TextStim(win=win, text='Hello, font', font=font_main)
Alternatively, you can directly register the font files with pyglet
instead of creating a temporary TextStim. This is what the .fontFiles
setter does under the hood (see the source code).
import pyglet
font_files = ['NotoSansSC-Regular.otf', 'NotoSerifSC-Regular.otf']
for font in font_files:
pyglet.font.add_file(font)
new_text = visual.TextStim(win=win, text='Hello, font', font='Noto Sans SC')
(tested with PsychoPy 2022.1.4)