From 17a1422a12d03b18d7fecffa8f24958a127ac14a Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Tue, 8 Sep 2015 17:15:33 -0700 Subject: [PATCH] Fix implicit lineTo issue b/23808876 Change-Id: I208e088bfc565ae0d09b826ceff6f9d3c5eb215f --- core/java/android/util/PathParser.java | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/core/java/android/util/PathParser.java b/core/java/android/util/PathParser.java index 18dc26279f6c4..954dcfbe9b2d4 100644 --- a/core/java/android/util/PathParser.java +++ b/core/java/android/util/PathParser.java @@ -364,18 +364,32 @@ public class PathParser { for (int k = 0; k < val.length; k += incr) { switch (cmd) { case 'm': // moveto - Start a new sub-path (relative) - path.rMoveTo(val[k + 0], val[k + 1]); currentX += val[k + 0]; currentY += val[k + 1]; - currentSegmentStartX = currentX; - currentSegmentStartY = currentY; + if (k > 0) { + // According to the spec, if a moveto is followed by multiple + // pairs of coordinates, the subsequent pairs are treated as + // implicit lineto commands. + path.rLineTo(val[k + 0], val[k + 1]); + } else { + path.rMoveTo(val[k + 0], val[k + 1]); + currentSegmentStartX = currentX; + currentSegmentStartY = currentY; + } break; case 'M': // moveto - Start a new sub-path - path.moveTo(val[k + 0], val[k + 1]); currentX = val[k + 0]; currentY = val[k + 1]; - currentSegmentStartX = currentX; - currentSegmentStartY = currentY; + if (k > 0) { + // According to the spec, if a moveto is followed by multiple + // pairs of coordinates, the subsequent pairs are treated as + // implicit lineto commands. + path.lineTo(val[k + 0], val[k + 1]); + } else { + path.moveTo(val[k + 0], val[k + 1]); + currentSegmentStartX = currentX; + currentSegmentStartY = currentY; + } break; case 'l': // lineto - Draw a line from the current point (relative) path.rLineTo(val[k + 0], val[k + 1]);