2008-04-09 22:09:34 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Google (Lei Zhang)
|
2015-06-13 09:53:58 +02:00
|
|
|
* Copyright (C) 2013 Dmitry Timoshkov
|
2008-04-09 22:09:34 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "gdiplus_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
|
|
|
|
|
2008-05-15 14:47:47 +02:00
|
|
|
/**********************************************************
|
|
|
|
*
|
2008-07-09 13:31:09 +02:00
|
|
|
* Data returned by GdipGetRegionData looks something like this:
|
2008-05-15 14:47:47 +02:00
|
|
|
*
|
|
|
|
* struct region_data_header
|
|
|
|
* {
|
|
|
|
* DWORD size; size in bytes of the data - 8.
|
|
|
|
* DWORD magic1; probably a checksum.
|
|
|
|
* DWORD magic2; always seems to be 0xdbc01001 - version?
|
|
|
|
* DWORD num_ops; number of combining ops * 2
|
|
|
|
* };
|
|
|
|
*
|
2008-07-09 13:31:09 +02:00
|
|
|
* Then follows a sequence of combining ops and region elements.
|
|
|
|
*
|
|
|
|
* A region element is either a RECTF or some path data.
|
2008-05-15 14:47:47 +02:00
|
|
|
*
|
|
|
|
* Combining ops are just stored as their CombineMode value.
|
|
|
|
*
|
|
|
|
* Each RECTF is preceded by the DWORD 0x10000000. An empty rect is
|
|
|
|
* stored as 0x10000002 (with no following RECTF) and an infinite rect
|
|
|
|
* is stored as 0x10000003 (again with no following RECTF).
|
|
|
|
*
|
2008-07-09 13:31:09 +02:00
|
|
|
* Path data is preceded by the DWORD 0x10000001. Then follows a
|
|
|
|
* DWORD size and then size bytes of data.
|
|
|
|
*
|
|
|
|
* The combining ops are stored in the reverse order to the region
|
|
|
|
* elements and in the reverse order to which the region was
|
|
|
|
* constructed.
|
2008-05-15 14:47:47 +02:00
|
|
|
*
|
2008-07-09 13:31:09 +02:00
|
|
|
* When two or more complex regions (ie those with more than one
|
|
|
|
* element) are combined, the combining op for the two regions comes
|
|
|
|
* first, then the combining ops for the region elements in region 1,
|
|
|
|
* followed by the region elements for region 1, then follows the
|
|
|
|
* combining ops for region 2 and finally region 2's region elements.
|
|
|
|
* Presumably you're supposed to use the 0x1000000x header to find the
|
|
|
|
* end of the op list (the count of the elements in each region is not
|
|
|
|
* stored).
|
2008-05-15 14:47:47 +02:00
|
|
|
*
|
2008-07-09 13:31:09 +02:00
|
|
|
* When a simple region (1 element) is combined, it's treated as if a
|
|
|
|
* single rect/path is being combined.
|
2008-05-15 14:47:47 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
#define FLAGS_NOFLAGS 0x0
|
|
|
|
#define FLAGS_INTPATH 0x4000
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
struct memory_buffer
|
|
|
|
{
|
|
|
|
const BYTE *buffer;
|
|
|
|
INT size, pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct region_header
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
DWORD checksum;
|
|
|
|
DWORD magic;
|
|
|
|
DWORD num_children;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct path_header
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
DWORD magic;
|
|
|
|
DWORD count;
|
|
|
|
DWORD flags;
|
|
|
|
};
|
|
|
|
|
2008-07-25 01:01:21 +02:00
|
|
|
/* Header size as far as header->size is concerned. This doesn't include
|
|
|
|
* header->size or header->checksum
|
|
|
|
*/
|
|
|
|
static const INT sizeheader_size = sizeof(DWORD) * 2;
|
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
typedef struct packed_point
|
|
|
|
{
|
|
|
|
short X;
|
|
|
|
short Y;
|
|
|
|
} packed_point;
|
|
|
|
|
2013-11-12 10:16:15 +01:00
|
|
|
/* Test to see if the path could be stored as an array of shorts */
|
|
|
|
static BOOL is_integer_path(const GpPath *path)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!path->pathdata.Count) return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < path->pathdata.Count; i++)
|
|
|
|
{
|
2013-11-13 06:00:30 +01:00
|
|
|
short x, y;
|
|
|
|
x = gdip_round(path->pathdata.Points[i].X);
|
|
|
|
y = gdip_round(path->pathdata.Points[i].Y);
|
|
|
|
if (path->pathdata.Points[i].X != (REAL)x || path->pathdata.Points[i].Y != (REAL)y)
|
2013-11-12 10:16:15 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
/* Everything is measured in DWORDS; round up if there's a remainder */
|
|
|
|
static inline INT get_pathtypes_size(const GpPath* path)
|
|
|
|
{
|
|
|
|
INT needed = path->pathdata.Count / sizeof(DWORD);
|
|
|
|
|
|
|
|
if (path->pathdata.Count % sizeof(DWORD) > 0)
|
|
|
|
needed++;
|
|
|
|
|
|
|
|
return needed * sizeof(DWORD);
|
|
|
|
}
|
|
|
|
|
2008-07-25 01:01:21 +02:00
|
|
|
static inline INT get_element_size(const region_element* element)
|
|
|
|
{
|
|
|
|
INT needed = sizeof(DWORD); /* DWORD for the type */
|
|
|
|
switch(element->type)
|
|
|
|
{
|
|
|
|
case RegionDataRect:
|
|
|
|
return needed + sizeof(GpRect);
|
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:15 +01:00
|
|
|
{
|
2013-11-12 10:16:28 +01:00
|
|
|
const GpPath *path = element->elementdata.path;
|
2013-11-12 10:16:15 +01:00
|
|
|
DWORD flags = is_integer_path(path) ? FLAGS_INTPATH : FLAGS_NOFLAGS;
|
|
|
|
/* 3 for headers, once again size doesn't count itself */
|
|
|
|
needed += sizeof(DWORD) * 3;
|
|
|
|
if (flags & FLAGS_INTPATH)
|
|
|
|
needed += 2 * sizeof(SHORT) * path->pathdata.Count;
|
|
|
|
else
|
|
|
|
needed += 2 * sizeof(FLOAT) * path->pathdata.Count;
|
|
|
|
|
|
|
|
needed += get_pathtypes_size(path);
|
|
|
|
needed += sizeof(DWORD); /* Extra DWORD for pathheader.size */
|
|
|
|
return needed;
|
|
|
|
}
|
2008-07-25 01:01:21 +02:00
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
return needed;
|
|
|
|
default:
|
|
|
|
needed += get_element_size(element->elementdata.combine.left);
|
|
|
|
needed += get_element_size(element->elementdata.combine.right);
|
|
|
|
return needed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Does not check parameters, caller must do that */
|
|
|
|
static inline GpStatus init_region(GpRegion* region, const RegionType type)
|
|
|
|
{
|
2013-11-12 10:16:28 +01:00
|
|
|
region->node.type = type;
|
|
|
|
region->num_children = 0;
|
2008-07-25 01:01:21 +02:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-08-04 19:56:45 +02:00
|
|
|
static inline GpStatus clone_element(const region_element* element,
|
|
|
|
region_element** element2)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
2008-08-27 00:03:23 +02:00
|
|
|
/* root node is allocated with GpRegion */
|
|
|
|
if(!*element2){
|
2015-10-05 00:22:34 +02:00
|
|
|
*element2 = heap_alloc_zero(sizeof(region_element));
|
2008-08-27 00:03:23 +02:00
|
|
|
if (!*element2)
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
2008-08-04 19:56:45 +02:00
|
|
|
|
|
|
|
(*element2)->type = element->type;
|
|
|
|
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case RegionDataRect:
|
|
|
|
(*element2)->elementdata.rect = element->elementdata.rect;
|
2012-05-24 06:49:02 +02:00
|
|
|
return Ok;
|
2008-08-04 19:56:45 +02:00
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
2012-05-24 06:49:02 +02:00
|
|
|
return Ok;
|
2008-08-04 19:56:45 +02:00
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:28 +01:00
|
|
|
stat = GdipClonePath(element->elementdata.path, &(*element2)->elementdata.path);
|
2012-05-24 06:49:02 +02:00
|
|
|
if (stat == Ok) return Ok;
|
2008-08-04 19:56:45 +02:00
|
|
|
break;
|
|
|
|
default:
|
2008-08-27 00:03:23 +02:00
|
|
|
(*element2)->elementdata.combine.left = NULL;
|
|
|
|
(*element2)->elementdata.combine.right = NULL;
|
|
|
|
|
2008-08-04 19:56:45 +02:00
|
|
|
stat = clone_element(element->elementdata.combine.left,
|
|
|
|
&(*element2)->elementdata.combine.left);
|
2012-05-24 06:49:02 +02:00
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = clone_element(element->elementdata.combine.right,
|
|
|
|
&(*element2)->elementdata.combine.right);
|
|
|
|
if (stat == Ok) return Ok;
|
|
|
|
}
|
2008-08-04 19:56:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_element(*element2);
|
|
|
|
*element2 = NULL;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-08-04 19:56:49 +02:00
|
|
|
/* Common code for CombineRegion*
|
|
|
|
* All the caller has to do is get its format into an element
|
|
|
|
*/
|
|
|
|
static inline void fuse_region(GpRegion* region, region_element* left,
|
|
|
|
region_element* right, const CombineMode mode)
|
|
|
|
{
|
|
|
|
region->node.type = mode;
|
|
|
|
region->node.elementdata.combine.left = left;
|
|
|
|
region->node.elementdata.combine.right = right;
|
2013-11-12 10:16:28 +01:00
|
|
|
region->num_children += 2;
|
2008-08-04 19:56:49 +02:00
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCloneRegion [GDIPLUS.@]
|
2008-08-04 19:56:45 +02:00
|
|
|
*
|
|
|
|
* Creates a deep copy of the region
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* region [I] source region
|
|
|
|
* clone [O] resulting clone
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter or OutOfMemory
|
2008-07-26 19:20:33 +02:00
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCloneRegion(GpRegion *region, GpRegion **clone)
|
|
|
|
{
|
2008-08-04 19:56:45 +02:00
|
|
|
region_element *element;
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2008-08-04 19:56:45 +02:00
|
|
|
TRACE("%p %p\n", region, clone);
|
|
|
|
|
|
|
|
if (!(region && clone))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*clone = heap_alloc_zero(sizeof(GpRegion));
|
2008-08-04 19:56:45 +02:00
|
|
|
if (!*clone)
|
|
|
|
return OutOfMemory;
|
|
|
|
element = &(*clone)->node;
|
|
|
|
|
2013-11-12 10:16:28 +01:00
|
|
|
(*clone)->num_children = region->num_children;
|
2008-08-04 19:56:45 +02:00
|
|
|
return clone_element(®ion->node, &element);
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCombineRegionPath [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCombineRegionPath(GpRegion *region, GpPath *path, CombineMode mode)
|
|
|
|
{
|
2008-08-04 19:56:59 +02:00
|
|
|
GpRegion *path_region;
|
|
|
|
region_element *left, *right = NULL;
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
TRACE("%p %p %d\n", region, path, mode);
|
|
|
|
|
|
|
|
if (!(region && path))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipCreateRegionPath(path, &path_region);
|
|
|
|
if (stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
2008-08-27 21:31:08 +02:00
|
|
|
/* simply replace region data */
|
|
|
|
if(mode == CombineModeReplace){
|
|
|
|
delete_element(®ion->node);
|
|
|
|
memcpy(region, path_region, sizeof(GpRegion));
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(path_region);
|
2008-08-27 21:31:08 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
left = heap_alloc_zero(sizeof(region_element));
|
2012-05-24 06:48:30 +02:00
|
|
|
if (left)
|
|
|
|
{
|
|
|
|
*left = region->node;
|
|
|
|
stat = clone_element(&path_region->node, &right);
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
fuse_region(region, left, right, mode);
|
|
|
|
GdipDeleteRegion(path_region);
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
2008-08-04 19:56:59 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(left);
|
2008-08-04 19:56:59 +02:00
|
|
|
GdipDeleteRegion(path_region);
|
|
|
|
return stat;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCombineRegionRect [GDIPLUS.@]
|
|
|
|
*/
|
2008-08-04 19:56:49 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCombineRegionRect(GpRegion *region,
|
|
|
|
GDIPCONST GpRectF *rect, CombineMode mode)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-04 19:56:49 +02:00
|
|
|
GpRegion *rect_region;
|
|
|
|
region_element *left, *right = NULL;
|
|
|
|
GpStatus stat;
|
|
|
|
|
2013-03-11 09:31:52 +01:00
|
|
|
TRACE("%p %s %d\n", region, debugstr_rectf(rect), mode);
|
2008-08-04 19:56:49 +02:00
|
|
|
|
|
|
|
if (!(region && rect))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipCreateRegionRect(rect, &rect_region);
|
|
|
|
if (stat != Ok)
|
|
|
|
return stat;
|
|
|
|
|
2008-08-27 21:31:08 +02:00
|
|
|
/* simply replace region data */
|
|
|
|
if(mode == CombineModeReplace){
|
|
|
|
delete_element(®ion->node);
|
|
|
|
memcpy(region, rect_region, sizeof(GpRegion));
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(rect_region);
|
2008-08-27 21:31:08 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
left = heap_alloc_zero(sizeof(region_element));
|
2012-05-24 06:48:30 +02:00
|
|
|
if (left)
|
|
|
|
{
|
|
|
|
memcpy(left, ®ion->node, sizeof(region_element));
|
|
|
|
stat = clone_element(&rect_region->node, &right);
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
fuse_region(region, left, right, mode);
|
|
|
|
GdipDeleteRegion(rect_region);
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
2008-08-04 19:56:49 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(left);
|
2008-08-04 19:56:49 +02:00
|
|
|
GdipDeleteRegion(rect_region);
|
|
|
|
return stat;
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCombineRegionRectI [GDIPLUS.@]
|
|
|
|
*/
|
2008-08-04 19:56:53 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCombineRegionRectI(GpRegion *region,
|
|
|
|
GDIPCONST GpRect *rect, CombineMode mode)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-04 19:56:53 +02:00
|
|
|
GpRectF rectf;
|
|
|
|
|
|
|
|
TRACE("%p %p %d\n", region, rect, mode);
|
|
|
|
|
|
|
|
if (!rect)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
rectf.X = (REAL)rect->X;
|
|
|
|
rectf.Y = (REAL)rect->Y;
|
|
|
|
rectf.Height = (REAL)rect->Height;
|
|
|
|
rectf.Width = (REAL)rect->Width;
|
|
|
|
|
|
|
|
return GdipCombineRegionRect(region, &rectf, mode);
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2009-02-17 10:29:47 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCombineRegionRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-08-04 19:56:56 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCombineRegionRegion(GpRegion *region1,
|
|
|
|
GpRegion *region2, CombineMode mode)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-27 00:03:23 +02:00
|
|
|
region_element *left, *right = NULL;
|
2008-08-04 19:56:56 +02:00
|
|
|
GpStatus stat;
|
2008-08-27 21:31:08 +02:00
|
|
|
GpRegion *reg2copy;
|
2008-08-04 19:56:56 +02:00
|
|
|
|
|
|
|
TRACE("%p %p %d\n", region1, region2, mode);
|
|
|
|
|
|
|
|
if(!(region1 && region2))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-08-27 21:31:08 +02:00
|
|
|
/* simply replace region data */
|
|
|
|
if(mode == CombineModeReplace){
|
|
|
|
stat = GdipCloneRegion(region2, ®2copy);
|
|
|
|
if(stat != Ok) return stat;
|
|
|
|
|
|
|
|
delete_element(®ion1->node);
|
|
|
|
memcpy(region1, reg2copy, sizeof(GpRegion));
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(reg2copy);
|
2008-08-27 21:31:08 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
left = heap_alloc_zero(sizeof(region_element));
|
2008-08-04 19:56:56 +02:00
|
|
|
if (!left)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
|
|
|
*left = region1->node;
|
|
|
|
stat = clone_element(®ion2->node, &right);
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(left);
|
2008-08-04 19:56:56 +02:00
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
fuse_region(region1, left, right, mode);
|
2013-11-12 10:16:28 +01:00
|
|
|
region1->num_children += region2->num_children;
|
2008-08-04 19:56:56 +02:00
|
|
|
|
|
|
|
return Ok;
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-05-12 17:45:36 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateRegion(GpRegion **region)
|
|
|
|
{
|
2008-08-27 21:30:51 +02:00
|
|
|
TRACE("%p\n", region);
|
|
|
|
|
2008-07-25 01:01:21 +02:00
|
|
|
if(!region)
|
|
|
|
return InvalidParameter;
|
2008-05-12 17:45:36 +02:00
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*region = heap_alloc_zero(sizeof(GpRegion));
|
2008-07-25 01:01:21 +02:00
|
|
|
if(!*region)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
2012-05-21 10:53:13 +02:00
|
|
|
TRACE("=> %p\n", *region);
|
|
|
|
|
2008-07-25 01:01:21 +02:00
|
|
|
return init_region(*region, RegionDataInfiniteRect);
|
2008-05-12 17:45:36 +02:00
|
|
|
}
|
|
|
|
|
2008-08-04 19:56:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateRegionPath [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Creates a GpRegion from a GpPath
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* path [I] path to base the region on
|
|
|
|
* region [O] pointer to the newly allocated region
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
|
|
|
* FAILURE: InvalidParameter
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* If a path has no floating point points, its points will be stored as shorts
|
|
|
|
* (INTPATH)
|
|
|
|
*
|
|
|
|
* If a path is empty, it is considered to be an INTPATH
|
|
|
|
*/
|
2008-05-12 17:45:36 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateRegionPath(GpPath *path, GpRegion **region)
|
|
|
|
{
|
2008-08-04 19:56:33 +02:00
|
|
|
region_element* element;
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
TRACE("%p, %p\n", path, region);
|
|
|
|
|
|
|
|
if (!(path && region))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*region = heap_alloc_zero(sizeof(GpRegion));
|
2008-08-04 19:56:33 +02:00
|
|
|
if(!*region)
|
|
|
|
return OutOfMemory;
|
|
|
|
stat = init_region(*region, RegionDataPath);
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
GdipDeleteRegion(*region);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
element = &(*region)->node;
|
|
|
|
|
2013-11-12 10:16:28 +01:00
|
|
|
stat = GdipClonePath(path, &element->elementdata.path);
|
2008-08-04 19:56:33 +02:00
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
GdipDeleteRegion(*region);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
2008-05-12 17:45:36 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateRegionRect [GDIPLUS.@]
|
|
|
|
*/
|
2008-08-04 19:56:37 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateRegionRect(GDIPCONST GpRectF *rect,
|
|
|
|
GpRegion **region)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-04 19:56:37 +02:00
|
|
|
GpStatus stat;
|
2008-06-30 15:54:26 +02:00
|
|
|
|
2008-08-04 19:56:37 +02:00
|
|
|
TRACE("%p, %p\n", rect, region);
|
|
|
|
|
|
|
|
if (!(rect && region))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*region = heap_alloc_zero(sizeof(GpRegion));
|
2008-08-04 19:56:37 +02:00
|
|
|
stat = init_region(*region, RegionDataRect);
|
|
|
|
if(stat != Ok)
|
|
|
|
{
|
|
|
|
GdipDeleteRegion(*region);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*region)->node.elementdata.rect.X = rect->X;
|
|
|
|
(*region)->node.elementdata.rect.Y = rect->Y;
|
|
|
|
(*region)->node.elementdata.rect.Width = rect->Width;
|
|
|
|
(*region)->node.elementdata.rect.Height = rect->Height;
|
|
|
|
|
|
|
|
return Ok;
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2009-02-17 10:29:47 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateRegionRectI [GDIPLUS.@]
|
|
|
|
*/
|
2008-08-04 19:56:41 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateRegionRectI(GDIPCONST GpRect *rect,
|
|
|
|
GpRegion **region)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-04 19:56:41 +02:00
|
|
|
GpRectF rectf;
|
2008-06-30 15:54:26 +02:00
|
|
|
|
2008-08-04 19:56:41 +02:00
|
|
|
TRACE("%p, %p\n", rect, region);
|
|
|
|
|
|
|
|
rectf.X = (REAL)rect->X;
|
|
|
|
rectf.Y = (REAL)rect->Y;
|
|
|
|
rectf.Width = (REAL)rect->Width;
|
|
|
|
rectf.Height = (REAL)rect->Height;
|
|
|
|
|
|
|
|
return GdipCreateRegionRect(&rectf, region);
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 01:49:54 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* GdipCreateRegionHrgn [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipCreateRegionHrgn(HRGN hrgn, GpRegion **region)
|
|
|
|
{
|
2009-01-30 01:49:54 +01:00
|
|
|
DWORD size;
|
2009-08-24 23:49:31 +02:00
|
|
|
LPRGNDATA buf;
|
|
|
|
LPRECT rect;
|
2009-01-30 01:49:54 +01:00
|
|
|
GpStatus stat;
|
2009-08-24 23:49:31 +02:00
|
|
|
GpPath* path;
|
|
|
|
GpRegion* local;
|
2013-01-23 22:42:47 +01:00
|
|
|
DWORD i;
|
2009-01-30 01:49:54 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", hrgn, region);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 01:49:54 +01:00
|
|
|
if(!region || !(size = GetRegionData(hrgn, 0, NULL)))
|
2008-10-19 19:13:23 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
buf = heap_alloc_zero(size);
|
2009-08-24 23:49:31 +02:00
|
|
|
if(!buf)
|
|
|
|
return OutOfMemory;
|
2009-01-30 01:49:54 +01:00
|
|
|
|
2009-08-24 23:49:31 +02:00
|
|
|
if(!GetRegionData(hrgn, size, buf)){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-01-30 01:49:54 +01:00
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
2009-08-24 23:49:31 +02:00
|
|
|
if(buf->rdh.nCount == 0){
|
|
|
|
if((stat = GdipCreateRegion(&local)) != Ok){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-08-24 23:49:31 +02:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
if((stat = GdipSetEmpty(local)) != Ok){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-08-24 23:49:31 +02:00
|
|
|
GdipDeleteRegion(local);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
*region = local;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-08-24 23:49:31 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
2009-01-30 01:49:54 +01:00
|
|
|
|
2009-08-24 23:49:31 +02:00
|
|
|
if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-01-30 01:49:54 +01:00
|
|
|
return stat;
|
2009-08-24 23:49:31 +02:00
|
|
|
}
|
2009-01-30 01:49:54 +01:00
|
|
|
|
2009-08-24 23:49:31 +02:00
|
|
|
rect = (LPRECT)buf->Buffer;
|
|
|
|
for(i = 0; i < buf->rdh.nCount; i++){
|
|
|
|
if((stat = GdipAddPathRectangle(path, (REAL)rect->left, (REAL)rect->top,
|
|
|
|
(REAL)(rect->right - rect->left), (REAL)(rect->bottom - rect->top))) != Ok){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-08-24 23:49:31 +02:00
|
|
|
GdipDeletePath(path);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
rect++;
|
|
|
|
}
|
2009-01-30 01:49:54 +01:00
|
|
|
|
|
|
|
stat = GdipCreateRegionPath(path, region);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(buf);
|
2009-08-24 23:49:31 +02:00
|
|
|
GdipDeletePath(path);
|
2009-01-30 01:49:54 +01:00
|
|
|
return stat;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-02-17 10:29:47 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipDeleteRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-05-12 17:45:36 +02:00
|
|
|
GpStatus WINGDIPAPI GdipDeleteRegion(GpRegion *region)
|
|
|
|
{
|
2008-07-25 01:01:32 +02:00
|
|
|
TRACE("%p\n", region);
|
|
|
|
|
|
|
|
if (!region)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
delete_element(®ion->node);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(region);
|
2008-07-25 01:01:32 +02:00
|
|
|
|
|
|
|
return Ok;
|
2008-05-12 17:45:36 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 21:56:01 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetRegionBounds [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetRegionBounds(GpRegion *region, GpGraphics *graphics, GpRectF *rect)
|
|
|
|
{
|
2009-01-30 21:56:01 +01:00
|
|
|
HRGN hrgn;
|
|
|
|
RECT r;
|
|
|
|
GpStatus status;
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 21:56:01 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", region, graphics, rect);
|
|
|
|
|
|
|
|
if(!region || !graphics || !rect)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2009-08-03 17:09:07 +02:00
|
|
|
/* Contrary to MSDN, native ignores the graphics transform. */
|
|
|
|
status = GdipGetRegionHRgn(region, NULL, &hrgn);
|
2009-01-30 21:56:01 +01:00
|
|
|
if(status != Ok)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* infinite */
|
|
|
|
if(!hrgn){
|
|
|
|
rect->X = rect->Y = -(REAL)(1 << 22);
|
|
|
|
rect->Width = rect->Height = (REAL)(1 << 23);
|
2012-05-21 10:53:13 +02:00
|
|
|
TRACE("%p => infinite\n", region);
|
2009-01-30 21:56:01 +01:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2011-03-21 16:39:59 +01:00
|
|
|
if(GetRgnBox(hrgn, &r)){
|
|
|
|
rect->X = r.left;
|
|
|
|
rect->Y = r.top;
|
|
|
|
rect->Width = r.right - r.left;
|
|
|
|
rect->Height = r.bottom - r.top;
|
2012-05-21 10:53:13 +02:00
|
|
|
TRACE("%p => %s\n", region, debugstr_rectf(rect));
|
2009-01-30 21:56:01 +01:00
|
|
|
}
|
2011-03-21 16:39:59 +01:00
|
|
|
else
|
|
|
|
status = GenericError;
|
2009-01-30 21:56:01 +01:00
|
|
|
|
2011-03-21 16:39:59 +01:00
|
|
|
DeleteObject(hrgn);
|
2009-01-30 21:56:01 +01:00
|
|
|
|
2011-03-21 16:39:59 +01:00
|
|
|
return status;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 21:56:01 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetRegionBoundsI [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetRegionBoundsI(GpRegion *region, GpGraphics *graphics, GpRect *rect)
|
|
|
|
{
|
2009-01-30 21:56:01 +01:00
|
|
|
GpRectF rectf;
|
|
|
|
GpStatus status;
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 21:56:01 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", region, graphics, rect);
|
|
|
|
|
|
|
|
if(!rect)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
status = GdipGetRegionBounds(region, graphics, &rectf);
|
|
|
|
if(status == Ok){
|
2012-08-21 04:02:06 +02:00
|
|
|
rect->X = gdip_round(rectf.X);
|
2013-04-03 00:51:47 +02:00
|
|
|
rect->Y = gdip_round(rectf.Y);
|
2012-08-21 04:02:06 +02:00
|
|
|
rect->Width = gdip_round(rectf.Width);
|
|
|
|
rect->Height = gdip_round(rectf.Height);
|
2009-01-30 21:56:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
static inline void write_dword(DWORD* location, INT* offset, const DWORD write)
|
2008-06-30 15:54:26 +02:00
|
|
|
{
|
2008-08-04 19:56:25 +02:00
|
|
|
location[*offset] = write;
|
|
|
|
(*offset)++;
|
|
|
|
}
|
2008-06-30 15:54:26 +02:00
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
static inline void write_float(DWORD* location, INT* offset, const FLOAT write)
|
|
|
|
{
|
|
|
|
((FLOAT*)location)[*offset] = write;
|
|
|
|
(*offset)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_packed_point(DWORD* location, INT* offset,
|
|
|
|
const GpPointF* write)
|
|
|
|
{
|
2013-11-08 08:33:26 +01:00
|
|
|
packed_point *point = (packed_point *)(location + *offset);
|
|
|
|
point->X = gdip_round(write->X);
|
|
|
|
point->Y = gdip_round(write->Y);
|
2008-08-04 19:56:25 +02:00
|
|
|
(*offset)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void write_path_types(DWORD* location, INT* offset,
|
|
|
|
const GpPath* path)
|
|
|
|
{
|
2013-11-15 10:04:32 +01:00
|
|
|
INT rounded_size = get_pathtypes_size(path);
|
|
|
|
|
2008-08-04 19:56:25 +02:00
|
|
|
memcpy(location + *offset, path->pathdata.Types, path->pathdata.Count);
|
|
|
|
|
|
|
|
/* The unwritten parts of the DWORD (if any) must be cleared */
|
2013-11-15 10:04:32 +01:00
|
|
|
if (rounded_size - path->pathdata.Count)
|
2008-08-04 19:56:25 +02:00
|
|
|
ZeroMemory(((BYTE*)location) + (*offset * sizeof(DWORD)) +
|
2013-11-15 10:04:32 +01:00
|
|
|
path->pathdata.Count, rounded_size - path->pathdata.Count);
|
|
|
|
*offset += rounded_size / sizeof(DWORD);
|
2008-08-04 19:56:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void write_element(const region_element* element, DWORD *buffer,
|
|
|
|
INT* filled)
|
|
|
|
{
|
|
|
|
write_dword(buffer, filled, element->type);
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case CombineModeReplace:
|
|
|
|
case CombineModeIntersect:
|
|
|
|
case CombineModeUnion:
|
|
|
|
case CombineModeXor:
|
|
|
|
case CombineModeExclude:
|
|
|
|
case CombineModeComplement:
|
|
|
|
write_element(element->elementdata.combine.left, buffer, filled);
|
|
|
|
write_element(element->elementdata.combine.right, buffer, filled);
|
|
|
|
break;
|
|
|
|
case RegionDataRect:
|
|
|
|
write_float(buffer, filled, element->elementdata.rect.X);
|
|
|
|
write_float(buffer, filled, element->elementdata.rect.Y);
|
|
|
|
write_float(buffer, filled, element->elementdata.rect.Width);
|
|
|
|
write_float(buffer, filled, element->elementdata.rect.Height);
|
|
|
|
break;
|
|
|
|
case RegionDataPath:
|
|
|
|
{
|
|
|
|
INT i;
|
2013-11-12 10:16:28 +01:00
|
|
|
const GpPath* path = element->elementdata.path;
|
2015-06-13 09:53:58 +02:00
|
|
|
struct path_header *pathheader;
|
2013-11-12 10:16:15 +01:00
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
pathheader = (struct path_header *)(buffer + *filled);
|
2013-11-12 10:16:15 +01:00
|
|
|
|
|
|
|
pathheader->flags = is_integer_path(path) ? FLAGS_INTPATH : FLAGS_NOFLAGS;
|
|
|
|
/* 3 for headers, once again size doesn't count itself */
|
|
|
|
pathheader->size = sizeof(DWORD) * 3;
|
|
|
|
if (pathheader->flags & FLAGS_INTPATH)
|
|
|
|
pathheader->size += 2 * sizeof(SHORT) * path->pathdata.Count;
|
|
|
|
else
|
|
|
|
pathheader->size += 2 * sizeof(FLOAT) * path->pathdata.Count;
|
|
|
|
pathheader->size += get_pathtypes_size(path);
|
|
|
|
pathheader->magic = VERSION_MAGIC;
|
|
|
|
pathheader->count = path->pathdata.Count;
|
|
|
|
|
|
|
|
*filled += 4;
|
|
|
|
|
|
|
|
switch (pathheader->flags & FLAGS_INTPATH)
|
2008-08-04 19:56:25 +02:00
|
|
|
{
|
|
|
|
case FLAGS_NOFLAGS:
|
|
|
|
for (i = 0; i < path->pathdata.Count; i++)
|
|
|
|
{
|
|
|
|
write_float(buffer, filled, path->pathdata.Points[i].X);
|
|
|
|
write_float(buffer, filled, path->pathdata.Points[i].Y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FLAGS_INTPATH:
|
|
|
|
for (i = 0; i < path->pathdata.Count; i++)
|
|
|
|
{
|
|
|
|
write_packed_point(buffer, filled,
|
|
|
|
&path->pathdata.Points[i]);
|
|
|
|
}
|
2013-11-12 10:16:15 +01:00
|
|
|
break;
|
2008-08-04 19:56:25 +02:00
|
|
|
}
|
|
|
|
write_path_types(buffer, filled, path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetRegionData [GDIPLUS.@]
|
|
|
|
*
|
|
|
|
* Returns the header, followed by combining ops and region elements.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* region [I] region to retrieve from
|
|
|
|
* buffer [O] buffer to hold the resulting data
|
|
|
|
* size [I] size of the buffer
|
|
|
|
* needed [O] (optional) how much data was written
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* SUCCESS: Ok
|
2009-02-17 10:29:47 +01:00
|
|
|
* FAILURE: InvalidParameter
|
2008-08-04 19:56:25 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The header contains the size, a checksum, a version string, and the number
|
|
|
|
* of children. The size does not count itself or the checksum.
|
|
|
|
* Version is always something like 0xdbc01001 or 0xdbc01002
|
|
|
|
*
|
|
|
|
* An element is a RECT, or PATH; Combining ops are stored as their
|
|
|
|
* CombineMode value. Special regions (infinite, empty) emit just their
|
|
|
|
* op-code; GpRectFs emit their code followed by their points; GpPaths emit
|
|
|
|
* their code followed by a second header for the path followed by the actual
|
|
|
|
* path data. Followed by the flags for each point. The pathheader contains
|
|
|
|
* the size of the data to follow, a version number again, followed by a count
|
|
|
|
* of how many points, and any special flags which may apply. 0x4000 means its
|
|
|
|
* a path of shorts instead of FLOAT.
|
|
|
|
*
|
|
|
|
* Combining Ops are stored in reverse order from when they were constructed;
|
|
|
|
* the output is a tree where the left side combining area is always taken
|
|
|
|
* first.
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipGetRegionData(GpRegion *region, BYTE *buffer, UINT size,
|
|
|
|
UINT *needed)
|
|
|
|
{
|
2015-06-09 08:35:38 +02:00
|
|
|
struct region_header *region_header;
|
2008-08-04 19:56:25 +02:00
|
|
|
INT filled = 0;
|
2013-11-13 06:00:26 +01:00
|
|
|
UINT required;
|
|
|
|
GpStatus status;
|
2008-08-04 19:56:25 +02:00
|
|
|
|
2008-08-27 21:30:51 +02:00
|
|
|
TRACE("%p, %p, %d, %p\n", region, buffer, size, needed);
|
|
|
|
|
2013-11-13 06:00:26 +01:00
|
|
|
if (!region || !buffer || !size)
|
2008-08-04 19:56:25 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2013-11-13 06:00:26 +01:00
|
|
|
status = GdipGetRegionDataSize(region, &required);
|
|
|
|
if (status != Ok) return status;
|
|
|
|
if (size < required)
|
|
|
|
{
|
|
|
|
if (needed) *needed = size;
|
|
|
|
return InsufficientBuffer;
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:35:38 +02:00
|
|
|
region_header = (struct region_header *)buffer;
|
2013-11-12 10:16:15 +01:00
|
|
|
region_header->size = sizeheader_size + get_element_size(®ion->node);
|
|
|
|
region_header->checksum = 0;
|
|
|
|
region_header->magic = VERSION_MAGIC;
|
2013-11-12 10:16:28 +01:00
|
|
|
region_header->num_children = region->num_children;
|
2013-11-12 10:16:15 +01:00
|
|
|
filled += 4;
|
2008-08-04 19:56:25 +02:00
|
|
|
/* With few exceptions, everything written is DWORD aligned,
|
|
|
|
* so use that as our base */
|
|
|
|
write_element(®ion->node, (DWORD*)buffer, &filled);
|
|
|
|
|
|
|
|
if (needed)
|
|
|
|
*needed = filled * sizeof(DWORD);
|
|
|
|
|
|
|
|
return Ok;
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
static inline void init_memory_buffer(struct memory_buffer *mbuf, const BYTE *buffer, INT size)
|
2015-06-09 08:35:38 +02:00
|
|
|
{
|
2015-06-13 09:53:58 +02:00
|
|
|
mbuf->buffer = buffer;
|
|
|
|
mbuf->size = size;
|
|
|
|
mbuf->pos = 0;
|
|
|
|
}
|
2015-06-09 08:35:38 +02:00
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
static inline const void *buffer_read(struct memory_buffer *mbuf, INT size)
|
|
|
|
{
|
|
|
|
if (mbuf->size - mbuf->pos >= size)
|
|
|
|
{
|
|
|
|
const void *data = mbuf->buffer + mbuf->pos;
|
|
|
|
mbuf->pos += size;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
return NULL;
|
2015-06-09 08:35:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
static GpStatus read_element(struct memory_buffer *mbuf, GpRegion *region, region_element *node, INT *count)
|
2015-06-09 08:35:38 +02:00
|
|
|
{
|
|
|
|
GpStatus status;
|
2015-06-13 09:53:58 +02:00
|
|
|
const DWORD *type;
|
2015-06-09 08:35:38 +02:00
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
type = buffer_read(mbuf, sizeof(*type));
|
|
|
|
if (!type) return Ok;
|
|
|
|
|
|
|
|
TRACE("type %#x\n", *type);
|
|
|
|
|
|
|
|
node->type = *type;
|
|
|
|
|
|
|
|
switch (node->type)
|
|
|
|
{
|
|
|
|
case CombineModeReplace:
|
|
|
|
case CombineModeIntersect:
|
|
|
|
case CombineModeUnion:
|
|
|
|
case CombineModeXor:
|
|
|
|
case CombineModeExclude:
|
|
|
|
case CombineModeComplement:
|
|
|
|
{
|
|
|
|
region_element *left, *right;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
left = heap_alloc_zero(sizeof(region_element));
|
2015-06-13 09:53:58 +02:00
|
|
|
if (!left) return OutOfMemory;
|
2015-10-05 00:22:34 +02:00
|
|
|
right = heap_alloc_zero(sizeof(region_element));
|
2015-06-13 09:53:58 +02:00
|
|
|
if (!right)
|
|
|
|
{
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(left);
|
2015-06-13 09:53:58 +02:00
|
|
|
return OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = read_element(mbuf, region, left, count);
|
|
|
|
if (status == Ok)
|
|
|
|
{
|
|
|
|
status = read_element(mbuf, region, right, count);
|
|
|
|
if (status == Ok)
|
|
|
|
{
|
|
|
|
node->elementdata.combine.left = left;
|
|
|
|
node->elementdata.combine.right = right;
|
|
|
|
region->num_children += 2;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(left);
|
|
|
|
heap_free(right);
|
2015-06-09 08:35:38 +02:00
|
|
|
return status;
|
2015-06-13 09:53:58 +02:00
|
|
|
}
|
2015-06-09 08:35:38 +02:00
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
case RegionDataRect:
|
2015-06-09 08:35:38 +02:00
|
|
|
{
|
2015-06-13 09:53:58 +02:00
|
|
|
const GpRectF *rc;
|
|
|
|
|
|
|
|
rc = buffer_read(mbuf, sizeof(*rc));
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
ERR("failed to read rect data\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->elementdata.rect = *rc;
|
|
|
|
*count += 1;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RegionDataPath:
|
|
|
|
{
|
|
|
|
GpPath *path;
|
|
|
|
const struct path_header *path_header;
|
|
|
|
const BYTE *types;
|
|
|
|
|
|
|
|
path_header = buffer_read(mbuf, sizeof(*path_header));
|
|
|
|
if (!path_header)
|
|
|
|
{
|
|
|
|
ERR("failed to read path header\n");
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
if (path_header->magic != VERSION_MAGIC)
|
|
|
|
{
|
|
|
|
ERR("invalid path header magic %#x\n", path_header->magic);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Windows always fails to create an empty path in a region */
|
|
|
|
if (!path_header->count)
|
|
|
|
{
|
|
|
|
TRACE("refusing to create an empty path in a region\n");
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = GdipCreatePath(FillModeAlternate, &path);
|
|
|
|
if (status) return status;
|
|
|
|
|
|
|
|
node->elementdata.path = path;
|
|
|
|
|
|
|
|
if (!lengthen_path(path, path_header->count))
|
|
|
|
return OutOfMemory;
|
|
|
|
|
|
|
|
path->pathdata.Count = path_header->count;
|
|
|
|
|
|
|
|
if (path_header->flags & ~FLAGS_INTPATH)
|
|
|
|
FIXME("unhandled path flags %#x\n", path_header->flags);
|
|
|
|
|
|
|
|
if (path_header->flags & FLAGS_INTPATH)
|
|
|
|
{
|
|
|
|
const packed_point *pt;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
pt = buffer_read(mbuf, sizeof(*pt) * path_header->count);
|
|
|
|
if (!pt)
|
|
|
|
{
|
|
|
|
ERR("failed to read packed %u path points\n", path_header->count);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < path_header->count; i++)
|
|
|
|
{
|
|
|
|
path->pathdata.Points[i].X = (REAL)pt[i].X;
|
|
|
|
path->pathdata.Points[i].Y = (REAL)pt[i].Y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const GpPointF *ptf;
|
|
|
|
|
|
|
|
ptf = buffer_read(mbuf, sizeof(*ptf) * path_header->count);
|
|
|
|
if (!ptf)
|
|
|
|
{
|
|
|
|
ERR("failed to read %u path points\n", path_header->count);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
memcpy(path->pathdata.Points, ptf, sizeof(*ptf) * path_header->count);
|
|
|
|
}
|
|
|
|
|
|
|
|
types = buffer_read(mbuf, path_header->count);
|
|
|
|
if (!types)
|
|
|
|
{
|
|
|
|
ERR("failed to read %u path types\n", path_header->count);
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
memcpy(path->pathdata.Types, types, path_header->count);
|
|
|
|
if (path_header->count & 3)
|
|
|
|
{
|
|
|
|
if (!buffer_read(mbuf, 4 - (path_header->count & 3)))
|
|
|
|
{
|
|
|
|
ERR("failed to read rounding %u bytes\n", 4 - (path_header->count & 3));
|
|
|
|
return InvalidParameter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*count += 1;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2015-06-09 08:35:38 +02:00
|
|
|
case RegionDataEmptyRect:
|
2015-06-13 09:53:58 +02:00
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
*count += 1;
|
|
|
|
return Ok;
|
|
|
|
|
2015-06-09 08:35:38 +02:00
|
|
|
default:
|
2015-06-13 09:53:58 +02:00
|
|
|
FIXME("element type %#x is not supported\n", *type);
|
|
|
|
break;
|
2015-06-09 08:35:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
return InvalidParameter;
|
2015-06-09 08:35:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipCreateRegionRgnData [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipCreateRegionRgnData(GDIPCONST BYTE *data, INT size, GpRegion **region)
|
|
|
|
{
|
2015-06-13 09:53:58 +02:00
|
|
|
const struct region_header *region_header;
|
|
|
|
struct memory_buffer mbuf;
|
2015-06-09 08:35:38 +02:00
|
|
|
GpStatus status;
|
2015-06-13 09:53:58 +02:00
|
|
|
INT count;
|
2015-06-09 08:35:38 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %d, %p)\n", data, size, region);
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
if (!data || !size)
|
2015-06-09 08:35:38 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
init_memory_buffer(&mbuf, data, size);
|
|
|
|
|
|
|
|
region_header = buffer_read(&mbuf, sizeof(*region_header));
|
|
|
|
if (!region_header || (region_header->magic != VERSION_MAGIC &&
|
|
|
|
region_header->magic != VERSION_MAGIC2))
|
2015-06-09 08:35:38 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
status = GdipCreateRegion(region);
|
|
|
|
if (status != Ok)
|
|
|
|
return status;
|
|
|
|
|
2015-06-13 09:53:58 +02:00
|
|
|
count = 0;
|
|
|
|
status = read_element(&mbuf, *region, &(*region)->node, &count);
|
|
|
|
if (status == Ok && !count)
|
|
|
|
status = InvalidParameter;
|
2015-06-09 08:35:38 +02:00
|
|
|
|
|
|
|
if (status != Ok)
|
|
|
|
{
|
|
|
|
GdipDeleteRegion(*region);
|
|
|
|
*region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetRegionDataSize [GDIPLUS.@]
|
|
|
|
*/
|
2008-06-30 15:54:26 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetRegionDataSize(GpRegion *region, UINT *needed)
|
|
|
|
{
|
2008-08-27 21:30:51 +02:00
|
|
|
TRACE("%p, %p\n", region, needed);
|
|
|
|
|
2008-07-25 01:01:45 +02:00
|
|
|
if (!(region && needed))
|
|
|
|
return InvalidParameter;
|
2008-06-30 15:54:26 +02:00
|
|
|
|
2008-07-25 01:01:45 +02:00
|
|
|
/* header.size doesn't count header.size and header.checksum */
|
2013-11-12 10:16:15 +01:00
|
|
|
*needed = sizeof(DWORD) * 2 + sizeheader_size + get_element_size(®ion->node);
|
2008-07-25 01:01:45 +02:00
|
|
|
|
|
|
|
return Ok;
|
2008-06-30 15:54:26 +02:00
|
|
|
}
|
|
|
|
|
2008-11-24 22:01:47 +01:00
|
|
|
static GpStatus get_path_hrgn(GpPath *path, GpGraphics *graphics, HRGN *hrgn)
|
|
|
|
{
|
|
|
|
HDC new_hdc=NULL;
|
2010-10-28 00:49:55 +02:00
|
|
|
GpGraphics *new_graphics=NULL;
|
2008-11-24 22:01:47 +01:00
|
|
|
GpStatus stat;
|
|
|
|
INT save_state;
|
|
|
|
|
2016-06-15 17:36:37 +02:00
|
|
|
if (!path->pathdata.Count) /* PathToRegion doesn't support empty paths */
|
|
|
|
{
|
|
|
|
*hrgn = CreateRectRgn( 0, 0, 0, 0 );
|
|
|
|
return *hrgn ? Ok : OutOfMemory;
|
|
|
|
}
|
|
|
|
|
2008-11-24 22:01:47 +01:00
|
|
|
if (!graphics)
|
|
|
|
{
|
2013-02-20 07:18:56 +01:00
|
|
|
new_hdc = CreateCompatibleDC(0);
|
2008-11-24 22:01:47 +01:00
|
|
|
if (!new_hdc)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
2010-10-28 00:49:55 +02:00
|
|
|
stat = GdipCreateFromHDC(new_hdc, &new_graphics);
|
|
|
|
graphics = new_graphics;
|
2008-11-24 22:01:47 +01:00
|
|
|
if (stat != Ok)
|
|
|
|
{
|
2013-02-20 07:18:56 +01:00
|
|
|
DeleteDC(new_hdc);
|
2008-11-24 22:01:47 +01:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
}
|
2010-10-28 00:49:55 +02:00
|
|
|
else if (!graphics->hdc)
|
|
|
|
{
|
2013-02-20 07:18:56 +01:00
|
|
|
graphics->hdc = new_hdc = CreateCompatibleDC(0);
|
2010-10-28 00:49:55 +02:00
|
|
|
if (!new_hdc)
|
|
|
|
return OutOfMemory;
|
|
|
|
}
|
2008-11-24 22:01:47 +01:00
|
|
|
|
|
|
|
save_state = SaveDC(graphics->hdc);
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
|
|
|
|
SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
|
|
|
|
: WINDING));
|
|
|
|
|
|
|
|
stat = trace_path(graphics, path);
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
*hrgn = PathToRegion(graphics->hdc);
|
|
|
|
stat = *hrgn ? Ok : OutOfMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
RestoreDC(graphics->hdc, save_state);
|
|
|
|
if (new_hdc)
|
|
|
|
{
|
2013-02-20 07:18:56 +01:00
|
|
|
DeleteDC(new_hdc);
|
2010-10-28 00:49:55 +02:00
|
|
|
if (new_graphics)
|
|
|
|
GdipDeleteGraphics(new_graphics);
|
|
|
|
else
|
|
|
|
graphics->hdc = NULL;
|
2008-11-24 22:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2008-11-24 21:12:39 +01:00
|
|
|
static GpStatus get_region_hrgn(struct region_element *element, GpGraphics *graphics, HRGN *hrgn)
|
|
|
|
{
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
*hrgn = NULL;
|
|
|
|
return Ok;
|
2008-11-24 21:30:08 +01:00
|
|
|
case RegionDataEmptyRect:
|
|
|
|
*hrgn = CreateRectRgn(0, 0, 0, 0);
|
|
|
|
return *hrgn ? Ok : OutOfMemory;
|
2008-11-24 22:01:47 +01:00
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:28 +01:00
|
|
|
return get_path_hrgn(element->elementdata.path, graphics, hrgn);
|
2008-11-24 23:06:32 +01:00
|
|
|
case RegionDataRect:
|
|
|
|
{
|
|
|
|
GpPath* path;
|
|
|
|
GpStatus stat;
|
|
|
|
GpRectF* rc = &element->elementdata.rect;
|
|
|
|
|
|
|
|
stat = GdipCreatePath(FillModeAlternate, &path);
|
|
|
|
if (stat != Ok)
|
|
|
|
return stat;
|
|
|
|
stat = GdipAddPathRectangle(path, rc->X, rc->Y, rc->Width, rc->Height);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
stat = get_path_hrgn(path, graphics, hrgn);
|
|
|
|
|
|
|
|
GdipDeletePath(path);
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
2008-11-25 00:20:00 +01:00
|
|
|
case CombineModeIntersect:
|
|
|
|
case CombineModeUnion:
|
|
|
|
case CombineModeXor:
|
|
|
|
case CombineModeExclude:
|
|
|
|
case CombineModeComplement:
|
|
|
|
{
|
|
|
|
HRGN left, right;
|
|
|
|
GpStatus stat;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
stat = get_region_hrgn(element->elementdata.combine.left, graphics, &left);
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
*hrgn = NULL;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left == NULL)
|
|
|
|
{
|
|
|
|
/* existing region is infinite */
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case CombineModeIntersect:
|
|
|
|
return get_region_hrgn(element->elementdata.combine.right, graphics, hrgn);
|
|
|
|
case CombineModeXor: case CombineModeExclude:
|
2015-06-09 08:35:38 +02:00
|
|
|
left = CreateRectRgn(-(1 << 22), -(1 << 22), 1 << 22, 1 << 22);
|
2013-10-30 17:46:30 +01:00
|
|
|
break;
|
2008-11-25 00:20:00 +01:00
|
|
|
case CombineModeUnion: case CombineModeComplement:
|
|
|
|
*hrgn = NULL;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stat = get_region_hrgn(element->elementdata.combine.right, graphics, &right);
|
|
|
|
if (stat != Ok)
|
|
|
|
{
|
|
|
|
DeleteObject(left);
|
|
|
|
*hrgn = NULL;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right == NULL)
|
|
|
|
{
|
|
|
|
/* new region is infinite */
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case CombineModeIntersect:
|
|
|
|
*hrgn = left;
|
|
|
|
return Ok;
|
|
|
|
case CombineModeXor: case CombineModeComplement:
|
2015-06-09 08:35:38 +02:00
|
|
|
right = CreateRectRgn(-(1 << 22), -(1 << 22), 1 << 22, 1 << 22);
|
2013-10-30 17:46:30 +01:00
|
|
|
break;
|
2008-11-25 00:20:00 +01:00
|
|
|
case CombineModeUnion: case CombineModeExclude:
|
|
|
|
DeleteObject(left);
|
|
|
|
*hrgn = NULL;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (element->type)
|
|
|
|
{
|
|
|
|
case CombineModeIntersect:
|
|
|
|
ret = CombineRgn(left, left, right, RGN_AND);
|
|
|
|
break;
|
|
|
|
case CombineModeUnion:
|
|
|
|
ret = CombineRgn(left, left, right, RGN_OR);
|
|
|
|
break;
|
|
|
|
case CombineModeXor:
|
|
|
|
ret = CombineRgn(left, left, right, RGN_XOR);
|
|
|
|
break;
|
|
|
|
case CombineModeExclude:
|
|
|
|
ret = CombineRgn(left, left, right, RGN_DIFF);
|
|
|
|
break;
|
|
|
|
case CombineModeComplement:
|
|
|
|
ret = CombineRgn(left, right, left, RGN_DIFF);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeleteObject(right);
|
|
|
|
|
|
|
|
if (ret == ERROR)
|
|
|
|
{
|
|
|
|
DeleteObject(left);
|
|
|
|
*hrgn = NULL;
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
*hrgn = left;
|
|
|
|
return Ok;
|
|
|
|
}
|
2008-11-24 21:12:39 +01:00
|
|
|
default:
|
|
|
|
FIXME("GdipGetRegionHRgn unimplemented for region type=%x\n", element->type);
|
|
|
|
*hrgn = NULL;
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-26 19:20:33 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipGetRegionHRgn [GDIPLUS.@]
|
|
|
|
*/
|
2008-05-12 17:45:36 +02:00
|
|
|
GpStatus WINGDIPAPI GdipGetRegionHRgn(GpRegion *region, GpGraphics *graphics, HRGN *hrgn)
|
|
|
|
{
|
2008-11-24 21:12:39 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", region, graphics, hrgn);
|
2008-05-12 17:45:36 +02:00
|
|
|
|
2008-11-24 20:55:20 +01:00
|
|
|
if (!region || !hrgn)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2008-11-24 21:12:39 +01:00
|
|
|
return get_region_hrgn(®ion->node, graphics, hrgn);
|
2008-05-12 17:45:36 +02:00
|
|
|
}
|
|
|
|
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipIsEmptyRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
2012-05-21 10:53:13 +02:00
|
|
|
GpStatus status;
|
|
|
|
GpRectF rect;
|
|
|
|
|
2008-08-27 21:30:55 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", region, graphics, res);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2008-08-27 21:30:55 +02:00
|
|
|
if(!region || !graphics || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2012-05-21 10:53:13 +02:00
|
|
|
status = GdipGetRegionBounds(region, graphics, &rect);
|
|
|
|
if (status != Ok) return status;
|
|
|
|
|
|
|
|
*res = rect.Width == 0.0 && rect.Height == 0.0;
|
|
|
|
TRACE("=> %d\n", *res);
|
2008-08-27 21:30:55 +02:00
|
|
|
|
|
|
|
return Ok;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 20:19:22 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsEqualRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipIsEqualRegion(GpRegion *region, GpRegion *region2, GpGraphics *graphics,
|
|
|
|
BOOL *res)
|
|
|
|
{
|
2009-01-30 20:19:22 +01:00
|
|
|
HRGN hrgn1, hrgn2;
|
|
|
|
GpStatus stat;
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 20:19:22 +01:00
|
|
|
TRACE("(%p, %p, %p, %p)\n", region, region2, graphics, res);
|
|
|
|
|
|
|
|
if(!region || !region2 || !graphics || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = GdipGetRegionHRgn(region, graphics, &hrgn1);
|
|
|
|
if(stat != Ok)
|
|
|
|
return stat;
|
|
|
|
stat = GdipGetRegionHRgn(region2, graphics, &hrgn2);
|
|
|
|
if(stat != Ok){
|
|
|
|
DeleteObject(hrgn1);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
*res = EqualRgn(hrgn1, hrgn2);
|
|
|
|
|
|
|
|
/* one of GpRegions is infinite */
|
|
|
|
if(*res == ERROR)
|
|
|
|
*res = (!hrgn1 && !hrgn2);
|
|
|
|
|
|
|
|
DeleteObject(hrgn1);
|
|
|
|
DeleteObject(hrgn2);
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsInfiniteRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipIsInfiniteRegion(GpRegion *region, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
2008-09-01 17:01:27 +02:00
|
|
|
/* I think graphics is ignored here */
|
2008-08-25 23:58:49 +02:00
|
|
|
TRACE("(%p, %p, %p)\n", region, graphics, res);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2008-08-25 23:58:49 +02:00
|
|
|
if(!region || !graphics || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*res = (region->node.type == RegionDataInfiniteRect);
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-08-25 20:39:18 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsVisibleRegionRect [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipIsVisibleRegionRect(GpRegion* region, REAL x, REAL y, REAL w, REAL h, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
|
|
|
HRGN hrgn;
|
|
|
|
GpStatus stat;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %p, %p)\n", region, x, y, w, h, graphics, res);
|
|
|
|
|
|
|
|
if(!region || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
/* infinite */
|
|
|
|
if(!hrgn){
|
|
|
|
*res = TRUE;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:28:09 +02:00
|
|
|
SetRect(&rect, ceilr(x), ceilr(y), ceilr(x + w), ceilr(y + h));
|
2009-08-25 20:39:18 +02:00
|
|
|
*res = RectInRegion(hrgn, &rect);
|
|
|
|
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsVisibleRegionRectI [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipIsVisibleRegionRectI(GpRegion* region, INT x, INT y, INT w, INT h, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %d, %d, %d, %p, %p)\n", region, x, y, w, h, graphics, res);
|
|
|
|
if(!region || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return GdipIsVisibleRegionRect(region, (REAL)x, (REAL)y, (REAL)w, (REAL)h, graphics, res);
|
|
|
|
}
|
|
|
|
|
2009-08-25 20:39:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsVisibleRegionPoint [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipIsVisibleRegionPoint(GpRegion* region, REAL x, REAL y, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
|
|
|
HRGN hrgn;
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
TRACE("(%p, %.2f, %.2f, %p, %p)\n", region, x, y, graphics, res);
|
|
|
|
|
|
|
|
if(!region || !res)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if((stat = GdipGetRegionHRgn(region, NULL, &hrgn)) != Ok)
|
|
|
|
return stat;
|
|
|
|
|
|
|
|
/* infinite */
|
|
|
|
if(!hrgn){
|
|
|
|
*res = TRUE;
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2012-08-21 04:02:06 +02:00
|
|
|
*res = PtInRegion(hrgn, gdip_round(x), gdip_round(y));
|
2009-08-25 20:39:12 +02:00
|
|
|
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipIsVisibleRegionPointI [GDIPLUS.@]
|
|
|
|
*/
|
|
|
|
GpStatus WINGDIPAPI GdipIsVisibleRegionPointI(GpRegion* region, INT x, INT y, GpGraphics *graphics, BOOL *res)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %d, %p, %p)\n", region, x, y, graphics, res);
|
|
|
|
|
|
|
|
return GdipIsVisibleRegionPoint(region, (REAL)x, (REAL)y, graphics, res);
|
|
|
|
}
|
|
|
|
|
2008-09-01 17:01:27 +02:00
|
|
|
/*****************************************************************************
|
2008-09-02 21:47:33 +02:00
|
|
|
* GdipSetEmpty [GDIPLUS.@]
|
2008-09-01 17:01:27 +02:00
|
|
|
*/
|
2008-04-09 22:09:34 +02:00
|
|
|
GpStatus WINGDIPAPI GdipSetEmpty(GpRegion *region)
|
|
|
|
{
|
2008-07-25 01:01:37 +02:00
|
|
|
GpStatus stat;
|
2008-04-09 22:09:34 +02:00
|
|
|
|
2008-07-25 01:01:37 +02:00
|
|
|
TRACE("%p\n", region);
|
2008-04-09 22:09:34 +02:00
|
|
|
|
2008-07-25 01:01:37 +02:00
|
|
|
if (!region)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
delete_element(®ion->node);
|
|
|
|
stat = init_region(region, RegionDataEmptyRect);
|
|
|
|
|
|
|
|
return stat;
|
2008-04-09 22:09:34 +02:00
|
|
|
}
|
2008-04-10 21:40:16 +02:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipSetInfinite(GpRegion *region)
|
|
|
|
{
|
2008-07-25 01:01:41 +02:00
|
|
|
GpStatus stat;
|
2008-04-10 21:40:16 +02:00
|
|
|
|
2008-08-27 21:30:51 +02:00
|
|
|
TRACE("%p\n", region);
|
|
|
|
|
2008-07-25 01:01:41 +02:00
|
|
|
if (!region)
|
|
|
|
return InvalidParameter;
|
2008-04-10 21:40:16 +02:00
|
|
|
|
2008-07-25 01:01:41 +02:00
|
|
|
delete_element(®ion->node);
|
|
|
|
stat = init_region(region, RegionDataInfiniteRect);
|
|
|
|
|
|
|
|
return stat;
|
2008-04-10 21:40:16 +02:00
|
|
|
}
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2010-09-30 21:39:27 +02:00
|
|
|
/* Transforms GpRegion elements with given matrix */
|
|
|
|
static GpStatus transform_region_element(region_element* element, GpMatrix *matrix)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
|
|
|
|
|
|
|
switch(element->type)
|
|
|
|
{
|
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
return Ok;
|
|
|
|
case RegionDataRect:
|
|
|
|
{
|
|
|
|
/* We can't transform a rectangle, so convert it to a path. */
|
|
|
|
GpRegion *new_region;
|
|
|
|
GpPath *path;
|
|
|
|
|
|
|
|
stat = GdipCreatePath(FillModeAlternate, &path);
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = GdipAddPathRectangle(path,
|
|
|
|
element->elementdata.rect.X, element->elementdata.rect.Y,
|
|
|
|
element->elementdata.rect.Width, element->elementdata.rect.Height);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
stat = GdipCreateRegionPath(path, &new_region);
|
|
|
|
|
|
|
|
GdipDeletePath(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
/* Steal the element from the created region. */
|
|
|
|
memcpy(element, &new_region->node, sizeof(region_element));
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(new_region);
|
2010-09-30 21:39:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
/* Fall-through to do the actual conversion. */
|
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:28 +01:00
|
|
|
if (!element->elementdata.path->pathdata.Count)
|
2013-09-24 04:25:57 +02:00
|
|
|
return Ok;
|
|
|
|
|
2010-09-30 21:39:27 +02:00
|
|
|
stat = GdipTransformMatrixPoints(matrix,
|
2013-11-12 10:16:28 +01:00
|
|
|
element->elementdata.path->pathdata.Points,
|
|
|
|
element->elementdata.path->pathdata.Count);
|
2010-09-30 21:39:27 +02:00
|
|
|
return stat;
|
|
|
|
default:
|
|
|
|
stat = transform_region_element(element->elementdata.combine.left, matrix);
|
|
|
|
if (stat == Ok)
|
|
|
|
stat = transform_region_element(element->elementdata.combine.right, matrix);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipTransformRegion(GpRegion *region, GpMatrix *matrix)
|
|
|
|
{
|
2010-09-30 21:39:27 +02:00
|
|
|
TRACE("(%p, %p)\n", region, matrix);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2010-09-30 21:39:27 +02:00
|
|
|
if (!region || !matrix)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return transform_region_element(®ion->node, matrix);
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 21:01:14 +01:00
|
|
|
/* Translates GpRegion elements with specified offsets */
|
|
|
|
static void translate_region_element(region_element* element, REAL dx, REAL dy)
|
|
|
|
{
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
switch(element->type)
|
|
|
|
{
|
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
return;
|
|
|
|
case RegionDataRect:
|
|
|
|
element->elementdata.rect.X += dx;
|
|
|
|
element->elementdata.rect.Y += dy;
|
|
|
|
return;
|
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:28 +01:00
|
|
|
for(i = 0; i < element->elementdata.path->pathdata.Count; i++){
|
|
|
|
element->elementdata.path->pathdata.Points[i].X += dx;
|
|
|
|
element->elementdata.path->pathdata.Points[i].Y += dy;
|
2009-01-30 21:01:14 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
translate_region_element(element->elementdata.combine.left, dx, dy);
|
|
|
|
translate_region_element(element->elementdata.combine.right, dx, dy);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GdipTranslateRegion [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipTranslateRegion(GpRegion *region, REAL dx, REAL dy)
|
|
|
|
{
|
2009-01-30 21:01:14 +01:00
|
|
|
TRACE("(%p, %f, %f)\n", region, dx, dy);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 21:01:14 +01:00
|
|
|
if(!region)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
translate_region_element(®ion->node, dx, dy);
|
|
|
|
|
|
|
|
return Ok;
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
|
|
|
|
2009-01-30 21:03:17 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* GdipTranslateRegionI [GDIPLUS.@]
|
|
|
|
*/
|
2008-07-02 12:53:54 +02:00
|
|
|
GpStatus WINGDIPAPI GdipTranslateRegionI(GpRegion *region, INT dx, INT dy)
|
|
|
|
{
|
2009-01-30 21:03:17 +01:00
|
|
|
TRACE("(%p, %d, %d)\n", region, dx, dy);
|
2008-07-02 12:53:54 +02:00
|
|
|
|
2009-01-30 21:03:17 +01:00
|
|
|
return GdipTranslateRegion(region, (REAL)dx, (REAL)dy);
|
2008-07-02 12:53:54 +02:00
|
|
|
}
|
2010-02-25 00:36:54 +01:00
|
|
|
|
2010-09-30 21:59:04 +02:00
|
|
|
static GpStatus get_region_scans_data(GpRegion *region, GpMatrix *matrix, LPRGNDATA *data)
|
|
|
|
{
|
|
|
|
GpRegion *region_copy;
|
|
|
|
GpStatus stat;
|
|
|
|
HRGN hrgn;
|
|
|
|
DWORD data_size;
|
|
|
|
|
|
|
|
stat = GdipCloneRegion(region, ®ion_copy);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
stat = GdipTransformRegion(region_copy, matrix);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
stat = GdipGetRegionHRgn(region_copy, NULL, &hrgn);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
if (hrgn)
|
|
|
|
{
|
|
|
|
data_size = GetRegionData(hrgn, 0, NULL);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*data = heap_alloc_zero(data_size);
|
2010-09-30 21:59:04 +02:00
|
|
|
|
|
|
|
if (*data)
|
|
|
|
GetRegionData(hrgn, data_size, *data);
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
|
|
|
|
|
|
|
DeleteObject(hrgn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data_size = sizeof(RGNDATAHEADER) + sizeof(RECT);
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
*data = heap_alloc_zero(data_size);
|
2010-09-30 21:59:04 +02:00
|
|
|
|
|
|
|
if (*data)
|
|
|
|
{
|
|
|
|
(*data)->rdh.dwSize = sizeof(RGNDATAHEADER);
|
|
|
|
(*data)->rdh.iType = RDH_RECTANGLES;
|
|
|
|
(*data)->rdh.nCount = 1;
|
|
|
|
(*data)->rdh.nRgnSize = sizeof(RECT);
|
|
|
|
(*data)->rdh.rcBound.left = (*data)->rdh.rcBound.top = -0x400000;
|
|
|
|
(*data)->rdh.rcBound.right = (*data)->rdh.rcBound.bottom = 0x400000;
|
|
|
|
|
2011-10-31 22:19:29 +01:00
|
|
|
memcpy((*data)->Buffer, &(*data)->rdh.rcBound, sizeof(RECT));
|
2010-09-30 21:59:04 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
stat = OutOfMemory;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GdipDeleteRegion(region_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2010-02-25 00:36:54 +01:00
|
|
|
GpStatus WINGDIPAPI GdipGetRegionScansCount(GpRegion *region, UINT *count, GpMatrix *matrix)
|
|
|
|
{
|
2010-09-30 21:59:04 +02:00
|
|
|
GpStatus stat;
|
|
|
|
LPRGNDATA data;
|
2010-02-25 00:36:54 +01:00
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", region, count, matrix);
|
|
|
|
|
2010-09-30 21:59:04 +02:00
|
|
|
if (!region || !count || !matrix)
|
|
|
|
return InvalidParameter;
|
2010-02-25 00:36:54 +01:00
|
|
|
|
2010-09-30 21:59:04 +02:00
|
|
|
stat = get_region_scans_data(region, matrix, &data);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
*count = data->rdh.nCount;
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(data);
|
2010-09-30 21:59:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
2010-02-25 00:36:54 +01:00
|
|
|
}
|
2010-09-30 22:38:03 +02:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetRegionScansI(GpRegion *region, GpRect *scans, INT *count, GpMatrix *matrix)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
2013-01-23 22:42:47 +01:00
|
|
|
DWORD i;
|
2010-09-30 22:38:03 +02:00
|
|
|
LPRGNDATA data;
|
|
|
|
RECT *rects;
|
|
|
|
|
|
|
|
if (!region || !count || !matrix)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = get_region_scans_data(region, matrix, &data);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
*count = data->rdh.nCount;
|
2011-10-31 22:19:29 +01:00
|
|
|
rects = (RECT*)data->Buffer;
|
2010-09-30 22:38:03 +02:00
|
|
|
|
|
|
|
if (scans)
|
|
|
|
{
|
|
|
|
for (i=0; i<data->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
scans[i].X = rects[i].left;
|
|
|
|
scans[i].Y = rects[i].top;
|
|
|
|
scans[i].Width = rects[i].right - rects[i].left;
|
|
|
|
scans[i].Height = rects[i].bottom - rects[i].top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(data);
|
2010-09-30 22:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipGetRegionScans(GpRegion *region, GpRectF *scans, INT *count, GpMatrix *matrix)
|
|
|
|
{
|
|
|
|
GpStatus stat;
|
2013-01-23 22:42:47 +01:00
|
|
|
DWORD i;
|
2010-09-30 22:38:03 +02:00
|
|
|
LPRGNDATA data;
|
|
|
|
RECT *rects;
|
|
|
|
|
|
|
|
if (!region || !count || !matrix)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
stat = get_region_scans_data(region, matrix, &data);
|
|
|
|
|
|
|
|
if (stat == Ok)
|
|
|
|
{
|
|
|
|
*count = data->rdh.nCount;
|
2011-10-31 22:19:29 +01:00
|
|
|
rects = (RECT*)data->Buffer;
|
2010-09-30 22:38:03 +02:00
|
|
|
|
|
|
|
if (scans)
|
|
|
|
{
|
|
|
|
for (i=0; i<data->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
scans[i].X = rects[i].left;
|
|
|
|
scans[i].Y = rects[i].top;
|
|
|
|
scans[i].Width = rects[i].right - rects[i].left;
|
|
|
|
scans[i].Height = rects[i].bottom - rects[i].top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(data);
|
2010-09-30 22:38:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|