Example #1
0
    def load_font(self, name, path=None):
        """ Add a new font to this manager. 
        
        Parameters
        ----------
        name : :obj:`str`
            The name of the font.  The font's metafile and texture filename's 
            should also be this value with the appropriate file extensions. 
        path : :obj:`str`, optional
            File path the font files. If not supplied will use the default 
            `res/fonts/` path.
        """

        if path is None: path = self._font_path

        # Load in the font texture atlas
        tex_file = path + name + ".png"
        image = self._app.tex_mgr.load_image(name, tex_file)
        builder = TextureBuilder().set_filtered(True).set_wrapped(
            GL_CLAMP_TO_EDGE)
        texture = self._app.tex_mgr.load_texture(name, image, builder)

        # Create the font object which automatically loades the font metadata
        font_file = path + name + ".fnt"
        font = Font(name, font_file, texture)

        # Add font to local caches and create loader obj
        self._fonts[font.name] = font
        self._loaders[font] = loader = TextLoader(font)
        self._texts[font] = []
        font._loader = loader  # Attempting to not expose a set option

        return font