From 336f1cbaf55f7ef3164427255494937341efac7b Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Wed, 23 Mar 2016 15:04:22 -0400 Subject: [PATCH] Enforce API preconditions in Java instead of deferring to Skia. The Skia API has been relaxed on the types of input it will accept, but in order to preserve the old API behavior we need to test for those conditions in Java. bug: 27682974 Change-Id: I9a33acdcd8f55c63d2e42f1733e94bf695193ac7 --- graphics/java/android/graphics/PathMeasure.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/graphics/java/android/graphics/PathMeasure.java b/graphics/java/android/graphics/PathMeasure.java index 041615969d878..2848949eb72f4 100644 --- a/graphics/java/android/graphics/PathMeasure.java +++ b/graphics/java/android/graphics/PathMeasure.java @@ -112,7 +112,7 @@ public class PathMeasure { * Given a start and stop distance, return in dst the intervening * segment(s). If the segment is zero-length, return false, else return * true. startD and stopD are pinned to legal values (0..getLength()). - * If startD <= stopD then return false (and leave dst untouched). + * If startD >= stopD then return false (and leave dst untouched). * Begin the segment with a moveTo if startWithMoveTo is true. * *

On {@link android.os.Build.VERSION_CODES#KITKAT} and earlier @@ -121,6 +121,19 @@ public class PathMeasure { * such as dst.rLineTo(0, 0).

*/ public boolean getSegment(float startD, float stopD, Path dst, boolean startWithMoveTo) { + // Skia used to enforce this as part of it's API, but has since relaxed that restriction + // so to maintain consistency in our API we enforce the preconditions here. + float length = getLength(); + if (startD < 0) { + startD = 0; + } + if (stopD > length) { + stopD = length; + } + if (startD >= stopD) { + return false; + } + dst.isSimplePath = false; return native_getSegment(native_instance, startD, stopD, dst.ni(), startWithMoveTo); }