From c31638f16b1fe709dd9df232afb9ab7fac3b231e Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 13 Jul 2021 11:24:08 +0200 Subject: [PATCH] When setting the line dash to be an empty array reset the style to Solid An empty line dash array is indicating that it should be reset to be a Solid line, otherwise it ends up reusing the previous settings for the pen instead of drawing a solid line. Fixes: QTBUG-75553 Pick-to: 6.2 6.1 5.15 Change-Id: I16466672de95da8ef0cf3fc261969e7cc6add227 Reviewed-by: Mitch Curtis --- .../qquickcontext2dcommandbuffer.cpp | 5 ++- .../quick/qquickcanvasitem/data/tst_line.qml | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp index e3f8acad00..18bfc66eee 100644 --- a/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp +++ b/src/quick/items/context2d/qquickcontext2dcommandbuffer.cpp @@ -371,7 +371,10 @@ void QQuickContext2DCommandBuffer::replay(QPainter* p, QQuickContext2D::State& s } state.lineDash = pattern; QPen nPen = p->pen(); - nPen.setDashPattern(pattern); + if (count > 0) + nPen.setDashPattern(pattern); + else + nPen.setStyle(Qt::SolidLine); p->setPen(nPen); break; } diff --git a/tests/auto/quick/qquickcanvasitem/data/tst_line.qml b/tests/auto/quick/qquickcanvasitem/data/tst_line.qml index dc960a24d0..fb4db5ae54 100644 --- a/tests/auto/quick/qquickcanvasitem/data/tst_line.qml +++ b/tests/auto/quick/qquickcanvasitem/data/tst_line.qml @@ -894,6 +894,37 @@ CanvasTestCase { comparePixel(ctx, 39,0, 0,0,0,0); } + function test_lineDashReset(row) { + var canvas = createCanvasObject(row); + var ctx = canvas.getContext('2d'); + ctx.reset(); + ctx.strokeStyle = "#ff0000"; + ctx.lineWidth = 2; + var pattern = [2, 3, 5, 1, 6, 3] + ctx.setLineDash(pattern) + + compare(ctx.getLineDash(), pattern); + + pattern = [] + ctx.setLineDash(pattern) + compare(ctx.getLineDash(), pattern); + + ctx.beginPath(); + ctx.moveTo(0, 0); + ctx.lineTo(40, 0); + ctx.stroke(); + + comparePixel(ctx, 0,0, 255,0,0,255); + comparePixel(ctx, 4,0, 255,0,0,255); + comparePixel(ctx, 5,0, 255,0,0,255); + comparePixel(ctx, 14,0, 255,0,0,255); + comparePixel(ctx, 20,0, 255,0,0,255); + comparePixel(ctx, 21,0, 255,0,0,255); + comparePixel(ctx, 22,0, 255,0,0,255); + comparePixel(ctx, 34,0, 255,0,0,255); + comparePixel(ctx, 35,0, 255,0,0,255); + } + function test_lineDashOffset(row) { var canvas = createCanvasObject(row); var ctx = canvas.getContext('2d');