Commit c500713d authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Fix updating the current position in PolyDraw.

parent dfa3c688
...@@ -205,7 +205,6 @@ BOOL nulldrv_PolyDraw( PHYSDEV dev, const POINT *points, const BYTE *types, DWOR ...@@ -205,7 +205,6 @@ BOOL nulldrv_PolyDraw( PHYSDEV dev, const POINT *points, const BYTE *types, DWOR
} }
if (num_pts >= 2) Polyline( dev->hdc, line_pts, num_pts ); if (num_pts >= 2) Polyline( dev->hdc, line_pts, num_pts );
MoveToEx( dev->hdc, line_pts[num_pts - 1].x, line_pts[num_pts - 1].y, NULL );
HeapFree( GetProcessHeap(), 0, line_pts ); HeapFree( GetProcessHeap(), 0, line_pts );
return TRUE; return TRUE;
} }
...@@ -830,6 +829,11 @@ BOOL WINAPI PolyDraw(HDC hdc, const POINT *lppt, const BYTE *lpbTypes, ...@@ -830,6 +829,11 @@ BOOL WINAPI PolyDraw(HDC hdc, const POINT *lppt, const BYTE *lpbTypes,
update_dc( dc ); update_dc( dc );
physdev = GET_DC_PHYSDEV( dc, pPolyDraw ); physdev = GET_DC_PHYSDEV( dc, pPolyDraw );
result = physdev->funcs->pPolyDraw( physdev, lppt, lpbTypes, cCount ); result = physdev->funcs->pPolyDraw( physdev, lppt, lpbTypes, cCount );
if (result && cCount)
{
dc->CursPosX = lppt[cCount - 1].x;
dc->CursPosY = lppt[cCount - 1].y;
}
release_dc_ptr( dc ); release_dc_ptr( dc );
return result; return result;
} }
......
...@@ -1204,56 +1204,52 @@ static BOOL pathdrv_PolyBezier( PHYSDEV dev, const POINT *pts, DWORD cbPoints ) ...@@ -1204,56 +1204,52 @@ static BOOL pathdrv_PolyBezier( PHYSDEV dev, const POINT *pts, DWORD cbPoints )
static BOOL pathdrv_PolyDraw( PHYSDEV dev, const POINT *pts, const BYTE *types, DWORD cbPoints ) static BOOL pathdrv_PolyDraw( PHYSDEV dev, const POINT *pts, const BYTE *types, DWORD cbPoints )
{ {
struct path_physdev *physdev = get_path_physdev( dev ); struct path_physdev *physdev = get_path_physdev( dev );
POINT lastmove, orig_pos; struct gdi_path *path = physdev->path;
INT i; POINT orig_pos;
INT i, lastmove = 0;
GetCurrentPositionEx( dev->hdc, &orig_pos ); for (i = 0; i < path->count; i++) if (path->flags[i] == PT_MOVETO) lastmove = i;
lastmove = orig_pos; orig_pos = path->pos;
for(i = physdev->path->count - 1; i >= 0; i--){
if(physdev->path->flags[i] == PT_MOVETO){
lastmove = physdev->path->points[i];
DPtoLP(dev->hdc, &lastmove, 1);
break;
}
}
for(i = 0; i < cbPoints; i++) for(i = 0; i < cbPoints; i++)
{ {
switch (types[i]) switch (types[i])
{ {
case PT_MOVETO: case PT_MOVETO:
MoveToEx( dev->hdc, pts[i].x, pts[i].y, NULL ); path->newStroke = TRUE;
path->pos = pts[i];
LPtoDP( dev->hdc, &path->pos, 1 );
lastmove = path->count;
break; break;
case PT_LINETO: case PT_LINETO:
case PT_LINETO | PT_CLOSEFIGURE: case PT_LINETO | PT_CLOSEFIGURE:
LineTo( dev->hdc, pts[i].x, pts[i].y ); if (!add_log_points_new_stroke( physdev, &pts[i], 1, PT_LINETO )) return FALSE;
break; break;
case PT_BEZIERTO: case PT_BEZIERTO:
if ((i + 2 < cbPoints) && (types[i + 1] == PT_BEZIERTO) && if ((i + 2 < cbPoints) && (types[i + 1] == PT_BEZIERTO) &&
(types[i + 2] & ~PT_CLOSEFIGURE) == PT_BEZIERTO) (types[i + 2] & ~PT_CLOSEFIGURE) == PT_BEZIERTO)
{ {
PolyBezierTo( dev->hdc, &pts[i], 3 ); if (!add_log_points_new_stroke( physdev, &pts[i], 3, PT_BEZIERTO )) return FALSE;
i += 2; i += 2;
break; break;
} }
/* fall through */ /* fall through */
default: default:
if (i) /* restore original position */ /* restore original position */
if (path->pos.x != orig_pos.x || path->pos.y != orig_pos.y)
{ {
if (!(types[i - 1] & PT_CLOSEFIGURE)) lastmove = pts[i - 1]; path->newStroke = TRUE;
if (lastmove.x != orig_pos.x || lastmove.y != orig_pos.y) path->pos = orig_pos;
MoveToEx( dev->hdc, orig_pos.x, orig_pos.y, NULL );
} }
return FALSE; return FALSE;
} }
if(types[i] & PT_CLOSEFIGURE){ if (types[i] & PT_CLOSEFIGURE)
physdev->path->flags[physdev->path->count-1] |= PT_CLOSEFIGURE; {
MoveToEx( dev->hdc, lastmove.x, lastmove.y, NULL ); close_figure( path );
path->pos = path->points[lastmove];
} }
} }
return TRUE; return TRUE;
} }
......
...@@ -565,33 +565,37 @@ done: ...@@ -565,33 +565,37 @@ done:
} }
static const path_test_t polydraw_path[] = { static const path_test_t polydraw_path[] = {
{0, 0, PT_MOVETO, 0, 0}, /*0*/ {-20, -20, PT_MOVETO, 0, 0}, /*0*/
{10, 10, PT_LINETO, 0, 0}, /*1*/ {10, 10, PT_LINETO, 0, 0},
{10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*2*/ {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0},
{100, 100, PT_MOVETO, 0, 0}, /*3*/ {-20, -20, PT_MOVETO, 0, 0},
{95, 95, PT_LINETO, 0, 0}, /*4*/ {-10, -10, PT_LINETO, 0, 0},
{10, 10, PT_LINETO, 0, 0}, /*5*/ {100, 100, PT_MOVETO, 0, 0}, /*5*/
{10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0}, /*6*/ {95, 95, PT_LINETO, 0, 0},
{100, 100, PT_MOVETO, 0, 0}, /*7*/ {10, 10, PT_LINETO, 0, 0},
{15, 15, PT_LINETO, 0, 0}, /*8*/ {10, 15, PT_LINETO | PT_CLOSEFIGURE, 0, 0},
{25, 25, PT_MOVETO, 0, 0}, /*9*/ {100, 100, PT_MOVETO, 0, 0},
{25, 30, PT_LINETO, 0, 0}, /*10*/ {15, 15, PT_LINETO, 0, 0}, /*10*/
{100, 100, PT_MOVETO, 0, 0}, /*11*/ {25, 25, PT_MOVETO, 0, 0},
{30, 30, PT_BEZIERTO, 0, 0}, /*12*/ {25, 30, PT_LINETO, 0, 0},
{30, 35, PT_BEZIERTO, 0, 0}, /*13*/ {100, 100, PT_MOVETO, 0, 0},
{35, 35, PT_BEZIERTO, 0, 0}, /*14*/ {30, 30, PT_BEZIERTO, 0, 0},
{35, 40, PT_LINETO, 0, 0}, /*15*/ {30, 35, PT_BEZIERTO, 0, 0}, /*15*/
{40, 40, PT_MOVETO, 0, 0}, /*16*/ {35, 35, PT_BEZIERTO, 0, 0},
{40, 45, PT_LINETO, 0, 0}, /*17*/ {35, 40, PT_LINETO, 0, 0},
{35, 40, PT_MOVETO, 0, 0}, /*18*/ {40, 40, PT_MOVETO, 0, 0},
{45, 50, PT_LINETO, 0, 0}, /*19*/ {40, 45, PT_LINETO, 0, 0},
{35, 40, PT_MOVETO, 0, 0}, /*20*/ {35, 40, PT_MOVETO, 0, 0}, /*20*/
{50, 55, PT_LINETO, 0, 0}, /*21*/ {45, 50, PT_LINETO, 0, 0},
{45, 50, PT_LINETO, 0, 0}, /*22*/ {35, 40, PT_MOVETO, 0, 0},
{35, 40, PT_MOVETO, 0, 0}, /*23*/ {50, 55, PT_LINETO, 0, 0},
{60, 60, PT_LINETO, 0, 0}, /*24*/ {45, 50, PT_LINETO, 0, 0},
{60, 65, PT_MOVETO, 0, 0}, /*25*/ {35, 40, PT_MOVETO, 0, 0}, /*25*/
{65, 65, PT_LINETO, 0, 0} /*26*/ {60, 60, PT_LINETO, 0, 0},
{60, 65, PT_MOVETO, 0, 0},
{65, 65, PT_LINETO, 0, 0},
{75, 75, PT_MOVETO, 0, 0},
{80, 80, PT_LINETO | PT_CLOSEFIGURE, 0, 0} /*30*/
}; };
static POINT polydraw_pts[] = { static POINT polydraw_pts[] = {
...@@ -602,7 +606,8 @@ static POINT polydraw_pts[] = { ...@@ -602,7 +606,8 @@ static POINT polydraw_pts[] = {
{40, 40}, {40, 45}, {45, 45}, {40, 40}, {40, 45}, {45, 45},
{45, 50}, {50, 50}, {45, 50}, {50, 50},
{50, 55}, {45, 50}, {55, 60}, {50, 55}, {45, 50}, {55, 60},
{60, 60}, {60, 65}, {65, 65}}; {60, 60}, {60, 65}, {65, 65},
{70, 70}, {75, 70}, {75, 75}, {80, 80}};
static BYTE polydraw_tps[] = static BYTE polydraw_tps[] =
{PT_LINETO, PT_CLOSEFIGURE | PT_LINETO, /* 2 */ {PT_LINETO, PT_CLOSEFIGURE | PT_LINETO, /* 2 */
...@@ -612,13 +617,20 @@ static BYTE polydraw_tps[] = ...@@ -612,13 +617,20 @@ static BYTE polydraw_tps[] =
PT_MOVETO, PT_LINETO, PT_CLOSEFIGURE, /* 15 */ PT_MOVETO, PT_LINETO, PT_CLOSEFIGURE, /* 15 */
PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 17 */ PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 17 */
PT_LINETO, PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 20 */ PT_LINETO, PT_LINETO, PT_MOVETO | PT_CLOSEFIGURE, /* 20 */
PT_LINETO, PT_MOVETO | PT_LINETO, PT_LINETO}; /* 23 */ PT_LINETO, PT_MOVETO | PT_LINETO, PT_LINETO, /* 23 */
PT_MOVETO, PT_MOVETO, PT_MOVETO, PT_LINETO | PT_CLOSEFIGURE}; /* 27 */
static void test_polydraw(void) static void test_polydraw(void)
{ {
BOOL retb; BOOL retb;
POINT pos;
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
MoveToEx( hdc, -20, -20, NULL );
BeginPath(hdc); BeginPath(hdc);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == -20 && pos.y == -20, "wrong pos %d,%d\n", pos.x, pos.y );
/* closefigure with no previous moveto */ /* closefigure with no previous moveto */
if (!(retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2)) && if (!(retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2)) &&
...@@ -629,50 +641,99 @@ static void test_polydraw(void) ...@@ -629,50 +641,99 @@ static void test_polydraw(void)
goto done; goto done;
} }
expect(TRUE, retb); expect(TRUE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 10 && pos.y == 15, "wrong pos %d,%d\n", pos.x, pos.y );
LineTo(hdc, -10, -10);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == -10 && pos.y == -10, "wrong pos %d,%d\n", pos.x, pos.y );
MoveToEx(hdc, 100, 100, NULL); MoveToEx(hdc, 100, 100, NULL);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 100 && pos.y == 100, "wrong pos %d,%d\n", pos.x, pos.y );
LineTo(hdc, 95, 95); LineTo(hdc, 95, 95);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 95 && pos.y == 95, "wrong pos %d,%d\n", pos.x, pos.y );
/* closefigure with previous moveto */ /* closefigure with previous moveto */
retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2); retb = PolyDraw(hdc, polydraw_pts, polydraw_tps, 2);
expect(TRUE, retb); expect(TRUE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 10 && pos.y == 15, "wrong pos %d,%d\n", pos.x, pos.y );
/* bad bezier points */ /* bad bezier points */
retb = PolyDraw(hdc, &(polydraw_pts[2]), &(polydraw_tps[2]), 4); retb = PolyDraw(hdc, &(polydraw_pts[2]), &(polydraw_tps[2]), 4);
expect(FALSE, retb); expect(FALSE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 10 && pos.y == 15, "wrong pos %d,%d\n", pos.x, pos.y );
retb = PolyDraw(hdc, &(polydraw_pts[6]), &(polydraw_tps[6]), 4); retb = PolyDraw(hdc, &(polydraw_pts[6]), &(polydraw_tps[6]), 4);
expect(FALSE, retb); expect(FALSE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 10 && pos.y == 15, "wrong pos %d,%d\n", pos.x, pos.y );
/* good bezier points */ /* good bezier points */
retb = PolyDraw(hdc, &(polydraw_pts[8]), &(polydraw_tps[8]), 4); retb = PolyDraw(hdc, &(polydraw_pts[8]), &(polydraw_tps[8]), 4);
expect(TRUE, retb); expect(TRUE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 35 && pos.y == 40, "wrong pos %d,%d\n", pos.x, pos.y );
/* does lineto or bezierto take precedence? */ /* does lineto or bezierto take precedence? */
retb = PolyDraw(hdc, &(polydraw_pts[12]), &(polydraw_tps[12]), 4); retb = PolyDraw(hdc, &(polydraw_pts[12]), &(polydraw_tps[12]), 4);
expect(FALSE, retb); expect(FALSE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 35 && pos.y == 40, "wrong pos %d,%d\n", pos.x, pos.y );
/* bad point type, has already moved cursor position */ /* bad point type, has already moved cursor position */
retb = PolyDraw(hdc, &(polydraw_pts[15]), &(polydraw_tps[15]), 4); retb = PolyDraw(hdc, &(polydraw_pts[15]), &(polydraw_tps[15]), 4);
expect(FALSE, retb); expect(FALSE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 35 && pos.y == 40, "wrong pos %d,%d\n", pos.x, pos.y );
/* bad point type, cursor position is moved, but back to its original spot */ /* bad point type, cursor position is moved, but back to its original spot */
retb = PolyDraw(hdc, &(polydraw_pts[17]), &(polydraw_tps[17]), 4); retb = PolyDraw(hdc, &(polydraw_pts[17]), &(polydraw_tps[17]), 4);
expect(FALSE, retb); expect(FALSE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 35 && pos.y == 40, "wrong pos %d,%d\n", pos.x, pos.y );
/* does lineto or moveto take precedence? */ /* does lineto or moveto take precedence? */
retb = PolyDraw(hdc, &(polydraw_pts[20]), &(polydraw_tps[20]), 3); retb = PolyDraw(hdc, &(polydraw_pts[20]), &(polydraw_tps[20]), 3);
expect(TRUE, retb); expect(TRUE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 65 && pos.y == 65, "wrong pos %d,%d\n", pos.x, pos.y );
/* consecutive movetos */
retb = PolyDraw(hdc, &(polydraw_pts[23]), &(polydraw_tps[23]), 4);
expect(TRUE, retb);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 80 && pos.y == 80, "wrong pos %d,%d\n", pos.x, pos.y );
EndPath(hdc); EndPath(hdc);
ok_path(hdc, "polydraw_path", polydraw_path, sizeof(polydraw_path)/sizeof(path_test_t), 0); ok_path(hdc, "polydraw_path", polydraw_path, sizeof(polydraw_path)/sizeof(path_test_t), 0);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 80 && pos.y == 80, "wrong pos %d,%d\n", pos.x, pos.y );
done: done:
ReleaseDC(0, hdc); ReleaseDC(0, hdc);
} }
static void test_closefigure(void) { static void test_closefigure(void) {
int nSize, nSizeWitness; int nSize, nSizeWitness;
POINT pos;
HDC hdc = GetDC(0); HDC hdc = GetDC(0);
MoveToEx( hdc, 100, 100, NULL );
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 100 && pos.y == 100, "wrong pos %d,%d\n", pos.x, pos.y );
BeginPath(hdc); BeginPath(hdc);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 100 && pos.y == 100, "wrong pos %d,%d\n", pos.x, pos.y );
MoveToEx(hdc, 95, 95, NULL); MoveToEx(hdc, 95, 95, NULL);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 95 && pos.y == 95, "wrong pos %d,%d\n", pos.x, pos.y );
LineTo(hdc, 95, 0); LineTo(hdc, 95, 0);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 95 && pos.y == 0, "wrong pos %d,%d\n", pos.x, pos.y );
LineTo(hdc, 0, 95); LineTo(hdc, 0, 95);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 0 && pos.y == 95, "wrong pos %d,%d\n", pos.x, pos.y );
CloseFigure(hdc); CloseFigure(hdc);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 0 && pos.y == 95, "wrong pos %d,%d\n", pos.x, pos.y );
EndPath(hdc); EndPath(hdc);
GetCurrentPositionEx( hdc, &pos );
ok( pos.x == 0 && pos.y == 95, "wrong pos %d,%d\n", pos.x, pos.y );
nSize = GetPath(hdc, NULL, NULL, 0); nSize = GetPath(hdc, NULL, NULL, 0);
AbortPath(hdc); AbortPath(hdc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment