gdiplus: Add a helper to check for metafile graphics context.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Esme Povirk <esme@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2021-03-18 15:18:02 +03:00 committed by Alexandre Julliard
parent 81b7555da8
commit b733e39ae5
2 changed files with 44 additions and 35 deletions

View File

@ -114,6 +114,11 @@ static COLORREF get_gdi_brush_color(const GpBrush *brush)
return ARGB2COLORREF(argb);
}
static BOOL is_metafile_graphics(const GpGraphics *graphics)
{
return graphics->image && graphics->image_type == ImageTypeMetafile;
}
static ARGB blend_colors(ARGB start, ARGB end, REAL position);
static void init_hatch_palette(ARGB *hatch_palette, ARGB fore_color, ARGB back_color)
@ -556,7 +561,7 @@ static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst
return stat;
}
else if (graphics->image && graphics->image->type == ImageTypeMetafile)
else if (is_metafile_graphics(graphics))
{
ERR("This should not be used for metafiles; fix caller\n");
return NotImplemented;
@ -2241,7 +2246,7 @@ static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
GpRegion* tmp;
/* Ignore graphics image bounds for metafiles */
if (graphics->image && graphics->image_type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
return GdipCombineRegionRegion(rgn, graphics->clip, CombineModeReplace);
if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
@ -2550,7 +2555,7 @@ GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
if(!graphics) return InvalidParameter;
if(graphics->busy) return ObjectBusy;
if (graphics->image && graphics->image_type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
stat = METAFILE_GraphicsDeleted((GpMetafile*)graphics->image);
if (stat != Ok)
@ -2916,7 +2921,7 @@ GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
rect.X = x;
rect.Y = y;
@ -3069,7 +3074,7 @@ GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image
TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
debugstr_pointf(&points[2]));
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
return METAFILE_DrawImagePointsRect((GpMetafile*)graphics->image,
image, points, count, srcx, srcy, srcwidth, srcheight,
@ -4035,7 +4040,7 @@ GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
if (path->pathdata.Count == 0)
return Ok;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
retval = METAFILE_DrawPath((GpMetafile*)graphics->image, pen, path);
else if (!graphics->hdc || graphics->alpha_hdc || !brush_can_fill_path(pen->brush, FALSE))
retval = SOFTWARE_GdipDrawPath(graphics, pen, path);
@ -4258,7 +4263,7 @@ GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
GpRectF rect;
@ -4371,7 +4376,7 @@ GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *p
if (!path->pathdata.Count)
return Ok;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
return METAFILE_FillPath((GpMetafile*)graphics->image, brush, path);
if (!graphics->image && !graphics->alpha_hdc)
@ -4543,7 +4548,7 @@ GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDI
if(!graphics || !brush || !rects || count <= 0)
return InvalidParameter;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
status = METAFILE_FillRectangles((GpMetafile*)graphics->image, brush, rects, count);
/* FIXME: Add gdi32 drawing. */
@ -4736,7 +4741,7 @@ GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
stat = METAFILE_FillRegion((GpMetafile*)graphics->image, brush, region);
else
{
@ -5076,7 +5081,7 @@ GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
return METAFILE_GraphicsClear((GpMetafile*)graphics->image, color);
if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
@ -5854,7 +5859,8 @@ GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics))
{
stat = METAFILE_ResetWorldTransform((GpMetafile*)graphics->image);
if (stat != Ok)
@ -5877,7 +5883,8 @@ GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics))
{
stat = METAFILE_RotateWorldTransform((GpMetafile*)graphics->image, angle, order);
if (stat != Ok)
@ -5903,7 +5910,7 @@ static GpStatus begin_container(GpGraphics *graphics,
list_add_head(&graphics->containers, &container->entry);
*state = graphics->contid = container->contid;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
if (type == BEGIN_CONTAINER)
METAFILE_BeginContainerNoParams((GpMetafile*)graphics->image, container->contid);
else
@ -5963,9 +5970,8 @@ GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *
GdipMultiplyMatrix(&graphics->worldtrans, &transform, MatrixOrderPrepend);
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics))
METAFILE_BeginContainer((GpMetafile*)graphics->image, dstrect, srcrect, unit, container->contid);
}
return Ok;
}
@ -6031,7 +6037,7 @@ static GpStatus end_container(GpGraphics *graphics, GraphicsContainerType type,
list_remove(&container->entry);
delete_container(container);
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
if (type == BEGIN_CONTAINER)
METAFILE_EndContainer((GpMetafile*)graphics->image, state);
else
@ -6066,7 +6072,7 @@ GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
stat = METAFILE_ScaleWorldTransform((GpMetafile*)graphics->image, sx, sy, order);
if (stat != Ok)
@ -6101,7 +6107,7 @@ GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
if(graphics->compmode == mode)
return Ok;
if(graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
GpStatus stat;
@ -6130,7 +6136,7 @@ GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
if(graphics->compqual == quality)
return Ok;
if(graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
GpStatus stat;
@ -6165,7 +6171,7 @@ GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
if (mode == graphics->interpolation)
return Ok;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
GpStatus stat;
@ -6192,7 +6198,7 @@ GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
stat = METAFILE_SetPageTransform((GpMetafile*)graphics->image, graphics->unit, scale);
if (stat != Ok)
@ -6219,7 +6225,7 @@ GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
if(unit == UnitWorld)
return InvalidParameter;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
stat = METAFILE_SetPageTransform((GpMetafile*)graphics->image, unit, graphics->scale);
if (stat != Ok)
@ -6245,7 +6251,7 @@ GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
if(graphics->pixeloffset == mode)
return Ok;
if(graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
GpStatus stat;
@ -6299,7 +6305,8 @@ GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mod
if(graphics->smoothing == mode)
return Ok;
if(graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics))
{
GpStatus stat;
BOOL antialias = (mode != SmoothingModeDefault &&
mode != SmoothingModeNone && mode != SmoothingModeHighSpeed);
@ -6308,7 +6315,7 @@ GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mod
EmfPlusRecordTypeSetAntiAliasMode, (mode << 1) + antialias);
if(stat != Ok)
return stat;
}
}
graphics->smoothing = mode;
@ -6341,7 +6348,7 @@ GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
if(graphics->texthint == hint)
return Ok;
if(graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
GpStatus stat;
stat = METAFILE_AddSimpleProperty((GpMetafile*)graphics->image,
@ -6371,7 +6378,7 @@ GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix
matrix->matrix[0], matrix->matrix[1], matrix->matrix[2],
matrix->matrix[3], matrix->matrix[4], matrix->matrix[5]);
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
stat = METAFILE_SetWorldTransform((GpMetafile*)graphics->image, matrix);
if (stat != Ok)
@ -6396,7 +6403,7 @@ GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics)) {
stat = METAFILE_TranslateWorldTransform((GpMetafile*)graphics->image, dx, dy, order);
if (stat != Ok)
@ -6486,7 +6493,7 @@ GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
status = METAFILE_SetClipRect((GpMetafile*)graphics->image, x, y, width, height, mode);
if (status != Ok)
@ -6544,7 +6551,7 @@ GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
status = METAFILE_SetClipRegion((GpMetafile*)graphics->image, region, mode);
if (status != Ok)
@ -6661,7 +6668,8 @@ GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST G
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile) {
if (is_metafile_graphics(graphics))
{
ret = METAFILE_MultiplyWorldTransform((GpMetafile*)graphics->image, matrix, order);
if (ret != Ok)
@ -6692,7 +6700,7 @@ GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
if(graphics->busy)
return ObjectBusy;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc);
}
@ -6773,7 +6781,7 @@ GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
if(!graphics || !hdc || !graphics->busy)
return InvalidParameter;
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
{
stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc);
}
@ -7489,7 +7497,7 @@ static GpStatus draw_driver_string(GpGraphics *graphics, GDIPCONST UINT16 *text,
if (length == -1)
length = lstrlenW(text);
if (graphics->image && graphics->image->type == ImageTypeMetafile)
if (is_metafile_graphics(graphics))
return METAFILE_DrawDriverString((GpMetafile*)graphics->image, text, length, font,
format, brush, positions, flags, matrix);

View File

@ -2239,6 +2239,7 @@ GpStatus WINGDIPAPI GdipGetImageGraphicsContext(GpImage *image,
if (stat == Ok)
{
(*graphics)->image = image;
(*graphics)->image_type = image->type;
(*graphics)->xres = image->xres;
(*graphics)->yres = image->yres;
}