2007-05-25 19:21:44 +02:00
|
|
|
/*
|
2007-06-08 22:46:27 +02:00
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
2007-05-25 19:21:44 +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>
|
2007-07-12 03:06:56 +02:00
|
|
|
#include <math.h>
|
2007-05-25 19:21:44 +02:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
2007-08-01 04:15:29 +02:00
|
|
|
#include "wingdi.h"
|
|
|
|
|
2007-08-01 04:15:48 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
|
2007-08-08 03:42:00 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2007-06-08 22:46:27 +02:00
|
|
|
#include "gdiplus.h"
|
2007-07-12 03:06:56 +02:00
|
|
|
#include "gdiplus_private.h"
|
2007-05-25 19:21:44 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
|
|
|
|
|
2012-07-16 07:56:30 +02:00
|
|
|
static const REAL mm_per_inch = 25.4;
|
2012-07-31 11:48:46 +02:00
|
|
|
static const REAL point_per_inch = 72.0;
|
2012-07-16 07:56:30 +02:00
|
|
|
|
2007-08-04 02:30:17 +02:00
|
|
|
static Status WINAPI NotificationHook(ULONG_PTR *token)
|
|
|
|
{
|
|
|
|
TRACE("%p\n", token);
|
|
|
|
if(!token)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI NotificationUnhook(ULONG_PTR token)
|
|
|
|
{
|
|
|
|
TRACE("%ld\n", token);
|
|
|
|
}
|
|
|
|
|
2007-05-25 19:21:44 +02:00
|
|
|
/*****************************************************
|
|
|
|
* DllMain
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %d, %p)\n", hinst, reason, reserved);
|
|
|
|
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls( hinst );
|
2017-04-28 00:20:31 +02:00
|
|
|
init_generic_string_formats();
|
2007-05-25 19:21:44 +02:00
|
|
|
break;
|
2009-04-28 01:56:56 +02:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-05-15 10:19:18 +02:00
|
|
|
if (reserved) break;
|
2009-04-28 01:56:56 +02:00
|
|
|
free_installed_fonts();
|
2017-04-28 00:20:31 +02:00
|
|
|
free_generic_string_formats();
|
2009-04-28 01:56:56 +02:00
|
|
|
break;
|
2007-05-25 19:21:44 +02:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-06-08 22:46:27 +02:00
|
|
|
|
2007-06-12 17:51:53 +02:00
|
|
|
/*****************************************************
|
|
|
|
* GdiplusStartup [GDIPLUS.@]
|
|
|
|
*/
|
2007-06-08 22:46:27 +02:00
|
|
|
Status WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input,
|
|
|
|
struct GdiplusStartupOutput *output)
|
|
|
|
{
|
2007-08-04 02:30:17 +02:00
|
|
|
if(!token || !input)
|
2007-06-08 22:46:27 +02:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-08-04 02:30:17 +02:00
|
|
|
TRACE("%p %p %p\n", token, input, output);
|
|
|
|
TRACE("GdiplusStartupInput %d %p %d %d\n", input->GdiplusVersion,
|
|
|
|
input->DebugEventCallback, input->SuppressBackgroundThread,
|
|
|
|
input->SuppressExternalCodecs);
|
|
|
|
|
2009-09-18 22:54:51 +02:00
|
|
|
if(input->GdiplusVersion < 1 || input->GdiplusVersion > 2)
|
2007-06-08 22:46:27 +02:00
|
|
|
return UnsupportedGdiplusVersion;
|
2007-08-04 02:30:17 +02:00
|
|
|
|
|
|
|
if(input->SuppressBackgroundThread){
|
|
|
|
if(!output)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
output->NotificationHook = NotificationHook;
|
|
|
|
output->NotificationUnhook = NotificationUnhook;
|
2007-06-08 22:46:27 +02:00
|
|
|
}
|
|
|
|
|
2008-11-13 14:00:12 +01:00
|
|
|
*token = 0xdeadbeef;
|
|
|
|
|
2007-08-04 02:30:17 +02:00
|
|
|
/* FIXME: DebugEventCallback ignored */
|
|
|
|
|
2007-06-08 22:46:27 +02:00
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2008-11-24 10:21:28 +01:00
|
|
|
GpStatus WINAPI GdiplusNotificationHook(ULONG_PTR *token)
|
|
|
|
{
|
|
|
|
FIXME("%p\n", token);
|
|
|
|
return NotificationHook(token);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WINAPI GdiplusNotificationUnhook(ULONG_PTR token)
|
|
|
|
{
|
|
|
|
FIXME("%ld\n", token);
|
2008-11-26 21:37:32 +01:00
|
|
|
NotificationUnhook(token);
|
2008-11-24 10:21:28 +01:00
|
|
|
}
|
|
|
|
|
2007-06-12 17:51:53 +02:00
|
|
|
/*****************************************************
|
|
|
|
* GdiplusShutdown [GDIPLUS.@]
|
|
|
|
*/
|
2010-09-30 20:02:22 +02:00
|
|
|
ULONG WINAPI GdiplusShutdown_wrapper(ULONG_PTR token)
|
|
|
|
{
|
2011-03-16 08:26:52 +01:00
|
|
|
/* Notice the slightly different prototype from the official
|
2011-05-09 09:03:40 +02:00
|
|
|
* signature which forces us to use the _wrapper suffix.
|
2011-03-16 08:26:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* FIXME: no object tracking */
|
2010-09-30 20:02:22 +02:00
|
|
|
|
2011-03-16 08:26:52 +01:00
|
|
|
/* "bricksntiles" expects a return value of 0, which native
|
|
|
|
* coincidentally gives.
|
|
|
|
*/
|
2010-09-30 20:02:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-12 17:51:53 +02:00
|
|
|
/*****************************************************
|
|
|
|
* GdipAlloc [GDIPLUS.@]
|
|
|
|
*/
|
2007-06-08 22:46:27 +02:00
|
|
|
void* WINGDIPAPI GdipAlloc(SIZE_T size)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
}
|
|
|
|
|
2007-06-12 17:51:53 +02:00
|
|
|
/*****************************************************
|
|
|
|
* GdipFree [GDIPLUS.@]
|
|
|
|
*/
|
2007-06-08 22:46:27 +02:00
|
|
|
void WINGDIPAPI GdipFree(void* ptr)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
}
|
2007-06-11 20:51:15 +02:00
|
|
|
|
2007-07-12 03:06:56 +02:00
|
|
|
/* Calculates the bezier points needed to fill in the arc portion starting at
|
|
|
|
* angle start and ending at end. These two angles should be no more than 90
|
|
|
|
* degrees from each other. x1, y1, x2, y2 describes the bounding box (upper
|
|
|
|
* left and width and height). Angles must be in radians. write_first indicates
|
|
|
|
* that the first bezier point should be written out (usually this is false).
|
|
|
|
* pt is the array of GpPointFs that gets written to.
|
|
|
|
**/
|
|
|
|
static void add_arc_part(GpPointF * pt, REAL x1, REAL y1, REAL x2, REAL y2,
|
|
|
|
REAL start, REAL end, BOOL write_first)
|
|
|
|
{
|
|
|
|
REAL center_x, center_y, rad_x, rad_y, cos_start, cos_end,
|
|
|
|
sin_start, sin_end, a, half;
|
|
|
|
INT i;
|
|
|
|
|
|
|
|
rad_x = x2 / 2.0;
|
|
|
|
rad_y = y2 / 2.0;
|
|
|
|
center_x = x1 + rad_x;
|
|
|
|
center_y = y1 + rad_y;
|
|
|
|
|
|
|
|
cos_start = cos(start);
|
|
|
|
cos_end = cos(end);
|
|
|
|
sin_start = sin(start);
|
|
|
|
sin_end = sin(end);
|
|
|
|
|
|
|
|
half = (end - start) / 2.0;
|
|
|
|
a = 4.0 / 3.0 * (1 - cos(half)) / sin(half);
|
|
|
|
|
|
|
|
if(write_first){
|
|
|
|
pt[0].X = cos_start;
|
|
|
|
pt[0].Y = sin_start;
|
|
|
|
}
|
|
|
|
pt[1].X = cos_start - a * sin_start;
|
|
|
|
pt[1].Y = sin_start + a * cos_start;
|
|
|
|
|
|
|
|
pt[3].X = cos_end;
|
|
|
|
pt[3].Y = sin_end;
|
|
|
|
pt[2].X = cos_end + a * sin_end;
|
|
|
|
pt[2].Y = sin_end - a * cos_end;
|
|
|
|
|
|
|
|
/* expand the points back from the unit circle to the ellipse */
|
|
|
|
for(i = (write_first ? 0 : 1); i < 4; i ++){
|
|
|
|
pt[i].X = pt[i].X * rad_x + center_x;
|
|
|
|
pt[i].Y = pt[i].Y * rad_y + center_y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We plot the curve as if it is on a circle then stretch the points. This
|
|
|
|
* adjusts the angles so that when we stretch the points they will end in the
|
|
|
|
* right place. This is only complicated because atan and atan2 do not behave
|
|
|
|
* conveniently. */
|
2020-08-04 15:57:12 +02:00
|
|
|
static REAL unstretch_angle(REAL angle, REAL dia_x, REAL dia_y)
|
2007-07-12 03:06:56 +02:00
|
|
|
{
|
|
|
|
REAL stretched;
|
|
|
|
INT revs_off;
|
|
|
|
|
2020-08-04 15:57:12 +02:00
|
|
|
if(fabs(cos(angle)) < 0.00001 || fabs(sin(angle)) < 0.00001)
|
|
|
|
return angle;
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2020-08-04 15:57:12 +02:00
|
|
|
stretched = gdiplus_atan2(sin(angle) / fabs(dia_y), cos(angle) / fabs(dia_x));
|
|
|
|
revs_off = gdip_round(angle / (2.0 * M_PI)) - gdip_round(stretched / (2.0 * M_PI));
|
2007-07-12 03:06:56 +02:00
|
|
|
stretched += ((REAL)revs_off) * M_PI * 2.0;
|
2020-08-04 15:57:12 +02:00
|
|
|
return stretched;
|
2007-07-12 03:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Stores the bezier points that correspond to the arc in points. If points is
|
|
|
|
* null, just return the number of points needed to represent the arc. */
|
2020-08-04 15:57:12 +02:00
|
|
|
INT arc2polybezier(GpPointF * points, REAL left, REAL top, REAL width, REAL height,
|
|
|
|
REAL start_angle, REAL sweep_angle)
|
2007-07-12 03:06:56 +02:00
|
|
|
{
|
2009-09-04 23:14:32 +02:00
|
|
|
INT i;
|
2020-08-04 15:57:12 +02:00
|
|
|
REAL partial_end_angle, end_angle;
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2020-08-04 15:57:12 +02:00
|
|
|
end_angle = deg2rad(start_angle + sweep_angle);
|
|
|
|
start_angle = deg2rad(start_angle);
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2020-08-04 15:57:12 +02:00
|
|
|
if (width != height)
|
|
|
|
{
|
|
|
|
start_angle = unstretch_angle(start_angle, width, height);
|
|
|
|
end_angle = unstretch_angle(end_angle, width, height);
|
|
|
|
}
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2009-09-04 23:14:32 +02:00
|
|
|
for(i = 0; i < MAX_ARC_PTS - 1; i += 3){
|
2007-07-12 03:06:56 +02:00
|
|
|
/* check if we've overshot the end angle */
|
2020-08-04 15:57:12 +02:00
|
|
|
if( sweep_angle > 0.0 )
|
2009-09-04 23:14:32 +02:00
|
|
|
{
|
2020-08-04 15:57:12 +02:00
|
|
|
if (start_angle >= end_angle) break;
|
|
|
|
partial_end_angle = min(start_angle + M_PI_2, end_angle);
|
2009-09-04 23:14:32 +02:00
|
|
|
}
|
2007-07-12 03:06:56 +02:00
|
|
|
else
|
2009-09-04 23:14:32 +02:00
|
|
|
{
|
2020-08-04 15:57:12 +02:00
|
|
|
if (start_angle <= end_angle) break;
|
|
|
|
partial_end_angle = max(start_angle - M_PI_2, end_angle);
|
2009-09-04 23:14:32 +02:00
|
|
|
}
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2009-09-04 23:14:32 +02:00
|
|
|
if (points)
|
2020-08-04 15:57:12 +02:00
|
|
|
add_arc_part(&points[i], left, top, width, height, start_angle, partial_end_angle, i == 0);
|
2007-07-12 03:06:56 +02:00
|
|
|
|
2020-08-04 15:57:12 +02:00
|
|
|
start_angle = partial_end_angle;
|
2007-07-12 03:06:56 +02:00
|
|
|
}
|
|
|
|
|
2009-09-04 23:14:32 +02:00
|
|
|
if (i == 0) return 0;
|
|
|
|
else return i+1;
|
2007-07-12 03:06:56 +02:00
|
|
|
}
|
|
|
|
|
2007-06-11 20:51:15 +02:00
|
|
|
COLORREF ARGB2COLORREF(ARGB color)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Packing of these color structures:
|
|
|
|
COLORREF: 00bbggrr
|
|
|
|
ARGB: aarrggbb
|
|
|
|
FIXME:doesn't handle alpha channel
|
|
|
|
*/
|
2008-01-07 23:13:19 +01:00
|
|
|
return ((color & 0x0000ff) << 16) +
|
|
|
|
(color & 0x00ff00) +
|
|
|
|
((color & 0xff0000) >> 16);
|
2007-06-11 20:51:15 +02:00
|
|
|
}
|
2007-07-21 02:50:14 +02:00
|
|
|
|
2009-05-20 18:24:18 +02:00
|
|
|
HBITMAP ARGB2BMP(ARGB color)
|
|
|
|
{
|
|
|
|
BITMAPINFO bi;
|
|
|
|
HBITMAP result;
|
|
|
|
RGBQUAD *bits;
|
|
|
|
int alpha;
|
|
|
|
|
|
|
|
if ((color & 0xff000000) == 0xff000000) return 0;
|
|
|
|
|
|
|
|
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
|
|
|
|
bi.bmiHeader.biWidth = 1;
|
|
|
|
bi.bmiHeader.biHeight = 1;
|
|
|
|
bi.bmiHeader.biPlanes = 1;
|
|
|
|
bi.bmiHeader.biBitCount = 32;
|
|
|
|
bi.bmiHeader.biCompression = BI_RGB;
|
|
|
|
bi.bmiHeader.biSizeImage = 0;
|
|
|
|
bi.bmiHeader.biXPelsPerMeter = 0;
|
|
|
|
bi.bmiHeader.biYPelsPerMeter = 0;
|
|
|
|
bi.bmiHeader.biClrUsed = 0;
|
|
|
|
bi.bmiHeader.biClrImportant = 0;
|
|
|
|
|
2012-05-02 12:02:17 +02:00
|
|
|
result = CreateDIBSection(0, &bi, DIB_RGB_COLORS, (void*)&bits, NULL, 0);
|
2009-05-20 18:24:18 +02:00
|
|
|
|
|
|
|
bits[0].rgbReserved = alpha = (color>>24)&0xff;
|
|
|
|
bits[0].rgbRed = ((color>>16)&0xff)*alpha/255;
|
|
|
|
bits[0].rgbGreen = ((color>>8)&0xff)*alpha/255;
|
|
|
|
bits[0].rgbBlue = (color&0xff)*alpha/255;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-07-21 02:50:14 +02:00
|
|
|
/* Like atan2, but puts angle in correct quadrant if dx is 0. */
|
2007-08-03 00:53:23 +02:00
|
|
|
REAL gdiplus_atan2(REAL dy, REAL dx)
|
2007-07-21 02:50:14 +02:00
|
|
|
{
|
|
|
|
if((dx == 0.0) && (dy != 0.0))
|
|
|
|
return dy > 0.0 ? M_PI_2 : -M_PI_2;
|
|
|
|
|
|
|
|
return atan2(dy, dx);
|
|
|
|
}
|
2007-08-08 03:42:00 +02:00
|
|
|
|
|
|
|
GpStatus hresult_to_status(HRESULT res)
|
|
|
|
{
|
|
|
|
switch(res){
|
|
|
|
case S_OK:
|
|
|
|
return Ok;
|
|
|
|
case E_OUTOFMEMORY:
|
|
|
|
return OutOfMemory;
|
|
|
|
case E_INVALIDARG:
|
|
|
|
return InvalidParameter;
|
|
|
|
default:
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
}
|
2007-08-08 03:42:09 +02:00
|
|
|
|
2012-07-16 07:56:30 +02:00
|
|
|
/* converts a given unit to its value in pixels */
|
2021-01-20 03:24:10 +01:00
|
|
|
REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi, BOOL printer_display)
|
2012-07-16 07:56:30 +02:00
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case UnitPixel:
|
|
|
|
case UnitWorld:
|
|
|
|
return units;
|
2021-01-20 03:24:10 +01:00
|
|
|
case UnitDisplay:
|
|
|
|
if (printer_display)
|
|
|
|
return units * dpi / 100.0;
|
|
|
|
else
|
|
|
|
return units;
|
2012-07-16 07:56:30 +02:00
|
|
|
case UnitPoint:
|
2012-07-31 11:48:46 +02:00
|
|
|
return units * dpi / point_per_inch;
|
2012-07-16 07:56:30 +02:00
|
|
|
case UnitInch:
|
|
|
|
return units * dpi;
|
|
|
|
case UnitDocument:
|
|
|
|
return units * dpi / 300.0; /* Per MSDN */
|
|
|
|
case UnitMillimeter:
|
|
|
|
return units * dpi / mm_per_inch;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled unit type: %d\n", unit);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-16 07:57:32 +02:00
|
|
|
/* converts value in pixels to a given unit */
|
2021-01-20 03:24:10 +01:00
|
|
|
REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi, BOOL printer_display)
|
2012-07-16 07:57:32 +02:00
|
|
|
{
|
|
|
|
switch (unit)
|
|
|
|
{
|
|
|
|
case UnitPixel:
|
|
|
|
case UnitWorld:
|
|
|
|
return pixels;
|
2021-01-20 03:24:10 +01:00
|
|
|
case UnitDisplay:
|
|
|
|
if (printer_display)
|
|
|
|
return pixels * 100.0 / dpi;
|
|
|
|
else
|
|
|
|
return pixels;
|
2012-07-16 07:57:32 +02:00
|
|
|
case UnitPoint:
|
2012-07-31 11:48:46 +02:00
|
|
|
return pixels * point_per_inch / dpi;
|
2012-07-16 07:57:32 +02:00
|
|
|
case UnitInch:
|
|
|
|
return pixels / dpi;
|
|
|
|
case UnitDocument:
|
|
|
|
return pixels * 300.0 / dpi;
|
|
|
|
case UnitMillimeter:
|
|
|
|
return pixels * mm_per_inch / dpi;
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled unit type: %d\n", unit);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 03:24:10 +01:00
|
|
|
REAL units_scale(GpUnit from, GpUnit to, REAL dpi, BOOL printer_display)
|
2012-08-09 05:55:19 +02:00
|
|
|
{
|
2021-01-20 03:24:10 +01:00
|
|
|
REAL pixels = units_to_pixels(1.0, from, dpi, printer_display);
|
|
|
|
return pixels_to_units(pixels, to, dpi, printer_display);
|
2012-08-09 05:55:19 +02:00
|
|
|
}
|
|
|
|
|
2008-08-03 00:44:57 +02:00
|
|
|
/* Calculates Bezier points from cardinal spline points. */
|
2013-09-23 00:36:04 +02:00
|
|
|
void calc_curve_bezier(const GpPointF *pts, REAL tension, REAL *x1,
|
2008-08-03 00:44:57 +02:00
|
|
|
REAL *y1, REAL *x2, REAL *y2)
|
|
|
|
{
|
|
|
|
REAL xdiff, ydiff;
|
|
|
|
|
|
|
|
/* calculate tangent */
|
|
|
|
xdiff = pts[2].X - pts[0].X;
|
|
|
|
ydiff = pts[2].Y - pts[0].Y;
|
|
|
|
|
|
|
|
/* apply tangent to get control points */
|
|
|
|
*x1 = pts[1].X - tension * xdiff;
|
|
|
|
*y1 = pts[1].Y - tension * ydiff;
|
|
|
|
*x2 = pts[1].X + tension * xdiff;
|
|
|
|
*y2 = pts[1].Y + tension * ydiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculates Bezier points from cardinal spline endpoints. */
|
|
|
|
void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
|
|
|
|
REAL tension, REAL *x, REAL *y)
|
|
|
|
{
|
|
|
|
/* tangent at endpoints is the line from the endpoint to the adjacent point */
|
2012-08-21 04:02:06 +02:00
|
|
|
*x = gdip_round(tension * (xadj - xend) + xend);
|
|
|
|
*y = gdip_round(tension * (yadj - yend) + yend);
|
2008-08-03 00:44:57 +02:00
|
|
|
}
|
2008-08-05 18:56:30 +02:00
|
|
|
|
|
|
|
/* make sure path has enough space for len more points */
|
|
|
|
BOOL lengthen_path(GpPath *path, INT len)
|
|
|
|
{
|
|
|
|
/* initial allocation */
|
|
|
|
if(path->datalen == 0){
|
|
|
|
path->datalen = len * 2;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
path->pathdata.Points = heap_alloc_zero(path->datalen * sizeof(PointF));
|
2008-08-05 18:56:30 +02:00
|
|
|
if(!path->pathdata.Points) return FALSE;
|
|
|
|
|
2015-10-05 00:22:34 +02:00
|
|
|
path->pathdata.Types = heap_alloc_zero(path->datalen);
|
2008-08-05 18:56:30 +02:00
|
|
|
if(!path->pathdata.Types){
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(path->pathdata.Points);
|
2008-08-05 18:56:30 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* reallocation, double size of arrays */
|
|
|
|
else if(path->datalen - path->pathdata.Count < len){
|
|
|
|
while(path->datalen - path->pathdata.Count < len)
|
|
|
|
path->datalen *= 2;
|
|
|
|
|
2015-10-21 00:53:31 +02:00
|
|
|
path->pathdata.Points = heap_realloc(path->pathdata.Points, path->datalen * sizeof(PointF));
|
2008-08-05 18:56:30 +02:00
|
|
|
if(!path->pathdata.Points) return FALSE;
|
|
|
|
|
2015-10-21 00:53:31 +02:00
|
|
|
path->pathdata.Types = heap_realloc(path->pathdata.Types, path->datalen);
|
2008-08-05 18:56:30 +02:00
|
|
|
if(!path->pathdata.Types) return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-08-27 00:03:27 +02:00
|
|
|
|
2009-08-29 00:21:10 +02:00
|
|
|
void convert_32bppARGB_to_32bppPARGB(UINT width, UINT height,
|
|
|
|
BYTE *dst_bits, INT dst_stride, const BYTE *src_bits, INT src_stride)
|
|
|
|
{
|
2011-10-04 21:11:06 +02:00
|
|
|
INT x, y;
|
2009-08-29 00:21:10 +02:00
|
|
|
for (y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
const BYTE *src=src_bits+y*src_stride;
|
|
|
|
BYTE *dst=dst_bits+y*dst_stride;
|
|
|
|
for (x=0; x<width; x++)
|
|
|
|
{
|
|
|
|
BYTE alpha=src[3];
|
2013-02-25 06:30:32 +01:00
|
|
|
*dst++ = (*src++ * alpha + 127) / 255;
|
|
|
|
*dst++ = (*src++ * alpha + 127) / 255;
|
|
|
|
*dst++ = (*src++ * alpha + 127) / 255;
|
2009-08-29 00:21:10 +02:00
|
|
|
*dst++ = *src++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-27 00:03:27 +02:00
|
|
|
/* recursive deletion of GpRegion nodes */
|
2009-10-19 11:44:39 +02:00
|
|
|
void delete_element(region_element* element)
|
2008-08-27 00:03:27 +02:00
|
|
|
{
|
|
|
|
switch(element->type)
|
|
|
|
{
|
|
|
|
case RegionDataRect:
|
|
|
|
break;
|
|
|
|
case RegionDataPath:
|
2013-11-12 10:16:28 +01:00
|
|
|
GdipDeletePath(element->elementdata.path);
|
2008-08-27 00:03:27 +02:00
|
|
|
break;
|
|
|
|
case RegionDataEmptyRect:
|
|
|
|
case RegionDataInfiniteRect:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
delete_element(element->elementdata.combine.left);
|
|
|
|
delete_element(element->elementdata.combine.right);
|
2015-10-05 00:22:34 +02:00
|
|
|
heap_free(element->elementdata.combine.left);
|
|
|
|
heap_free(element->elementdata.combine.right);
|
2008-08-27 00:03:27 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-13 20:55:46 +02:00
|
|
|
|
2013-09-23 00:36:04 +02:00
|
|
|
const char *debugstr_rectf(const RectF* rc)
|
2009-05-13 20:55:46 +02:00
|
|
|
{
|
|
|
|
if (!rc) return "(null)";
|
|
|
|
return wine_dbg_sprintf("(%0.2f,%0.2f,%0.2f,%0.2f)", rc->X, rc->Y, rc->Width, rc->Height);
|
|
|
|
}
|
2009-12-18 22:45:02 +01:00
|
|
|
|
2013-09-23 00:36:04 +02:00
|
|
|
const char *debugstr_pointf(const PointF* pt)
|
2009-12-18 22:45:02 +01:00
|
|
|
{
|
|
|
|
if (!pt) return "(null)";
|
|
|
|
return wine_dbg_sprintf("(%0.2f,%0.2f)", pt->X, pt->Y);
|
|
|
|
}
|