1 /* 2 * Copyright 2006 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef Sk1DPathEffect_DEFINED 9 #define Sk1DPathEffect_DEFINED 10 11 #include "include/core/SkFlattenable.h" 12 #include "include/core/SkPath.h" 13 #include "include/core/SkPathEffect.h" 14 15 class SkPathMeasure; 16 17 // This class is not exported to java. 18 class SK_API Sk1DPathEffect : public SkPathEffect { 19 public: 20 protected: 21 bool onFilterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, const SkRect*) const override; 22 23 /** Called at the start of each contour, returns the initial offset 24 into that contour. 25 */ 26 virtual SkScalar begin(SkScalar contourLength) const = 0; 27 /** Called with the current distance along the path, with the current matrix 28 for the point/tangent at the specified distance. 29 Return the distance to travel for the next call. If return <= 0, then that 30 contour is done. 31 */ 32 virtual SkScalar next(SkPath* dst, SkScalar dist, SkPathMeasure&) const = 0; 33 34 private: 35 // For simplicity, assume fast bounds cannot be computed computeFastBounds(SkRect *)36 bool computeFastBounds(SkRect*) const override { return false; } 37 38 using INHERITED = SkPathEffect; 39 }; 40 41 class SK_API SkPath1DPathEffect : public Sk1DPathEffect { 42 public: 43 enum Style { 44 kTranslate_Style, // translate the shape to each position 45 kRotate_Style, // rotate the shape about its center 46 kMorph_Style, // transform each point, and turn lines into curves 47 48 kLastEnum_Style = kMorph_Style, 49 }; 50 51 /** Dash by replicating the specified path. 52 @param path The path to replicate (dash) 53 @param advance The space between instances of path 54 @param phase distance (mod advance) along path for its initial position 55 @param style how to transform path at each point (based on the current 56 position and tangent) 57 */ 58 static sk_sp<SkPathEffect> Make(const SkPath& path, SkScalar advance, SkScalar phase, Style); 59 60 protected: 61 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); 62 void flatten(SkWriteBuffer&) const override; 63 bool onFilterPath(SkPath*, const SkPath&, SkStrokeRec*, const SkRect*) const override; 64 65 // overrides from Sk1DPathEffect 66 SkScalar begin(SkScalar contourLength) const override; 67 SkScalar next(SkPath*, SkScalar, SkPathMeasure&) const override; 68 69 private: 70 SK_FLATTENABLE_HOOKS(SkPath1DPathEffect) 71 72 SkPath fPath; // copied from constructor 73 SkScalar fAdvance; // copied from constructor 74 SkScalar fInitialOffset; // computed from phase 75 Style fStyle; // copied from constructor 76 77 using INHERITED = Sk1DPathEffect; 78 }; 79 80 #endif 81