From 3de5c62bf343273e36489af4060b342e33eeb5a4 Mon Sep 17 00:00:00 2001 From: Zhang Zhaolong Date: Thu, 9 Oct 2014 18:11:38 +0800 Subject: [PATCH] fix polyline. --- client/Windows/wf_gdi.c | 30 +++++++++++++++--------------- client/X11/xf_gdi.c | 15 +++++++++------ include/freerdp/primary.h | 2 +- libfreerdp/core/message.c | 4 ++-- libfreerdp/core/orders.c | 8 ++++---- libfreerdp/gdi/gdi.c | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/client/Windows/wf_gdi.c b/client/Windows/wf_gdi.c index e08d1fadb..bfa469922 100644 --- a/client/Windows/wf_gdi.c +++ b/client/Windows/wf_gdi.c @@ -608,8 +608,6 @@ void wf_gdi_line_to(wfContext* wfc, LINE_TO_ORDER* line_to) void wf_gdi_polyline(wfContext* wfc, POLYLINE_ORDER* polyline) { - int i; - POINT* pts; int org_rop2; HPEN hpen; HPEN org_hpen; @@ -621,26 +619,28 @@ void wf_gdi_polyline(wfContext* wfc, POLYLINE_ORDER* polyline) org_rop2 = wf_set_rop2(wfc->drawing->hdc, polyline->bRop2); org_hpen = (HPEN) SelectObject(wfc->drawing->hdc, hpen); - if (polyline->numPoints > 0) + if (polyline->numDeltaEntries > 0) { - POINT temp; + POINT *pts; + POINT temp; + int numPoints; + int i; - temp.x = polyline->xStart; - temp.y = polyline->yStart; - pts = (POINT*) malloc(sizeof(POINT) * polyline->numPoints); + numPoints = polyline->numDeltaEntries + 1; + pts = (POINT*) malloc(sizeof(POINT) * numPoints); + pts[0].x = temp.x = polyline->xStart; + pts[0].y = temp.y = polyline->yStart; - for (i = 0; i < (int) polyline->numPoints; i++) + for (i = 0; i < (int) polyline->numDeltaEntries; i++) { temp.x += polyline->points[i].x; temp.y += polyline->points[i].y; - pts[i].x = temp.x; - pts[i].y = temp.y; - - if (wfc->drawing == wfc->primary) - wf_invalidate_region(wfc, pts[i].x, pts[i].y, pts[i].x + 1, pts[i].y + 1); + pts[i + 1].x = temp.x; + pts[i + 1].y = temp.y; } - - Polyline(wfc->drawing->hdc, pts, polyline->numPoints); + if (wfc->drawing == wfc->primary) + wf_invalidate_region(wfc, wfc->client_x, wfc->client_y, wfc->client_width, wfc->client_height); + Polyline(wfc->drawing->hdc, pts, numPoints); free(pts); } diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index fcf4db5e2..36a1563cd 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -730,6 +730,7 @@ void xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) int npoints; UINT32 color; XPoint* points; + XPoint tmp; int width, height; xfContext* xfc = (xfContext*) context; @@ -742,16 +743,18 @@ void xf_gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, color); - npoints = polyline->numPoints + 1; + npoints = polyline->numDeltaEntries + 1; points = malloc(sizeof(XPoint) * npoints); - points[0].x = polyline->xStart; - points[0].y = polyline->yStart; + points[0].x = tmp.x = polyline->xStart; + points[0].y = tmp.y = polyline->yStart; - for (i = 0; i < polyline->numPoints; i++) + for (i = 0; i < polyline->numDeltaEntries; i++) { - points[i + 1].x = polyline->points[i].x; - points[i + 1].y = polyline->points[i].y; + tmp.x += polyline->points[i].x; + tmp.y += polyline->points[i].y; + points[i + 1].x = tmp.x; + points[i + 1].y = tmp.y; } XDrawLines(xfc->display, xfc->drawing, xfc->gc, points, npoints, CoordModePrevious); diff --git a/include/freerdp/primary.h b/include/freerdp/primary.h index 8cb1d716a..48d9af005 100644 --- a/include/freerdp/primary.h +++ b/include/freerdp/primary.h @@ -244,7 +244,7 @@ struct _POLYLINE_ORDER INT32 yStart; UINT32 bRop2; UINT32 penColor; - UINT32 numPoints; + UINT32 numDeltaEntries; UINT32 cbData; DELTA_POINT* points; }; diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index 2eaf34ade..3a2367453 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -343,8 +343,8 @@ static void update_message_Polyline(rdpContext* context, POLYLINE_ORDER* polylin wParam = (POLYLINE_ORDER*) malloc(sizeof(POLYLINE_ORDER)); CopyMemory(wParam, polyline, sizeof(POLYLINE_ORDER)); - wParam->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * wParam->numPoints); - CopyMemory(wParam->points, polyline->points, sizeof(DELTA_POINT) * wParam->numPoints); + wParam->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * wParam->numDeltaEntries); + CopyMemory(wParam->points, polyline->points, sizeof(DELTA_POINT) * wParam->numDeltaEntries); MessageQueue_Post(context->update->queue, (void*) context, MakeMessageId(PrimaryUpdate, Polyline), (void*) wParam, NULL); diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c index 3142aba7b..7d00b7dfb 100644 --- a/libfreerdp/core/orders.c +++ b/libfreerdp/core/orders.c @@ -1320,7 +1320,7 @@ BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDE ORDER_FIELD_BYTE(3, polyline->bRop2); ORDER_FIELD_UINT16(4, word); ORDER_FIELD_COLOR(5, polyline->penColor); - ORDER_FIELD_BYTE(6, polyline->numPoints); + ORDER_FIELD_BYTE(6, polyline->numDeltaEntries); if (orderInfo->fieldFlags & ORDER_FIELD_07) { @@ -1329,11 +1329,11 @@ BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDE Stream_Read_UINT8(s, polyline->cbData); if (polyline->points == NULL) - polyline->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * polyline->numPoints); + polyline->points = (DELTA_POINT*) malloc(sizeof(DELTA_POINT) * polyline->numDeltaEntries); else - polyline->points = (DELTA_POINT*) realloc(polyline->points, sizeof(DELTA_POINT) * polyline->numPoints); + polyline->points = (DELTA_POINT*) realloc(polyline->points, sizeof(DELTA_POINT) * polyline->numDeltaEntries); - return update_read_delta_points(s, polyline->points, polyline->numPoints, polyline->xStart, polyline->yStart); + return update_read_delta_points(s, polyline->points, polyline->numDeltaEntries, polyline->xStart, polyline->yStart); } return TRUE; diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index 72720daf1..330b56bdd 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -753,7 +753,7 @@ static void gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline) gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL); points = polyline->points; - for (i = 0; i < (int) polyline->numPoints; i++) + for (i = 0; i < (int) polyline->numDeltaEntries; i++) { x += points[i].x; y += points[i].y;