views:

112

answers:

2

I'm writing an open source program (key-train) in Python and GTK (with Cairo) and I would like to use some more attractive fonts. I was hoping that it would be possible to load a ttf font from within the program and just use it (instead of installing it), but I haven't been able to figure out how to do this.

+1  A: 

You could use pango to set the ttf font:

#!/usr/bin/env python
import pango
import gtk

window = gtk.Window(gtk.WINDOW_TOPLEVEL)
main_vbox = gtk.VBox(homogeneous=False,spacing=0)
window.add(main_vbox)
textview = gtk.TextView()
main_vbox.pack_start(textview,expand=False,fill=True,padding=0)
textbuffer = textview.get_buffer()
font_desc=pango.FontDescription('FreeSans Bold 64')
textview.modify_font(font_desc)
textbuffer.set_text('Hi Scott Kirkwood')
textview.show()
main_vbox.show()
window.show()
gtk.main()
unutbu
How is this using a custom (uninstalled) font?
Matthew Talbert
This I know how to do, I'm more interested in loading a ttf file.
Scott Kirkwood
+1  A: 

You might want to take a look at this feature request It shows a work-a-round if using cairo and freetype for the backend.

Matthew Talbert
So I'll take this to mean that there's no proper way to do this yet, but there might be in the future.There are hacks that may work.For my program I've decided to go another way: - For the seven segment font I wanted to use, I'll just use 10 svg images which I've created myself (see http://scottkirkwood.blogspot.com/2009/12/seven-segment-display-in-inkscape.html). - For any additional fonts I'll install them as part of the the install.
Scott Kirkwood
I think that's a good decision. Nice looking program, btw. I'm going to have to check it out.
Matthew Talbert