<commit_before># -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, <NAME>
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
import os
import numpy as np
from glumpy import data
from glumpy.log import log
from glumpy.gloo.atlas import Atlas
from glumpy.graphics.text import Font


class FontManager(object):

    # Default atlas
    _atlas = None

    # Font cache
    _cache = {}

    # The singleton instance
    _instance = None


    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = object.__new__(cls, *args, **kwargs)
        return cls._instance

    @classmethod
    def get(cls, filename):
        filename = data.get(filename)
        dirname  = os.path.dirname(filename)
        basename = os.path.basename(filename)
        if basename in FontManager._cache.keys():
            return FontManager._cache[basename]
        FontManager._cache[basename] = Font(filename, FontManager._atlas)
        return FontManager._cache[basename]


    # def get_font(self, family, weight=400, stretch='regular', slant='regular'):
    #     log.warn("Not yet implemented")
    #     return self.get_file('')


    @property
    def atlas(self):
        if FontManager._atlas is None:
            FontManager._atlas = np.zeros((1024,1024),np.float32).view(Atlas)
        return FontManager._atlas


    @property
    def cache(self):
        return FontManager._cache<commit_msg>Added documentation, close #19<commit_after># -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, <NAME>
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
""" Font Manager """
import os
import numpy as np
from glumpy import data
from glumpy.log import log
from glumpy.gloo.atlas import Atlas
from glumpy.graphics.text import Font


class FontManager(object):
    """
    Font Manager

    The Font manager takes care of caching already loaded font. Currently, the only
    way to get a font is to get it via its filename. If the font is not available
    on the local data directory, it will be fetched from the font server which
    lives at https://github.com/glumpy/glumpy-font/.
    """

    # Default atlas
    _atlas = None

    # Font cache
    _cache = {}

    # The singleton instance
    _instance = None


    def __new__(cls, *args, **kwargs):
        if not cls._instance:
            cls._instance = object.__new__(cls, *args, **kwargs)
        return cls._instance

    @classmethod
    def get(cls, filename):
        """
        Get a font from the cache, the local data directory or the distant server
        (in that order).
        """

        filename = data.get(filename)
        dirname  = os.path.dirname(filename)
        basename = os.path.basename(filename)
        if basename in FontManager._cache.keys():
            return FontManager._cache[basename]
        FontManager._cache[basename] = Font(filename, FontManager._atlas)
        return FontManager._cache[basename]


    @property
    def atlas(self):
        """ Texture atlas """

        if FontManager._atlas is None:
            FontManager._atlas = np.zeros((1024,1024),np.float32).view(Atlas)
        return FontManager._atlas


    @property
    def cache(self):
        """ Font cache """

        return FontManager._cache
{'fraction_non_alphanumeric': 0.17706013363028952, 'fraction_numerical': 0.009743875278396437, 'mean_word_length': 1.9450819672131148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3381642', 'n_tokens_mistral': 990, 'n_tokens_neox': 930, 'n_words': 294}