2019-07-06 23:40:53 +03:00
|
|
|
from PIL import Image, WmfImagePlugin
|
2017-09-01 13:36:51 +03:00
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2016-11-27 19:03:51 +03:00
|
|
|
|
2017-04-20 14:14:23 +03:00
|
|
|
|
2016-11-27 19:03:51 +03:00
|
|
|
class TestFileWmf(PillowTestCase):
|
|
|
|
def test_load_raw(self):
|
|
|
|
|
|
|
|
# Test basic EMF open and rendering
|
2019-06-13 18:54:11 +03:00
|
|
|
im = Image.open("Tests/images/drawing.emf")
|
2016-11-27 19:03:51 +03:00
|
|
|
if hasattr(Image.core, "drawwmf"):
|
|
|
|
# Currently, support for WMF/EMF is Windows-only
|
|
|
|
im.load()
|
|
|
|
# Compare to reference rendering
|
2019-06-13 18:54:11 +03:00
|
|
|
imref = Image.open("Tests/images/drawing_emf_ref.png")
|
2016-11-27 19:03:51 +03:00
|
|
|
imref.load()
|
|
|
|
self.assert_image_similar(im, imref, 0)
|
|
|
|
|
|
|
|
# Test basic WMF open and rendering
|
2019-06-13 18:54:11 +03:00
|
|
|
im = Image.open("Tests/images/drawing.wmf")
|
2016-11-27 19:03:51 +03:00
|
|
|
if hasattr(Image.core, "drawwmf"):
|
|
|
|
# Currently, support for WMF/EMF is Windows-only
|
|
|
|
im.load()
|
|
|
|
# Compare to reference rendering
|
2019-06-13 18:54:11 +03:00
|
|
|
imref = Image.open("Tests/images/drawing_wmf_ref.png")
|
2016-11-27 19:03:51 +03:00
|
|
|
imref.load()
|
2016-12-31 20:38:35 +03:00
|
|
|
self.assert_image_similar(im, imref, 2.0)
|
2016-11-27 19:03:51 +03:00
|
|
|
|
2017-09-01 13:36:51 +03:00
|
|
|
def test_register_handler(self):
|
|
|
|
class TestHandler:
|
|
|
|
methodCalled = False
|
|
|
|
|
|
|
|
def save(self, im, fp, filename):
|
|
|
|
self.methodCalled = True
|
2019-06-13 18:54:11 +03:00
|
|
|
|
2017-09-01 13:36:51 +03:00
|
|
|
handler = TestHandler()
|
|
|
|
WmfImagePlugin.register_handler(handler)
|
|
|
|
|
|
|
|
im = hopper()
|
|
|
|
tmpfile = self.tempfile("temp.wmf")
|
|
|
|
im.save(tmpfile)
|
|
|
|
self.assertTrue(handler.methodCalled)
|
|
|
|
|
|
|
|
# Restore the state before this test
|
|
|
|
WmfImagePlugin.register_handler(None)
|
|
|
|
|
2019-03-30 07:03:57 +03:00
|
|
|
def test_load_dpi_rounding(self):
|
|
|
|
# Round up
|
2019-06-13 18:54:11 +03:00
|
|
|
im = Image.open("Tests/images/drawing.emf")
|
2019-03-30 07:03:57 +03:00
|
|
|
self.assertEqual(im.info["dpi"], 1424)
|
|
|
|
|
|
|
|
# Round down
|
2019-06-13 18:54:11 +03:00
|
|
|
im = Image.open("Tests/images/drawing_roundDown.emf")
|
2019-03-30 07:03:57 +03:00
|
|
|
self.assertEqual(im.info["dpi"], 1426)
|
|
|
|
|
2017-03-01 12:20:18 +03:00
|
|
|
def test_save(self):
|
|
|
|
im = hopper()
|
|
|
|
|
|
|
|
for ext in [".wmf", ".emf"]:
|
2019-06-13 18:54:11 +03:00
|
|
|
tmpfile = self.tempfile("temp" + ext)
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(IOError, im.save, tmpfile)
|