def __init__(self, atlas, filename, size): ''' Initialize font Parameters: ----------- atlas: TextureAtlas Texture atlas where glyph texture will be stored filename: str Font filename size : float Font size ''' self.atlas = atlas self.filename = filename.encode('utf-8') # Make bytes self.size = size self.glyphs = {} face = Face(self.filename) face.set_char_size(int(self.size * 64)) self._dirty = False metrics = face.size self.ascender = metrics.ascender / 64.0 self.descender = metrics.descender / 64.0 self.height = metrics.height / 64.0 self.linegap = self.height - self.ascender + self.descender self.depth = atlas.depth
def load(self, charcodes=''): ''' Build glyphs corresponding to individual characters in charcodes. Parameters: ----------- charcodes: [str | unicode] Set of characters to be represented ''' face = Face(self.filename) try: return self._load(charcodes, face) finally: # Make sure to clear the face. I've seen some pretty bad # crashes on Windows when an exception was thrown in the code # in _load(), because the hold all the variables, preventing the # face from being cleared. face.__del__() face._FT_Face = None