gdiplus: Implement GetDC for metafiles.

This commit is contained in:
Vincent Povirk 2011-07-07 11:30:06 -05:00 committed by Alexandre Julliard
parent fd7475546b
commit 44c57121ea
4 changed files with 60 additions and 14 deletions

View File

@ -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 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 void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,

View File

@ -5311,6 +5311,8 @@ static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
{
GpStatus stat=Ok;
TRACE("(%p, %p)\n", graphics, hdc);
if(!graphics || !hdc)
@ -5319,13 +5321,16 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
if(graphics->busy)
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))
{
/* Create a fake HDC and fill it with a constant color. */
HDC temp_hdc;
HBITMAP hbitmap;
GpStatus stat;
GpRectF bounds;
BITMAPINFOHEADER bmih;
int i;
@ -5374,22 +5379,26 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
*hdc = graphics->hdc;
}
if (stat == Ok)
graphics->busy = TRUE;
return Ok;
return stat;
}
GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
{
GpStatus stat=Ok;
TRACE("(%p, %p)\n", graphics, hdc);
if(!graphics || !hdc)
if(!graphics || !hdc || !graphics->busy)
return InvalidParameter;
if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
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;
int i;
@ -5416,10 +5425,15 @@ GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
graphics->temp_hdc = NULL;
graphics->temp_hbitmap = NULL;
}
else if (hdc != graphics->hdc)
{
stat = InvalidParameter;
}
if (stat == Ok)
graphics->busy = FALSE;
return Ok;
return stat;
}
GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)

View File

@ -297,6 +297,36 @@ GpStatus METAFILE_GetGraphicsContext(GpMetafile* metafile, GpGraphics **result)
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 stat;

View File

@ -278,9 +278,9 @@ static void test_empty(void)
static const emfplus_record getdc_records[] = {
{0, EMR_HEADER},
{0, EmfPlusRecordTypeHeader},
{1, EmfPlusRecordTypeGetDC},
{1, EMR_CREATEBRUSHINDIRECT},
{1, EMR_SELECTOBJECT},
{0, EmfPlusRecordTypeGetDC},
{0, EMR_CREATEBRUSHINDIRECT},
{0, EMR_SELECTOBJECT},
{0, EMR_RECTANGLE},
{0, EMR_SELECTOBJECT},
{0, EMR_DELETEOBJECT},