1 /* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef Sk1DPathEffect_DEFINED 18 #define Sk1DPathEffect_DEFINED 19 20 #include "SkPathEffect.h" 21 #include "SkPath.h" 22 23 class SkPathMeasure; 24 25 // This class is not exported to java. 26 class Sk1DPathEffect : public SkPathEffect { 27 public: 28 // override from SkPathEffect 29 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 30 31 protected: 32 /** Called at the start of each contour, returns the initial offset 33 into that contour. 34 */ 35 virtual SkScalar begin(SkScalar contourLength) = 0; 36 /** Called with the current distance along the path, with the current matrix 37 for the point/tangent at the specified distance. 38 Return the distance to travel for the next call. If return <= 0, then that 39 contour is done. 40 */ 41 virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) = 0; 42 43 private: 44 typedef SkPathEffect INHERITED; 45 }; 46 47 class SkPath1DPathEffect : public Sk1DPathEffect { 48 public: 49 enum Style { 50 kTranslate_Style, // translate the shape to each position 51 kRotate_Style, // rotate the shape about its center 52 kMorph_Style, // transform each point, and turn lines into curves 53 54 kStyleCount 55 }; 56 57 /** Dash by replicating the specified path. 58 @param path The path to replicate (dash) 59 @param advance The space between instances of path 60 @param phase distance (mod advance) along path for its initial position 61 @param style how to transform path at each point (based on the current 62 position and tangent) 63 */ 64 SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style); 65 66 // override from SkPathEffect 67 virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width); 68 69 protected: 70 SkPath1DPathEffect(SkFlattenableReadBuffer& buffer); 71 72 // overrides from Sk1DPathEffect 73 virtual SkScalar begin(SkScalar contourLength); 74 virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&); 75 // overrides from SkFlattenable 76 virtual void flatten(SkFlattenableWriteBuffer& ); getFactory()77 virtual Factory getFactory() { return CreateProc; } 78 79 private: 80 SkPath fPath; // copied from constructor 81 SkScalar fAdvance; // copied from constructor 82 SkScalar fInitialOffset; // computed from phase 83 Style fStyle; // copied from constructor 84 CreateProc(SkFlattenableReadBuffer & buffer)85 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) { 86 return SkNEW_ARGS(SkPath1DPathEffect, (buffer)); 87 } 88 89 typedef Sk1DPathEffect INHERITED; 90 }; 91 92 93 #endif 94