GpStatus WINGDIPAPI GdipSetPenDashArray(GpPen *pen, GDIPCONST REAL *dash, INT count) { INT i; REAL sum = 0; TRACE("(%p, %p, %d)\n", pen, dash, count); if(!pen || !dash) return InvalidParameter; if(count <= 0) return OutOfMemory; for(i = 0; i < count; i++){ sum += dash[i]; if(dash[i] < 0.0) return InvalidParameter; } if(sum == 0.0 && count) return InvalidParameter; heap_free(pen->dashes); pen->dashes = NULL; if(count > 0) pen->dashes = heap_alloc_zero(count * sizeof(REAL)); if(!pen->dashes){ pen->numdashes = 0; return OutOfMemory; } GdipSetPenDashStyle(pen, DashStyleCustom); memcpy(pen->dashes, dash, count * sizeof(REAL)); pen->numdashes = count; return Ok; }
static void test_dasharray(void) { GpPen *pen; GpDashStyle style; GpStatus status; REAL dashes[12]; GdipCreatePen1(0xdeadbeef, 10.0, UnitWorld, &pen); dashes[0] = 10.0; dashes[1] = 11.0; dashes[2] = 12.0; dashes[3] = 13.0; dashes[4] = 14.0; dashes[5] = -100.0; dashes[6] = -100.0; dashes[7] = dashes[8] = dashes[9] = dashes[10] = dashes[11] = 0.0; /* setting the array sets the type to custom */ GdipGetPenDashStyle(pen, &style); expect(DashStyleSolid, style); status = GdipSetPenDashArray(pen, dashes, 2); expect(Ok, status); GdipGetPenDashStyle(pen, &style); expect(DashStyleCustom, style); /* Getting the array on a non-custom pen returns invalid parameter (unless * you are getting 0 elements).*/ GdipSetPenDashStyle(pen, DashStyleSolid); status = GdipGetPenDashArray(pen, &dashes[5], 2); expect(InvalidParameter, status); status = GdipGetPenDashArray(pen, &dashes[5], 0); expect(Ok, status); /* What does setting DashStyleCustom do to the array length? */ GdipSetPenDashArray(pen, dashes, 2); GdipSetPenDashStyle(pen, DashStyleCustom); status = GdipGetPenDashArray(pen, &dashes[5], 2); expect(Ok, status); expectf(10.0, dashes[5]); expectf(11.0, dashes[6]); /* Set the array, then get with different sized buffers. */ status = GdipSetPenDashArray(pen, dashes, 5); expect(Ok, status); dashes[5] = -100.0; dashes[6] = -100.0; status = GdipGetPenDashArray(pen, &dashes[5], 1); expect(Ok, status); /* not InsufficientBuffer! */ expectf(10.0, dashes[5]); expectf(-100.0, dashes[6]); dashes[5] = -100.0; status = GdipGetPenDashArray(pen, &dashes[5], 6); expect(InvalidParameter, status); /* not Ok! */ expectf(-100.0, dashes[5]); expectf(-100.0, dashes[6]); /* Some invalid array values. */ status = GdipSetPenDashArray(pen, &dashes[7], 5); expect(InvalidParameter, status); dashes[9] = -1.0; status = GdipSetPenDashArray(pen, &dashes[7], 5); expect(InvalidParameter, status); /* Try to set with count = 0. */ GdipSetPenDashStyle(pen, DashStyleDot); if (0) /* corrupts stack on 64-bit Vista */ { status = GdipSetPenDashArray(pen, dashes, 0); ok(status == OutOfMemory || status == InvalidParameter, "Expected OutOfMemory or InvalidParameter, got %.8x\n", status); } status = GdipSetPenDashArray(pen, dashes, -1); ok(status == OutOfMemory || status == InvalidParameter, "Expected OutOfMemory or InvalidParameter, got %.8x\n", status); GdipGetPenDashStyle(pen, &style); expect(DashStyleDot, style); GdipDeletePen(pen); }
static void test_widen(void) { GpStatus status; GpPath *path; GpPen *pen; GpMatrix *m; INT count=-1; status = GdipCreatePath(FillModeAlternate, &path); expect(Ok, status); status = GdipCreatePen1(0xffffffff, 10.0, UnitPixel, &pen); expect(Ok, status); status = GdipCreateMatrix(&m); expect(Ok, status); /* NULL arguments */ status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 10.0); expect(Ok, status); status = GdipWidenPath(NULL, NULL, NULL, 0.0); expect(InvalidParameter, status); status = GdipWidenPath(path, pen, m, 0.0); expect(Ok, status); status = GdipWidenPath(path, pen, NULL, 1.0); expect(Ok, status); status = GdipWidenPath(path, NULL, m, 1.0); expect(InvalidParameter, status); status = GdipWidenPath(NULL, pen, m, 1.0); expect(InvalidParameter, status); /* widen empty path */ status = GdipResetPath(path); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(OutOfMemory, status); /* horizontal line */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 10.0); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); /* horizontal 2x stretch */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 2.5, 10.0, 25.0, 10.0); expect(Ok, status); status = GdipScaleMatrix(m, 2.0, 1.0, MatrixOrderAppend); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); /* vertical 2x stretch */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 5.0, 50.0, 5.0); expect(Ok, status); status = GdipScaleMatrix(m, 0.5, 2.0, MatrixOrderAppend); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); status = GdipScaleMatrix(m, 1.0, 0.5, MatrixOrderAppend); expect(Ok, status); /* dashed line */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 5.0, 50.0, 5.0); expect(Ok, status); status = GdipSetPenDashStyle(pen, DashStyleDash); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_dash_path, sizeof(widenline_dash_path)/sizeof(path_test_t), FALSE); status = GdipSetPenDashStyle(pen, DashStyleSolid); expect(Ok, status); /* pen width in UnitWorld */ GdipDeletePen(pen); status = GdipCreatePen1(0xffffffff, 10.0, UnitWorld, &pen); expect(Ok, status); status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 10.0); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); /* horizontal 2x stretch */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 2.5, 10.0, 25.0, 10.0); expect(Ok, status); status = GdipScaleMatrix(m, 2.0, 1.0, MatrixOrderAppend); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); /* vertical 2x stretch */ status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 5.0, 50.0, 5.0); expect(Ok, status); status = GdipScaleMatrix(m, 0.5, 2.0, MatrixOrderAppend); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_wide_path, sizeof(widenline_wide_path)/sizeof(path_test_t), FALSE); status = GdipScaleMatrix(m, 1.0, 0.5, MatrixOrderAppend); expect(Ok, status); /* pen width in UnitInch */ GdipDeletePen(pen); status = GdipCreatePen1(0xffffffff, 10.0, UnitWorld, &pen); expect(Ok, status); status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 10.0); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); ok_path(path, widenline_path, sizeof(widenline_path)/sizeof(path_test_t), FALSE); /* pen width = 0 pixels - native fails to widen but can draw with this pen */ GdipDeletePen(pen); status = GdipCreatePen1(0xffffffff, 0.0, UnitPixel, &pen); expect(Ok, status); status = GdipResetPath(path); expect(Ok, status); status = GdipAddPathLine(path, 5.0, 10.0, 50.0, 10.0); expect(Ok, status); status = GdipWidenPath(path, pen, m, 1.0); expect(Ok, status); status = GdipGetPointCount(path, &count); expect(Ok, status); todo_wine expect(0, count); GdipDeleteMatrix(m); GdipDeletePen(pen); GdipDeletePath(path); }