SkPath.h revision c778904a5b686617ad7fdec850ddc21e103dca0f
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2006 The Android Open Source Project 48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPath_DEFINED 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPath_DEFINED 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1365a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com#include "SkInstCnt.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkMatrix.h" 15ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com#include "SkPathRef.h" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDArray.h" 171dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com#include "SkRefCnt.h" 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 19739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkReader32; 20739456585a0cc52b335cd1c0a9fc6b01782a7f89reed@google.comclass SkWriter32; 218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkAutoPathBoundsUpdate; 228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkString; 234ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.comclass SkRRect; 2466a5d8bf13fe98baae268db0211e9c25e5ece7facaryclarkclass SkWStream; 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** \class SkPath 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com The SkPath class encapsulates compound (multiple contour) geometric paths 298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com consisting of straight line segments, quadratic curves, and cubic curves. 308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com*/ 317ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.orgclass SK_API SkPath { 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 336f07665768dc84453316e7b2bbd6049576764cb1mtklein SK_DECLARE_INST_COUNT(SkPath); 3465a87cc13d6babcf12844cca244ca7cc5258cadcbsalomon@google.com 358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPath(); 361ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org SkPath(const SkPath&); 378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com ~SkPath(); 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 391ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org SkPath& operator=(const SkPath&); 405e728450247c677343e072f37150967b36892573bsalomon@google.com friend SK_API bool operator==(const SkPath&, const SkPath&); 413abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com friend bool operator!=(const SkPath& a, const SkPath& b) { 423abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com return !(a == b); 433abec1d7c38e9bd786fc6057f9608f3eeec98c86reed@android.com } 448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum FillType { 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specifies that "inside" is computed by a non-zero sum of signed 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com edge crossings 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kWinding_FillType, 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Specifies that "inside" is computed by an odd number of edge 518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com crossings 528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kEvenOdd_FillType, 548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as Winding, but draws outside of the path, rather than inside 558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kInverseWinding_FillType, 578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as EvenOdd, but draws outside of the path, rather than inside 588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kInverseEvenOdd_FillType 608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the path's fill type. This is used to define how "inside" is 638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com computed. The default value is kWinding_FillType. 648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the path's fill type 668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com FillType getFillType() const { return (FillType)fFillType; } 688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the path's fill type. This is used to define how "inside" is 708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com computed. The default value is kWinding_FillType. 71b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param ft The new fill type for this path 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 74f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void setFillType(FillType ft) { 75f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com fFillType = SkToU8(ft); 76f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com } 778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the filltype is one of the Inverse variants */ 795f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com bool isInverseFillType() const { return IsInverseFillType((FillType)fFillType); } 808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 81b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com /** 82b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Toggle between inverse and normal filltypes. This reverse the return 83b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * value of isInverseFillType() 84b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com */ 85f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void toggleInverseFillType() { 86f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com fFillType ^= 2; 876b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com } 888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com enum Convexity { 9004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kUnknown_Convexity, 9104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kConvex_Convexity, 9204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com kConcave_Convexity 9304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com }; 9404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 9504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 9630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * Return the path's convexity, as stored in the path. If it is currently unknown, 9730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * then this function will attempt to compute the convexity (and cache the result). 98b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com */ 99b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com Convexity getConvexity() const { 10030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com if (kUnknown_Convexity != fConvexity) { 10130c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com return static_cast<Convexity>(fConvexity); 10230c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com } else { 10330c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com return this->internalGetConvexity(); 104b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com } 105b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com } 106b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com 107b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com /** 108b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Return the currently cached value for convexity, even if that is set to 109b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * kUnknown_Convexity. Note: getConvexity() will automatically call 110b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * ComputeConvexity and cache its return value if the current setting is 111b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * kUnknown. 11204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 113b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com Convexity getConvexityOrUnknown() const { return (Convexity)fConvexity; } 11404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 11504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 11604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Store a convexity setting in the path. There is no automatic check to 11730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * see if this value actually agrees with the return value that would be 11830c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * computed by getConvexity(). 119b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * 120b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * Note: even if this is set to a "known" value, if the path is later 121b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * changed (e.g. lineTo(), addRect(), etc.) then the cached value will be 122b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com * reset to kUnknown_Convexity. 12304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 12404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com void setConvexity(Convexity); 12504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 12604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 12704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Returns true if the path is flagged as being convex. This is not a 12804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * confirmed by any analysis, it is just the value set earlier. 12904863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com */ 13004863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com bool isConvex() const { 13104863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com return kConvex_Convexity == this->getConvexity(); 13204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com } 13304863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com 13404863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com /** 13504863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * Set the isConvex flag to true or false. Convex paths may draw faster if 13604863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * this flag is set, though setting this to true on a path that is in fact 13704863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * not convex can give undefined results when drawn. Paths default to 13804863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com * isConvex == false 1396b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com */ 1404469938e92d779dff05e745559e67907bbf21e78reed@google.com SK_ATTR_DEPRECATED("use setConvexity") 141f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com void setIsConvex(bool isConvex) { 14204863fa14a44ddf85acbc6268690ebc3f0d1d6dbreed@google.com this->setConvexity(isConvex ? kConvex_Convexity : kConcave_Convexity); 143f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com } 1446b82d1adc6a4726e36674e468ff1157e0b75373freed@android.com 1456aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com /** Returns true if the path is an oval. 1466aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * 1476aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * @param rect returns the bounding rect of this oval. It's a circle 1486aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * if the height and width are the same. 1496aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * 1506aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * @return true if this path is an oval. 1516aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * Tracking whether a path is an oval is considered an 1526aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * optimization for performance and so some paths that are in 1536aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com * fact ovals can report false. 1546aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com */ 155466310dbd3073add2ec934e336c30deaaf702eaerobertphillips@google.com bool isOval(SkRect* rect) const { return fPathRef->isOval(rect); } 1566aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com 1578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Clear any lines and curves from the path, making it empty. This frees up 1588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com internal storage associated with those segments. 159cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com On Android, does not change fSourcePath. 1608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reset(); 162fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 1638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Similar to reset(), in that all lines and curves are removed from the 1648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path. However, any internal storage for those lines/curves is retained, 1658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com making reuse of the path potentially faster. 166cb8b0eeacfc2ff79a2b9721e3ef21d1efb507dc8mtklein@google.com On Android, does not change fSourcePath. 1678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 1688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rewind(); 1698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the path is empty (contains no lines or curves) 1718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the path is empty (contains no lines or curves) 1738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 174ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com bool isEmpty() const { 175ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 176ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return 0 == fPathRef->countVerbs(); 177ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1790bb18bb264b26afca45452910437c09445e23a3creed@google.com /** 1800bb18bb264b26afca45452910437c09445e23a3creed@google.com * Returns true if all of the points in this path are finite, meaning there 1810bb18bb264b26afca45452910437c09445e23a3creed@google.com * are no infinities and no NaNs. 1820bb18bb264b26afca45452910437c09445e23a3creed@google.com */ 1830bb18bb264b26afca45452910437c09445e23a3creed@google.com bool isFinite() const { 184ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 185ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->isFinite(); 1860bb18bb264b26afca45452910437c09445e23a3creed@google.com } 1870bb18bb264b26afca45452910437c09445e23a3creed@google.com 188b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth /** Returns true if the path is volatile (i.e. should not be cached by devices.) 189b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth */ 190b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth bool isVolatile() const { 191b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth return SkToBool(fIsVolatile); 192b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth } 193b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth 194b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth /** Specify whether this path is volatile. Paths are not volatile by 195b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth default. Temporary paths that are discarded or modified after use should be 196b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth marked as volatile. This provides a hint to the device that the path 197b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth should not be cached. Providing this hint when appropriate can 198b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth improve performance by avoiding unnecessary overhead and resource 199b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth consumption on the device. 200b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth */ 201b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth void setIsVolatile(bool isVolatile) { 202b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth fIsVolatile = isVolatile; 203b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth } 204b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth 2054da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a line for zero length 2064da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2074da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the line is of zero length; otherwise false. 2084da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2094da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) { 21094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2); 2114da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2124da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2134da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a quad for zero length 2144da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2154da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the quad is of zero length; otherwise false. 2164da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2174da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2, 2184da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org const SkPoint& p3) { 21994fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2) && 22094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p2.equalsWithinTolerance(p3); 2214da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2224da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2234da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org /** Test a cubic curve for zero length 2244da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2254da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org @return true if the cubic is of zero length; otherwise false. 2264da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org */ 2274da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2, 2284da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org const SkPoint& p3, const SkPoint& p4) { 22994fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com return p1.equalsWithinTolerance(p2) && 23094fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p2.equalsWithinTolerance(p3) && 23194fa43c6255906660c2ff001fb462b6492cbdc07epoger@google.com p3.equalsWithinTolerance(p4); 2324da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org } 2334da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org 2347e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com /** 2357e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * Returns true if the path specifies a single line (i.e. it contains just 2367e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * a moveTo and a lineTo). If so, and line[] is not null, it sets the 2 2377e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * points in line[] to the end-points of the line. If the path is not a 2387e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com * line, returns false and ignores line[]. 2397e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com */ 2407e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com bool isLine(SkPoint line[2]) const; 2417e6c4d16010550ee148f1c79cf088c0320fed5c1reed@google.com 242d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com /** Return the number of points in the path 243d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com */ 2441dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com int countPoints() const; 245d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com 246d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com /** Return the point at the specified index. If the index is out of range 247d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com (i.e. is not 0 <= index < countPoints()) then the returned coordinates 248d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com will be (0,0) 249d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com */ 250d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com SkPoint getPoint(int index) const; 251d3aa4ff7a564953dff9a15ff03fd42eebf64569freed@android.com 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns the number of points in the path. Up to max points are copied. 253fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 2548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param points If not null, receives up to max points 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param max The maximum number of points to copy into points 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return the actual number of points in the path 2578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int getPoints(SkPoint points[], int max) const; 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 260df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com /** Return the number of verbs in the path 261df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com */ 2621dfe88e00aeddf20690fd2469fd17e43f670ee3absalomon@google.com int countVerbs() const; 263df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com 264df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com /** Returns the number of verbs in the path. Up to max verbs are copied. The 265df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com verbs are copied as one byte per verb. 266fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 267df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @param verbs If not null, receives up to max verbs 268df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @param max The maximum number of verbs to copy into verbs 269df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com @return the actual number of verbs in the path 270df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com */ 271df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com int getVerbs(uint8_t verbs[], int max) const; 272df9d656c352928f995abce0a62c4ec3255232a45bsalomon@google.com 2738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //! Swap contents of this and other. Guaranteed not to throw 2748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void swap(SkPath& other); 2758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 276d252db03d9650013b545ef9781fe993c07f8f314reed@android.com /** Returns the bounds of the path's points. If the path contains 0 or 1 277d252db03d9650013b545ef9781fe993c07f8f314reed@android.com points, the bounds is set to (0,0,0,0), and isEmpty() will return true. 278d252db03d9650013b545ef9781fe993c07f8f314reed@android.com Note: this bounds may be larger than the actual shape, since curves 27991b0a3587342c48a1a6e1c4687686688737359darobertphillips do not extend as far as their control points. Additionally this bound 28091b0a3587342c48a1a6e1c4687686688737359darobertphillips can contain trailing MoveTo points (cf. isRect). 281d252db03d9650013b545ef9781fe993c07f8f314reed@android.com */ 282d252db03d9650013b545ef9781fe993c07f8f314reed@android.com const SkRect& getBounds() const { 283ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->getBounds(); 284d252db03d9650013b545ef9781fe993c07f8f314reed@android.com } 2858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Calling this will, if the internal cache of the bounds is out of date, 2879bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com update it so that subsequent calls to getBounds will be instantaneous. 2888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com This also means that any copies or simple transformations of the path 2898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com will inherit the cached bounds. 290d252db03d9650013b545ef9781fe993c07f8f314reed@android.com */ 291d252db03d9650013b545ef9781fe993c07f8f314reed@android.com void updateBoundsCache() const { 292d252db03d9650013b545ef9781fe993c07f8f314reed@android.com // for now, just calling getBounds() is sufficient 293d252db03d9650013b545ef9781fe993c07f8f314reed@android.com this->getBounds(); 294d252db03d9650013b545ef9781fe993c07f8f314reed@android.com } 2958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2969bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com /** 2979bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * Does a conservative test to see whether a rectangle is inside a path. Currently it only 2989bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * will ever return true for single convex contour paths. The empty-status of the rect is not 2999bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * considered (e.g. a rect that is a point can be inside a path). Points or line segments where 3009bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com * the rect edge touches the path border are not considered containment violations. 3019bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com */ 3029bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com bool conservativelyContainsRect(const SkRect& rect) const; 3039bee33afbeca29f531c8455513b925f6e93da633bsalomon@google.com 3048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // Construction methods 3058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Hint to the path to prepare for adding more points. This can allow the 3078a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com path to more efficiently grow its storage. 308fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param extraPtCount The number of extra points the path should 3108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com preallocate for. 3118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void incReserve(unsigned extraPtCount); 3138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour to the point (x,y). 315fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the start of a new contour 3178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the start of a new contour 3188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void moveTo(SkScalar x, SkScalar y); 3208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour to the point 322fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The start of a new contour 3248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void moveTo(const SkPoint& p) { 3268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->moveTo(p.fX, p.fY); 3278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the beginning of the next contour relative to the last point on the 3308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour. If there is no previous contour, this is treated the 3318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com same as moveTo(). 332fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to add to the x-coordinate of the end of the 3348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour, to specify the start of a new contour 3358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to add to the y-coordinate of the end of the 3368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com previous contour, to specify the start of a new contour 3378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rMoveTo(SkScalar dx, SkScalar dy); 3398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a line from the last point to the specified point (x,y). If no 3418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo() call has been made for this contour, the first point is 3428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com automatically set to (0,0). 3438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The x-coordinate of the end of a line 3458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The y-coordinate of the end of a line 3468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lineTo(SkScalar x, SkScalar y); 3488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a line from the last point to the specified point. If no moveTo() 3508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com call has been made for this contour, the first point is automatically 3518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com set to (0,0). 3528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The end of a line 3548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void lineTo(const SkPoint& p) { 3568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->lineTo(p.fX, p.fY); 3578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as lineTo, but the coordinates are considered relative to the last 3608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com point on this contour. If there is no previous point, then a moveTo(0,0) 3618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is inserted automatically. 362fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to add to the x-coordinate of the previous point 3648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com on this contour, to specify a line 3658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy The amount to add to the y-coordinate of the previous point 3668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com on this contour, to specify a line 3678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rLineTo(SkScalar dx, SkScalar dy); 3698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a quadratic bezier from the last point, approaching control point 3718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for 3728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, the first point is automatically set to (0,0). 373fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the control point on a quadratic curve 3758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the control point on a quadratic curve 3768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x2 The x-coordinate of the end point on a quadratic curve 3778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y2 The y-coordinate of the end point on a quadratic curve 3788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2); 3808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a quadratic bezier from the last point, approaching control point 3828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com p1, and ending at p2. If no moveTo() call has been made for this 3838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contour, the first point is automatically set to (0,0). 384fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 3858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p1 The control point on a quadratic curve 3868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p2 The end point on a quadratic curve 3878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 3888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void quadTo(const SkPoint& p1, const SkPoint& p2) { 3898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY); 3908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 3918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as quadTo, but the coordinates are considered relative to the last 3938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com point on this contour. If there is no previous point, then a moveTo(0,0) 3948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is inserted automatically. 3958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 3968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx1 The amount to add to the x-coordinate of the last point on 3978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the control point of a quadratic curve 3988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy1 The amount to add to the y-coordinate of the last point on 3998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the control point of a quadratic curve 4008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx2 The amount to add to the x-coordinate of the last point on 4018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a quadratic curve 4028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy2 The amount to add to the y-coordinate of the last point on 4038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a quadratic curve 4048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2); 4068a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 407277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 408277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar w); 409277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) { 410277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w); 411277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com } 412277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com void rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, 413277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar w); 41426da7f00aedba107d4b3e382283034e265db09b6skia.committer@gmail.com 4158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a cubic bezier from the last point, approaching control points 4168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been 4178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com made for this contour, the first point is automatically set to (0,0). 418fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x1 The x-coordinate of the 1st control point on a cubic curve 4208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y1 The y-coordinate of the 1st control point on a cubic curve 4218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x2 The x-coordinate of the 2nd control point on a cubic curve 4228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y2 The y-coordinate of the 2nd control point on a cubic curve 4238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x3 The x-coordinate of the end point on a cubic curve 4248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y3 The y-coordinate of the end point on a cubic curve 4258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 4278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkScalar x3, SkScalar y3); 4288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a cubic bezier from the last point, approaching control points p1 4308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com and p2, and ending at p3. If no moveTo() call has been made for this 4318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com contour, the first point is automatically set to (0,0). 432fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p1 The 1st control point on a cubic curve 4348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p2 The 2nd control point on a cubic curve 4358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p3 The end point on a cubic curve 4368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) { 4388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY); 4398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Same as cubicTo, but the coordinates are considered relative to the 4428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com current point on this contour. If there is no previous point, then a 4438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo(0,0) is inserted automatically. 444fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 4458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx1 The amount to add to the x-coordinate of the last point on 4468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 1st control point of a cubic curve 4478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy1 The amount to add to the y-coordinate of the last point on 4488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 1st control point of a cubic curve 4498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx2 The amount to add to the x-coordinate of the last point on 4508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 2nd control point of a cubic curve 4518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy2 The amount to add to the y-coordinate of the last point on 4528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the 2nd control point of a cubic curve 4538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx3 The amount to add to the x-coordinate of the last point on 4548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a cubic curve 4558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dy3 The amount to add to the y-coordinate of the last point on 4568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this contour, to specify the end point of a cubic curve 4578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4586b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com void rCubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, 4596b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com SkScalar x3, SkScalar y3); 4608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 461c778904a5b686617ad7fdec850ddc21e103dca0freed /** 462c778904a5b686617ad7fdec850ddc21e103dca0freed * Append the specified arc to the path. If the start of the arc is different from the path's 463c778904a5b686617ad7fdec850ddc21e103dca0freed * current last point, then an automatic lineTo() is added to connect the current contour 464c778904a5b686617ad7fdec850ddc21e103dca0freed * to the start of the arc. However, if the path is empty, then we call moveTo() with 465c778904a5b686617ad7fdec850ddc21e103dca0freed * the first point of the arc. The sweep angle is treated mod 360. 466c778904a5b686617ad7fdec850ddc21e103dca0freed * 467c778904a5b686617ad7fdec850ddc21e103dca0freed * @param oval The bounding oval defining the shape and size of the arc 468c778904a5b686617ad7fdec850ddc21e103dca0freed * @param startAngle Starting angle (in degrees) where the arc begins 469c778904a5b686617ad7fdec850ddc21e103dca0freed * @param sweepAngle Sweep angle (in degrees) measured clockwise. This is treated mod 360. 470c778904a5b686617ad7fdec850ddc21e103dca0freed * @param forceMoveTo If true, always begin a new contour with the arc 471c778904a5b686617ad7fdec850ddc21e103dca0freed */ 472c778904a5b686617ad7fdec850ddc21e103dca0freed void arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo); 4738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 474c778904a5b686617ad7fdec850ddc21e103dca0freed /** 475c778904a5b686617ad7fdec850ddc21e103dca0freed * Append a line and arc to the current path. This is the same as the PostScript call "arct". 476c778904a5b686617ad7fdec850ddc21e103dca0freed */ 477c778904a5b686617ad7fdec850ddc21e103dca0freed void arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius); 4788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Append a line and arc to the current path. This is the same as the 4808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com PostScript call "arct". 4818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) { 4838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius); 4848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 4858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Close the current contour. If the current point is not equal to the 4878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com first point of the contour, a line segment is automatically added. 4888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 4898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void close(); 4908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 4918fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com enum Direction { 4928fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** Direction either has not been or could not be computed */ 4938fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kUnknown_Direction, 4948fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** clockwise direction for adding closed contours */ 4958fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kCW_Direction, 4968fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** counter-clockwise direction for adding closed contours */ 4978fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com kCCW_Direction, 4988fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com }; 4998fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 500a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 501a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Return the opposite of the specified direction. kUnknown is its own 502a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * opposite. 503a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 50430c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com static Direction OppositeDirection(Direction dir) { 505a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com static const Direction gOppositeDir[] = { 506a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com kUnknown_Direction, kCCW_Direction, kCW_Direction 507a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com }; 508a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com return gOppositeDir[dir]; 50930c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com } 51030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com 51169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com /** 51212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com * Returns whether or not a fill type is inverted 5135f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * 5145f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kWinding_FillType -> false 5155f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kEvenOdd_FillType -> false 5165f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseWinding_FillType -> true 5175f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseEvenOdd_FillType -> true 51812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com */ 5195f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com static bool IsInverseFillType(FillType fill) { 52012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); 52112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); 52212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); 52312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); 52412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com return (fill & 2) != 0; 52512b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com } 52612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 52712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com /** 52812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com * Returns the equivalent non-inverted fill type to the given fill type 5295f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * 5305f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kWinding_FillType -> kWinding_FillType 5315f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kEvenOdd_FillType -> kEvenOdd_FillType 5325f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseWinding_FillType -> kWinding_FillType 5335f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com * kInverseEvenOdd_FillType -> kEvenOdd_FillType 53412b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com */ 5355f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com static FillType ConvertToNonInverseFillType(FillType fill) { 53612b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(0 == kWinding_FillType, fill_type_mismatch); 53712b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(1 == kEvenOdd_FillType, fill_type_mismatch); 53812b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(2 == kInverseWinding_FillType, fill_type_mismatch); 53912b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com SK_COMPILE_ASSERT(3 == kInverseEvenOdd_FillType, fill_type_mismatch); 54012b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com return (FillType)(fill & 1); 54112b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com } 54212b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com 54312b4e27ae1a29460e91a59f38122483e1faec697sugoi@google.com /** 54469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * Tries to quickly compute the direction of the first non-degenerate 54569a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * contour. If it can be computed, return true and set dir to that 54669a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * direction. If it cannot be (quickly) determined, return false and ignore 54730c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * the dir parameter. If the direction was determined, it is cached to make 54830c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com * subsequent calls return quickly. 54969a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com */ 55069a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com bool cheapComputeDirection(Direction* dir) const; 55169a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com 55269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com /** 55369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * Returns true if the path's direction can be computed via 55469a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com * cheapComputDirection() and if that computed direction matches the 555a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * specified direction. If dir is kUnknown, returns true if the direction 556a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * cannot be computed. 55769a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com */ 55869a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com bool cheapIsDirection(Direction dir) const { 559a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com Direction computedDir = kUnknown_Direction; 560a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com (void)this->cheapComputeDirection(&computedDir); 561a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com return computedDir == dir; 56269a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com } 56369a9943b67cc52c24beac853c6f8865dcb197b85reed@google.com 5644f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips /** 5654f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * Returns true if the path specifies a rectangle. 5664f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * 5674f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * If this returns false, then all output parameters are ignored, and left 5684f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * unchanged. If this returns true, then each of the output parameters 5694f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * are checked for NULL. If they are not, they return their value. 5704f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * 57191b0a3587342c48a1a6e1c4687686688737359darobertphillips * @param rect If not null, set to the bounds of the rectangle. 57291b0a3587342c48a1a6e1c4687686688737359darobertphillips * Note : this bounds may be smaller than the path's bounds, since it is just 57391b0a3587342c48a1a6e1c4687686688737359darobertphillips * the bounds of the "drawable" parts of the path. e.g. a trailing MoveTo would 57491b0a3587342c48a1a6e1c4687686688737359darobertphillips * be ignored in this rect, but not by the path's bounds 5754f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @param isClosed If not null, set to true if the path is closed 5764f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @param direction If not null, set to the rectangle's direction 5774f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips * @return true if the path specifies a rectangle 5784f662e62cd44e302ef689fabdb2c0ae8d9471b02robertphillips */ 57991b0a3587342c48a1a6e1c4687686688737359darobertphillips bool isRect(SkRect* rect, bool* isClosed = NULL, Direction* direction = NULL) const; 5808fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 5818fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com /** Returns true if the path specifies a pair of nested rectangles. If so, and if 5828fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com rect is not null, set rect[0] to the outer rectangle and rect[1] to the inner 5838fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com rectangle. If so, and dirs is not null, set dirs[0] to the direction of 5848fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com the outer rectangle and dirs[1] to the direction of the inner rectangle. If 5858fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com the path does not specify a pair of nested rectangles, return 5868fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com false and ignore rect and dirs. 5878fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 5888fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @param rect If not null, returns the path as a pair of nested rectangles 5898fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @param dirs If not null, returns the direction of the rects 5908fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com @return true if the path describes a pair of nested rectangles 5918fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com */ 5928fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com bool isNestedRects(SkRect rect[2], Direction dirs[2] = NULL) const; 5938fd160350ca5f57fbb1b2e03383c5778414a9b48robertphillips@google.com 594a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 595a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed rectangle contour to the path 596a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The rectangle to add as a closed contour to the path 597a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 598a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 599a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 600ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void addRect(const SkRect& rect, Direction dir = kCW_Direction); 6018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 602a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 603a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed rectangle contour to the path 604a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 605a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param left The left side of a rectangle to add as a closed contour 606a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * to the path 607a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param top The top of a rectangle to add as a closed contour to the 608a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * path 609a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param right The right side of a rectangle to add as a closed contour 610a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * to the path 611a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param bottom The bottom of a rectangle to add as a closed contour to 612a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * the path 613a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 614a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 615a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, 6178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 619a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 620a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed oval contour to the path 621a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 622a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param oval The bounding oval to add as a closed contour to the path 623a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the oval's contour. Cannot be 624a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 625a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addOval(const SkRect& oval, Direction dir = kCW_Direction); 6278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 628a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 629a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed circle contour to the path 630a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * 631a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param x The x-coordinate of the center of a circle to add as a 632a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * closed contour to the path 633a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param y The y-coordinate of the center of a circle to add as a 634a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * closed contour to the path 635a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param radius The radius of a circle to add as a closed contour to the 636a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * path 637a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the circle's contour. Cannot be 638a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 639a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addCircle(SkScalar x, SkScalar y, SkScalar radius, 6418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 6438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add the specified arc to the path as a new contour. 644fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 6458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param oval The bounds of oval used to define the size of the arc 6468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param startAngle Starting angle (in degrees) where the arc begins 6478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param sweepAngle Sweep angle (in degrees) measured clockwise 6488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 6498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle); 6508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 651a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 652a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed round-rectangle contour to the path 653a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The bounds of a round-rectangle to add as a closed contour 654a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rx The x-radius of the rounded corners on the round-rectangle 655a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param ry The y-radius of the rounded corners on the round-rectangle 656a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 657a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 658a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 659ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void addRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, 660ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com Direction dir = kCW_Direction); 6618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 662a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com /** 663a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * Add a closed round-rectangle contour to the path. Each corner receives 664a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * two radius values [X, Y]. The corners are ordered top-left, top-right, 665a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * bottom-right, bottom-left. 666a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param rect The bounds of a round-rectangle to add as a closed contour 667a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param radii Array of 8 scalars, 4 [X,Y] pairs for each corner 668a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * @param dir The direction to wind the rectangle's contour. Cannot be 669a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com * kUnknown_Direction. 6704e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * Note: The radii here now go through the same constraint handling as the 6714e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * SkRRect radii (i.e., either radii at a corner being 0 implies a 6724e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * sqaure corner and oversized radii are proportionally scaled down). 673a8a3b3d9a027ad54ce20f8b4ed7c577a176b31careed@google.com */ 6748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void addRoundRect(const SkRect& rect, const SkScalar radii[], 6758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Direction dir = kCW_Direction); 6768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 677744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com /** 6784e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * Add an SkRRect contour to the path 6794e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * @param rrect The rounded rect to add as a closed contour 6804e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * @param dir The winding direction for the new contour. Cannot be 6814e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com * kUnknown_Direction. 6824ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com */ 6834e18c7a9bbef6ac949d535aa61dfe1462ebb4452robertphillips@google.com void addRRect(const SkRRect& rrect, Direction dir = kCW_Direction); 6844ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com 6854ed0fb768409bf97b79899c3990d8c15f5e9d784reed@google.com /** 686744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * Add a new contour made of just lines. This is just a fast version of 687744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * the following: 688744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->moveTo(pts[0]); 689744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * for (int i = 1; i < count; ++i) { 690744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->lineTo(pts[i]); 691744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * } 692744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * if (close) { 693744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * this->close(); 694744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com * } 695744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com */ 696744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com void addPoly(const SkPoint pts[], int count, bool close); 697744fabad474e3e111e7cbd8609cf7e209df17f32reed@google.com 69814747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org enum AddPathMode { 69914747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org /** Source path contours are added as new contours. 70014747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org */ 70114747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org kAppend_AddPathMode, 70214747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org /** Path is added by extending the last contour of the destination path 70314747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org with the first contour of the source path. If the last contour of 704877c44956dceff038c0e315c8d311b0d581f2680skia.committer@gmail.com the destination path is closed, then it will not be extended. 70514747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org Instead, the start of source path will be extended by a straight 70614747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org line to the end point of the destination path. 70714747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org */ 708877c44956dceff038c0e315c8d311b0d581f2680skia.committer@gmail.com kExtend_AddPathMode 70914747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org }; 71014747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org 7118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path, offset by (dx,dy) 7128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src The path to add as a new contour 7138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to translate the path in X as it is added 7148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dx The amount to translate the path in Y as it is added 7158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 71614747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, SkScalar dx, SkScalar dy, 71714747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org AddPathMode mode = kAppend_AddPathMode); 7188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path 7208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 72114747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) { 7228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkMatrix m; 7238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com m.reset(); 72414747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org this->addPath(src, m, mode); 7258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Add a copy of src to the path, transformed by matrix 7288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param src The path to add as a new contour 72914747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org @param matrix Transform applied to src 73014747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org @param mode Determines how path is added 7318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 73214747e58f8127a6d6b3c748bf0642b0d6a3a79e8commit-bot@chromium.org void addPath(const SkPath& src, const SkMatrix& matrix, AddPathMode mode = kAppend_AddPathMode); 7338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 73463d73749fbe36491403ea521005fd298dc70a94creed@google.com /** 73563d73749fbe36491403ea521005fd298dc70a94creed@google.com * Same as addPath(), but reverses the src input 73663d73749fbe36491403ea521005fd298dc70a94creed@google.com */ 73763d73749fbe36491403ea521005fd298dc70a94creed@google.com void reverseAddPath(const SkPath& src); 73863d73749fbe36491403ea521005fd298dc70a94creed@google.com 7398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset the path by (dx,dy), returning true on success 740fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 741fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dx The amount in the X direction to offset the entire path 742fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dy The amount in the Y direction to offset the entire path 7438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The translated path is written here 7448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy, SkPath* dst) const; 7468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Offset the path by (dx,dy), returning true on success 748fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 749fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dx The amount in the X direction to offset the entire path 750fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com @param dy The amount in the Y direction to offset the entire path 7518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void offset(SkScalar dx, SkScalar dy) { 7538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->offset(dx, dy, this); 7548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Transform the points in this path by matrix, and write the answer into 7578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com dst. 758fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to apply to the path 7608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param dst The transformed path is written here 7618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void transform(const SkMatrix& matrix, SkPath* dst) const; 7638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Transform the points in this path by matrix 7658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param matrix The matrix to apply to the path 7678a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void transform(const SkMatrix& matrix) { 7698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->transform(matrix, this); 7708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the last point on the path. If no points have been added, (0,0) 773294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com is returned. If there are no points, this returns false, otherwise it 774294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com returns true. 775fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param lastPt The last point on the path is returned here 7778a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 778294dd7b3d7b55ba38881cd4cabb6636abda23eb9reed@google.com bool getLastPt(SkPoint* lastPt) const; 7798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the last point on the path. If no points have been added, 7818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com moveTo(x,y) is automatically called. 782fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 7838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param x The new x-coordinate for the last point 7848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param y The new y-coordinate for the last point 7858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLastPt(SkScalar x, SkScalar y); 7878a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Set the last point on the path. If no points have been added, moveTo(p) 7898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com is automatically called. 7908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 7918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param p The new location for the last point 7928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 7938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setLastPt(const SkPoint& p) { 7948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->setLastPt(p.fX, p.fY); 7958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 7968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 79710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com enum SegmentMask { 79810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com kLine_SegmentMask = 1 << 0, 79910296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com kQuad_SegmentMask = 1 << 1, 800277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kConic_SegmentMask = 1 << 2, 801277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kCubic_SegmentMask = 1 << 3, 80210296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com }; 80310296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com 80410296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com /** 80510296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * Returns a mask, where each bit corresponding to a SegmentMask is 80610296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * set if the path contains 1 or more segments of that type. 80710296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com * Returns 0 for an empty path (no segments). 80810296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com */ 8096b8dbb668f1f069270d35a47cfe98decd059c625robertphillips@google.com uint32_t getSegmentMasks() const { return fPathRef->getSegmentMasks(); } 81010296ccb6a63c65b2e60733a929bf15d8bf94309reed@google.com 8118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com enum Verb { 8128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kMove_Verb, //!< iter.next returns 1 point 8138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kLine_Verb, //!< iter.next returns 2 points 8148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kQuad_Verb, //!< iter.next returns 3 points 815277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kConic_Verb, //!< iter.next returns 3 points + iter.conicWeight() 8168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com kCubic_Verb, //!< iter.next returns 4 points 817b3b8dfa31326c51dab8b5ed569e19ee715582d1bbsalomon@google.com kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt) 818277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com kDone_Verb, //!< iter.next returns 0 points 8198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 8208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Iterate through all of the segments (lines, quadratics, cubics) of 8228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com each contours in a path. 82372785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org 82472785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org The iterator cleans up the segments along the way, removing degenerate 82572785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org segments and adding close verbs where necessary. When the forceClose 82672785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org argument is provided, each contour (as defined by a new starting 82772785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org move command) will be completed with a close verb regardless of the 82872785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org contour's contents. 8298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8307ffb1b21abcc7bbed5a0fc711f6dd7b9dbb4f577ctguil@chromium.org class SK_API Iter { 8318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com public: 83272785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org Iter(); 83372785c4c8928a8b0fc5bbdb48929f9356554daceschenney@chromium.org Iter(const SkPath&, bool forceClose); 8348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void setPath(const SkPath&, bool forceClose); 8368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Return the next verb in this iteration of the path. When all 8388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com segments have been visited, return kDone_Verb. 839b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @param pts The points representing the current verb and/or segment 8414a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com @param doConsumeDegerates If true, first scan for segments that are 8424a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com deemed degenerate (too short) and skip those. 8438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return The verb for the current segment 8448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8454a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com Verb next(SkPoint pts[4], bool doConsumeDegerates = true) { 8464a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com if (doConsumeDegerates) { 8474a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com this->consumeDegenerateSegments(); 8484a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com } 8494a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com return this->doNext(pts); 8504a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com } 8518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 852277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com /** 853277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com * Return the weight for the current conic. Only valid if the current 854277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com * segment return by next() was a conic. 855277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com */ 856277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar conicWeight() const { return *fConicWeights; } 857277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com 8588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** If next() returns kLine_Verb, then this query returns true if the 8598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com line was the result of a close() command (i.e. the end point is the 8608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com initial moveto for this contour). If next() returned a different 8618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com verb, this returns an undefined value. 862b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8638a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return If the last call to next() returned kLine_Verb, return true 8648a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if it was the result of an explicit close command. 8658a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8668a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isCloseLine() const { return SkToBool(fCloseLine); } 867b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org 8688a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /** Returns true if the current contour is closed (has a kClose_Verb) 8698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com @return true if the current contour is closed (has a kClose_Verb) 8708a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 8718a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com bool isClosedContour() const; 8728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com private: 8748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPoint* fPts; 8758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* fVerbs; 8768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const uint8_t* fVerbStop; 877277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com const SkScalar* fConicWeights; 8788a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fMoveTo; 8798a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkPoint fLastPt; 8808a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fForceClose; 8818a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fNeedClose; 8828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkBool8 fCloseLine; 883b0af6dad94f3c51ea0d5d6426a9509354338c6b2schenney@chromium.org SkBool8 fSegmentState; 8848a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8859e25dbf589539dd44244bc2581590bd7591e17a2reed@google.com inline const SkPoint& cons_moveTo(); 8868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com Verb autoClose(SkPoint pts[2]); 8874da06ab3351f2a96f9216d96106db33a77b19644schenney@chromium.org void consumeDegenerateSegments(); 8884a3b714d73e585a3985d614600c6b79d5c8b1f1ereed@google.com Verb doNext(SkPoint pts[4]); 8898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com }; 8908a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 8916630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org /** Iterate through the verbs in the path, providing the associated points. 8926630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org */ 8936630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org class SK_API RawIter { 8946630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org public: 8956630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org RawIter(); 8966630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org RawIter(const SkPath&); 8976630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 8986630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org void setPath(const SkPath&); 8996630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 9006630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org /** Return the next verb in this iteration of the path. When all 9016630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org segments have been visited, return kDone_Verb. 902fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 9036630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org @param pts The points representing the current verb and/or segment 904f6d3c5aa5f93e4c3cc7a7aebf014e960cf837783bsalomon@google.com This must not be NULL. 9056630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org @return The verb for the current segment 9066630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org */ 9076630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org Verb next(SkPoint pts[4]); 9086630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 909277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com SkScalar conicWeight() const { return *fConicWeights; } 910277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com 9116630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org private: 9126630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const SkPoint* fPts; 9136630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const uint8_t* fVerbs; 9146630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org const uint8_t* fVerbStop; 915277c3f87656c44e0a651ed0dd56efa16c0ab07b4reed@google.com const SkScalar* fConicWeights; 9166630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org SkPoint fMoveTo; 9176630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org SkPoint fLastPt; 9186630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org }; 9196630d8d8ea7a897a18e3d950bab9fa40f065804aschenney@chromium.org 920bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org /** 921bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org * Returns true if the point { x, y } is contained by the path, taking into 922bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org * account the FillType. 923bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org */ 924bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org bool contains(SkScalar x, SkScalar y) const; 925bad1b2ff1d34ff86693b776f89d7b46995746127mike@reedtribe.org 926e956259c5a4f71768afb34ec032eaed49dcbe9f2caryclark void dump(SkWStream* , bool forceClose, bool dumpAsHex) const; 927e522ca5d5f249bd51a00cb68bb051f811d0a9e85reed@android.com void dump() const; 928e956259c5a4f71768afb34ec032eaed49dcbe9f2caryclark void dumpHex() const; 9298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 93094e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com /** 9314faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * Write the path to the buffer, and return the number of bytes written. 93294e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com * If buffer is NULL, it still returns the number of bytes. 93394e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com */ 9344faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org size_t writeToMemory(void* buffer) const; 93594e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com /** 9364faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * Initializes the path from the buffer 9374faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * 9384faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @param buffer Memory to read from 9394faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @param length Amount of memory available in the buffer 9404faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * @return number of bytes read (must be a multiple of 4) or 9414faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org * 0 if there was not enough memory available 94294e75ee46a569cbcdf61fb7f04ee3a69d3ca0896djsollen@google.com */ 9434faa869cdabbdcf4867118b4a1272296baaeeb52commit-bot@chromium.org size_t readFromMemory(const void* buffer, size_t length); 9448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9451ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org /** Returns a non-zero, globally unique value corresponding to the set of verbs 9461ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org and points in the path (but not the fill type [except on Android skbug.com/1762]). 9477ed98df9ba14bdb58e381508eb0505c963a4b6dbskia.committer@gmail.com Each time the path is modified, a different generation ID will be returned. 9481ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org */ 9497101abe5b37d82ea222e971a42615a97a2419edbrobertphillips@google.com uint32_t getGenerationID() const; 9501ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org 9511ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org#ifdef SK_BUILD_FOR_ANDROID 9521ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org static const int kPathRefGenIDBitCnt = 30; // leave room for the fill type (skbug.com/1762) 953e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com const SkPath* getSourcePath() const; 954e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com void setSourcePath(const SkPath* path); 9551ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org#else 9561ab9f737f000e530f0c7713c8fad282f39e26efecommit-bot@chromium.org static const int kPathRefGenIDBitCnt = 32; 957f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif 958f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com 9598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkDEBUGCODE(void validate() const;) 9608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 96201ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com enum SerializationOffsets { 963fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 1 free bit at 29 96411e055518a0cbe5329232a55fe2cd177e83836d8robertphillips@google.com kUnused1_SerializationShift = 28, // 1 free bit 96530c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com kDirection_SerializationShift = 26, // requires 2 bits 966b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth kIsVolatile_SerializationShift = 25, // requires 1 bit 967fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 1 free bit at 24 968ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com kConvexity_SerializationShift = 16, // requires 8 bits 969ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com kFillType_SerializationShift = 8, // requires 8 bits 970fed2ab648341ec153ad2af746a31d368963171e4commit-bot@chromium.org // 8 free bits at 0 97101ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com }; 97201ec2eb42e9c64f8d06afd51f80c055710147141robertphillips@google.com 973ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com SkAutoTUnref<SkPathRef> fPathRef; 974ae09f2dc3fb1e8a8db99b214c8a71d0b9613a856bsalomon@google.com 9755e1a7f2cc621d357da5c62a7bc4ef750d94b96f3commit-bot@chromium.org int fLastMoveToIndex; 9768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com uint8_t fFillType; 977b54455e440e66e0b1c30954d226226f49aac26d6reed@google.com mutable uint8_t fConvexity; 97830c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com mutable uint8_t fDirection; 979b3eb687f8a89eb1eacd1afb4016401eb392f66abjvanverth mutable SkBool8 fIsVolatile; 98056c69773aea56c6c6bd47bc7e7970dd081205184djsollen@google.com#ifdef SK_BUILD_FOR_ANDROID 981e63793a2c8d2871bf7d95195be7b93ff669688d7djsollen@google.com const SkPath* fSourcePath; 982f5dbe2f00f853c6a1719924bdd0c33335a53423adjsollen@google.com#endif 9838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 984a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com /** Resets all fields other than fPathRef to their initial 'empty' values. 985a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * Assumes the caller has already emptied fPathRef. 986a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * On Android increments fGenerationID without reseting it. 987a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com */ 988a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com void resetFields(); 989a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com 990a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com /** Sets all fields other than fPathRef to the values in 'that'. 991a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com * Assumes the caller has already set fPathRef. 9929c9d4a70028ef8dc33a46cfc0b22e254443effe3mtklein@google.com * Doesn't change fGenerationID or fSourcePath on Android. 993a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com */ 994a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com void copyFields(const SkPath& that); 995a5809a3e4cb356387c5201ab9c0a10edf11a01bebungeman@google.com 9968a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class Iter; 9978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 9988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkPathStroker; 9998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com /* Append, in reverse order, the first contour of path, ignoring path's 10018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com last point. If no moveTo() call has been made for this contour, the 10028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com first point is automatically set to (0,0). 10038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */ 10048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com void reversePathTo(const SkPath&); 10058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1006d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // called before we add points for lineTo, quadTo, cubicTo, checking to see 1007d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // if we need to inject a leading moveTo first 1008d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // 1009d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0) 1010d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo) 1011d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com // 10125e1a7f2cc621d357da5c62a7bc4ef750d94b96f3commit-bot@chromium.org inline void injectMoveToIfNeeded(); 1013d335d1d784167f8b9a4bf8a35e04d8e82d0a9507reed@google.com 10146aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com inline bool hasOnlyMoveTos() const; 10156aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com 101630c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com Convexity internalGetConvexity() const; 10173458716b52aa25dcd1b270141c7628c380696e35skia.committer@gmail.com 1018f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com bool isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts, 1019f68154a3cf43eb22d45be11f3b09e25440c366a6caryclark@google.com bool* isClosed, Direction* direction) const; 102030c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com 1021ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com /** Returns if the path can return a bound at no cost (true) or will have to 1022ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com perform some computation (false). 1023ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com */ 1024ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com bool hasComputedBounds() const { 1025ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com SkDEBUGCODE(this->validate();) 1026ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com return fPathRef->hasComputedBounds(); 1027ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1028ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 1029ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 1030ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com // 'rect' needs to be sorted 1031ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com void setBounds(const SkRect& rect) { 10320efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com SkPathRef::Editor ed(&fPathRef); 10330efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com 10340efb21bd1cd359b732a59753f3c1da096aab561arobertphillips@google.com ed.setBounds(rect); 1035ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com } 1036ca0c8389e2fd1c7f528869beb77a6c8587d59f29robertphillips@google.com 10378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com friend class SkAutoPathBoundsUpdate; 10386aa2965ca814dd3329b65398b5c5af980e54b101bsalomon@google.com friend class SkAutoDisableOvalCheck; 103930c174b9ce6b9777ee50ae0d0565a01b2a060f01bsalomon@google.com friend class SkAutoDisableDirectionCheck; 1040a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org friend class SkBench_AddPathTest; // perf test reversePathTo 1041a1a097ee814d05a92487d85db8ad02e1d852fd6fcommit-bot@chromium.org friend class PathTest_Private; // unit test reversePathTo 10428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 10438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 10448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1045