Load a custom symbol font from within running script?
Is there a way to load a custom font for use in a custom view inside of a script?
To be clear, I don't want to load a font for the user to use in general, in this use case the font has symbols I want to be able to use, and it's a convenient way to store vector icon images. I don't see an obvious way to load a font from my local script area...wondering if this is a sandbox security thing?
Slightly off-topic: as of iOS 13 Apple is supplying a special system standard symbols "font" which UIImages will be able to load individual icons from, which is basically the same idea as what I want to do here.
ccc last edited by
I saw that post in my search...that's almost literally the opposite of what I want.
What I absolutely don't want is to load this font from an external source, or to have any user interaction involved.
I'd like to simply have the font .ttf file located in my script's directory and then load it for use at run time.
I'm sensing that's not possible, due to some security implications?
JonB last edited by
PIL includes ImageFont.truetype which let's you load a file. You then have to use ImageDraw to create an PIL image, which can then be dumped to BytesIO -> ui.Image.from_data.
As an example, see:
I'm not 100% sure I pythonista's ImageFont let's you load ttf from file -- I think it does -- but if not, you could convert your font to the PIL native font format.
cvp last edited by cvp
Note In Pythonista, the truetype() function can be used to load built-in system fonts, e.g. font = ImageFont.truetype('Helvetica', 20).
cvp last edited by
Downloaded tiny.tff from here
from PIL import Image, ImageFont, ImageDraw font = ImageFont.truetype('tiny.ttf',20) img = Image.new('RGBA', (100,100), "white") draw = ImageDraw.Draw(img) draw.text((2,2), 'test', font=font, fill='blue') img.show()
upwart last edited by
If you install the font via AnyFont it becomes system wide available.
Then you can just load it directly, without the need for a .ttf to be loaded.
JonB last edited by
The original question was about not installing system fonts. Obviously you cant use an ImageFont in a textfield.