2007-06-11 18:54:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Google (Evan Stade)
|
|
|
|
*
|
|
|
|
* 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 <math.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "wingdi.h"
|
2007-07-31 02:10:03 +00:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "ocidl.h"
|
|
|
|
#include "olectl.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
|
2007-06-11 18:54:03 +00:00
|
|
|
#include "gdiplus.h"
|
|
|
|
#include "gdiplus_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2007-07-07 20:20:41 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
|
|
|
|
|
|
|
|
/* looks-right constants */
|
2007-06-20 02:31:28 +00:00
|
|
|
#define TENSION_CONST (0.3)
|
2007-07-07 20:20:41 +00:00
|
|
|
#define ANCHOR_WIDTH (2.0)
|
2007-07-06 23:13:49 +00:00
|
|
|
#define MAX_ITERS (50)
|
2007-06-20 02:31:28 +00:00
|
|
|
|
2007-06-18 23:55:51 +00:00
|
|
|
/* Converts angle (in degrees) to x/y coordinates */
|
|
|
|
static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
|
|
|
|
{
|
|
|
|
REAL radAngle, hypotenuse;
|
|
|
|
|
|
|
|
radAngle = deg2rad(angle);
|
|
|
|
hypotenuse = 50.0; /* arbitrary */
|
|
|
|
|
|
|
|
*x = x_0 + cos(radAngle) * hypotenuse;
|
|
|
|
*y = y_0 + sin(radAngle) * hypotenuse;
|
|
|
|
}
|
|
|
|
|
2007-07-20 01:22:51 +00:00
|
|
|
/* Converts from gdiplus path point type to gdi path point type. */
|
|
|
|
static BYTE convert_path_point_type(BYTE type)
|
|
|
|
{
|
|
|
|
BYTE ret;
|
|
|
|
|
|
|
|
switch(type & PathPointTypePathTypeMask){
|
|
|
|
case PathPointTypeBezier:
|
|
|
|
ret = PT_BEZIERTO;
|
|
|
|
break;
|
|
|
|
case PathPointTypeLine:
|
|
|
|
ret = PT_LINETO;
|
|
|
|
break;
|
|
|
|
case PathPointTypeStart:
|
|
|
|
ret = PT_MOVETO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Bad point type\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type & PathPointTypeCloseSubpath)
|
|
|
|
ret |= PT_CLOSEFIGURE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
static REAL convert_unit(HDC hdc, GpUnit unit)
|
|
|
|
{
|
|
|
|
switch(unit)
|
|
|
|
{
|
|
|
|
case UnitInch:
|
|
|
|
return (REAL) GetDeviceCaps(hdc, LOGPIXELSX);
|
|
|
|
case UnitPoint:
|
|
|
|
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0;
|
|
|
|
case UnitDocument:
|
|
|
|
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0;
|
|
|
|
case UnitMillimeter:
|
|
|
|
return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4;
|
|
|
|
case UnitWorld:
|
|
|
|
ERR("cannot convert UnitWorld\n");
|
|
|
|
return 0.0;
|
|
|
|
case UnitPixel:
|
|
|
|
case UnitDisplay:
|
|
|
|
default:
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
|
|
|
|
{
|
|
|
|
HPEN gdipen;
|
|
|
|
REAL width;
|
2007-07-27 23:07:39 +00:00
|
|
|
INT save_state = SaveDC(graphics->hdc), i, numdashes;
|
2007-07-25 00:18:58 +00:00
|
|
|
GpPointF pt[2];
|
2007-07-27 23:07:39 +00:00
|
|
|
DWORD dash_array[MAX_DASHLEN];
|
2007-07-25 00:18:54 +00:00
|
|
|
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
|
2007-07-25 00:18:58 +00:00
|
|
|
/* Get an estimate for the amount the pen width is affected by the world
|
|
|
|
* transform. (This is similar to what some of the wine drivers do.) */
|
|
|
|
pt[0].X = 0.0;
|
|
|
|
pt[0].Y = 0.0;
|
|
|
|
pt[1].X = 1.0;
|
|
|
|
pt[1].Y = 1.0;
|
|
|
|
GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
|
|
|
|
width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
|
|
|
|
(pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
|
|
|
|
|
|
|
|
width *= pen->width * convert_unit(graphics->hdc,
|
2007-07-25 00:18:54 +00:00
|
|
|
pen->unit == UnitWorld ? graphics->unit : pen->unit);
|
|
|
|
|
2007-07-27 23:07:39 +00:00
|
|
|
if(pen->dash == DashStyleCustom){
|
|
|
|
numdashes = min(pen->numdashes, MAX_DASHLEN);
|
|
|
|
|
|
|
|
TRACE("dashes are: ");
|
|
|
|
for(i = 0; i < numdashes; i++){
|
|
|
|
dash_array[i] = roundr(width * pen->dashes[i]);
|
|
|
|
TRACE("%d, ", dash_array[i]);
|
|
|
|
}
|
|
|
|
TRACE("\n and the pen style is %x\n", pen->style);
|
|
|
|
|
|
|
|
gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
|
|
|
|
numdashes, dash_array);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
SelectObject(graphics->hdc, gdipen);
|
|
|
|
|
|
|
|
return save_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_dc(GpGraphics *graphics, INT state)
|
|
|
|
{
|
|
|
|
DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
|
|
|
|
RestoreDC(graphics->hdc, state);
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
/* This helper applies all the changes that the points listed in ptf need in
|
|
|
|
* order to be drawn on the device context. In the end, this should include at
|
|
|
|
* least:
|
|
|
|
* -scaling by page unit
|
|
|
|
* -applying world transformation
|
|
|
|
* -converting from float to int
|
|
|
|
* Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
|
|
|
|
* SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
|
|
|
|
* gdi to draw, and these functions would irreparably mess with line widths.
|
|
|
|
*/
|
|
|
|
static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
|
2007-07-25 00:18:50 +00:00
|
|
|
GpPointF *ptf, INT count)
|
2007-07-24 03:24:53 +00:00
|
|
|
{
|
|
|
|
REAL unitscale;
|
2007-07-25 00:18:50 +00:00
|
|
|
GpMatrix *matrix;
|
2007-07-24 03:24:53 +00:00
|
|
|
int i;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
unitscale = convert_unit(graphics->hdc, graphics->unit);
|
2007-07-24 03:24:53 +00:00
|
|
|
|
2007-07-25 00:18:39 +00:00
|
|
|
/* apply page scale */
|
|
|
|
if(graphics->unit != UnitDisplay)
|
|
|
|
unitscale *= graphics->scale;
|
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
GdipCloneMatrix(graphics->worldtrans, &matrix);
|
|
|
|
GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
|
|
|
|
GdipTransformMatrixPoints(matrix, ptf, count);
|
2007-07-26 02:15:20 +00:00
|
|
|
GdipDeleteMatrix(matrix);
|
2007-07-25 00:18:50 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
for(i = 0; i < count; i++){
|
2007-07-25 00:18:50 +00:00
|
|
|
pti[i].x = roundr(ptf[i].X);
|
|
|
|
pti[i].y = roundr(ptf[i].Y);
|
2007-07-24 03:24:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-18 23:55:51 +00:00
|
|
|
/* GdipDrawPie/GdipFillPie helper function */
|
2007-07-25 00:18:54 +00:00
|
|
|
static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
|
|
|
|
REAL height, REAL startAngle, REAL sweepAngle)
|
2007-06-18 23:55:51 +00:00
|
|
|
{
|
2007-07-24 03:24:53 +00:00
|
|
|
GpPointF ptf[4];
|
|
|
|
POINT pti[4];
|
2007-06-18 23:55:51 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].X = x;
|
|
|
|
ptf[0].Y = y;
|
|
|
|
ptf[1].X = x + width;
|
|
|
|
ptf[1].Y = y + height;
|
|
|
|
|
|
|
|
deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
|
|
|
|
deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
|
2007-06-18 23:55:51 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, pti, ptf, 4);
|
2007-06-18 23:55:51 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
|
|
|
|
pti[2].y, pti[3].x, pti[3].y);
|
2007-06-18 23:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 02:31:28 +00:00
|
|
|
/* GdipDrawCurve helper function.
|
|
|
|
* Calculates Bezier points from cardinal spline points. */
|
|
|
|
static void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GdipDrawCurve helper function.
|
|
|
|
* Calculates Bezier points from cardinal spline endpoints. */
|
|
|
|
static 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 */
|
|
|
|
*x = roundr(tension * (xadj - xend) + xend);
|
|
|
|
*y = roundr(tension * (yadj - yend) + yend);
|
|
|
|
}
|
|
|
|
|
2007-07-07 20:20:41 +00:00
|
|
|
/* Draws the linecap the specified color and size on the hdc. The linecap is in
|
2007-07-21 00:50:02 +00:00
|
|
|
* direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
|
|
|
|
* should not be called on an hdc that has a path you care about. */
|
2007-07-24 03:24:53 +00:00
|
|
|
static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
|
2007-07-20 01:22:51 +00:00
|
|
|
const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
|
2007-07-07 20:20:41 +00:00
|
|
|
{
|
2007-07-25 00:18:58 +00:00
|
|
|
HGDIOBJ oldbrush = NULL, oldpen = NULL;
|
2007-07-20 01:22:51 +00:00
|
|
|
GpMatrix *matrix = NULL;
|
2007-07-25 00:18:58 +00:00
|
|
|
HBRUSH brush = NULL;
|
|
|
|
HPEN pen = NULL;
|
2007-07-24 03:24:53 +00:00
|
|
|
PointF ptf[4], *custptf = NULL;
|
2007-07-20 01:22:51 +00:00
|
|
|
POINT pt[4], *custpt = NULL;
|
|
|
|
BYTE *tp = NULL;
|
2007-07-24 03:24:53 +00:00
|
|
|
REAL theta, dsmall, dbig, dx, dy = 0.0;
|
2007-07-20 01:22:51 +00:00
|
|
|
INT i, count;
|
|
|
|
LOGBRUSH lb;
|
2007-07-25 00:18:58 +00:00
|
|
|
BOOL customstroke;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-21 00:50:14 +00:00
|
|
|
if((x1 == x2) && (y1 == y2))
|
2007-07-07 20:20:41 +00:00
|
|
|
return;
|
|
|
|
|
2007-07-21 00:50:14 +00:00
|
|
|
theta = gdiplus_atan2(y2 - y1, x2 - x1);
|
|
|
|
|
2007-07-25 00:18:58 +00:00
|
|
|
customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
|
|
|
|
if(!customstroke){
|
|
|
|
brush = CreateSolidBrush(color);
|
|
|
|
lb.lbStyle = BS_SOLID;
|
|
|
|
lb.lbColor = color;
|
|
|
|
lb.lbHatch = 0;
|
|
|
|
pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
|
|
|
|
PS_JOIN_MITER, 1, &lb, 0,
|
|
|
|
NULL);
|
|
|
|
oldbrush = SelectObject(graphics->hdc, brush);
|
|
|
|
oldpen = SelectObject(graphics->hdc, pen);
|
|
|
|
}
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
switch(cap){
|
|
|
|
case LineCapFlat:
|
|
|
|
break;
|
|
|
|
case LineCapSquare:
|
|
|
|
case LineCapSquareAnchor:
|
|
|
|
case LineCapDiamondAnchor:
|
|
|
|
size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
|
|
|
|
if(cap == LineCapDiamondAnchor){
|
|
|
|
dsmall = cos(theta + M_PI_2) * size;
|
|
|
|
dbig = sin(theta + M_PI_2) * size;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
dsmall = cos(theta + M_PI_4) * size;
|
|
|
|
dbig = sin(theta + M_PI_4) * size;
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].X = x2 - dsmall;
|
|
|
|
ptf[1].X = x2 + dbig;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].Y = y2 - dbig;
|
|
|
|
ptf[3].Y = y2 + dsmall;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[1].Y = y2 - dsmall;
|
|
|
|
ptf[2].Y = y2 + dbig;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[3].X = x2 - dbig;
|
|
|
|
ptf[2].X = x2 + dsmall;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, pt, ptf, 4);
|
|
|
|
Polygon(graphics->hdc, pt, 4);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case LineCapArrowAnchor:
|
|
|
|
size = size * 4.0 / sqrt(3.0);
|
|
|
|
|
2007-07-20 01:22:47 +00:00
|
|
|
dx = cos(M_PI / 6.0 + theta) * size;
|
|
|
|
dy = sin(M_PI / 6.0 + theta) * size;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].X = x2 - dx;
|
|
|
|
ptf[0].Y = y2 - dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-20 01:22:47 +00:00
|
|
|
dx = cos(- M_PI / 6.0 + theta) * size;
|
|
|
|
dy = sin(- M_PI / 6.0 + theta) * size;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[1].X = x2 - dx;
|
|
|
|
ptf[1].Y = y2 - dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[2].X = x2;
|
|
|
|
ptf[2].Y = y2;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, pt, ptf, 3);
|
|
|
|
Polygon(graphics->hdc, pt, 3);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case LineCapRoundAnchor:
|
|
|
|
dx = dy = ANCHOR_WIDTH * size / 2.0;
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].X = x2 - dx;
|
|
|
|
ptf[0].Y = y2 - dy;
|
|
|
|
ptf[1].X = x2 + dx;
|
|
|
|
ptf[1].Y = y2 + dy;
|
|
|
|
|
|
|
|
transform_and_round_points(graphics, pt, ptf, 2);
|
|
|
|
Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case LineCapTriangle:
|
|
|
|
size = size / 2.0;
|
|
|
|
dx = cos(M_PI_2 + theta) * size;
|
|
|
|
dy = sin(M_PI_2 + theta) * size;
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[0].X = x2 - dx;
|
|
|
|
ptf[0].Y = y2 - dy;
|
|
|
|
ptf[1].X = x2 + dx;
|
|
|
|
ptf[1].Y = y2 + dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-20 01:22:47 +00:00
|
|
|
dx = cos(theta) * size;
|
|
|
|
dy = sin(theta) * size;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[2].X = x2 + dx;
|
|
|
|
ptf[2].Y = y2 + dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, pt, ptf, 3);
|
|
|
|
Polygon(graphics->hdc, pt, 3);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case LineCapRound:
|
2007-07-24 03:24:53 +00:00
|
|
|
dx = dy = size / 2.0;
|
|
|
|
|
|
|
|
ptf[0].X = x2 - dx;
|
|
|
|
ptf[0].Y = y2 - dy;
|
|
|
|
ptf[1].X = x2 + dx;
|
|
|
|
ptf[1].Y = y2 + dy;
|
|
|
|
|
2007-07-20 01:22:47 +00:00
|
|
|
dx = -cos(M_PI_2 + theta) * size;
|
|
|
|
dy = -sin(M_PI_2 + theta) * size;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf[2].X = x2 - dx;
|
|
|
|
ptf[2].Y = y2 - dy;
|
|
|
|
ptf[3].X = x2 + dx;
|
|
|
|
ptf[3].Y = y2 + dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, pt, ptf, 4);
|
|
|
|
Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
|
|
|
|
pt[2].y, pt[3].x, pt[3].y);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
case LineCapCustom:
|
2007-07-20 01:22:51 +00:00
|
|
|
if(!custom)
|
|
|
|
break;
|
|
|
|
|
|
|
|
count = custom->pathdata.Count;
|
|
|
|
custptf = GdipAlloc(count * sizeof(PointF));
|
|
|
|
custpt = GdipAlloc(count * sizeof(POINT));
|
|
|
|
tp = GdipAlloc(count);
|
|
|
|
|
|
|
|
if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
|
|
|
|
goto custend;
|
|
|
|
|
|
|
|
memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
|
|
|
|
|
|
|
|
GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
|
|
|
|
GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
|
|
|
|
MatrixOrderAppend);
|
|
|
|
GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
|
|
|
|
GdipTransformMatrixPoints(matrix, custptf, count);
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
transform_and_round_points(graphics, custpt, custptf, count);
|
|
|
|
|
|
|
|
for(i = 0; i < count; i++)
|
2007-07-20 01:22:51 +00:00
|
|
|
tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
|
|
|
|
|
2007-07-21 00:50:02 +00:00
|
|
|
if(custom->fill){
|
2007-07-24 03:24:53 +00:00
|
|
|
BeginPath(graphics->hdc);
|
|
|
|
PolyDraw(graphics->hdc, custpt, tp, count);
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
StrokeAndFillPath(graphics->hdc);
|
2007-07-21 00:50:02 +00:00
|
|
|
}
|
|
|
|
else
|
2007-07-24 03:24:53 +00:00
|
|
|
PolyDraw(graphics->hdc, custpt, tp, count);
|
2007-07-20 01:22:51 +00:00
|
|
|
|
|
|
|
custend:
|
|
|
|
GdipFree(custptf);
|
|
|
|
GdipFree(custpt);
|
|
|
|
GdipFree(tp);
|
|
|
|
GdipDeleteMatrix(matrix);
|
|
|
|
break;
|
2007-07-07 20:20:41 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:58 +00:00
|
|
|
if(!customstroke){
|
|
|
|
SelectObject(graphics->hdc, oldbrush);
|
|
|
|
SelectObject(graphics->hdc, oldpen);
|
|
|
|
DeleteObject(brush);
|
|
|
|
DeleteObject(pen);
|
|
|
|
}
|
2007-07-07 20:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Shortens the line by the given percent by changing x2, y2.
|
2007-07-21 00:50:07 +00:00
|
|
|
* If percent is > 1.0 then the line will change direction.
|
|
|
|
* If percent is negative it can lengthen the line. */
|
2007-07-07 20:20:41 +00:00
|
|
|
static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
|
|
|
|
{
|
|
|
|
REAL dist, theta, dx, dy;
|
|
|
|
|
|
|
|
if((y1 == *y2) && (x1 == *x2))
|
|
|
|
return;
|
|
|
|
|
2007-07-21 00:50:07 +00:00
|
|
|
dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
|
2007-07-21 00:50:14 +00:00
|
|
|
theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
|
2007-07-07 20:20:41 +00:00
|
|
|
dx = cos(theta) * dist;
|
|
|
|
dy = sin(theta) * dist;
|
|
|
|
|
2007-07-21 00:50:07 +00:00
|
|
|
*x2 = *x2 + dx;
|
|
|
|
*y2 = *y2 + dy;
|
2007-07-07 20:20:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Shortens the line by the given amount by changing x2, y2.
|
2007-07-21 00:50:07 +00:00
|
|
|
* If the amount is greater than the distance, the line will become length 0.
|
|
|
|
* If the amount is negative, it can lengthen the line. */
|
2007-07-07 20:20:41 +00:00
|
|
|
static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
|
|
|
|
{
|
|
|
|
REAL dx, dy, percent;
|
|
|
|
|
|
|
|
dx = *x2 - x1;
|
|
|
|
dy = *y2 - y1;
|
|
|
|
if(dx == 0 && dy == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
percent = amt / sqrt(dx * dx + dy * dy);
|
|
|
|
if(percent >= 1.0){
|
|
|
|
*x2 = x1;
|
|
|
|
*y2 = y1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
shorten_line_percent(x1, y1, x2, y2, percent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draws lines between the given points, and if caps is true then draws an endcap
|
|
|
|
* at the end of the last line. FIXME: Startcaps not implemented. */
|
2007-07-24 03:24:53 +00:00
|
|
|
static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
|
|
|
|
GDIPCONST GpPointF * pt, INT count, BOOL caps)
|
2007-07-07 20:20:41 +00:00
|
|
|
{
|
2007-07-21 00:50:11 +00:00
|
|
|
POINT *pti = NULL;
|
|
|
|
GpPointF *ptcopy = NULL;
|
2007-07-12 01:07:44 +00:00
|
|
|
GpStatus status = GenericError;
|
|
|
|
|
|
|
|
if(!count)
|
|
|
|
return Ok;
|
|
|
|
|
|
|
|
pti = GdipAlloc(count * sizeof(POINT));
|
2007-07-21 00:50:11 +00:00
|
|
|
ptcopy = GdipAlloc(count * sizeof(GpPointF));
|
2007-07-12 01:07:44 +00:00
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
if(!pti || !ptcopy){
|
2007-07-12 01:07:44 +00:00
|
|
|
status = OutOfMemory;
|
|
|
|
goto end;
|
|
|
|
}
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
memcpy(ptcopy, pt, count * sizeof(GpPointF));
|
2007-07-24 03:24:53 +00:00
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
if(caps){
|
2007-07-07 20:20:41 +00:00
|
|
|
if(pen->endcap == LineCapArrowAnchor)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
|
|
|
|
&ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
|
2007-07-21 00:50:07 +00:00
|
|
|
else if((pen->endcap == LineCapCustom) && pen->customend)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
|
|
|
|
&ptcopy[count-1].X, &ptcopy[count-1].Y,
|
|
|
|
pen->customend->inset * pen->width);
|
|
|
|
|
|
|
|
if(pen->startcap == LineCapArrowAnchor)
|
|
|
|
shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
|
|
|
|
&ptcopy[0].X, &ptcopy[0].Y, pen->width);
|
|
|
|
else if((pen->startcap == LineCapCustom) && pen->customstart)
|
|
|
|
shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
|
|
|
|
&ptcopy[0].X, &ptcopy[0].Y,
|
2007-07-21 00:50:07 +00:00
|
|
|
pen->customend->inset * pen->width);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
|
|
|
|
pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);\
|
2007-07-07 20:20:41 +00:00
|
|
|
}
|
2007-07-25 00:18:50 +00:00
|
|
|
|
|
|
|
transform_and_round_points(graphics, pti, ptcopy, count);
|
2007-07-07 20:20:41 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
Polyline(graphics->hdc, pti, count);
|
2007-07-12 01:07:44 +00:00
|
|
|
|
|
|
|
end:
|
2007-07-07 20:20:41 +00:00
|
|
|
GdipFree(pti);
|
2007-07-21 00:50:11 +00:00
|
|
|
GdipFree(ptcopy);
|
2007-07-12 01:07:44 +00:00
|
|
|
|
|
|
|
return status;
|
2007-07-07 20:20:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 23:13:49 +00:00
|
|
|
/* Conducts a linear search to find the bezier points that will back off
|
|
|
|
* the endpoint of the curve by a distance of amt. Linear search works
|
|
|
|
* better than binary in this case because there are multiple solutions,
|
|
|
|
* and binary searches often find a bad one. I don't think this is what
|
|
|
|
* Windows does but short of rendering the bezier without GDI's help it's
|
2007-07-21 00:50:11 +00:00
|
|
|
* the best we can do. If rev then work from the start of the passed points
|
|
|
|
* instead of the end. */
|
|
|
|
static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
|
2007-07-06 23:13:49 +00:00
|
|
|
{
|
|
|
|
GpPointF origpt[4];
|
2007-07-21 00:50:11 +00:00
|
|
|
REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
|
|
|
|
INT i, first = 0, second = 1, third = 2, fourth = 3;
|
|
|
|
|
|
|
|
if(rev){
|
|
|
|
first = 3;
|
|
|
|
second = 2;
|
|
|
|
third = 1;
|
|
|
|
fourth = 0;
|
|
|
|
}
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
origx = pt[fourth].X;
|
|
|
|
origy = pt[fourth].Y;
|
2007-07-06 23:13:49 +00:00
|
|
|
memcpy(origpt, pt, sizeof(GpPointF) * 4);
|
|
|
|
|
|
|
|
for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
|
|
|
|
/* reset bezier points to original values */
|
|
|
|
memcpy(pt, origpt, sizeof(GpPointF) * 4);
|
|
|
|
/* Perform magic on bezier points. Order is important here.*/
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
|
|
|
|
shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
|
|
|
|
shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
|
|
|
|
shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
|
|
|
|
shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
|
|
|
|
shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
dx = pt[fourth].X - origx;
|
|
|
|
dy = pt[fourth].Y - origy;
|
2007-07-06 23:13:49 +00:00
|
|
|
|
|
|
|
diff = sqrt(dx * dx + dy * dy);
|
|
|
|
percent += 0.0005 * amt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draws bezier curves between given points, and if caps is true then draws an
|
|
|
|
* endcap at the end of the last line. FIXME: Startcaps not implemented. */
|
2007-07-24 03:24:53 +00:00
|
|
|
static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
|
|
|
|
GDIPCONST GpPointF * pt, INT count, BOOL caps)
|
2007-07-06 23:13:49 +00:00
|
|
|
{
|
2007-07-21 00:50:07 +00:00
|
|
|
POINT *pti, curpos;
|
2007-07-21 00:50:11 +00:00
|
|
|
GpPointF *ptcopy;
|
2007-07-21 00:50:07 +00:00
|
|
|
REAL x, y;
|
2007-07-12 01:07:39 +00:00
|
|
|
GpStatus status = GenericError;
|
|
|
|
|
|
|
|
if(!count)
|
|
|
|
return Ok;
|
|
|
|
|
|
|
|
pti = GdipAlloc(count * sizeof(POINT));
|
2007-07-21 00:50:11 +00:00
|
|
|
ptcopy = GdipAlloc(count * sizeof(GpPointF));
|
2007-07-12 01:07:39 +00:00
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
if(!pti || !ptcopy){
|
2007-07-12 01:07:39 +00:00
|
|
|
status = OutOfMemory;
|
|
|
|
goto end;
|
|
|
|
}
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
memcpy(ptcopy, pt, count * sizeof(GpPointF));
|
2007-07-24 03:24:53 +00:00
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
if(caps){
|
2007-07-06 23:13:49 +00:00
|
|
|
if(pen->endcap == LineCapArrowAnchor)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
|
2007-07-21 00:50:07 +00:00
|
|
|
/* FIXME The following is seemingly correct only for baseinset < 0 or
|
|
|
|
* baseinset > ~3. With smaller baseinsets, windows actually
|
|
|
|
* lengthens the bezier line instead of shortening it. */
|
|
|
|
else if((pen->endcap == LineCapCustom) && pen->customend){
|
|
|
|
x = pt[count - 1].X;
|
|
|
|
y = pt[count - 1].Y;
|
|
|
|
shorten_line_amt(pt[count - 2].X, pt[count - 2].Y, &x, &y,
|
|
|
|
pen->width * pen->customend->inset);
|
2007-07-24 03:24:53 +00:00
|
|
|
MoveToEx(graphics->hdc, roundr(pt[count - 1].X), roundr(pt[count - 1].Y), &curpos);
|
|
|
|
LineTo(graphics->hdc, roundr(x), roundr(y));
|
|
|
|
MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
|
2007-07-21 00:50:07 +00:00
|
|
|
}
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
if(pen->startcap == LineCapArrowAnchor)
|
|
|
|
shorten_bezier_amt(ptcopy, pen->width, TRUE);
|
|
|
|
else if((pen->startcap == LineCapCustom) && pen->customstart){
|
|
|
|
x = ptcopy[0].X;
|
|
|
|
y = ptcopy[0].Y;
|
|
|
|
shorten_line_amt(ptcopy[1].X, ptcopy[1].Y, &x, &y,
|
|
|
|
pen->width * pen->customend->inset);
|
2007-07-24 03:24:53 +00:00
|
|
|
MoveToEx(graphics->hdc, roundr(pt[0].X), roundr(pt[0].Y), &curpos);
|
|
|
|
LineTo(graphics->hdc, roundr(x), roundr(y));
|
|
|
|
MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
|
2007-07-21 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 01:08:26 +00:00
|
|
|
/* the direction of the line cap is parallel to the direction at the
|
|
|
|
* end of the bezier (which, if it has been shortened, is not the same
|
|
|
|
* as the direction from pt[count-2] to pt[count-1]) */
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
|
|
|
|
pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
|
2007-07-12 01:08:26 +00:00
|
|
|
pt[count - 1].X, pt[count - 1].Y);
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[0].X - (ptcopy[0].X - ptcopy[1].X),
|
|
|
|
pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
|
2007-07-06 23:13:49 +00:00
|
|
|
}
|
2007-07-25 00:18:50 +00:00
|
|
|
|
|
|
|
transform_and_round_points(graphics, pti, ptcopy, count);
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
PolyBezier(graphics->hdc, pti, count);
|
2007-07-12 01:07:39 +00:00
|
|
|
|
|
|
|
status = Ok;
|
|
|
|
|
|
|
|
end:
|
2007-07-06 23:13:49 +00:00
|
|
|
GdipFree(pti);
|
2007-07-21 00:50:11 +00:00
|
|
|
GdipFree(ptcopy);
|
2007-07-12 01:07:39 +00:00
|
|
|
|
|
|
|
return status;
|
2007-07-06 23:13:49 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 01:07:34 +00:00
|
|
|
/* Draws a combination of bezier curves and lines between points. */
|
2007-07-24 03:24:53 +00:00
|
|
|
static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
|
2007-07-12 01:07:34 +00:00
|
|
|
GDIPCONST BYTE * types, INT count, BOOL caps)
|
|
|
|
{
|
2007-07-21 00:50:07 +00:00
|
|
|
POINT *pti = GdipAlloc(count * sizeof(POINT)), curpos;
|
2007-07-12 01:07:34 +00:00
|
|
|
BYTE *tp = GdipAlloc(count);
|
2007-07-21 00:50:11 +00:00
|
|
|
GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
|
2007-07-12 01:07:34 +00:00
|
|
|
REAL x = pt[count - 1].X, y = pt[count - 1].Y;
|
2007-07-21 00:50:11 +00:00
|
|
|
INT i, j;
|
2007-07-12 01:07:34 +00:00
|
|
|
GpStatus status = GenericError;
|
|
|
|
|
|
|
|
if(!count){
|
|
|
|
status = Ok;
|
|
|
|
goto end;
|
|
|
|
}
|
2007-07-21 00:50:11 +00:00
|
|
|
if(!pti || !tp || !ptcopy){
|
2007-07-12 01:07:34 +00:00
|
|
|
status = OutOfMemory;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2007-07-21 00:50:11 +00:00
|
|
|
for(i = 1; i < count; i++){
|
2007-07-12 01:07:34 +00:00
|
|
|
if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
|
|
|
|
if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
|
|
|
|
|| !(types[i + 1] & PathPointTypeBezier)){
|
|
|
|
ERR("Bad bezier points\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:50 +00:00
|
|
|
memcpy(ptcopy, pt, count * sizeof(GpPointF));
|
|
|
|
|
2007-07-14 00:51:49 +00:00
|
|
|
/* If we are drawing caps, go through the points and adjust them accordingly,
|
|
|
|
* and draw the caps. */
|
|
|
|
if(caps){
|
|
|
|
switch(types[count - 1] & PathPointTypePathTypeMask){
|
|
|
|
case PathPointTypeBezier:
|
|
|
|
if(pen->endcap == LineCapArrowAnchor)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
|
2007-07-21 00:50:07 +00:00
|
|
|
else if((pen->endcap == LineCapCustom) && pen->customend){
|
|
|
|
x = pt[count - 1].X;
|
|
|
|
y = pt[count - 1].Y;
|
|
|
|
shorten_line_amt(pt[count - 2].X, pt[count - 2].Y, &x, &y,
|
|
|
|
pen->width * pen->customend->inset);
|
2007-07-24 03:24:53 +00:00
|
|
|
MoveToEx(graphics->hdc, roundr(pt[count - 1].X),
|
|
|
|
roundr(pt[count - 1].Y), &curpos);
|
|
|
|
LineTo(graphics->hdc, roundr(x), roundr(y));
|
|
|
|
MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
|
2007-07-21 00:50:07 +00:00
|
|
|
}
|
2007-07-12 01:07:34 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
|
|
|
|
pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
|
2007-07-14 00:51:49 +00:00
|
|
|
pt[count - 1].X, pt[count - 1].Y);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case PathPointTypeLine:
|
|
|
|
if(pen->endcap == LineCapArrowAnchor)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
|
|
|
|
&ptcopy[count - 1].X, &ptcopy[count - 1].Y,
|
2007-07-14 00:51:49 +00:00
|
|
|
pen->width);
|
2007-07-21 00:50:07 +00:00
|
|
|
else if((pen->endcap == LineCapCustom) && pen->customend)
|
2007-07-21 00:50:11 +00:00
|
|
|
shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
|
|
|
|
&ptcopy[count - 1].X, &ptcopy[count - 1].Y,
|
2007-07-21 00:50:07 +00:00
|
|
|
pen->customend->inset * pen->width);
|
2007-07-14 00:51:49 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
|
2007-07-20 01:22:51 +00:00
|
|
|
pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
|
|
|
|
pt[count - 1].Y);
|
2007-07-14 00:51:49 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Bad path last point\n");
|
|
|
|
goto end;
|
2007-07-12 01:07:34 +00:00
|
|
|
}
|
2007-07-21 00:50:11 +00:00
|
|
|
|
|
|
|
/* Find start of points */
|
|
|
|
for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
|
|
|
|
== PathPointTypeStart); j++);
|
|
|
|
|
|
|
|
switch(types[j] & PathPointTypePathTypeMask){
|
|
|
|
case PathPointTypeBezier:
|
|
|
|
if(pen->startcap == LineCapArrowAnchor)
|
|
|
|
shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
|
|
|
|
else if((pen->startcap == LineCapCustom) && pen->customstart){
|
|
|
|
x = pt[j - 1].X;
|
|
|
|
y = pt[j - 1].Y;
|
|
|
|
shorten_line_amt(ptcopy[j].X, ptcopy[j].Y, &x, &y,
|
|
|
|
pen->width * pen->customstart->inset);
|
2007-07-24 03:24:53 +00:00
|
|
|
MoveToEx(graphics->hdc, roundr(pt[j - 1].X), roundr(pt[j - 1].Y), &curpos);
|
|
|
|
LineTo(graphics->hdc, roundr(x), roundr(y));
|
|
|
|
MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
|
2007-07-21 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
|
|
|
|
pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
|
|
|
|
pt[j - 1].X, pt[j - 1].Y);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case PathPointTypeLine:
|
|
|
|
if(pen->startcap == LineCapArrowAnchor)
|
|
|
|
shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
|
|
|
|
&ptcopy[j - 1].X, &ptcopy[j - 1].Y,
|
|
|
|
pen->width);
|
|
|
|
else if((pen->startcap == LineCapCustom) && pen->customstart)
|
|
|
|
shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
|
|
|
|
&ptcopy[j - 1].X, &ptcopy[j - 1].Y,
|
|
|
|
pen->customstart->inset * pen->width);
|
|
|
|
|
2007-07-27 23:07:50 +00:00
|
|
|
draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
|
2007-07-21 00:50:11 +00:00
|
|
|
pt[j].X, pt[j].Y, pt[j - 1].X,
|
|
|
|
pt[j - 1].Y);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Bad path points\n");
|
|
|
|
goto end;
|
|
|
|
}
|
2007-07-12 01:07:34 +00:00
|
|
|
}
|
2007-07-25 00:18:50 +00:00
|
|
|
|
|
|
|
transform_and_round_points(graphics, pti, ptcopy, count);
|
2007-07-12 01:07:34 +00:00
|
|
|
|
|
|
|
for(i = 0; i < count; i++){
|
|
|
|
tp[i] = convert_path_point_type(types[i]);
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
PolyDraw(graphics->hdc, pti, tp, count);
|
2007-07-12 01:07:34 +00:00
|
|
|
|
|
|
|
status = Ok;
|
|
|
|
|
|
|
|
end:
|
|
|
|
GdipFree(pti);
|
2007-07-21 00:50:11 +00:00
|
|
|
GdipFree(ptcopy);
|
2007-07-12 01:07:34 +00:00
|
|
|
GdipFree(tp);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-06-11 18:54:03 +00:00
|
|
|
GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
|
|
|
|
{
|
2007-07-25 00:18:47 +00:00
|
|
|
GpStatus retval;
|
|
|
|
|
2007-06-11 18:54:03 +00:00
|
|
|
if(hdc == NULL)
|
|
|
|
return OutOfMemory;
|
|
|
|
|
|
|
|
if(graphics == NULL)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-06-23 02:27:02 +00:00
|
|
|
*graphics = GdipAlloc(sizeof(GpGraphics));
|
|
|
|
if(!*graphics) return OutOfMemory;
|
|
|
|
|
2007-07-25 00:18:47 +00:00
|
|
|
if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
|
|
|
|
GdipFree(*graphics);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-06-11 18:54:03 +00:00
|
|
|
(*graphics)->hdc = hdc;
|
|
|
|
(*graphics)->hwnd = NULL;
|
2007-07-14 00:51:13 +00:00
|
|
|
(*graphics)->smoothing = SmoothingModeDefault;
|
2007-07-14 00:51:25 +00:00
|
|
|
(*graphics)->compqual = CompositingQualityDefault;
|
2007-07-14 00:51:29 +00:00
|
|
|
(*graphics)->interpolation = InterpolationModeDefault;
|
2007-07-14 00:51:33 +00:00
|
|
|
(*graphics)->pixeloffset = PixelOffsetModeDefault;
|
2007-07-24 03:24:41 +00:00
|
|
|
(*graphics)->unit = UnitDisplay;
|
2007-07-25 00:18:39 +00:00
|
|
|
(*graphics)->scale = 1.0;
|
2007-06-11 18:54:03 +00:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
|
|
|
|
{
|
|
|
|
GpStatus ret;
|
|
|
|
|
|
|
|
if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
(*graphics)->hwnd = hwnd;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:05 +00:00
|
|
|
GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
|
|
|
|
GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
static int calls;
|
|
|
|
|
|
|
|
if(!hemf || !metafile)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
|
|
|
FIXME("not implemented\n");
|
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:19:15 +00:00
|
|
|
GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
|
|
|
|
GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
|
|
|
|
{
|
|
|
|
static int calls;
|
2007-08-01 02:15:12 +00:00
|
|
|
IStream *stream = NULL;
|
2007-07-31 02:10:03 +00:00
|
|
|
UINT read;
|
|
|
|
BYTE* copy;
|
|
|
|
METAFILEPICT mfp;
|
|
|
|
HENHMETAFILE hemf;
|
2007-08-01 02:15:12 +00:00
|
|
|
GpStatus retval = GenericError;
|
2007-07-25 00:19:15 +00:00
|
|
|
|
|
|
|
if(!hwmf || !metafile || !placeable)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
if(!(calls++))
|
2007-07-31 02:10:03 +00:00
|
|
|
FIXME("partially implemented\n");
|
2007-07-25 00:19:15 +00:00
|
|
|
|
2007-07-31 02:10:03 +00:00
|
|
|
if(placeable->Inch != INCH_HIMETRIC)
|
|
|
|
return NotImplemented;
|
|
|
|
|
|
|
|
mfp.mm = MM_HIMETRIC;
|
|
|
|
mfp.xExt = placeable->BoundingBox.Right - placeable->BoundingBox.Left;
|
|
|
|
mfp.yExt = placeable->BoundingBox.Bottom - placeable->BoundingBox.Top;
|
|
|
|
mfp.hMF = NULL;
|
|
|
|
|
|
|
|
read = GetMetaFileBitsEx(hwmf, 0, NULL);
|
|
|
|
if(!read)
|
|
|
|
return GenericError;
|
|
|
|
copy = GdipAlloc(read);
|
|
|
|
GetMetaFileBitsEx(hwmf, read, copy);
|
|
|
|
|
|
|
|
hemf = SetWinMetaFileBits(read, copy, NULL, &mfp);
|
|
|
|
GdipFree(copy);
|
|
|
|
|
|
|
|
read = GetEnhMetaFileBits(hemf, 0, NULL);
|
|
|
|
copy = GdipAlloc(read);
|
|
|
|
GetEnhMetaFileBits(hemf, read, copy);
|
|
|
|
DeleteEnhMetaFile(hemf);
|
|
|
|
|
|
|
|
if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
|
|
|
|
ERR("could not make stream\n");
|
2007-08-01 02:15:12 +00:00
|
|
|
goto end;
|
2007-07-31 02:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*metafile = GdipAlloc(sizeof(GpMetafile));
|
2007-08-01 02:15:12 +00:00
|
|
|
if(!*metafile){
|
|
|
|
retval = OutOfMemory;
|
|
|
|
goto end;
|
|
|
|
}
|
2007-07-31 02:10:03 +00:00
|
|
|
|
|
|
|
if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
|
|
|
|
(LPVOID*) &((*metafile)->image.picture)) != S_OK){
|
|
|
|
GdipFree(*metafile);
|
2007-08-01 02:15:12 +00:00
|
|
|
goto end;
|
2007-07-31 02:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
(*metafile)->image.type = ImageTypeMetafile;
|
2007-07-31 02:09:57 +00:00
|
|
|
(*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
|
|
|
|
(*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch);
|
|
|
|
(*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
|
|
|
|
- placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
|
|
|
|
(*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
|
|
|
|
- placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
|
|
|
|
(*metafile)->unit = UnitInch;
|
|
|
|
|
2007-07-31 02:10:03 +00:00
|
|
|
if(delete)
|
|
|
|
DeleteMetaFile(hwmf);
|
|
|
|
|
2007-08-01 02:15:12 +00:00
|
|
|
retval = Ok;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release(stream);
|
|
|
|
GdipFree(copy);
|
|
|
|
return retval;
|
2007-07-25 00:19:15 +00:00
|
|
|
}
|
|
|
|
|
2007-06-11 18:54:03 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
|
|
|
|
{
|
|
|
|
if(!graphics) return InvalidParameter;
|
|
|
|
if(graphics->hwnd)
|
|
|
|
ReleaseDC(graphics->hwnd, graphics->hdc);
|
|
|
|
|
2007-07-25 00:18:47 +00:00
|
|
|
GdipDeleteMatrix(graphics->worldtrans);
|
2007-06-11 18:54:03 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, graphics);
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2007-06-12 17:44:31 +00:00
|
|
|
|
2007-06-20 02:31:19 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
|
|
|
|
REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
|
|
|
|
{
|
2007-07-12 01:07:09 +00:00
|
|
|
INT save_state, num_pts;
|
|
|
|
GpPointF points[MAX_ARC_PTS];
|
2007-07-12 01:07:39 +00:00
|
|
|
GpStatus retval;
|
2007-06-20 02:31:19 +00:00
|
|
|
|
|
|
|
if(!graphics || !pen)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-12 01:07:09 +00:00
|
|
|
num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
|
2007-06-20 02:31:19 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-06-20 02:31:19 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
|
2007-06-20 02:31:19 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-20 02:31:19 +00:00
|
|
|
|
2007-07-12 01:07:39 +00:00
|
|
|
return retval;
|
2007-06-20 02:31:19 +00:00
|
|
|
}
|
|
|
|
|
2007-06-16 04:27:38 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
|
|
|
|
REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
|
|
|
|
{
|
2007-07-06 23:13:49 +00:00
|
|
|
INT save_state;
|
|
|
|
GpPointF pt[4];
|
2007-07-12 01:07:39 +00:00
|
|
|
GpStatus retval;
|
2007-06-16 04:27:38 +00:00
|
|
|
|
|
|
|
if(!graphics || !pen)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-06 23:13:49 +00:00
|
|
|
pt[0].X = x1;
|
|
|
|
pt[0].Y = y1;
|
|
|
|
pt[1].X = x2;
|
|
|
|
pt[1].Y = y2;
|
|
|
|
pt[2].X = x3;
|
|
|
|
pt[2].Y = y3;
|
|
|
|
pt[3].X = x4;
|
|
|
|
pt[3].Y = y4;
|
2007-06-16 04:27:38 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-06-16 04:27:38 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
|
2007-07-06 23:13:49 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-16 04:27:38 +00:00
|
|
|
|
2007-07-12 01:07:39 +00:00
|
|
|
return retval;
|
2007-06-16 04:27:38 +00:00
|
|
|
}
|
|
|
|
|
2007-06-20 02:31:28 +00:00
|
|
|
/* Approximates cardinal spline with Bezier curves. */
|
|
|
|
GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
|
|
|
|
GDIPCONST GpPointF *points, INT count, REAL tension)
|
|
|
|
{
|
|
|
|
/* PolyBezier expects count*3-2 points. */
|
2007-07-10 03:54:23 +00:00
|
|
|
INT i, len_pt = count*3-2, save_state;
|
|
|
|
GpPointF *pt;
|
2007-06-20 02:31:28 +00:00
|
|
|
REAL x1, x2, y1, y2;
|
2007-07-12 01:07:39 +00:00
|
|
|
GpStatus retval;
|
2007-06-20 02:31:28 +00:00
|
|
|
|
|
|
|
if(!graphics || !pen)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-10 03:54:23 +00:00
|
|
|
pt = GdipAlloc(len_pt * sizeof(GpPointF));
|
2007-06-20 02:31:28 +00:00
|
|
|
tension = tension * TENSION_CONST;
|
|
|
|
|
|
|
|
calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
|
|
|
|
tension, &x1, &y1);
|
|
|
|
|
2007-07-10 03:54:23 +00:00
|
|
|
pt[0].X = points[0].X;
|
|
|
|
pt[0].Y = points[0].Y;
|
|
|
|
pt[1].X = x1;
|
|
|
|
pt[1].Y = y1;
|
2007-06-20 02:31:28 +00:00
|
|
|
|
|
|
|
for(i = 0; i < count-2; i++){
|
|
|
|
calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
|
|
|
|
|
2007-07-10 03:54:23 +00:00
|
|
|
pt[3*i+2].X = x1;
|
|
|
|
pt[3*i+2].Y = y1;
|
|
|
|
pt[3*i+3].X = points[i+1].X;
|
|
|
|
pt[3*i+3].Y = points[i+1].Y;
|
|
|
|
pt[3*i+4].X = x2;
|
|
|
|
pt[3*i+4].Y = y2;
|
2007-06-20 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
|
|
|
|
points[count-2].X, points[count-2].Y, tension, &x1, &y1);
|
|
|
|
|
2007-07-10 03:54:23 +00:00
|
|
|
pt[len_pt-2].X = x1;
|
|
|
|
pt[len_pt-2].Y = y1;
|
|
|
|
pt[len_pt-1].X = points[count-1].X;
|
|
|
|
pt[len_pt-1].Y = points[count-1].Y;
|
2007-06-20 02:31:28 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-06-20 02:31:28 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
|
2007-06-20 02:31:28 +00:00
|
|
|
|
2007-07-10 03:54:23 +00:00
|
|
|
GdipFree(pt);
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-20 02:31:28 +00:00
|
|
|
|
2007-07-12 01:07:39 +00:00
|
|
|
return retval;
|
2007-06-20 02:31:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-31 02:10:07 +00:00
|
|
|
/* FIXME: partially implemented */
|
2007-07-31 02:09:45 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
|
2007-07-31 02:10:07 +00:00
|
|
|
GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
|
|
|
|
REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
|
|
|
|
DrawImageAbort callback, VOID * callbackData)
|
2007-07-31 02:09:45 +00:00
|
|
|
{
|
2007-07-31 02:10:07 +00:00
|
|
|
GpPointF ptf[3];
|
|
|
|
POINT pti[3];
|
2007-08-01 02:16:23 +00:00
|
|
|
REAL dx, dy;
|
2007-07-31 02:09:45 +00:00
|
|
|
|
2007-07-31 02:10:07 +00:00
|
|
|
TRACE("%p %p %p %d %f %f %f %f %d %p %p %p\n", graphics, image, points, count,
|
|
|
|
srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
|
|
|
|
callbackData);
|
2007-07-31 02:09:45 +00:00
|
|
|
|
2007-07-31 02:10:07 +00:00
|
|
|
if(!graphics || !image || !points || !imageAttributes || count != 3)
|
|
|
|
return InvalidParameter;
|
2007-07-31 02:09:45 +00:00
|
|
|
|
2007-08-01 02:16:23 +00:00
|
|
|
if(srcUnit == UnitInch)
|
|
|
|
dx = dy = (REAL) INCH_HIMETRIC;
|
|
|
|
else if(srcUnit == UnitPixel){
|
|
|
|
dx = ((REAL) INCH_HIMETRIC) /
|
|
|
|
((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
|
|
|
|
dy = ((REAL) INCH_HIMETRIC) /
|
|
|
|
((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
|
|
|
|
}
|
|
|
|
else
|
2007-07-31 02:10:07 +00:00
|
|
|
return NotImplemented;
|
|
|
|
|
|
|
|
memcpy(ptf, points, 3 * sizeof(GpPointF));
|
|
|
|
transform_and_round_points(graphics, pti, ptf, 3);
|
|
|
|
|
2007-08-01 02:16:23 +00:00
|
|
|
/* IPicture renders bitmaps with the y-axis reversed
|
|
|
|
* FIXME: flipping for unknown image type might not be correct. */
|
|
|
|
if(image->type != ImageTypeMetafile){
|
|
|
|
INT temp;
|
|
|
|
temp = pti[0].y;
|
|
|
|
pti[0].y = pti[2].y;
|
|
|
|
pti[2].y = temp;
|
|
|
|
}
|
|
|
|
|
2007-07-31 02:10:07 +00:00
|
|
|
if(IPicture_Render(image->picture, graphics->hdc,
|
|
|
|
pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
|
2007-08-01 02:16:23 +00:00
|
|
|
srcx * dx, srcy * dy,
|
|
|
|
srcwidth * dx, srcheight * dy,
|
2007-07-31 02:10:07 +00:00
|
|
|
NULL) != S_OK){
|
|
|
|
if(callback)
|
|
|
|
callback(callbackData);
|
|
|
|
return GenericError;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Ok;
|
2007-07-31 02:09:45 +00:00
|
|
|
}
|
|
|
|
|
2007-06-12 17:44:31 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
|
|
|
|
INT y1, INT x2, INT y2)
|
|
|
|
{
|
2007-07-02 22:13:05 +00:00
|
|
|
INT save_state;
|
2007-07-07 20:20:41 +00:00
|
|
|
GpPointF pt[2];
|
2007-07-12 01:07:44 +00:00
|
|
|
GpStatus retval;
|
2007-06-12 17:44:31 +00:00
|
|
|
|
|
|
|
if(!pen || !graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-07 20:20:41 +00:00
|
|
|
pt[0].X = (REAL)x1;
|
|
|
|
pt[0].Y = (REAL)y1;
|
|
|
|
pt[1].X = (REAL)x2;
|
|
|
|
pt[1].Y = (REAL)y2;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-07-02 22:13:05 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_polyline(graphics, pen, pt, 2, TRUE);
|
2007-07-02 22:13:05 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-12 17:44:31 +00:00
|
|
|
|
2007-07-12 01:07:44 +00:00
|
|
|
return retval;
|
2007-06-12 17:44:31 +00:00
|
|
|
}
|
2007-06-12 17:51:20 +00:00
|
|
|
|
2007-06-21 23:15:13 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
|
|
|
|
GpPointF *points, INT count)
|
|
|
|
{
|
2007-07-12 01:07:16 +00:00
|
|
|
INT save_state;
|
2007-07-12 01:07:44 +00:00
|
|
|
GpStatus retval;
|
2007-06-21 23:15:13 +00:00
|
|
|
|
|
|
|
if(!pen || !graphics || (count < 2))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-06-21 23:15:13 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_polyline(graphics, pen, points, count, TRUE);
|
2007-06-21 23:15:13 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-21 23:15:13 +00:00
|
|
|
|
2007-07-12 01:07:44 +00:00
|
|
|
return retval;
|
2007-06-21 23:15:13 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 01:07:34 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
|
|
|
|
{
|
2007-07-14 00:51:49 +00:00
|
|
|
INT save_state;
|
2007-07-12 01:07:34 +00:00
|
|
|
GpStatus retval;
|
|
|
|
|
|
|
|
if(!pen || !graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-07-12 01:07:34 +00:00
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_poly(graphics, pen, path->pathdata.Points,
|
2007-07-14 00:51:49 +00:00
|
|
|
path->pathdata.Types, path->pathdata.Count, TRUE);
|
2007-07-12 01:07:34 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-07-12 01:07:34 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-06-18 23:55:51 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
|
|
|
|
REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
|
|
|
|
{
|
2007-07-25 00:18:54 +00:00
|
|
|
INT save_state;
|
|
|
|
|
|
|
|
if(!graphics || !pen)
|
2007-06-18 23:55:51 +00:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
|
|
|
SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
|
|
|
|
|
|
|
|
draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
|
|
|
|
|
|
|
|
restore_dc(graphics, save_state);
|
|
|
|
|
|
|
|
return Ok;
|
2007-06-18 23:55:51 +00:00
|
|
|
}
|
|
|
|
|
2007-06-12 17:51:20 +00:00
|
|
|
GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
|
|
|
|
INT y, INT width, INT height)
|
|
|
|
{
|
2007-07-10 03:54:18 +00:00
|
|
|
INT save_state;
|
2007-06-12 17:51:20 +00:00
|
|
|
|
|
|
|
if(!pen || !graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = prepare_dc(graphics, pen);
|
2007-07-10 03:54:18 +00:00
|
|
|
SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
|
2007-06-12 17:51:20 +00:00
|
|
|
|
2007-07-10 03:54:18 +00:00
|
|
|
Rectangle(graphics->hdc, x, y, x + width, y + height);
|
2007-06-12 17:51:20 +00:00
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
restore_dc(graphics, save_state);
|
2007-06-12 17:51:20 +00:00
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2007-06-18 23:55:51 +00:00
|
|
|
|
2007-07-14 03:19:46 +00:00
|
|
|
GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
|
|
|
|
{
|
|
|
|
INT save_state;
|
|
|
|
GpStatus retval;
|
|
|
|
|
|
|
|
if(!brush || !graphics || !path)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
save_state = SaveDC(graphics->hdc);
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
SelectObject(graphics->hdc, brush->gdibrush);
|
|
|
|
SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
|
|
|
|
: WINDING));
|
|
|
|
|
|
|
|
BeginPath(graphics->hdc);
|
2007-07-24 03:24:53 +00:00
|
|
|
retval = draw_poly(graphics, NULL, path->pathdata.Points,
|
2007-07-14 03:19:46 +00:00
|
|
|
path->pathdata.Types, path->pathdata.Count, FALSE);
|
|
|
|
|
|
|
|
if(retval != Ok)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
FillPath(graphics->hdc);
|
|
|
|
|
|
|
|
retval = Ok;
|
|
|
|
|
|
|
|
end:
|
|
|
|
RestoreDC(graphics->hdc, save_state);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-06-18 23:55:51 +00:00
|
|
|
GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
|
|
|
|
REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
|
|
|
|
{
|
2007-07-25 00:18:54 +00:00
|
|
|
INT save_state;
|
|
|
|
|
|
|
|
if(!graphics || !brush)
|
2007-06-18 23:55:51 +00:00
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:18:54 +00:00
|
|
|
save_state = SaveDC(graphics->hdc);
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
SelectObject(graphics->hdc, brush->gdibrush);
|
|
|
|
SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
|
|
|
|
|
|
|
|
draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
|
|
|
|
|
|
|
|
RestoreDC(graphics->hdc, save_state);
|
|
|
|
|
|
|
|
return Ok;
|
2007-06-18 23:55:51 +00:00
|
|
|
}
|
2007-07-14 00:51:13 +00:00
|
|
|
|
2007-07-24 03:24:35 +00:00
|
|
|
GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
|
|
|
|
GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
|
|
|
|
{
|
2007-07-24 03:24:53 +00:00
|
|
|
INT save_state, i;
|
|
|
|
GpPointF *ptf = NULL;
|
|
|
|
POINT *pti = NULL;
|
|
|
|
GpStatus retval = Ok;
|
2007-07-24 03:24:35 +00:00
|
|
|
|
|
|
|
if(!graphics || !brush || !points || !count)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-24 03:24:53 +00:00
|
|
|
ptf = GdipAlloc(count * sizeof(GpPointF));
|
|
|
|
pti = GdipAlloc(count * sizeof(POINT));
|
|
|
|
if(!ptf || !pti){
|
|
|
|
retval = OutOfMemory;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < count; i ++){
|
|
|
|
ptf[i].X = (REAL) points[i].X;
|
|
|
|
ptf[i].Y = (REAL) points[i].Y;
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:35 +00:00
|
|
|
save_state = SaveDC(graphics->hdc);
|
|
|
|
EndPath(graphics->hdc);
|
|
|
|
SelectObject(graphics->hdc, brush->gdibrush);
|
|
|
|
SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
|
|
|
|
SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
|
|
|
|
: WINDING));
|
2007-07-24 03:24:53 +00:00
|
|
|
|
|
|
|
transform_and_round_points(graphics, pti, ptf, count);
|
|
|
|
Polygon(graphics->hdc, pti, count);
|
2007-07-24 03:24:35 +00:00
|
|
|
|
|
|
|
RestoreDC(graphics->hdc, save_state);
|
2007-07-24 03:24:53 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
GdipFree(ptf);
|
|
|
|
GdipFree(pti);
|
|
|
|
|
|
|
|
return retval;
|
2007-07-24 03:24:35 +00:00
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:25 +00:00
|
|
|
/* FIXME: Compositing quality is not used anywhere except the getter/setter. */
|
|
|
|
GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
|
|
|
|
CompositingQuality *quality)
|
|
|
|
{
|
|
|
|
if(!graphics || !quality)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*quality = graphics->compqual;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:29 +00:00
|
|
|
/* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
|
|
|
|
GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
|
|
|
|
InterpolationMode *mode)
|
|
|
|
{
|
|
|
|
if(!graphics || !mode)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*mode = graphics->interpolation;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:39 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
|
|
|
|
{
|
|
|
|
if(!graphics || !scale)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*scale = graphics->scale;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:41 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
|
|
|
|
{
|
|
|
|
if(!graphics || !unit)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*unit = graphics->unit;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:33 +00:00
|
|
|
/* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
|
|
|
|
GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
|
|
|
|
*mode)
|
|
|
|
{
|
|
|
|
if(!graphics || !mode)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*mode = graphics->pixeloffset;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:13 +00:00
|
|
|
/* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
|
|
|
|
GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
|
|
|
|
{
|
|
|
|
if(!graphics || !mode)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
*mode = graphics->smoothing;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:47 +00:00
|
|
|
GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
|
|
|
|
{
|
|
|
|
if(!graphics || !matrix)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
memcpy(matrix, graphics->worldtrans, sizeof(GpMatrix));
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:37 +00:00
|
|
|
GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
|
|
|
|
{
|
2007-07-25 00:19:09 +00:00
|
|
|
static int calls;
|
|
|
|
|
2007-07-14 00:51:37 +00:00
|
|
|
if(!graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:19:09 +00:00
|
|
|
if(!(calls++))
|
|
|
|
FIXME("graphics state not implemented\n");
|
2007-07-14 00:51:37 +00:00
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
|
|
|
|
{
|
2007-07-25 00:19:09 +00:00
|
|
|
static int calls;
|
|
|
|
|
2007-07-14 00:51:37 +00:00
|
|
|
if(!graphics || !state)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
2007-07-25 00:19:09 +00:00
|
|
|
if(!(calls++))
|
|
|
|
FIXME("graphics state not implemented\n");
|
2007-07-14 00:51:37 +00:00
|
|
|
|
|
|
|
return NotImplemented;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:25 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
|
|
|
|
CompositingQuality quality)
|
|
|
|
{
|
|
|
|
if(!graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->compqual = quality;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:29 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
|
|
|
|
InterpolationMode mode)
|
|
|
|
{
|
|
|
|
if(!graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->interpolation = mode;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-25 00:18:39 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
|
|
|
|
{
|
|
|
|
if(!graphics || (scale <= 0.0))
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->scale = scale;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-24 03:24:41 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
|
|
|
|
{
|
2007-07-25 00:18:34 +00:00
|
|
|
if(!graphics || (unit == UnitWorld))
|
2007-07-24 03:24:41 +00:00
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->unit = unit;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:33 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
|
|
|
|
mode)
|
|
|
|
{
|
|
|
|
if(!graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->pixeloffset = mode;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
|
|
|
|
2007-07-14 00:51:13 +00:00
|
|
|
GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
|
|
|
|
{
|
|
|
|
if(!graphics)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
graphics->smoothing = mode;
|
|
|
|
|
|
|
|
return Ok;
|
|
|
|
}
|
2007-07-25 00:18:47 +00:00
|
|
|
|
|
|
|
GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
|
|
|
|
{
|
|
|
|
if(!graphics || !matrix)
|
|
|
|
return InvalidParameter;
|
|
|
|
|
|
|
|
GdipDeleteMatrix(graphics->worldtrans);
|
|
|
|
return GdipCloneMatrix(matrix, &graphics->worldtrans);
|
|
|
|
}
|