18a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 38a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 68a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPath_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPath_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1165a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com#include "SkInstCnt.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h" 13ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com#include "SkPathRef.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDArray.h" 151dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com#include "SkRefCnt.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 17739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkReader32; 18739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkWriter32; 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoPathBoundsUpdate; 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkString; 214ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect; 2266a5d8bf13fe98baae268db0211e9c25e5ece7facaryclarkclass SkWStream; 238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPath 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkPath class encapsulates compound (multiple contour) geometric paths 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com consisting of straight line segments, quadratic curves, and cubic curves. 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 297ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkPath { 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 316f07665768dc84453316e7b2bbd6049576764cb1mtklein SK_DECLARE_INST_COUNT(SkPath); 3265a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com 338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath(); 341ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org SkPath(const SkPath&); 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkPath(); 368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 371ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org SkPath& operator=(const SkPath&); 385e728450247c677343e072f37150967b36892573bsalomon@google.com friend SK_API bool operator==(const SkPath&, const SkPath&); 393abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com friend bool operator!=(const SkPath& a, const SkPath& b) { 403abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com return !(a == b); 413abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com } 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4390b5c0ced0e7ecc8812509d4c6c8017b1d08308fdjsollen#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 4490b5c0ced0e7ecc8812509d4c6c8017b1d08308fdjsollen /** Returns true if the caller is the only owner of the underlying path data */ 4590b5c0ced0e7ecc8812509d4c6c8017b1d08308fdjsollen bool unique() const { return fPathRef->unique(); } 4690b5c0ced0e7ecc8812509d4c6c8017b1d08308fdjsollen#endif 4790b5c0ced0e7ecc8812509d4c6c8017b1d08308fdjsollen 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum FillType { 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specifies that "inside" is computed by a non-zero sum of signed 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com edge crossings 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kWinding_FillType, 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specifies that "inside" is computed by an odd number of edge 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com crossings 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEvenOdd_FillType, 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as Winding, but draws outside of the path, rather than inside 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kInverseWinding_FillType, 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as EvenOdd, but draws outside of the path, rather than inside 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kInverseEvenOdd_FillType 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the path's fill type. This is used to define how "inside" is 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com computed. The default value is kWinding_FillType. 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the path's fill type 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com FillType getFillType() const { return (FillType)fFillType; } 718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the path's fill type. This is used to define how "inside" is 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com computed. The default value is kWinding_FillType. 74b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ft The new fill type for this path 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 77f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void setFillType(FillType ft) { 78f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com fFillType = SkToU8(ft); 79f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com } 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the filltype is one of the Inverse variants */ 825f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com bool isInverseFillType() const { return IsInverseFillType((FillType)fFillType); } 838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 84b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com /** 85b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Toggle between inverse and normal filltypes. This reverse the return 86b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * value of isInverseFillType() 87b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com */ 88f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void toggleInverseFillType() { 89f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com fFillType ^= 2; 906b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com } 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com enum Convexity { 9304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kUnknown_Convexity, 9404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kConvex_Convexity, 9504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kConcave_Convexity 9604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com }; 9704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 9804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 9930c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * Return the path's convexity, as stored in the path. If it is currently unknown, 10030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * then this function will attempt to compute the convexity (and cache the result). 101b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com */ 102b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com Convexity getConvexity() const { 10330c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com if (kUnknown_Convexity != fConvexity) { 10430c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com return static_cast<Convexity>(fConvexity); 10530c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com } else { 10630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com return this->internalGetConvexity(); 107b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com } 108b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com } 109b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com 110b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com /** 111b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Return the currently cached value for convexity, even if that is set to 112b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * kUnknown_Convexity. Note: getConvexity() will automatically call 113b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * ComputeConvexity and cache its return value if the current setting is 114b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * kUnknown. 11504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 116b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com Convexity getConvexityOrUnknown() const { return (Convexity)fConvexity; } 11704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 11804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 11904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Store a convexity setting in the path. There is no automatic check to 12030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * see if this value actually agrees with the return value that would be 12130c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * computed by getConvexity(). 122b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * 123b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Note: even if this is set to a "known" value, if the path is later 124b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * changed (e.g. lineTo(), addRect(), etc.) then the cached value will be 125b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * reset to kUnknown_Convexity. 12604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 12704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com void setConvexity(Convexity); 12804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 12904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 13004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Returns true if the path is flagged as being convex. This is not a 13104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * confirmed by any analysis, it is just the value set earlier. 13204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 13304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com bool isConvex() const { 13404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com return kConvex_Convexity == this->getConvexity(); 13504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com } 13604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 13704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 13804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Set the isConvex flag to true or false. Convex paths may draw faster if 13904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * this flag is set, though setting this to true on a path that is in fact 14004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * not convex can give undefined results when drawn. Paths default to 14104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * isConvex == false 1426b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com */ 1434469938e92d779dff05e745559e67907bbf21e78reed@google.com SK_ATTR_DEPRECATED("use setConvexity") 144f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void setIsConvex(bool isConvex) { 14504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); 146f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com } 1476b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com 1486aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com /** Returns true if the path is an oval. 1496aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * 1506aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * @param rect returns the bounding rect of this oval. It's a circle 1516aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * if the height and width are the same. 1526aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * 1536aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * @return true if this path is an oval. 1546aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * Tracking whether a path is an oval is considered an 1556aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * optimization for performance and so some paths that are in 1566aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * fact ovals can report false. 1576aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com */ 158466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); } 1596aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Clear any lines and curves from the path, making it empty. This frees up 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com internal storage associated with those segments. 162cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com On Android, does not change fSourcePath. 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reset(); 165fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 1668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Similar to reset(), in that all lines and curves are removed from the 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path. However, any internal storage for those lines/curves is retained, 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com making reuse of the path potentially faster. 169cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com On Android, does not change fSourcePath. 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rewind(); 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the path is empty (contains no lines or curves) 1748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path is empty (contains no lines or curves) 1768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 177ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com bool isEmpty() const { 178ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 179ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return 0 == fPathRef->countVerbs(); 180ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1820bb18bb264b26afca45452910437c09445e23a3creed@google.com /** 1830bb18bb264b26afca45452910437c09445e23a3creed@google.com * Returns true if all of the points in this path are finite, meaning there 1840bb18bb264b26afca45452910437c09445e23a3creed@google.com * are no infinities and no NaNs. 1850bb18bb264b26afca45452910437c09445e23a3creed@google.com */ 1860bb18bb264b26afca45452910437c09445e23a3creed@google.com bool isFinite() const { 187ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 188ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->isFinite(); 1890bb18bb264b26afca45452910437c09445e23a3creed@google.com } 1900bb18bb264b26afca45452910437c09445e23a3creed@google.com 191b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth /** Returns true if the path is volatile (i.e. should not be cached by devices.) 192b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth */ 193b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth bool isVolatile() const { 194b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth return SkToBool(fIsVolatile); 195b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth } 196b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth 197b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth /** Specify whether this path is volatile. Paths are not volatile by 198b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth default. Temporary paths that are discarded or modified after use should be 199b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth marked as volatile. This provides a hint to the device that the path 200b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth should not be cached. Providing this hint when appropriate can 201b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth improve performance by avoiding unnecessary overhead and resource 202b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth consumption on the device. 203b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth */ 204b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth void setIsVolatile(bool isVolatile) { 205b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth fIsVolatile = isVolatile; 206b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth } 207b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth 2084da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a line for zero length 2094da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2104da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the line is of zero length; otherwise false. 2114da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2124da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) { 21394fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2); 2144da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2154da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2164da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a quad for zero length 2174da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2184da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the quad is of zero length; otherwise false. 2194da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2204da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2, 2214da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org const SkPoint& p3) { 22294fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2) && 22394fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p2.equalsWithinTolerance(p3); 2244da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2254da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2264da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a cubic curve for zero length 2274da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2284da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the cubic is of zero length; otherwise false. 2294da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2304da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2, 2314da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org const SkPoint& p3, const SkPoint& p4) { 23294fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2) && 23394fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p2.equalsWithinTolerance(p3) && 23494fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p3.equalsWithinTolerance(p4); 2354da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2364da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2377e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com /** 2387e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * Returns true if the path specifies a single line (i.e. it contains just 2397e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * a moveTo and a lineTo). If so, and line[] is not null, it sets the 2 2407e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * points in line[] to the end-points of the line. If the path is not a 2417e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * line, returns false and ignores line[]. 2427e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com */ 2437e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com bool isLine(SkPoint line[2]) const; 2447e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com 245d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com /** Return the number of points in the path 246d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com */ 2471dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com int countPoints() const; 248d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com 249d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com /** Return the point at the specified index. If the index is out of range 250d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com (i.e. is not 0 <= index < countPoints()) then the returned coordinates 251d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com will be (0,0) 252d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com */ 253d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com SkPoint getPoint(int index) const; 254d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of points in the path. Up to max points are copied. 256fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param points If not null, receives up to max points 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param max The maximum number of points to copy into points 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the actual number of points in the path 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int getPoints(SkPoint points[], int max) const; 2628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 263df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com /** Return the number of verbs in the path 264df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com */ 2651dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com int countVerbs() const; 266df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com 267df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com /** Returns the number of verbs in the path. Up to max verbs are copied. The 268df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com verbs are copied as one byte per verb. 269fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 270df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @param verbs If not null, receives up to max verbs 271df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @param max The maximum number of verbs to copy into verbs 272df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @return the actual number of verbs in the path 273df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com */ 274df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com int getVerbs(uint8_t verbs[], int max) const; 275df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com 2768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //! Swap contents of this and other. Guaranteed not to throw 2778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void swap(SkPath& other); 2788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 279d252db03d9650013b545ef9781fe993c07f8f314reed@android.com /** Returns the bounds of the path's points. If the path contains 0 or 1 280d252db03d9650013b545ef9781fe993c07f8f314reed@android.com points, the bounds is set to (0,0,0,0), and isEmpty() will return true. 281d252db03d9650013b545ef9781fe993c07f8f314reed@android.com Note: this bounds may be larger than the actual shape, since curves 28291b0a3587342c48a1a6e1c4687686688737359darobertphillips do not extend as far as their control points. Additionally this bound 28391b0a3587342c48a1a6e1c4687686688737359darobertphillips can contain trailing MoveTo points (cf. isRect). 284d252db03d9650013b545ef9781fe993c07f8f314reed@android.com */ 285d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& getBounds() const { 286ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->getBounds(); 287d252db03d9650013b545ef9781fe993c07f8f314reed@android.com } 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Calling this will, if the internal cache of the bounds is out of date, 2909bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com update it so that subsequent calls to getBounds will be instantaneous. 2918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This also means that any copies or simple transformations of the path 2928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will inherit the cached bounds. 293d252db03d9650013b545ef9781fe993c07f8f314reed@android.com */ 294d252db03d9650013b545ef9781fe993c07f8f314reed@android.com void updateBoundsCache() const { 295d252db03d9650013b545ef9781fe993c07f8f314reed@android.com // for now, just calling getBounds() is sufficient 296d252db03d9650013b545ef9781fe993c07f8f314reed@android.com this->getBounds(); 297d252db03d9650013b545ef9781fe993c07f8f314reed@android.com } 2988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2999bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com /** 3009bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * Does a conservative test to see whether a rectangle is inside a path. Currently it only 3019bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * will ever return true for single convex contour paths. The empty-status of the rect is not 3029bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * considered (e.g. a rect that is a point can be inside a path). Points or line segments where 3039bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * the rect edge touches the path border are not considered containment violations. 3049bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com */ 3059bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com bool conservativelyContainsRect(const SkRect& rect) const; 3069bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Construction methods 3088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Hint to the path to prepare for adding more points. This can allow the 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to more efficiently grow its storage. 311fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param extraPtCount The number of extra points the path should 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preallocate for. 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void incReserve(unsigned extraPtCount); 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour to the point (x,y). 318fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the start of a new contour 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the start of a new contour 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void moveTo(SkScalar x, SkScalar y); 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour to the point 325fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The start of a new contour 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void moveTo(const SkPoint& p) { 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->moveTo(p.fX, p.fY); 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour relative to the last point on the 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour. If there is no previous contour, this is treated the 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com same as moveTo(). 335fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to add to the x-coordinate of the end of the 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour, to specify the start of a new contour 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to add to the y-coordinate of the end of the 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour, to specify the start of a new contour 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rMoveTo(SkScalar dx, SkScalar dy); 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a line from the last point to the specified point (x,y). If no 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo() call has been made for this contour, the first point is 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com automatically set to (0,0). 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the end of a line 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the end of a line 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lineTo(SkScalar x, SkScalar y); 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a line from the last point to the specified point. If no moveTo() 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call has been made for this contour, the first point is automatically 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com set to (0,0). 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The end of a line 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lineTo(const SkPoint& p) { 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->lineTo(p.fX, p.fY); 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as lineTo, but the coordinates are considered relative to the last 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com point on this contour. If there is no previous point, then a moveTo(0,0) 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is inserted automatically. 365fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to add to the x-coordinate of the previous point 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com on this contour, to specify a line 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to add to the y-coordinate of the previous point 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com on this contour, to specify a line 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rLineTo(SkScalar dx, SkScalar dy); 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a quadratic bezier from the last point, approaching control point 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, the first point is automatically set to (0,0). 376fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the control point on a quadratic curve 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the control point on a quadratic curve 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x2 The x-coordinate of the end point on a quadratic curve 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y2 The y-coordinate of the end point on a quadratic curve 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2); 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a quadratic bezier from the last point, approaching control point 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p1, and ending at p2. If no moveTo() call has been made for this 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contour, the first point is automatically set to (0,0). 387fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p1 The control point on a quadratic curve 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p2 The end point on a quadratic curve 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void quadTo(const SkPoint& p1, const SkPoint& p2) { 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY); 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as quadTo, but the coordinates are considered relative to the last 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com point on this contour. If there is no previous point, then a moveTo(0,0) 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is inserted automatically. 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx1 The amount to add to the x-coordinate of the last point on 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the control point of a quadratic curve 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy1 The amount to add to the y-coordinate of the last point on 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the control point of a quadratic curve 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx2 The amount to add to the x-coordinate of the last point on 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a quadratic curve 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy2 The amount to add to the y-coordinate of the last point on 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a quadratic curve 4078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4088a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2); 4098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 410277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 411277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar w); 412277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) { 413277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w); 414277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com } 415277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, 416277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar w); 41726da7f00aedba107d4b3e382283034e265db09b6skia.committer@gmail.com 4188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a cubic bezier from the last point, approaching control points 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com made for this contour, the first point is automatically set to (0,0). 421fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the 1st control point on a cubic curve 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the 1st control point on a cubic curve 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x2 The x-coordinate of the 2nd control point on a cubic curve 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y2 The y-coordinate of the 2nd control point on a cubic curve 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x3 The x-coordinate of the end point on a cubic curve 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y3 The y-coordinate of the end point on a cubic curve 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x3, SkScalar y3); 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a cubic bezier from the last point, approaching control points p1 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and p2, and ending at p3. If no moveTo() call has been made for this 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contour, the first point is automatically set to (0,0). 435fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p1 The 1st control point on a cubic curve 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p2 The 2nd control point on a cubic curve 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p3 The end point on a cubic curve 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) { 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY); 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as cubicTo, but the coordinates are considered relative to the 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current point on this contour. If there is no previous point, then a 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo(0,0) is inserted automatically. 447fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx1 The amount to add to the x-coordinate of the last point on 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 1st control point of a cubic curve 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy1 The amount to add to the y-coordinate of the last point on 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 1st control point of a cubic curve 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx2 The amount to add to the x-coordinate of the last point on 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 2nd control point of a cubic curve 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy2 The amount to add to the y-coordinate of the last point on 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 2nd control point of a cubic curve 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx3 The amount to add to the x-coordinate of the last point on 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a cubic curve 4588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy3 The amount to add to the y-coordinate of the last point on 4598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a cubic curve 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4616b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 4626b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com SkScalar x3, SkScalar y3); 4638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 464c778904a5b686617ad7fdec850ddc21e103dca0freed /** 465c778904a5b686617ad7fdec850ddc21e103dca0freed * Append the specified arc to the path. If the start of the arc is different from the path's 466c778904a5b686617ad7fdec850ddc21e103dca0freed * current last point, then an automatic lineTo() is added to connect the current contour 467c778904a5b686617ad7fdec850ddc21e103dca0freed * to the start of the arc. However, if the path is empty, then we call moveTo() with 468c778904a5b686617ad7fdec850ddc21e103dca0freed * the first point of the arc. The sweep angle is treated mod 360. 469c778904a5b686617ad7fdec850ddc21e103dca0freed * 470c778904a5b686617ad7fdec850ddc21e103dca0freed * @param oval The bounding oval defining the shape and size of the arc 471c778904a5b686617ad7fdec850ddc21e103dca0freed * @param startAngle Starting angle (in degrees) where the arc begins 472c778904a5b686617ad7fdec850ddc21e103dca0freed * @param sweepAngle Sweep angle (in degrees) measured clockwise. This is treated mod 360. 473c778904a5b686617ad7fdec850ddc21e103dca0freed * @param forceMoveTo If true, always begin a new contour with the arc 474c778904a5b686617ad7fdec850ddc21e103dca0freed */ 475c778904a5b686617ad7fdec850ddc21e103dca0freed void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo); 4768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 477c778904a5b686617ad7fdec850ddc21e103dca0freed /** 478c778904a5b686617ad7fdec850ddc21e103dca0freed * Append a line and arc to the current path. This is the same as the PostScript call "arct". 479c778904a5b686617ad7fdec850ddc21e103dca0freed */ 480c778904a5b686617ad7fdec850ddc21e103dca0freed void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius); 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Append a line and arc to the current path. This is the same as the 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PostScript call "arct". 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) { 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Close the current contour. If the current point is not equal to the 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com first point of the contour, a line segment is automatically added. 4918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void close(); 4938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4948fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com enum Direction { 4958fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** Direction either has not been or could not be computed */ 4968fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kUnknown_Direction, 4978fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** clockwise direction for adding closed contours */ 4988fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kCW_Direction, 4998fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** counter-clockwise direction for adding closed contours */ 5008fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kCCW_Direction, 5018fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com }; 5028fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 503a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 504a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Return the opposite of the specified direction. kUnknown is its own 505a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * opposite. 506a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 50730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com static Direction OppositeDirection(Direction dir) { 508a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com static const Direction gOppositeDir[] = { 509a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com kUnknown_Direction, kCCW_Direction, kCW_Direction 510a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com }; 511a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com return gOppositeDir[dir]; 51230c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com } 51330c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com 51469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com /** 51512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com * Returns whether or not a fill type is inverted 5165f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * 5175f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kWinding_FillType -> false 5185f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kEvenOdd_FillType -> false 5195f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseWinding_FillType -> true 5205f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseEvenOdd_FillType -> true 52112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com */ 5225f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com static bool IsInverseFillType(FillType fill) { 52312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); 52412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); 52512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); 52612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); 52712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com return (fill & 2) != 0; 52812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com } 52912b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 53012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com /** 53112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com * Returns the equivalent non-inverted fill type to the given fill type 5325f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * 5335f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kWinding_FillType -> kWinding_FillType 5345f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kEvenOdd_FillType -> kEvenOdd_FillType 5355f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseWinding_FillType -> kWinding_FillType 5365f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseEvenOdd_FillType -> kEvenOdd_FillType 53712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com */ 5385f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com static FillType ConvertToNonInverseFillType(FillType fill) { 53912b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); 54012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); 54112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); 54212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); 54312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com return (FillType)(fill & 1); 54412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com } 54512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 54612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com /** 54769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * Tries to quickly compute the direction of the first non-degenerate 54869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * contour. If it can be computed, return true and set dir to that 54969a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * direction. If it cannot be (quickly) determined, return false and ignore 55030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * the dir parameter. If the direction was determined, it is cached to make 55130c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * subsequent calls return quickly. 55269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com */ 55369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com bool cheapComputeDirection(Direction* dir) const; 55469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com 55569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com /** 55669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * Returns true if the path's direction can be computed via 55769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * cheapComputDirection() and if that computed direction matches the 558a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * specified direction. If dir is kUnknown, returns true if the direction 559a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * cannot be computed. 56069a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com */ 56169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com bool cheapIsDirection(Direction dir) const { 562a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com Direction computedDir = kUnknown_Direction; 563a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com (void)this->cheapComputeDirection(&computedDir); 564a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com return computedDir == dir; 56569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com } 56669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com 5674f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips /** 5684f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * Returns true if the path specifies a rectangle. 5694f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * 5704f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * If this returns false, then all output parameters are ignored, and left 5714f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * unchanged. If this returns true, then each of the output parameters 5724f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * are checked for NULL. If they are not, they return their value. 5734f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * 57491b0a3587342c48a1a6e1c4687686688737359darobertphillips * @param rect If not null, set to the bounds of the rectangle. 57591b0a3587342c48a1a6e1c4687686688737359darobertphillips * Note : this bounds may be smaller than the path's bounds, since it is just 57691b0a3587342c48a1a6e1c4687686688737359darobertphillips * the bounds of the "drawable" parts of the path. e.g. a trailing MoveTo would 57791b0a3587342c48a1a6e1c4687686688737359darobertphillips * be ignored in this rect, but not by the path's bounds 5784f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @param isClosed If not null, set to true if the path is closed 5794f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @param direction If not null, set to the rectangle's direction 5804f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @return true if the path specifies a rectangle 5814f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips */ 58291b0a3587342c48a1a6e1c4687686688737359darobertphillips bool isRect(SkRect* rect, bool* isClosed = NULL, Direction* direction = NULL) const; 5838fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 58495bc5f349561fef2d6fbae71adb08cf5c2eec0c9caryclark /** Returns true if the path specifies a pair of nested rectangles, or would draw a 58595bc5f349561fef2d6fbae71adb08cf5c2eec0c9caryclark pair of nested rectangles when filled. If so, and if 5868fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com rect is not null, set rect[0] to the outer rectangle and rect[1] to the inner 5878fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com rectangle. If so, and dirs is not null, set dirs[0] to the direction of 5888fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com the outer rectangle and dirs[1] to the direction of the inner rectangle. If 5898fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com the path does not specify a pair of nested rectangles, return 5908fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com false and ignore rect and dirs. 5918fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 5928fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @param rect If not null, returns the path as a pair of nested rectangles 5938fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @param dirs If not null, returns the direction of the rects 5948fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @return true if the path describes a pair of nested rectangles 5958fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com */ 59695bc5f349561fef2d6fbae71adb08cf5c2eec0c9caryclark bool isNestedFillRects(SkRect rect[2], Direction dirs[2] = NULL) const; 5978fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 598a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 599a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed rectangle contour to the path 600a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The rectangle to add as a closed contour to the path 601a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 602a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 603a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 604ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void addRect(const SkRect& rect, Direction dir = kCW_Direction); 6058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 606a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 607a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed rectangle contour to the path 608a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 609a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param left The left side of a rectangle to add as a closed contour 610a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * to the path 611a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param top The top of a rectangle to add as a closed contour to the 612a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * path 613a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param right The right side of a rectangle to add as a closed contour 614a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * to the path 615a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param bottom The bottom of a rectangle to add as a closed contour to 616a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * the path 617a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 618a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 619a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, 6218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 623a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 624a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed oval contour to the path 625a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 626a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param oval The bounding oval to add as a closed contour to the path 627a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the oval's contour. Cannot be 628a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 629a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addOval(const SkRect& oval, Direction dir = kCW_Direction); 6318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 632a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 633a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed circle contour to the path 634a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 635a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param x The x-coordinate of the center of a circle to add as a 636a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * closed contour to the path 637a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param y The y-coordinate of the center of a circle to add as a 638a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * closed contour to the path 639a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param radius The radius of a circle to add as a closed contour to the 640a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * path 641a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the circle's contour. Cannot be 642a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 643a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addCircle(SkScalar x, SkScalar y, SkScalar radius, 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add the specified arc to the path as a new contour. 648fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the size of the arc 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 6518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 6528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle); 6548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 655a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 656a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed round-rectangle contour to the path 657a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The bounds of a round-rectangle to add as a closed contour 658a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rx The x-radius of the rounded corners on the round-rectangle 659a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param ry The y-radius of the rounded corners on the round-rectangle 660a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 661a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 662a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 663ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 664ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com Direction dir = kCW_Direction); 6658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 666a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 667a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed round-rectangle contour to the path. Each corner receives 668a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * two radius values [X, Y]. The corners are ordered top-left, top-right, 669a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * bottom-right, bottom-left. 670a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The bounds of a round-rectangle to add as a closed contour 671a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner 672a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 673a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 6744e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * Note: The radii here now go through the same constraint handling as the 6754e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * SkRRect radii (i.e., either radii at a corner being 0 implies a 6764e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * sqaure corner and oversized radii are proportionally scaled down). 677a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addRoundRect(const SkRect& rect, const SkScalar radii[], 6798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 681744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com /** 6824e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * Add an SkRRect contour to the path 6834e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * @param rrect The rounded rect to add as a closed contour 6844e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * @param dir The winding direction for the new contour. Cannot be 6854e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * kUnknown_Direction. 6864ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 6874e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction); 6884ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 6894ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 690744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * Add a new contour made of just lines. This is just a fast version of 691744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * the following: 692744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->moveTo(pts[0]); 693744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * for (int i = 1; i < count; ++i) { 694744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->lineTo(pts[i]); 695744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * } 696744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * if (close) { 697744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->close(); 698744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * } 699744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com */ 700744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com void addPoly(const SkPoint pts[], int count, bool close); 701744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com 70214747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org enum AddPathMode { 70314747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org /** Source path contours are added as new contours. 70414747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org */ 70514747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org kAppend_AddPathMode, 70614747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org /** Path is added by extending the last contour of the destination path 70714747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org with the first contour of the source path. If the last contour of 708877c44956dceff038c0e315c8d311b0d581f2680skia.committer@gmail.com the destination path is closed, then it will not be extended. 70914747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org Instead, the start of source path will be extended by a straight 71014747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org line to the end point of the destination path. 71114747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org */ 712877c44956dceff038c0e315c8d311b0d581f2680skia.committer@gmail.com kExtend_AddPathMode 71314747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org }; 71414747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path, offset by (dx,dy) 7168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src The path to add as a new contour 7178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to translate the path in X as it is added 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to translate the path in Y as it is added 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 72014747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, SkScalar dx, SkScalar dy, 72114747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org AddPathMode mode = kAppend_AddPathMode); 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path 7248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 72514747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) { 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m; 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 72814747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org this->addPath(src, m, mode); 7298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path, transformed by matrix 7328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src The path to add as a new contour 73314747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org @param matrix Transform applied to src 73414747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org @param mode Determines how path is added 7358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 73614747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode); 7378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 73863d73749fbe36491403ea521005fd298dc70a94creed@google.com /** 73963d73749fbe36491403ea521005fd298dc70a94creed@google.com * Same as addPath(), but reverses the src input 74063d73749fbe36491403ea521005fd298dc70a94creed@google.com */ 74163d73749fbe36491403ea521005fd298dc70a94creed@google.com void reverseAddPath(const SkPath& src); 74263d73749fbe36491403ea521005fd298dc70a94creed@google.com 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset the path by (dx,dy), returning true on success 744fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 745fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dx The amount in the X direction to offset the entire path 746fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dy The amount in the Y direction to offset the entire path 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The translated path is written here 7488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy, SkPath* dst) const; 7508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset the path by (dx,dy), returning true on success 752fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 753fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dx The amount in the X direction to offset the entire path 754fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dy The amount in the Y direction to offset the entire path 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy) { 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->offset(dx, dy, this); 7588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Transform the points in this path by matrix, and write the answer into 7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst. 762fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to apply to the path 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The transformed path is written here 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void transform(const SkMatrix& matrix, SkPath* dst) const; 7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Transform the points in this path by matrix 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to apply to the path 7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void transform(const SkMatrix& matrix) { 7738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->transform(matrix, this); 7748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the last point on the path. If no points have been added, (0,0) 777294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com is returned. If there are no points, this returns false, otherwise it 778294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com returns true. 779fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param lastPt The last point on the path is returned here 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 782294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com bool getLastPt(SkPoint* lastPt) const; 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the last point on the path. If no points have been added, 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo(x,y) is automatically called. 786fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The new x-coordinate for the last point 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The new y-coordinate for the last point 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLastPt(SkScalar x, SkScalar y); 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the last point on the path. If no points have been added, moveTo(p) 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is automatically called. 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The new location for the last point 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLastPt(const SkPoint& p) { 7988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->setLastPt(p.fX, p.fY); 7998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 8008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 80110296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com enum SegmentMask { 80210296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com kLine_SegmentMask = 1 << 0, 80310296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com kQuad_SegmentMask = 1 << 1, 804277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kConic_SegmentMask = 1 << 2, 805277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kCubic_SegmentMask = 1 << 3, 80610296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com }; 80710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com 80810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com /** 80910296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * Returns a mask, where each bit corresponding to a SegmentMask is 81010296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * set if the path contains 1 or more segments of that type. 81110296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * Returns 0 for an empty path (no segments). 81210296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com */ 8136b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com uint32_t getSegmentMasks() const { return fPathRef->getSegmentMasks(); } 81410296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com 8158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Verb { 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMove_Verb, //!< iter.next returns 1 point 8178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLine_Verb, //!< iter.next returns 2 points 8188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kQuad_Verb, //!< iter.next returns 3 points 819277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kConic_Verb, //!< iter.next returns 3 points + iter.conicWeight() 8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kCubic_Verb, //!< iter.next returns 4 points 821b3b8dfa31326c51dab8b5ed569e19ee715582d1bbsalomon@google.com kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt) 822277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kDone_Verb, //!< iter.next returns 0 points 8238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 8248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Iterate through all of the segments (lines, quadratics, cubics) of 8268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each contours in a path. 82772785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org 82872785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org The iterator cleans up the segments along the way, removing degenerate 82972785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org segments and adding close verbs where necessary. When the forceClose 83072785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org argument is provided, each contour (as defined by a new starting 83172785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org move command) will be completed with a close verb regardless of the 83272785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org contour's contents. 8338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8347ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org class SK_API Iter { 8358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 83672785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org Iter(); 83772785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org Iter(const SkPath&, bool forceClose); 8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPath(const SkPath&, bool forceClose); 8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the next verb in this iteration of the path. When all 8428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com segments have been visited, return kDone_Verb. 843b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts The points representing the current verb and/or segment 8454a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com @param doConsumeDegerates If true, first scan for segments that are 8464a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com deemed degenerate (too short) and skip those. 8478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The verb for the current segment 8488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8494a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com Verb next(SkPoint pts[4], bool doConsumeDegerates = true) { 8504a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com if (doConsumeDegerates) { 8514a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com this->consumeDegenerateSegments(); 8524a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com } 8534a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com return this->doNext(pts); 8544a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com } 8558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 856277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com /** 857277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com * Return the weight for the current conic. Only valid if the current 858277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com * segment return by next() was a conic. 859277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com */ 860277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar conicWeight() const { return *fConicWeights; } 861277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com 8628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If next() returns kLine_Verb, then this query returns true if the 8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line was the result of a close() command (i.e. the end point is the 8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com initial moveto for this contour). If next() returned a different 8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com verb, this returns an undefined value. 866b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return If the last call to next() returned kLine_Verb, return true 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if it was the result of an explicit close command. 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isCloseLine() const { return SkToBool(fCloseLine); } 871b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the current contour is closed (has a kClose_Verb) 8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the current contour is closed (has a kClose_Verb) 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isClosedContour() const; 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint* fPts; 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* fVerbs; 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* fVerbStop; 881277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com const SkScalar* fConicWeights; 8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fMoveTo; 8838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fLastPt; 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fForceClose; 8858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fNeedClose; 8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fCloseLine; 887b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org SkBool8 fSegmentState; 8888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8899e25dbf589539dd44244bc2581590bd7591e17a2reed@google.com inline const SkPoint& cons_moveTo(); 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Verb autoClose(SkPoint pts[2]); 8914da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org void consumeDegenerateSegments(); 8924a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com Verb doNext(SkPoint pts[4]); 8938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 8948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8956630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org /** Iterate through the verbs in the path, providing the associated points. 8966630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org */ 8976630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org class SK_API RawIter { 8986630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org public: 8996630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org RawIter(); 9006630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org RawIter(const SkPath&); 9016630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 9026630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org void setPath(const SkPath&); 9036630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 9046630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org /** Return the next verb in this iteration of the path. When all 9056630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org segments have been visited, return kDone_Verb. 906fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 9076630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org @param pts The points representing the current verb and/or segment 908f6d3c5aa5f93e4c3cc7a7aebf014e960cf837783bsalomon@google.com This must not be NULL. 9096630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org @return The verb for the current segment 9106630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org */ 9116630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org Verb next(SkPoint pts[4]); 9126630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 913277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar conicWeight() const { return *fConicWeights; } 914277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com 9156630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org private: 9166630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const SkPoint* fPts; 9176630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const uint8_t* fVerbs; 9186630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const uint8_t* fVerbStop; 919277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com const SkScalar* fConicWeights; 9206630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org SkPoint fMoveTo; 9216630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org }; 9226630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 923bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org /** 924bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org * Returns true if the point { x, y } is contained by the path, taking into 925bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org * account the FillType. 926bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org */ 927bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org bool contains(SkScalar x, SkScalar y) const; 928bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org 929e956259c5a4f71768afb34ec032eaed49dcbe9f2caryclark void dump(SkWStream* , bool forceClose, bool dumpAsHex) const; 930e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com void dump() const; 931e956259c5a4f71768afb34ec032eaed49dcbe9f2caryclark void dumpHex() const; 9328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 93394e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com /** 9344faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * Write the path to the buffer, and return the number of bytes written. 93594e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com * If buffer is NULL, it still returns the number of bytes. 93694e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com */ 9374faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org size_t writeToMemory(void* buffer) const; 93894e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com /** 9394faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * Initializes the path from the buffer 9404faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * 9414faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @param buffer Memory to read from 9424faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @param length Amount of memory available in the buffer 9434faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @return number of bytes read (must be a multiple of 4) or 9444faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * 0 if there was not enough memory available 94594e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com */ 9464faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org size_t readFromMemory(const void* buffer, size_t length); 9478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9481ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org /** Returns a non-zero, globally unique value corresponding to the set of verbs 9491ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org and points in the path (but not the fill type [except on Android skbug.com/1762]). 9507ed98df9ba14bdb58e381508eb0505c963a4b6dbskia.committer@gmail.com Each time the path is modified, a different generation ID will be returned. 9511ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org */ 9527101abe5b37d82ea222e971a42615a97a2419edbrobertphillips@google.com uint32_t getGenerationID() const; 9531ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org 954523cda39435256bcb3e5665f47612d661d3c6bf9djsollen#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 9551ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org static const int kPathRefGenIDBitCnt = 30; // leave room for the fill type (skbug.com/1762) 9561ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org#else 9571ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org static const int kPathRefGenIDBitCnt = 32; 958f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif 959f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void validate() const;) 96163c684a8a609d39da11b4a656223cebf52ca85dccaryclark SkDEBUGCODE(void experimentalValidateRef() const { fPathRef->validate(); } ) 9628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 96401ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com enum SerializationOffsets { 965fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 1 free bit at 29 96611e055518a0cbe5329232a55fe2cd177e83836d8robertphillips@google.com kUnused1_SerializationShift = 28, // 1 free bit 96730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com kDirection_SerializationShift = 26, // requires 2 bits 968b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth kIsVolatile_SerializationShift = 25, // requires 1 bit 969fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 1 free bit at 24 970ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com kConvexity_SerializationShift = 16, // requires 8 bits 971ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com kFillType_SerializationShift = 8, // requires 8 bits 972fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 8 free bits at 0 97301ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com }; 97401ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com 975ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com SkAutoTUnref<SkPathRef> fPathRef; 976ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com 9775e1a7f2cc621d357da5c62a7bc4ef750d94b96f3commit-bot@chromium.org int fLastMoveToIndex; 9788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFillType; 979b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com mutable uint8_t fConvexity; 98030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com mutable uint8_t fDirection; 981b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth mutable SkBool8 fIsVolatile; 9828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 983a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com /** Resets all fields other than fPathRef to their initial 'empty' values. 984a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * Assumes the caller has already emptied fPathRef. 985a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * On Android increments fGenerationID without reseting it. 986a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com */ 987a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com void resetFields(); 988a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com 989a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com /** Sets all fields other than fPathRef to the values in 'that'. 990a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * Assumes the caller has already set fPathRef. 9919c9d4a70028ef8dc33a46cfc0b22e254443effe3mtklein@google.com * Doesn't change fGenerationID or fSourcePath on Android. 992a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com */ 993a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com void copyFields(const SkPath& that); 994a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com 9958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class Iter; 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkPathStroker; 9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* Append, in reverse order, the first contour of path, ignoring path's 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com last point. If no moveTo() call has been made for this contour, the 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com first point is automatically set to (0,0). 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reversePathTo(const SkPath&); 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1005d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // called before we add points for lineTo, quadTo, cubicTo, checking to see 1006d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // if we need to inject a leading moveTo first 1007d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // 1008d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0) 1009d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo) 1010d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // 10115e1a7f2cc621d357da5c62a7bc4ef750d94b96f3commit-bot@chromium.org inline void injectMoveToIfNeeded(); 1012d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com 10136aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com inline bool hasOnlyMoveTos() const; 10146aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com 101530c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com Convexity internalGetConvexity() const; 10163458716b52aa25dcd1b270141c7628c380696e35skia.committer@gmail.com 1017f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts, 1018f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com bool* isClosed, Direction* direction) const; 101930c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com 1020ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com /** Returns if the path can return a bound at no cost (true) or will have to 1021ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com perform some computation (false). 1022ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com */ 1023ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com bool hasComputedBounds() const { 1024ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 1025ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->hasComputedBounds(); 1026ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1027ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 1028ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 1029ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com // 'rect' needs to be sorted 1030ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void setBounds(const SkRect& rect) { 10310efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com SkPathRef::Editor ed(&fPathRef); 10320efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com 10330efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com ed.setBounds(rect); 1034ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1035ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 1036aec251012542e971100e218bf463adbfb5d21d20caryclark void setPt(int index, SkScalar x, SkScalar y); 1037aec251012542e971100e218bf463adbfb5d21d20caryclark 10388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkAutoPathBoundsUpdate; 10396aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com friend class SkAutoDisableOvalCheck; 104030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com friend class SkAutoDisableDirectionCheck; 1041a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org friend class SkBench_AddPathTest; // perf test reversePathTo 1042a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org friend class PathTest_Private; // unit test reversePathTo 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1046