gdiplus: Implemented GdipDrawCurve2.
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index a4ba0ca..f917b65 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -27,6 +27,9 @@
#include "gdiplus_private.h"
#include "wine/debug.h"
+/* looks-right constant */
+#define TENSION_CONST (0.3)
+
static inline INT roundr(REAL x)
{
return (INT) floor(x+0.5);
@@ -77,6 +80,34 @@
return Ok;
}
+/* 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);
+}
+
GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
{
if(hdc == NULL)
@@ -160,6 +191,58 @@
return Ok;
}
+/* Approximates cardinal spline with Bezier curves. */
+GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
+ GDIPCONST GpPointF *points, INT count, REAL tension)
+{
+ HGDIOBJ old_pen;
+
+ /* PolyBezier expects count*3-2 points. */
+ int i, len_pt = count*3-2;
+ POINT pt[len_pt];
+ REAL x1, x2, y1, y2;
+
+ if(!graphics || !pen)
+ return InvalidParameter;
+
+ tension = tension * TENSION_CONST;
+
+ calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
+ tension, &x1, &y1);
+
+ pt[0].x = roundr(points[0].X);
+ pt[0].y = roundr(points[0].Y);
+ pt[1].x = roundr(x1);
+ pt[1].y = roundr(y1);
+
+ for(i = 0; i < count-2; i++){
+ calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
+
+ pt[3*i+2].x = roundr(x1);
+ pt[3*i+2].y = roundr(y1);
+ pt[3*i+3].x = roundr(points[i+1].X);
+ pt[3*i+3].y = roundr(points[i+1].Y);
+ pt[3*i+4].x = roundr(x2);
+ pt[3*i+4].y = roundr(y2);
+ }
+
+ calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
+ points[count-2].X, points[count-2].Y, tension, &x1, &y1);
+
+ pt[len_pt-2].x = x1;
+ pt[len_pt-2].y = y1;
+ pt[len_pt-1].x = roundr(points[count-1].X);
+ pt[len_pt-1].y = roundr(points[count-1].Y);
+
+ old_pen = SelectObject(graphics->hdc, pen->gdipen);
+
+ PolyBezier(graphics->hdc, pt, len_pt);
+
+ SelectObject(graphics->hdc, old_pen);
+
+ return Ok;
+}
+
GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
INT y1, INT x2, INT y2)
{