Skip to content

Commit 2579973

Browse files
authored
Merge pull request #8506 from radarhere/emf_records
Skip failing records when rendering WMF images
2 parents ae52f9f + e16e334 commit 2579973

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

Tests/test_file_wmf.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from PIL import Image, ImageFile, WmfImagePlugin
1010

11-
from .helper import assert_image_similar_tofile, hopper
11+
from .helper import assert_image_equal_tofile, assert_image_similar_tofile, hopper
1212

1313

1414
def test_load_raw() -> None:
@@ -44,6 +44,15 @@ def test_load_zero_inch() -> None:
4444
pass
4545

4646

47+
def test_render() -> None:
48+
with open("Tests/images/drawing.emf", "rb") as fp:
49+
data = fp.read()
50+
b = BytesIO(data[:808] + b"\x00" + data[809:])
51+
with Image.open(b) as im:
52+
if hasattr(Image.core, "drawwmf"):
53+
assert_image_equal_tofile(im, "Tests/images/drawing.emf")
54+
55+
4756
def test_register_handler(tmp_path: Path) -> None:
4857
class TestHandler(ImageFile.StubHandler):
4958
methodCalled = False

src/display.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ PyImaging_EventLoopWin32(PyObject *self, PyObject *args) {
687687

688688
#define GET32(p, o) ((DWORD *)(p + o))[0]
689689

690+
static int CALLBACK
691+
enhMetaFileProc(
692+
HDC hdc, HANDLETABLE *lpht, const ENHMETARECORD *lpmr, int nHandles, LPARAM data
693+
) {
694+
PlayEnhMetaFileRecord(hdc, lpht, lpmr, nHandles);
695+
return 1;
696+
}
697+
690698
PyObject *
691699
PyImaging_DrawWmf(PyObject *self, PyObject *args) {
692700
HBITMAP bitmap;
@@ -767,10 +775,7 @@ PyImaging_DrawWmf(PyObject *self, PyObject *args) {
767775
/* FIXME: make background transparent? configurable? */
768776
FillRect(dc, &rect, GetStockObject(WHITE_BRUSH));
769777

770-
if (!PlayEnhMetaFile(dc, meta, &rect)) {
771-
PyErr_SetString(PyExc_OSError, "cannot render metafile");
772-
goto error;
773-
}
778+
EnumEnhMetaFile(dc, meta, enhMetaFileProc, NULL, &rect);
774779

775780
/* step 4: extract bits from bitmap */
776781

0 commit comments

Comments
 (0)