def test_load_from_pillow_exceptions(): """ Test that exceptions are thrown as appropriate if bitmap_font is asked to load a pillow font that is not a PIL.ImageFont file, is damaged or does not include the required font metrics data. """ with pytest.raises(SyntaxError) as ex: filename = get_reference_file(Path('font').joinpath('hd44780a02.pbm')) bitmap_font.load_pillow_font(filename, FONTDATA['mappings'][1]) assert str(ex.value) == "Not a PIL.ImageFont file" with pytest.raises(SyntaxError) as ex: filename = get_reference_file(Path('font').joinpath('hd44780a02_nodata.pil')) bitmap_font.load_pillow_font(filename, FONTDATA['mappings'][1]) assert str(ex.value) == "PIL.ImageFont file missing metric data" with pytest.raises(SyntaxError) as ex: filename = get_reference_file(Path('font').joinpath('hd44780a02_incomplete.pil')) bitmap_font.load_pillow_font(filename, FONTDATA['mappings'][1]) assert str(ex.value) == "PIL.ImageFont file metric data incomplete" filename = get_reference_file(Path('font').joinpath('wrong_mode.pil')) with pytest.raises(OSError) as ex: bitmap_font.load_pillow_font(filename) assert str(ex.value) == 'cannot find glyph data file'
def test_load_from_pillow_font(): """ Test the loading of a pillow font from disk by loading the font from bitmap_font and PIL.ImageFont, rendering a page of glyphs which each and testing to make sure the results are the same. """ fnt = get_reference_pillow_font('hd44780a02.pil') filename = get_reference_file(Path('font').joinpath('hd44780a02.pil')) bmf = bitmap_font.load_pillow_font(filename) img1 = make_sprite_table(fnt) img2 = make_sprite_table(bmf) assert img1 == img2
def test_mapping(): """ Test to make sure that values that have unicode mappings work correctly """ fnt = get_reference_pillow_font('hd44780a02.pil') filename = get_reference_file(Path('font').joinpath('hd44780a02.pil')) bmf = bitmap_font.load_pillow_font(filename, FONTDATA['mappings'][1]) size = bmf.getsize('\u0010') img1 = Image.new('1', size, 0) img2 = Image.new('1', (5, 8), 0) drw = ImageDraw.Draw(img1) drw.text((0, 0), '\u0010', font=fnt, fill='white') drw = ImageDraw.Draw(img2) drw.text((0, 0), '\u25b6', font=bmf, fill='white') assert img1 == img2