*.ttf
) and Type 1
(*.pfb
) fonts to render text. When a font is loaded
(with the load_font()
or search_font()
functions), Slithy creates a texture map with one instance of each
character rasterized at the given size (which usually looks like this) and along with a table giving the
coordinates of each character in the texture map. Slithy can then
render text on the screen by drawing rectangles with the appropriate
character textures.Distributing presentations along with fonts is problematic, since you can't legally send out copies of your TTF and PFB files. I've been kind of ignoring the issue with the sample presentations, using commonly available font files that I think most people already have. Some people have asked about this, though, so now there's a better mechanism.
Slithy can now save the texture map and coordinate table it creates when loading a font, and load them back in just like loading the original font file. These files don't contain character outlines or hinting data, so I believe it should be perfectly legal to redistribute them. It's just like distributing a piece of paper with the characters printed out on it.
load_font()
and search_font()
now come in
two flavors:
load_font( 'foo.pfb', 50 ) # with pixel size, load a TTF or PFB file load_font( 'foo.slf' ) # without, load a "Slithy font"The new function
create_slithy_fonts()
is used to make a
Slithy font from a TTF or PFB file (at a particular pixel size).
resources.py
) which loads all the fonts and images, and
puts them into dictionaries. Here's a sample (the numbers refer to
the comments below):
from slithy.library import * fontpath.append( '.' ) # 1 add_extra_characters( u'\u201c\u201d' ) # 2 create_slithy_fonts( ('times.ttf', 50, 'times.slf'), # 3 ('ehrhardt.pfb', 50, 'ehrhardt.slf'), ('mob.pfb', 50, 'minion.slf'), ('mobi.pfb', 50, 'minion_i.slf'), ) fonts = { 'times' : search_font( 'times.slf' ), # 4 'ehrhardt' : search_font( 'ehrhardt.slf' ), 'body' : search_font( 'minion.slf' ), 'bodyi' : search_font( 'minion_i.slf' ), } imagepath.append( '.' ) # 5 images = { 'tanguy' : search_image( 'tanguy.jpg' ), # 6 }
fontpath
is a list of directories
that search_font()
will look in.
create_slithy_fonts()
are zero or
more 3-tuples, where each one is "(original font file, pixelsize,
output Slithy font file)".
fonts['body']
". This makes it easy to
keep a consistent style throughout the presentation and make global
style changes.
imagepath : search_image :: fontpath : search_font
When I run this file directly (with "python
resources.py
"), the create_slithy_fonts()
call
will create the requested font files and it will not return.
It will look like this:
% python resources.py
creating 'times.slf' from 'times.ttf' (at 50 pixels)
creating 'ehrhardt.slf' from 'ehrhardt.pfb' (at 50 pixels)
creating 'minion.slf' from 'mob.pfb' (at 50 pixels)
creating 'minion_i.slf' from 'mobi.pfb' (at 50 pixels)
4 slithy fonts created.
%
Of course, you will need to have the TTF and PFB files available to do this. (This won't work on the samples in the archive because these files aren't included.)
To make use of the things I've loaded in my animations and diagrams, I need to do something like this:
from slithy.library import *
from resources import fonts, images
. . .
def some_animation():
tx = Text( ..., font = fonts['body'], ... )
. . .
When resources.py
is loaded this way, from within another
file, create_slithy_fonts()
will do nothing. Only the
SLF files are needed to view the presentation.