Skip to content

Commit ce40591

Browse files
committed
Skip failing records when rendering
1 parent 81a3bf5 commit ce40591

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

Tests/test_file_wmf.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
from __future__ import annotations
22

3+
from io import BytesIO
34
from pathlib import Path
45
from typing import IO
56

67
import pytest
78

89
from PIL import Image, ImageFile, WmfImagePlugin
910

10-
from .helper import assert_image_similar_tofile, hopper
11+
from .helper import assert_image_equal_tofile, assert_image_similar_tofile, hopper
1112

1213

1314
def test_load_raw() -> None:
@@ -34,6 +35,15 @@ def test_load() -> None:
3435
assert im.load()[0, 0] == (255, 255, 255)
3536

3637

38+
def test_render() -> None:
39+
with open("Tests/images/drawing.emf", "rb") as fp:
40+
data = fp.read()
41+
b = BytesIO(data[:808] + b"\x00" + data[809:])
42+
with Image.open(b) as im:
43+
if hasattr(Image.core, "drawwmf"):
44+
assert_image_equal_tofile(im, "Tests/images/drawing.emf")
45+
46+
3747
def test_register_handler(tmp_path: Path) -> None:
3848
class TestHandler(ImageFile.StubHandler):
3949
methodCalled = False

src/display.c

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

717717
#define GET32(p, o) ((DWORD *)(p + o))[0]
718718

719+
BOOL
720+
enhMetaFileProc(
721+
HDC hdc, HANDLETABLE FAR *lpht, CONST ENHMETARECORD *lpmr, int nHandles, LPARAM data
722+
) {
723+
PlayEnhMetaFileRecord(hdc, lpht, lpmr, nHandles);
724+
return TRUE;
725+
}
726+
719727
PyObject *
720728
PyImaging_DrawWmf(PyObject *self, PyObject *args) {
721729
HBITMAP bitmap;
@@ -796,10 +804,7 @@ PyImaging_DrawWmf(PyObject *self, PyObject *args) {
796804
/* FIXME: make background transparent? configurable? */
797805
FillRect(dc, &rect, GetStockObject(WHITE_BRUSH));
798806

799-
if (!PlayEnhMetaFile(dc, meta, &rect)) {
800-
PyErr_SetString(PyExc_OSError, "cannot render metafile");
801-
goto error;
802-
}
807+
EnumEnhMetaFile(dc, meta, enhMetaFileProc, NULL, &rect);
803808

804809
/* step 4: extract bits from bitmap */
805810

0 commit comments

Comments
 (0)