Commit 44c57121 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

gdiplus: Implement GetDC for metafiles.

parent fd747554
...@@ -52,6 +52,8 @@ extern REAL convert_unit(REAL logpixels, GpUnit unit) DECLSPEC_HIDDEN; ...@@ -52,6 +52,8 @@ extern REAL convert_unit(REAL logpixels, GpUnit unit) DECLSPEC_HIDDEN;
extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN; extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN; extern GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) DECLSPEC_HIDDEN;
extern GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc) DECLSPEC_HIDDEN;
extern GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc) DECLSPEC_HIDDEN;
extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN; extern GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) DECLSPEC_HIDDEN;
extern void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1, extern void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
......
...@@ -5311,6 +5311,8 @@ static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d; ...@@ -5311,6 +5311,8 @@ static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc) GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
{ {
GpStatus stat=Ok;
TRACE("(%p, %p)\n", graphics, hdc); TRACE("(%p, %p)\n", graphics, hdc);
if(!graphics || !hdc) if(!graphics || !hdc)
...@@ -5319,13 +5321,16 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc) ...@@ -5319,13 +5321,16 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
if(graphics->busy) if(graphics->busy)
return ObjectBusy; return ObjectBusy;
if (!graphics->hdc || if (graphics->image && graphics->image->type == ImageTypeMetafile)
{
stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc);
}
else if (!graphics->hdc ||
(graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha)) (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
{ {
/* Create a fake HDC and fill it with a constant color. */ /* Create a fake HDC and fill it with a constant color. */
HDC temp_hdc; HDC temp_hdc;
HBITMAP hbitmap; HBITMAP hbitmap;
GpStatus stat;
GpRectF bounds; GpRectF bounds;
BITMAPINFOHEADER bmih; BITMAPINFOHEADER bmih;
int i; int i;
...@@ -5374,22 +5379,26 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc) ...@@ -5374,22 +5379,26 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
*hdc = graphics->hdc; *hdc = graphics->hdc;
} }
graphics->busy = TRUE; if (stat == Ok)
graphics->busy = TRUE;
return Ok; return stat;
} }
GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc) GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
{ {
TRACE("(%p, %p)\n", graphics, hdc); GpStatus stat=Ok;
if(!graphics || !hdc) TRACE("(%p, %p)\n", graphics, hdc);
return InvalidParameter;
if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy)) if(!graphics || !hdc || !graphics->busy)
return InvalidParameter; return InvalidParameter;
if (graphics->temp_hdc == hdc) if (graphics->image && graphics->image->type == ImageTypeMetafile)
{
stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc);
}
else if (graphics->temp_hdc == hdc)
{ {
DWORD* pos; DWORD* pos;
int i; int i;
...@@ -5416,10 +5425,15 @@ GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc) ...@@ -5416,10 +5425,15 @@ GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
graphics->temp_hdc = NULL; graphics->temp_hdc = NULL;
graphics->temp_hbitmap = NULL; graphics->temp_hbitmap = NULL;
} }
else if (hdc != graphics->hdc)
{
stat = InvalidParameter;
}
graphics->busy = FALSE; if (stat == Ok)
graphics->busy = FALSE;
return Ok; return stat;
} }
GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region) GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
......
...@@ -297,6 +297,36 @@ GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result) ...@@ -297,6 +297,36 @@ GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result)
return stat; return stat;
} }
GpStatus METAFILE_GetDC(GpMetafile* metafile, HDC *hdc)
{
if (metafile->metafile_type == MetafileTypeEmfPlusOnly || metafile->metafile_type == MetafileTypeEmfPlusDual)
{
EmfPlusRecordHeader *record;
GpStatus stat;
stat = METAFILE_AllocateRecord(metafile, sizeof(EmfPlusRecordHeader), (void**)&record);
if (stat != Ok)
return stat;
record->Type = EmfPlusRecordTypeGetDC;
record->Flags = 0;
METAFILE_WriteRecords(metafile);
}
*hdc = metafile->record_dc;
return Ok;
}
GpStatus METAFILE_ReleaseDC(GpMetafile* metafile, HDC hdc)
{
if (hdc != metafile->record_dc)
return InvalidParameter;
return Ok;
}
GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile) GpStatus METAFILE_GraphicsDeleted(GpMetafile* metafile)
{ {
GpStatus stat; GpStatus stat;
......
...@@ -278,9 +278,9 @@ static void test_empty(void) ...@@ -278,9 +278,9 @@ static void test_empty(void)
static const emfplus_record getdc_records[] = { static const emfplus_record getdc_records[] = {
{0, EMR_HEADER}, {0, EMR_HEADER},
{0, EmfPlusRecordTypeHeader}, {0, EmfPlusRecordTypeHeader},
{1, EmfPlusRecordTypeGetDC}, {0, EmfPlusRecordTypeGetDC},
{1, EMR_CREATEBRUSHINDIRECT}, {0, EMR_CREATEBRUSHINDIRECT},
{1, EMR_SELECTOBJECT}, {0, EMR_SELECTOBJECT},
{0, EMR_RECTANGLE}, {0, EMR_RECTANGLE},
{0, EMR_SELECTOBJECT}, {0, EMR_SELECTOBJECT},
{0, EMR_DELETEOBJECT}, {0, EMR_DELETEOBJECT},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment