mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-09-26 22:16:59 +03:00
Merge dff86fc23f
into 6c0fcef5e5
This commit is contained in:
commit
d9e63c4fad
|
@ -26,6 +26,7 @@ except ImportError:
|
|||
|
||||
WIDTH = 800
|
||||
|
||||
|
||||
def puti16(fp, values):
|
||||
# write network order (big-endian) 16-bit sequence
|
||||
for v in values:
|
||||
|
@ -33,6 +34,7 @@ def puti16(fp, values):
|
|||
v += 65536
|
||||
fp.write(_binary.o16be(v))
|
||||
|
||||
|
||||
##
|
||||
# Base class for raster font file handlers.
|
||||
|
||||
|
@ -95,7 +97,6 @@ class FontFile:
|
|||
# print chr(i), dst, s
|
||||
self.metrics[i] = d, dst, s
|
||||
|
||||
|
||||
def save1(self, filename):
|
||||
"Save font in version 1 format"
|
||||
|
||||
|
@ -107,7 +108,7 @@ class FontFile:
|
|||
# font metrics
|
||||
fp = open(os.path.splitext(filename)[0] + ".pil", "wb")
|
||||
fp.write(b"PILfont\n")
|
||||
fp.write((";;;;;;%d;\n" % self.ysize).encode('ascii')) # HACK!!!
|
||||
fp.write((";;;;;;%d;\n" % self.ysize).encode('ascii')) # HACK!!!
|
||||
fp.write(b"DATA\n")
|
||||
for id in range(256):
|
||||
m = self.metrics[id]
|
||||
|
@ -117,7 +118,6 @@ class FontFile:
|
|||
puti16(fp, m[0] + m[1] + m[2])
|
||||
fp.close()
|
||||
|
||||
|
||||
def save2(self, filename):
|
||||
"Save font in version 2 format"
|
||||
|
||||
|
@ -134,7 +134,7 @@ class FontFile:
|
|||
|
||||
fp = open(os.path.splitext(filename)[0] + ".pil", "wb")
|
||||
|
||||
fp.write(b"PILfont2\n" + self.name + "\n" + "DATA\n")
|
||||
fp.write(b"PILfont2\n" + self.name.encode('ascii') + b"\n" + b"DATA\n")
|
||||
|
||||
fp.write(data)
|
||||
|
||||
|
@ -142,5 +142,4 @@ class FontFile:
|
|||
|
||||
fp.close()
|
||||
|
||||
|
||||
save = save1 # for now
|
||||
save = save1 # for now
|
||||
|
|
|
@ -3,40 +3,53 @@ from helper import unittest, PillowTestCase, tearDownModule
|
|||
from PIL import Image, FontFile, PcfFontFile
|
||||
from PIL import ImageFont, ImageDraw
|
||||
|
||||
codecs = dir(Image.core)
|
||||
CODECS = dir(Image.core)
|
||||
|
||||
fontname = "Tests/fonts/helvO18.pcf"
|
||||
FONTNAME = "Tests/fonts/helvO18.pcf"
|
||||
|
||||
message = "hello, world"
|
||||
MESSAGE = "hello, world"
|
||||
|
||||
|
||||
class TestFontPcf(PillowTestCase):
|
||||
|
||||
def setUp(self):
|
||||
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
|
||||
if "zip_encoder" not in CODECS or "zip_decoder" not in CODECS:
|
||||
self.skipTest("zlib support not available")
|
||||
|
||||
def save_font(self):
|
||||
file = open(fontname, "rb")
|
||||
def open_font(self):
|
||||
file = open(FONTNAME, "rb")
|
||||
font = PcfFontFile.PcfFontFile(file)
|
||||
self.assertIsInstance(font, FontFile.FontFile)
|
||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 192)
|
||||
return font
|
||||
|
||||
def get_tempname(self):
|
||||
tempname = self.tempfile("temp.pil")
|
||||
self.addCleanup(self.delete_tempfile, tempname[:-4]+'.pbm')
|
||||
return tempname
|
||||
|
||||
def save_font(self):
|
||||
font = self.open_font()
|
||||
tempname = self.get_tempname()
|
||||
font.save(tempname)
|
||||
return tempname
|
||||
|
||||
def save_font2(self):
|
||||
font = self.open_font()
|
||||
tempname = self.get_tempname()
|
||||
font.save2(tempname)
|
||||
|
||||
def test_sanity(self):
|
||||
self.save_font()
|
||||
self.save_font2()
|
||||
|
||||
def xtest_draw(self):
|
||||
|
||||
tempname = self.save_font()
|
||||
font = ImageFont.load(tempname)
|
||||
image = Image.new("L", font.getsize(message), "white")
|
||||
image = Image.new("L", font.getsize(MESSAGE), "white")
|
||||
draw = ImageDraw.Draw(image)
|
||||
draw.text((0, 0), message, font=font)
|
||||
draw.text((0, 0), MESSAGE, font=font)
|
||||
# assert_signature(image, "7216c60f988dea43a46bb68321e3c1b03ec62aee")
|
||||
|
||||
def _test_high_characters(self, message):
|
||||
|
|
Loading…
Reference in New Issue
Block a user