mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Merge pull request #1123 from radarhere/font_variant
Added copy method font_variant() and accessible properties to truetype()
This commit is contained in:
commit
cabbc5d599
|
@ -133,6 +133,11 @@ class FreeTypeFont:
|
||||||
DeprecationWarning)
|
DeprecationWarning)
|
||||||
font = file
|
font = file
|
||||||
|
|
||||||
|
self.path = font
|
||||||
|
self.size = size
|
||||||
|
self.index = index
|
||||||
|
self.encoding = encoding
|
||||||
|
|
||||||
if isPath(font):
|
if isPath(font):
|
||||||
self.font = core.getfont(font, size, index, encoding)
|
self.font = core.getfont(font, size, index, encoding)
|
||||||
else:
|
else:
|
||||||
|
@ -162,6 +167,21 @@ class FreeTypeFont:
|
||||||
self.font.render(text, im.id, mode == "1")
|
self.font.render(text, im.id, mode == "1")
|
||||||
return im, offset
|
return im, offset
|
||||||
|
|
||||||
|
def font_variant(self, font=None, size=None, index=None, encoding=None):
|
||||||
|
"""
|
||||||
|
Create a copy of this FreeTypeFont object,
|
||||||
|
using any specified arguments to override the settings.
|
||||||
|
|
||||||
|
Parameters are identical to the parameters used to initialize this object,
|
||||||
|
minus the deprecated 'file' argument.
|
||||||
|
|
||||||
|
:return: A FreeTypeFont object.
|
||||||
|
"""
|
||||||
|
return FreeTypeFont(font = self.path if font == None else font,
|
||||||
|
size = self.size if size == None else size,
|
||||||
|
index = self.index if index == None else index,
|
||||||
|
encoding = self.encoding if encoding == None else encoding)
|
||||||
|
|
||||||
##
|
##
|
||||||
# Wrapper that creates a transposed font from any existing font
|
# Wrapper that creates a transposed font from any existing font
|
||||||
# object.
|
# object.
|
||||||
|
|
|
@ -44,6 +44,22 @@ try:
|
||||||
self.assertRegexpMatches(
|
self.assertRegexpMatches(
|
||||||
ImageFont.core.freetype2_version, "\d+\.\d+\.\d+$")
|
ImageFont.core.freetype2_version, "\d+\.\d+\.\d+$")
|
||||||
|
|
||||||
|
def test_font_properties(self):
|
||||||
|
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
|
self.assertEqual(ttf.path, FONT_PATH)
|
||||||
|
self.assertEqual(ttf.size, FONT_SIZE)
|
||||||
|
|
||||||
|
ttf_copy = ttf.font_variant()
|
||||||
|
self.assertEqual(ttf_copy.path, FONT_PATH)
|
||||||
|
self.assertEqual(ttf_copy.size, FONT_SIZE)
|
||||||
|
|
||||||
|
ttf_copy = ttf.font_variant(size=FONT_SIZE+1)
|
||||||
|
self.assertEqual(ttf_copy.size, FONT_SIZE+1)
|
||||||
|
|
||||||
|
second_font_path = "Tests/fonts/DejaVuSans.ttf"
|
||||||
|
ttf_copy = ttf.font_variant(font=second_font_path)
|
||||||
|
self.assertEqual(ttf_copy.path, second_font_path)
|
||||||
|
|
||||||
def test_font_with_name(self):
|
def test_font_with_name(self):
|
||||||
ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
ImageFont.truetype(FONT_PATH, FONT_SIZE)
|
||||||
self._render(FONT_PATH)
|
self._render(FONT_PATH)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user