mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 09:56:17 +03:00
If font is file-like object, do not re-read from object to get variant
This commit is contained in:
parent
de1ba373e1
commit
a40c7a6bea
|
@ -65,9 +65,12 @@ class TestImageFont:
|
||||||
return font_bytes
|
return font_bytes
|
||||||
|
|
||||||
def test_font_with_filelike(self):
|
def test_font_with_filelike(self):
|
||||||
ImageFont.truetype(
|
ttf = ImageFont.truetype(
|
||||||
self._font_as_bytes(), FONT_SIZE, layout_engine=self.LAYOUT_ENGINE
|
self._font_as_bytes(), FONT_SIZE, layout_engine=self.LAYOUT_ENGINE
|
||||||
)
|
)
|
||||||
|
ttf_copy = ttf.font_variant()
|
||||||
|
assert ttf_copy.font_bytes == ttf.font_bytes
|
||||||
|
|
||||||
self._render(self._font_as_bytes())
|
self._render(self._font_as_bytes())
|
||||||
# Usage note: making two fonts from the same buffer fails.
|
# Usage note: making two fonts from the same buffer fails.
|
||||||
# shared_bytes = self._font_as_bytes()
|
# shared_bytes = self._font_as_bytes()
|
||||||
|
|
|
@ -711,8 +711,13 @@ class FreeTypeFont:
|
||||||
|
|
||||||
:return: A FreeTypeFont object.
|
:return: A FreeTypeFont object.
|
||||||
"""
|
"""
|
||||||
|
if font is None:
|
||||||
|
try:
|
||||||
|
font = BytesIO(self.font_bytes)
|
||||||
|
except AttributeError:
|
||||||
|
font = self.path
|
||||||
return FreeTypeFont(
|
return FreeTypeFont(
|
||||||
font=self.path if font is None else font,
|
font=font,
|
||||||
size=self.size if size is None else size,
|
size=self.size if size is None else size,
|
||||||
index=self.index if index is None else index,
|
index=self.index if index is None else index,
|
||||||
encoding=self.encoding if encoding is None else encoding,
|
encoding=self.encoding if encoding is None else encoding,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user