1/* 2 * Copyright 2014 Google Inc. 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#include "SkArcToPathEffect.h" 9#include "SkPath.h" 10#include "SkPoint.h" 11#include "SkReadBuffer.h" 12#include "SkWriteBuffer.h" 13 14SkArcToPathEffect::SkArcToPathEffect(SkScalar radius) : fRadius(radius) {} 15 16bool SkArcToPathEffect::filterPath(SkPath* dst, const SkPath& src, 17 SkStrokeRec*, const SkRect*) const { 18 SkPath::Iter iter(src, false); 19 SkPath::Verb verb; 20 SkPoint pts[4]; 21 22 SkPoint lastCorner = { 0, 0 }; // avoid warning 23 SkPath::Verb prevVerb = SkPath::kMove_Verb; 24 25 for (;;) { 26 switch (verb = iter.next(pts, false)) { 27 case SkPath::kMove_Verb: 28 if (SkPath::kLine_Verb == prevVerb) { 29 dst->lineTo(lastCorner); 30 } 31 dst->moveTo(pts[0]); 32 break; 33 case SkPath::kLine_Verb: 34 if (prevVerb == SkPath::kLine_Verb) { 35 dst->arcTo(pts[0], pts[1], fRadius); 36 } 37 lastCorner = pts[1]; 38 break; 39 case SkPath::kQuad_Verb: 40 dst->quadTo(pts[1], pts[2]); 41 lastCorner = pts[2]; 42 break; 43 case SkPath::kConic_Verb: 44 dst->conicTo(pts[1], pts[2], iter.conicWeight()); 45 lastCorner = pts[2]; 46 break; 47 case SkPath::kCubic_Verb: 48 dst->cubicTo(pts[1], pts[2], pts[3]); 49 lastCorner = pts[3]; 50 break; 51 case SkPath::kClose_Verb: 52 dst->lineTo(lastCorner); 53 break; 54 case SkPath::kDone_Verb: 55 dst->lineTo(lastCorner); 56 goto DONE; 57 } 58 prevVerb = verb; 59 } 60DONE: 61 return true; 62} 63 64SkFlattenable* SkArcToPathEffect::CreateProc(SkReadBuffer& buffer) { 65 return SkArcToPathEffect::Create(buffer.readScalar()); 66} 67 68void SkArcToPathEffect::flatten(SkWriteBuffer& buffer) const { 69 buffer.writeScalar(fRadius); 70} 71 72#ifndef SK_IGNORE_TO_STRING 73void SkArcToPathEffect::toString(SkString* str) const { 74 str->appendf("SkArcToPathEffect: ("); 75 str->appendf("radius: %f", fRadius); 76 str->appendf(")"); 77} 78#endif 79