mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-10 07:14:46 +03:00
Added load_pilfont()
This commit is contained in:
parent
f790878853
commit
170ac18007
|
@ -4,42 +4,48 @@ from PIL import Image, ImageDraw, ImageFont, features
|
||||||
|
|
||||||
from .helper import assert_image_equal_tofile
|
from .helper import assert_image_equal_tofile
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(
|
funcs = [ImageFont.load_pilfont]
|
||||||
features.check_module("freetype2"),
|
if not features.check_module("freetype2"):
|
||||||
reason="PILfont superseded if FreeType is supported",
|
funcs.append(ImageFont.load_default)
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_default_font():
|
@pytest.mark.parametrize("func", funcs)
|
||||||
|
def test_default_font(func):
|
||||||
# Arrange
|
# Arrange
|
||||||
txt = 'This is a "better than nothing" default font.'
|
txt = 'This is a "better than nothing" default font.'
|
||||||
im = Image.new(mode="RGB", size=(300, 100))
|
im = Image.new(mode="RGB", size=(300, 100))
|
||||||
draw = ImageDraw.Draw(im)
|
draw = ImageDraw.Draw(im)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
default_font = ImageFont.load_default()
|
default_font = func()
|
||||||
draw.text((10, 10), txt, font=default_font)
|
draw.text((10, 10), txt, font=default_font)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert_image_equal_tofile(im, "Tests/images/default_font.png")
|
assert_image_equal_tofile(im, "Tests/images/default_font.png")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(
|
||||||
|
features.check_module("freetype2"),
|
||||||
|
reason="PILfont superseded if FreeType is supported",
|
||||||
|
)
|
||||||
def test_size_without_freetype():
|
def test_size_without_freetype():
|
||||||
with pytest.raises(ImportError):
|
with pytest.raises(ImportError):
|
||||||
ImageFont.load_default(size=14)
|
ImageFont.load_default(size=14)
|
||||||
|
|
||||||
|
|
||||||
def test_unicode():
|
@pytest.mark.parametrize("func", funcs)
|
||||||
|
def test_unicode(func):
|
||||||
# should not segfault, should return UnicodeDecodeError
|
# should not segfault, should return UnicodeDecodeError
|
||||||
# issue #2826
|
# issue #2826
|
||||||
font = ImageFont.load_default()
|
font = func()
|
||||||
with pytest.raises(UnicodeEncodeError):
|
with pytest.raises(UnicodeEncodeError):
|
||||||
font.getbbox("’")
|
font.getbbox("’")
|
||||||
|
|
||||||
|
|
||||||
def test_textbbox():
|
@pytest.mark.parametrize("func", funcs)
|
||||||
|
def test_textbbox(func):
|
||||||
im = Image.new("RGB", (200, 200))
|
im = Image.new("RGB", (200, 200))
|
||||||
d = ImageDraw.Draw(im)
|
d = ImageDraw.Draw(im)
|
||||||
default_font = ImageFont.load_default()
|
default_font = func()
|
||||||
assert d.textlength("test", font=default_font) == 24
|
assert d.textlength("test", font=default_font) == 24
|
||||||
assert d.textbbox((0, 0), "test", font=default_font) == (0, 0, 24, 11)
|
assert d.textbbox((0, 0), "test", font=default_font) == (0, 0, 24, 11)
|
||||||
|
|
|
@ -53,6 +53,7 @@ Functions
|
||||||
.. autofunction:: PIL.ImageFont.load_path
|
.. autofunction:: PIL.ImageFont.load_path
|
||||||
.. autofunction:: PIL.ImageFont.truetype
|
.. autofunction:: PIL.ImageFont.truetype
|
||||||
.. autofunction:: PIL.ImageFont.load_default
|
.. autofunction:: PIL.ImageFont.load_default
|
||||||
|
.. autofunction:: PIL.ImageFont.load_pilfont
|
||||||
|
|
||||||
Methods
|
Methods
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -1107,12 +1107,21 @@ AAAAAAQAAAADa3tfFAAAAANAan9kAAAAA4QodoQ==
|
||||||
layout_engine=Layout.BASIC,
|
layout_engine=Layout.BASIC,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
f = ImageFont()
|
f = load_pilfont()
|
||||||
f._load_pilfont_data(
|
return f
|
||||||
# courB08
|
|
||||||
BytesIO(
|
|
||||||
base64.b64decode(
|
def load_pilfont():
|
||||||
b"""
|
"""Load a "better than nothing" font.
|
||||||
|
|
||||||
|
:return: A font object.
|
||||||
|
"""
|
||||||
|
f = ImageFont()
|
||||||
|
f._load_pilfont_data(
|
||||||
|
# courB08
|
||||||
|
BytesIO(
|
||||||
|
base64.b64decode(
|
||||||
|
b"""
|
||||||
UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
||||||
|
@ -1205,12 +1214,12 @@ pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
|
||||||
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
|
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
|
||||||
+QAGAAIAzgAKANUAEw==
|
+QAGAAIAzgAKANUAEw==
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Image.open(
|
Image.open(
|
||||||
BytesIO(
|
BytesIO(
|
||||||
base64.b64decode(
|
base64.b64decode(
|
||||||
b"""
|
b"""
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
|
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
|
||||||
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
|
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
|
||||||
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
|
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
|
||||||
|
@ -1235,8 +1244,8 @@ AAD//2Ji2FrkY3iYpYC5qDeGgeEMAwPDvwQBBoYvcTwOVLMEAAAA//9isDBgkP///0EOg9z35v//
|
||||||
Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
|
Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
|
||||||
w7IkEbzhVQAAAABJRU5ErkJggg==
|
w7IkEbzhVQAAAABJRU5ErkJggg==
|
||||||
"""
|
"""
|
||||||
)
|
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
)
|
),
|
||||||
|
)
|
||||||
return f
|
return f
|
||||||
|
|
Loading…
Reference in New Issue
Block a user