Example #1
0
def load_font(filename, bitmap=None):
    if not bitmap:
        import displayio
        bitmap = displayio.Bitmap
    f = open(filename, "rb")
    first_four = f.read(4)
    #print(first_four)
    if filename.endswith("bdf") and first_four == b"STAR":
        from . import bdf
        return bdf.BDF(f, bitmap)
    elif filename.endswith("pcf") and first_four == b"\x01fcp":
        import pcf
        return pcf.PCF(f)
    elif filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00":
        import ttf
        return ttf.TTF(f)
Example #2
0
def load_font(filename, bitmap=None):
    """Loads a font file. Returns None if unsupported."""
    if not bitmap:
        import displayio
        bitmap = displayio.Bitmap
    font_file = open(filename, "rb")
    first_four = font_file.read(4)
    #print(first_four)
    if filename.endswith("bdf") and first_four == b"STAR":
        from . import bdf
        return bdf.BDF(font_file, bitmap)
    if filename.endswith("pcf") and first_four == b"\x01fcp":
        import pcf
        return pcf.PCF(font_file)
    if filename.endswith("ttf") and first_four == b"\x00\x01\x00\x00":
        import ttf
        return ttf.TTF(font_file)
    return None