19066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/* 29066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Copyright (C) 2006 The Android Open Source Project 39066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 49066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 59066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * you may not use this file except in compliance with the License. 69066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * You may obtain a copy of the License at 79066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 89066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 99066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * See the License for the specific language governing permissions and 149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * limitations under the License. 159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpackage android.graphics; 189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project/** 209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * The Path class encapsulates compound (multiple contour) geometric paths 219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * consisting of straight line segments, quadratic curves, and cubic curves. 229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * It can be drawn with canvas.drawPath(path, paint), either filled or stroked 239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (based on the paint's Style), or it can be used for clipping or to draw 249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * text on a path. 259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Projectpublic class Path { 2761c8c9c5b2006d18e9310b6521c65b36ffe75ce4Romain Guy /** 2861c8c9c5b2006d18e9310b6521c65b36ffe75ce4Romain Guy * @hide 2961c8c9c5b2006d18e9310b6521c65b36ffe75ce4Romain Guy */ 3036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat public final long mNativePath; 319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 33a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy * @hide 34a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy */ 35a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy public boolean isSimplePath = true; 36a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy /** 37a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy * @hide 38a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy */ 39a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy public Region rects; 40d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy private Direction mLastDirection = null; 41a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy 42a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy /** 439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Create an empty path 449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Path() { 469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mNativePath = init1(); 479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Create a new path, copying the contents from the src path. 519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param src The path to copy from when initializing the new path 539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public Path(Path src) { 5536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat long valNative = 0; 569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (src != null) { 579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project valNative = src.mNativePath; 58fa0853e0b92617128531188edd6a749a72b86432Chris Craik isSimplePath = src.isSimplePath; 59fa0853e0b92617128531188edd6a749a72b86432Chris Craik if (src.rects != null) { 60fa0853e0b92617128531188edd6a749a72b86432Chris Craik rects = new Region(src.rects); 61fa0853e0b92617128531188edd6a749a72b86432Chris Craik } 629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project mNativePath = init2(valNative); 649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Clear any lines and curves from the path, making it empty. 689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * This does NOT change the fill-type setting. 699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void reset() { 71a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = true; 7202a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck mLastDirection = null; 7302a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck if (rects != null) rects.setEmpty(); 74d0f379c1976c600313f1f4c39f2587a649e3a4fcMike Klein // We promised not to change this, so preserve it around the native 75d0f379c1976c600313f1f4c39f2587a649e3a4fcMike Klein // call, which does now reset fill type. 76d0f379c1976c600313f1f4c39f2587a649e3a4fcMike Klein final FillType fillType = getFillType(); 779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_reset(mNativePath); 78d0f379c1976c600313f1f4c39f2587a649e3a4fcMike Klein setFillType(fillType); 799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Rewinds the path: clears any lines and curves from the path but 839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * keeps the internal data structure for faster reuse. 849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void rewind() { 86a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = true; 8702a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck mLastDirection = null; 8802a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck if (rects != null) rects.setEmpty(); 899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_rewind(mNativePath); 909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** Replace the contents of this with the contents of src. 939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void set(Path src) { 959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (this != src) { 96a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = src.isSimplePath; 979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_set(mNativePath, src.mNativePath); 989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 1009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 1018018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1028018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * The logical operations that can be performed when combining two paths. 1038018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1048018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see #op(Path, android.graphics.Path.Op) 1058018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see #op(Path, Path, android.graphics.Path.Op) 1068018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1078018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy public enum Op { 1088018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1098018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Subtract the second path from the first path. 1108018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1118018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy DIFFERENCE, 1128018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1138018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Intersect the two paths. 1148018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1158018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy INTERSECT, 1168018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1178018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Union (inclusive-or) the two paths. 1188018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1198018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy UNION, 1208018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1218018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Exclusive-or the two paths. 1228018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1238018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy XOR, 1248018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1258018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Subtract the first path from the second path. 1268018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1278018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy REVERSE_DIFFERENCE 1288018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy } 1298018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy 1308018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1318018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Set this path to the result of applying the Op to this path and the specified path. 1328018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * The resulting path will be constructed from non-overlapping contours. 1338018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * The curve order is reduced where possible so that cubics may be turned 1348018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * into quadratics, and quadratics maybe turned into lines. 1358018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1368018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @param path The second operand (for difference, the subtrahend) 1378018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1388018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @return True if operation succeeded, false otherwise and this path remains unmodified. 1398018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1408018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see Op 1418018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see #op(Path, Path, android.graphics.Path.Op) 1428018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1438018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy public boolean op(Path path, Op op) { 1448018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy return op(this, path, op); 1458018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy } 1468018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy 1478018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1488018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Set this path to the result of applying the Op to the two specified paths. 1498018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * The resulting path will be constructed from non-overlapping contours. 1508018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * The curve order is reduced where possible so that cubics may be turned 1518018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * into quadratics, and quadratics maybe turned into lines. 1528018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1538018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @param path1 The first operand (for difference, the minuend) 1548018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @param path2 The second operand (for difference, the subtrahend) 1558018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1568018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @return True if operation succeeded, false otherwise and this path remains unmodified. 1578018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * 1588018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see Op 1598018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * @see #op(Path, android.graphics.Path.Op) 1608018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1618018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy public boolean op(Path path1, Path path2, Op op) { 1628018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy if (native_op(path1.mNativePath, path2.mNativePath, op.ordinal(), this.mNativePath)) { 1638018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy isSimplePath = false; 1648018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy rects = null; 1658018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy return true; 1668018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy } 1678018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy return false; 1688018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy } 1698018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy 1708018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1715be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * Returns the path's convexity, as defined by the content of the path. 1725be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * <p> 1735be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * A path is convex if it has a single contour, and only ever curves in a 1745be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * single direction. 1755be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * <p> 1765be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * This function will calculate the convexity of the path from its control 1775be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * points, and cache the result. 1785be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * 1795be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik * @return True if the path is convex. 1805be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik */ 1815be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik public boolean isConvex() { 1825be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik return native_isConvex(mNativePath); 1835be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik } 1845be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik 1855be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik /** 1868018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Enum for the ways a path may be filled. 1878018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public enum FillType { 1899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // these must match the values in SkPath.h 1908018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1918018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Specifies that "inside" is computed by a non-zero sum of signed 1928018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * edge crossings. 1938018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project WINDING (0), 1958018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 1968018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Specifies that "inside" is computed by an odd number of edge 1978018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * crossings. 1988018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 1999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project EVEN_ODD (1), 2008018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 2018018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Same as {@link #WINDING}, but draws outside of the path, rather than inside. 2028018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 2039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project INVERSE_WINDING (2), 2048018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy /** 2058018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy * Same as {@link #EVEN_ODD}, but draws outside of the path, rather than inside. 2068018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy */ 2079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project INVERSE_EVEN_ODD(3); 20824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 2099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project FillType(int ni) { 2109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project nativeInt = ni; 2119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2128018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy 2139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project final int nativeInt; 2149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2158018c8db8221aa604b3c083e09d173cc27e53d83Romain Guy 2169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project // these must be in the same order as their native values 2177f9f99ea11051614a7727dfb9f9578b518e76e3cXavier Ducrohet static final FillType[] sFillTypeArray = { 2189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project FillType.WINDING, 2199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project FillType.EVEN_ODD, 2209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project FillType.INVERSE_WINDING, 2219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project FillType.INVERSE_EVEN_ODD 2229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project }; 2239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Return the path's fill type. This defines how "inside" is 2269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * computed. The default value is WINDING. 2279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return the path's fill type 2299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public FillType getFillType() { 2319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return sFillTypeArray[native_getFillType(mNativePath)]; 2329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Set the path's fill type. This defines how "inside" is computed. 2369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param ft The new fill type for this path 2389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setFillType(FillType ft) { 2409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_setFillType(mNativePath, ft.nativeInt); 2419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2425be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik 2439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns true if the filltype is one of the INVERSE variants 2459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the filltype is one of the INVERSE variants 2479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean isInverseFillType() { 2499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project final int ft = native_getFillType(mNativePath); 2505be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik return (ft & FillType.INVERSE_WINDING.nativeInt) != 0; 2519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2525be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik 2539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Toggles the INVERSE state of the filltype 2559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void toggleInverseFillType() { 2579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project int ft = native_getFillType(mNativePath); 2585be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik ft ^= FillType.INVERSE_WINDING.nativeInt; 2599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_setFillType(mNativePath, ft); 2609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2615be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik 2629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns true if the path is empty (contains no lines or curves) 2649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the path is empty (contains no lines or curves) 2669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean isEmpty() { 2689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return native_isEmpty(mNativePath); 2699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Returns true if the path specifies a rectangle. If so, and if rect is 2739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * not null, set rect to the bounds of the path. If the path does not 2749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * specify a rectangle, return false and ignore rect. 2759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 2769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect If not null, returns the bounds of the path if it specifies 2779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * a rectangle 2789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @return true if the path specifies a rectangle 2799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 2809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public boolean isRect(RectF rect) { 2819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return native_isRect(mNativePath, rect); 2829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 28554900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed * Compute the bounds of the control points of the path, and write the 28654900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed * answer into bounds. If the path contains 0 or 1 points, the bounds is 28754900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed * set to (0,0,0,0) 2889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 28954900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed * @param bounds Returns the computed bounds of the path's control points. 29054900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed * @param exact This parameter is no longer used. 2919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 292a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy @SuppressWarnings({"UnusedDeclaration"}) 2939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void computeBounds(RectF bounds, boolean exact) { 29454900e8c05e92a0783e8468ad7c4513eb66adc80Mike Reed native_computeBounds(mNativePath, bounds); 2959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 2969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 2979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 2989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Hint to the path to prepare for adding more points. This can allow the 2999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * path to more efficiently allocate its storage. 3009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param extraPtCount The number of extra points that may be added to this 3029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * path 3039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void incReserve(int extraPtCount) { 3059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_incReserve(mNativePath, extraPtCount); 3069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Set the beginning of the next contour to the point (x,y). 3109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x The x-coordinate of the start of a new contour 3129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y The y-coordinate of the start of a new contour 3139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void moveTo(float x, float y) { 3159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_moveTo(mNativePath, x, y); 3169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Set the beginning of the next contour relative to the last point on the 3209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * previous contour. If there is no previous contour, this is treated the 3219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * same as moveTo(). 3229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The amount to add to the x-coordinate of the end of the 3249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * previous contour, to specify the start of a new contour 3259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The amount to add to the y-coordinate of the end of the 3269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * previous contour, to specify the start of a new contour 3279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void rMoveTo(float dx, float dy) { 3299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_rMoveTo(mNativePath, dx, dy); 3309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a line from the last point to the specified point (x,y). 3349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * If no moveTo() call has been made for this contour, the first point is 3359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * automatically set to (0,0). 3369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x The x-coordinate of the end of a line 3389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y The y-coordinate of the end of a line 3399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void lineTo(float x, float y) { 341d79991277043d6bdbd90bb63fd8aff73ef9e06a5Romain Guy isSimplePath = false; 3429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_lineTo(mNativePath, x, y); 3439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Same as lineTo, but the coordinates are considered relative to the last 3479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * point on this contour. If there is no previous point, then a moveTo(0,0) 3489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is inserted automatically. 3499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The amount to add to the x-coordinate of the previous point on 3519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, to specify a line 3529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The amount to add to the y-coordinate of the previous point on 3539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, to specify a line 3549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void rLineTo(float dx, float dy) { 356d79991277043d6bdbd90bb63fd8aff73ef9e06a5Romain Guy isSimplePath = false; 3579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_rLineTo(mNativePath, dx, dy); 3589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a quadratic bezier from the last point, approaching control point 3629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for 3639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, the first point is automatically set to (0,0). 3649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x1 The x-coordinate of the control point on a quadratic curve 3669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y1 The y-coordinate of the control point on a quadratic curve 3679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x2 The x-coordinate of the end point on a quadratic curve 3689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y2 The y-coordinate of the end point on a quadratic curve 3699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void quadTo(float x1, float y1, float x2, float y2) { 371a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 3729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_quadTo(mNativePath, x1, y1, x2, y2); 3739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Same as quadTo, but the coordinates are considered relative to the last 3779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * point on this contour. If there is no previous point, then a moveTo(0,0) 3789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * is inserted automatically. 3799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx1 The amount to add to the x-coordinate of the last point on 3819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, for the control point of a quadratic curve 3829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy1 The amount to add to the y-coordinate of the last point on 3839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, for the control point of a quadratic curve 3849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx2 The amount to add to the x-coordinate of the last point on 3859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, for the end point of a quadratic curve 3869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy2 The amount to add to the y-coordinate of the last point on 3879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * this contour, for the end point of a quadratic curve 3889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 3899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void rQuadTo(float dx1, float dy1, float dx2, float dy2) { 390a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 3919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_rQuadTo(mNativePath, dx1, dy1, dx2, dy2); 3929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 3939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 3949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 3959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a cubic bezier from the last point, approaching control points 3969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been 3979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * made for this contour, the first point is automatically set to (0,0). 3989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 3999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x1 The x-coordinate of the 1st control point on a cubic curve 4009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y1 The y-coordinate of the 1st control point on a cubic curve 4019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x2 The x-coordinate of the 2nd control point on a cubic curve 4029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y2 The y-coordinate of the 2nd control point on a cubic curve 4039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x3 The x-coordinate of the end point on a cubic curve 4049066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y3 The y-coordinate of the end point on a cubic curve 4059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void cubicTo(float x1, float y1, float x2, float y2, 4079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float x3, float y3) { 408a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 4099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_cubicTo(mNativePath, x1, y1, x2, y2, x3, y3); 4109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Same as cubicTo, but the coordinates are considered relative to the 4149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * current point on this contour. If there is no previous point, then a 4159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * moveTo(0,0) is inserted automatically. 4169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void rCubicTo(float x1, float y1, float x2, float y2, 4189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float x3, float y3) { 419a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 4209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_rCubicTo(mNativePath, x1, y1, x2, y2, x3, y3); 4219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Append the specified arc to the path as a new contour. If the start of 4259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the path is different from the path's current last point, then an 4269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * automatic lineTo() is added to connect the current contour to the 4279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * start of the arc. However, if the path is empty, then we call moveTo() 42824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * with the first point of the arc. 4299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4309066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param oval The bounds of oval defining shape and size of the arc 4319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param startAngle Starting angle (in degrees) where the arc begins 4329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sweepAngle Sweep angle (in degrees) measured clockwise, treated 4339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * mod 360. 4349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param forceMoveTo If true, always begin a new contour with the arc 4359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void arcTo(RectF oval, float startAngle, float sweepAngle, 4379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project boolean forceMoveTo) { 43824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese arcTo(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle, forceMoveTo); 4399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 44024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 4419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Append the specified arc to the path as a new contour. If the start of 4439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the path is different from the path's current last point, then an 4449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * automatic lineTo() is added to connect the current contour to the 4459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * start of the arc. However, if the path is empty, then we call moveTo() 4469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * with the first point of the arc. 4479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 4489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param oval The bounds of oval defining shape and size of the arc 4499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param startAngle Starting angle (in degrees) where the arc begins 4509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sweepAngle Sweep angle (in degrees) measured clockwise 4519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void arcTo(RectF oval, float startAngle, float sweepAngle) { 45324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese arcTo(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle, false); 45424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese } 45524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 45624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese /** 45724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * Append the specified arc to the path as a new contour. If the start of 45824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * the path is different from the path's current last point, then an 45924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * automatic lineTo() is added to connect the current contour to the 46024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * start of the arc. However, if the path is empty, then we call moveTo() 46124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * with the first point of the arc. 46224609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * 46324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param startAngle Starting angle (in degrees) where the arc begins 46424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param sweepAngle Sweep angle (in degrees) measured clockwise, treated 46524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * mod 360. 46624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param forceMoveTo If true, always begin a new contour with the arc 46724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese */ 46824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese public void arcTo(float left, float top, float right, float bottom, float startAngle, 46924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float sweepAngle, boolean forceMoveTo) { 470a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 47124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese native_arcTo(mNativePath, left, top, right, bottom, startAngle, sweepAngle, forceMoveTo); 4729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 47324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 4749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Close the current contour. If the current point is not equal to the 4769066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * first point of the contour, a line segment is automatically added. 4779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void close() { 479a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 4809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_close(mNativePath); 4819066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 4839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 4849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Specifies how closed shapes (e.g. rects, ovals) are oriented when they 4859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * are added to a path. 4869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 4879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public enum Direction { 4889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** clockwise */ 48970336dd0eb4d06004687bfdeda0047b5675433e3Derek Sollenberger CW (1), // must match enum in SkPath.h 4909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** counter-clockwise */ 49170336dd0eb4d06004687bfdeda0047b5675433e3Derek Sollenberger CCW (2); // must match enum in SkPath.h 49224609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 4939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project Direction(int ni) { 4949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project nativeInt = ni; 4959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 4969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project final int nativeInt; 4979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 49824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 499d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy private void detectSimplePath(float left, float top, float right, float bottom, Direction dir) { 50002a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck if (mLastDirection == null) { 50102a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck mLastDirection = dir; 50202a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck } 50302a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck if (mLastDirection != dir) { 50402a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck isSimplePath = false; 50502a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck } else { 50602a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck if (rects == null) rects = new Region(); 50702a2aab57c71f1058348cec0fc3a6aaa07250bc9John Reck rects.op((int) left, (int) top, (int) right, (int) bottom, Region.Op.UNION); 508d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy } 509d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy } 510d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy 5119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed rectangle contour to the path 5139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The rectangle to add as a closed contour to the path 5159066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the rectangle's contour 5169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addRect(RectF rect, Direction dir) { 5187979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik addRect(rect.left, rect.top, rect.right, rect.bottom, dir); 5199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed rectangle contour to the path 5239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param left The left side of a rectangle to add to the path 5259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param top The top of a rectangle to add to the path 5269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param right The right side of a rectangle to add to the path 5279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param bottom The bottom of a rectangle to add to the path 5289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the rectangle's contour 5299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 530a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy public void addRect(float left, float top, float right, float bottom, Direction dir) { 531d4b5795e5efd05be7e482e013dfdec519ad2601eRomain Guy detectSimplePath(left, top, right, bottom, dir); 5329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_addRect(mNativePath, left, top, right, bottom, dir.nativeInt); 5339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed oval contour to the path 5379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param oval The bounds of the oval to add as a closed contour to the path 5399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the oval's contour 5409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addOval(RectF oval, Direction dir) { 5427979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik addOval(oval.left, oval.top, oval.right, oval.bottom, dir); 5437979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik } 5447979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik 5457979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik /** 5467979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik * Add a closed oval contour to the path 5477979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik * 5487979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik * @param dir The direction to wind the oval's contour 5497979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik */ 5507979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik public void addOval(float left, float top, float right, float bottom, Direction dir) { 551a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 5527979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik native_addOval(mNativePath, left, top, right, bottom, dir.nativeInt); 5539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed circle contour to the path 5579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param x The x-coordinate of the center of a circle to add to the path 5599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param y The y-coordinate of the center of a circle to add to the path 5609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param radius The radius of a circle to add to the path 5619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the circle's contour 5629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addCircle(float x, float y, float radius, Direction dir) { 564a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 5659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_addCircle(mNativePath, x, y, radius, dir.nativeInt); 5669066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add the specified arc to the path as a new contour. 5709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param oval The bounds of oval defining the shape and size of the arc 5729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param startAngle Starting angle (in degrees) where the arc begins 5739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param sweepAngle Sweep angle (in degrees) measured clockwise 5749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addArc(RectF oval, float startAngle, float sweepAngle) { 57624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese addArc(oval.left, oval.top, oval.right, oval.bottom, startAngle, sweepAngle); 57724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese } 57824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 57924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese /** 58024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * Add the specified arc to the path as a new contour. 58124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * 58224609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param startAngle Starting angle (in degrees) where the arc begins 58324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param sweepAngle Sweep angle (in degrees) measured clockwise 58424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese */ 58524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese public void addArc(float left, float top, float right, float bottom, float startAngle, 58624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float sweepAngle) { 587a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 58824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese native_addArc(mNativePath, left, top, right, bottom, startAngle, sweepAngle); 5899066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 5909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 5919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 5929066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed round-rectangle contour to the path 5939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 5949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The bounds of a round-rectangle to add to the path 5959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rx The x-radius of the rounded corners on the round-rectangle 5969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param ry The y-radius of the rounded corners on the round-rectangle 5979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the round-rectangle's contour 5989066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 5999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addRoundRect(RectF rect, float rx, float ry, Direction dir) { 60024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese addRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, dir); 60124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese } 60224609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 60324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese /** 60424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * Add a closed round-rectangle contour to the path 60524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * 60624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param rx The x-radius of the rounded corners on the round-rectangle 60724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param ry The y-radius of the rounded corners on the round-rectangle 60824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param dir The direction to wind the round-rectangle's contour 60924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese */ 61024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese public void addRoundRect(float left, float top, float right, float bottom, float rx, float ry, 61124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese Direction dir) { 612a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 61324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese native_addRoundRect(mNativePath, left, top, right, bottom, rx, ry, dir.nativeInt); 6149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 61524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 6169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a closed round-rectangle contour to the path. Each corner receives 6189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * two radius values [X, Y]. The corners are ordered top-left, top-right, 6199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * bottom-right, bottom-left 6209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param rect The bounds of a round-rectangle to add to the path 6229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param radii Array of 8 values, 4 pairs of [X,Y] radii 6239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dir The direction to wind the round-rectangle's contour 6249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addRoundRect(RectF rect, float[] radii, Direction dir) { 6269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (rect == null) { 6279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new NullPointerException("need rect parameter"); 6289066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 62924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese addRoundRect(rect.left, rect.top, rect.right, rect.bottom, radii, dir); 63024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese } 63124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 63224609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese /** 63324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * Add a closed round-rectangle contour to the path. Each corner receives 63424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * two radius values [X, Y]. The corners are ordered top-left, top-right, 63524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * bottom-right, bottom-left 63624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * 63724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param radii Array of 8 values, 4 pairs of [X,Y] radii 63824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese * @param dir The direction to wind the round-rectangle's contour 63924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese */ 64024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese public void addRoundRect(float left, float top, float right, float bottom, float[] radii, 64124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese Direction dir) { 6429066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (radii.length < 8) { 6439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project throw new ArrayIndexOutOfBoundsException("radii[] needs 8 values"); 6449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 645a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 64624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese native_addRoundRect(mNativePath, left, top, right, bottom, radii, dir.nativeInt); 6479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 64824609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese 6499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a copy of src to the path, offset by (dx,dy) 6519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param src The path to add as a new contour 6539066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The amount to translate the path in X as it is added 6549066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addPath(Path src, float dx, float dy) { 656a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 6579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_addPath(mNativePath, src.mNativePath, dx, dy); 6589066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6599066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6609066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6619066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a copy of src to the path 6629066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6639066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param src The path that is appended to the current path 6649066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6659066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addPath(Path src) { 666a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 6679066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_addPath(mNativePath, src.mNativePath); 6689066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6699066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6709066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6719066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Add a copy of src to the path, transformed by matrix 6729066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6739066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param src The path to add as a new contour 6749066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6759066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void addPath(Path src, Matrix matrix) { 676a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy if (!src.isSimplePath) isSimplePath = false; 6779066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_addPath(mNativePath, src.mNativePath, matrix.native_instance); 6789066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6799066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6809066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6810e12fa12cb2cd4e049e560bdad8f1cd654825f3bChris Craik * Offset the path by (dx,dy) 6829066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 6839066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The amount in the X direction to offset the entire path 6849066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The amount in the Y direction to offset the entire path 6859066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dst The translated path is written here. If this is null, then 6869066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * the original path is modified. 6879066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 6889066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void offset(float dx, float dy, Path dst) { 68936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat long dstNative = 0; 6909066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (dst != null) { 6919066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project dstNative = dst.mNativePath; 692fa0853e0b92617128531188edd6a749a72b86432Chris Craik dst.isSimplePath = false; 6939066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6949066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_offset(mNativePath, dx, dy, dstNative); 6959066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 6969066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 6979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 6980e12fa12cb2cd4e049e560bdad8f1cd654825f3bChris Craik * Offset the path by (dx,dy) 6999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7009066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The amount in the X direction to offset the entire path 7019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The amount in the Y direction to offset the entire path 7029066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void offset(float dx, float dy) { 704fa0853e0b92617128531188edd6a749a72b86432Chris Craik isSimplePath = false; 7059066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_offset(mNativePath, dx, dy); 7069066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7079066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7089066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Sets the last point of the path. 7109066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7119066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dx The new X coordinate for the last point 7129066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dy The new Y coordinate for the last point 7139066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7149066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void setLastPoint(float dx, float dy) { 715a48a1a87ba17f20f7006eaab21dcedf86c015c13Romain Guy isSimplePath = false; 7169066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_setLastPoint(mNativePath, dx, dy); 7179066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7199066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7209066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Transform the points in this path by matrix, and write the answer 7219066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * into dst. If dst is null, then the the original path is modified. 7229066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7239066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param matrix The matrix to apply to the path 7249066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param dst The transformed path is written here. If dst is null, 7259066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * then the the original path is modified 7269066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7279066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void transform(Matrix matrix, Path dst) { 72836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat long dstNative = 0; 7299066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project if (dst != null) { 730fa0853e0b92617128531188edd6a749a72b86432Chris Craik dst.isSimplePath = false; 7319066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project dstNative = dst.mNativePath; 7329066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_transform(mNativePath, matrix.native_instance, dstNative); 7349066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7359066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7369066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project /** 7379066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * Transform the points in this path by matrix. 7389066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * 7399066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project * @param matrix The matrix to apply to the path 7409066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project */ 7419066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project public void transform(Matrix matrix) { 742fa0853e0b92617128531188edd6a749a72b86432Chris Craik isSimplePath = false; 7439066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project native_transform(mNativePath, matrix.native_instance); 7449066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7459066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 7469066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project protected void finalize() throws Throwable { 7479066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project try { 7489066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project finalizer(mNativePath); 7499066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } finally { 7509066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project super.finalize(); 7519066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7529066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 75361c8c9c5b2006d18e9310b6521c65b36ffe75ce4Romain Guy 75436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat final long ni() { 7559066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project return mNativePath; 7569066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project } 7579066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project 758c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 759c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Approximate the <code>Path</code> with a series of line segments. 760c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * This returns float[] with the array containing point components. 761c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * There are three components for each point, in order: 762c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <ul> 763c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <li>Fraction along the length of the path that the point resides</li> 764c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <li>The x coordinate of the point</li> 765c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <li>The y coordinate of the point</li> 766c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * </ul> 767c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <p>Two points may share the same fraction along its length when there is 768c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * a move action within the Path.</p> 769c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 770c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param acceptableError The acceptable error for a line on the 771c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Path. Typically this would be 0.5 so that 772c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * the error is less than half a pixel. 773c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An array of components for points approximating the Path. 774c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @hide 775c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 776c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public float[] approximate(float acceptableError) { 777c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return native_approximate(mNativePath, acceptableError); 778c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 779c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 78036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native long init1(); 78136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native long init2(long nPath); 78236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_reset(long nPath); 78336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_rewind(long nPath); 78436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_set(long native_dst, long native_src); 7855be83edd15e11420287cc0af93a95d5a6dfae68fChris Craik private static native boolean native_isConvex(long nPath); 78636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native int native_getFillType(long nPath); 78736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_setFillType(long nPath, int ft); 78836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native boolean native_isEmpty(long nPath); 78936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native boolean native_isRect(long nPath, RectF rect); 79036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_computeBounds(long nPath, RectF bounds); 79136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_incReserve(long nPath, int extraPtCount); 79236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_moveTo(long nPath, float x, float y); 79336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_rMoveTo(long nPath, float dx, float dy); 79436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_lineTo(long nPath, float x, float y); 79536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_rLineTo(long nPath, float dx, float dy); 79636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_quadTo(long nPath, float x1, float y1, 7979066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float x2, float y2); 79836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_rQuadTo(long nPath, float dx1, float dy1, 7999066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float dx2, float dy2); 80036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_cubicTo(long nPath, float x1, float y1, 8019066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float x2, float y2, float x3, float y3); 80236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_rCubicTo(long nPath, float x1, float y1, 8039066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float x2, float y2, float x3, float y3); 80424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese private static native void native_arcTo(long nPath, float left, float top, 80524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float right, float bottom, float startAngle, 80624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float sweepAngle, boolean forceMoveTo); 80736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_close(long nPath); 80836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_addRect(long nPath, float left, float top, 8099066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float right, float bottom, int dir); 8107979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik private static native void native_addOval(long nPath, float left, float top, 8117979388d4f7d5d9dbfcf7e1cc4709f8088c034aeChris Craik float right, float bottom, int dir); 81236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_addCircle(long nPath, float x, float y, float radius, int dir); 81324609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese private static native void native_addArc(long nPath, float left, float top, 81424609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float right, float bottom, 81524609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float startAngle, float sweepAngle); 81624609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese private static native void native_addRoundRect(long nPath, float left, float top, 81724609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float right, float bottom, 8189066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project float rx, float ry, int dir); 81924609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese private static native void native_addRoundRect(long nPath, float left, float top, 82024609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float right, float bottom, 82124609581330bc350f797179e3c1a59789c645ec2Antonio Calabrese float[] radii, int dir); 82236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_addPath(long nPath, long src, float dx, float dy); 82336bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_addPath(long nPath, long src); 82436bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_addPath(long nPath, long src, long matrix); 82536bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_offset(long nPath, float dx, float dy, long dst_path); 82636bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_offset(long nPath, float dx, float dy); 82736bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_setLastPoint(long nPath, float dx, float dy); 82836bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_transform(long nPath, long matrix, long dst_path); 82936bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void native_transform(long nPath, long matrix); 83036bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native boolean native_op(long path1, long path2, int op, long result); 83136bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native void finalizer(long nPath); 83236bef0bf30d6bae48cf3837df351075ca4fce654Ashok Bhat private static native float[] native_approximate(long nPath, float error); 8339066cfe9886ac131c34d59ed0e2d287b0e3c0087The Android Open Source Project} 834