From a9e4e3b4031c86b476f3b2488df130655212908c Mon Sep 17 00:00:00 2001 From: Vincent Povirk Date: Wed, 6 Apr 2016 14:36:58 -0500 Subject: [PATCH] gdiplus: Implement GdipRecordMetafileStream. Signed-off-by: Vincent Povirk Signed-off-by: Alexandre Julliard --- dlls/gdiplus/gdiplus_private.h | 1 + dlls/gdiplus/graphics.c | 7 ----- dlls/gdiplus/image.c | 4 +++ dlls/gdiplus/metafile.c | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index 0013d75e460..10092f1c034 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -343,6 +343,7 @@ struct GpMetafile{ BYTE *comment_data; DWORD comment_data_size; DWORD comment_data_length; + IStream *record_stream; /* playback */ GpGraphics *playback_graphics; diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 15c0bed434b..dac52efea3c 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -6436,13 +6436,6 @@ GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 brush, positions, flags, matrix); } -GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect, - MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile) -{ - FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile); - return NotImplemented; -} - /***************************************************************************** * GdipIsVisibleClipEmpty [GDIPLUS.@] */ diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index f803efae5ac..d1a5593f97d 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -2142,6 +2142,10 @@ static GpStatus free_image_data(GpImage *image) metafile->record_graphics->image = NULL; metafile->record_graphics->busy = TRUE; } + if (metafile->record_stream) + { + IStream_Release(metafile->record_stream); + } } else { diff --git a/dlls/gdiplus/metafile.c b/dlls/gdiplus/metafile.c index 82a7abf91e2..ee16d8e74f7 100644 --- a/dlls/gdiplus/metafile.c +++ b/dlls/gdiplus/metafile.c @@ -308,6 +308,27 @@ GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect return GdipRecordMetafile(hdc, type, pFrameRectF, frameUnit, desc, metafile); } +GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect, + MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile) +{ + GpStatus stat; + + TRACE("(%p %p %d %p %d %p %p)\n", stream, hdc, type, frameRect, frameUnit, desc, metafile); + + if (!stream) + return InvalidParameter; + + stat = GdipRecordMetafile(hdc, type, frameRect, frameUnit, desc, metafile); + + if (stat == Ok) + { + (*metafile)->record_stream = stream; + IStream_AddRef(stream); + } + + return stat; +} + GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) { GpStatus stat; @@ -487,6 +508,37 @@ GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) } } + if (stat == Ok && metafile->record_stream) + { + BYTE *buffer; + UINT buffer_size; + + buffer_size = GetEnhMetaFileBits(metafile->hemf, 0, NULL); + + buffer = heap_alloc(buffer_size); + if (buffer) + { + HRESULT hr; + + GetEnhMetaFileBits(metafile->hemf, buffer_size, buffer); + + hr = IStream_Write(metafile->record_stream, buffer, buffer_size, NULL); + + if (FAILED(hr)) + stat = hresult_to_status(hr); + + heap_free(buffer); + } + else + stat = OutOfMemory; + } + + if (metafile->record_stream) + { + IStream_Release(metafile->record_stream); + metafile->record_stream = NULL; + } + return stat; }