bitwidgets: Import X11 misc fonts since they're PD

We really heavily depend on these fonts, so in the name of portability, it's
okayish to import them here. The license for these files is apparently the
public domain, so this should be okay.

Adjusts the fonts package to load in the fonts using importlib and some BytesIO
wizardry.
This commit is contained in:
June Tate-Gans 2022-05-13 15:21:25 -05:00
parent 206c096829
commit 38384f512c
7 changed files with 11 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
"Public domain font. Share and enjoy."

View File

@ -16,20 +16,20 @@ import gzip
import pathlib import pathlib
import enum import enum
import PIL import PIL
import importlib.resources as pkg_resources
from PIL.ImageFont import ImageFont from PIL.ImageFont import ImageFont
from PIL.PcfFontFile import PcfFontFile from PIL.PcfFontFile import PcfFontFile
from PIL.FontFile import puti16 from PIL.FontFile import puti16
from . import assets
X11_FONT_PATH = pathlib.Path('/usr/share/fonts/X11/misc')
class Fonts(enum.Enum): class Fonts(enum.Enum):
TINY = X11_FONT_PATH / '4x6.pcf.gz' TINY = '4x6.pcf.gz'
SMALL = X11_FONT_PATH / '5x7.pcf.gz' SMALL = '5x7.pcf.gz'
MEDIUM = X11_FONT_PATH / '8x13.pcf.gz' MEDIUM = '8x13.pcf.gz'
LARGE = X11_FONT_PATH / '9x18.pcf.gz' LARGE = '9x18.pcf.gz'
HUGE = X11_FONT_PATH / '10x20.pcf.gz' HUGE = '10x20.pcf.gz'
class PcfFontConverter(PcfFontFile): class PcfFontConverter(PcfFontFile):
@ -108,7 +108,9 @@ class FontManager(object):
return FontManager._fonts[font] return FontManager._fonts[font]
def _loadPcfFont(filename): def _loadPcfFont(filename):
with gzip.open(filename, 'rb') as fp: compressed_data = pkg_resources.read_binary(assets, filename)
data = gzip.decompress(compressed_data)
with io.BytesIO(data) as fp:
pff = PcfFontConverter(fp) pff = PcfFontConverter(fp)
imageFont = pff.getImageFont() imageFont = pff.getImageFont()
return imageFont return imageFont