OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 "SkCurveMeasure.h" |
| 9 #include "SkDashMeasure.h" |
| 10 #include "SkPathMeasurePriv.h" |
| 11 |
| 12 void getDashedPath(const SkPath& path, |
| 13 const struct SkPathEffect::DashInfo& dashInfo, |
| 14 SkPath* dst) { |
| 15 const SkScalar* intervals = dashInfo.fIntervals; |
| 16 |
| 17 int32_t interval_index = 0; |
| 18 SkScalar interval_accum = intervals[interval_index]; |
| 19 |
| 20 SkPath::Iter iter(path, false); |
| 21 SkPath::Verb current; |
| 22 SkPoint pts[4]; |
| 23 |
| 24 while ((current = iter.next(pts)) != SkPath::kDone_Verb) { |
| 25 SkSegType segtype; |
| 26 SkPoint end; |
| 27 switch (current) { |
| 28 case SkPath::kMove_Verb: |
| 29 dst->moveTo(pts[0]); |
| 30 continue; |
| 31 case SkPath::kLine_Verb: |
| 32 segtype = kLine_SegType; |
| 33 end = pts[1]; |
| 34 break; |
| 35 case SkPath::kQuad_Verb: |
| 36 segtype = kQuad_SegType; |
| 37 end = pts[2]; |
| 38 break; |
| 39 case SkPath::kConic_Verb: |
| 40 segtype = kConic_SegType; |
| 41 end = pts[2]; |
| 42 break; |
| 43 case SkPath::kCubic_Verb: |
| 44 segtype = kCubic_SegType; |
| 45 end = pts[3]; |
| 46 break; |
| 47 case SkPath::kClose_Verb: |
| 48 // should not appear in the iter since we're not using RawIter |
| 49 SkASSERT(false); |
| 50 break; |
| 51 default: // unreachable |
| 52 SkASSERT(false); |
| 53 break; |
| 54 } |
| 55 |
| 56 // TODO(hstern): Do heuristic check to see whether we should do |
| 57 // pathmeasure or curvemeasure. probably do it before the outer loop |
| 58 // by giving CurveMeasure a reset() and reusing the object inside. |
| 59 SkCurveMeasure meas(pts, segtype); |
| 60 |
| 61 SkScalar prevT = 0; |
| 62 |
| 63 SkScalar current_length = meas.getLength(); |
| 64 while (interval_accum < current_length) { |
| 65 SkScalar time; |
| 66 SkPoint pos; |
| 67 meas.getPosTanTime(interval_accum, &pos, nullptr, &time); |
| 68 if (dashIsOn(interval_index)) { |
| 69 SkPathMeasure_segTo(pts, segtype, prevT, time, dst); |
| 70 } else { |
| 71 dst->moveTo(pos); |
| 72 } |
| 73 prevT = time; |
| 74 |
| 75 interval_accum += intervals[interval_index]; |
| 76 interval_index = (interval_index+1) % dashInfo.fCount; |
| 77 } |
| 78 if (dashIsOn(interval_index)) { |
| 79 SkPathMeasure_segTo(pts, segtype, prevT, 1, dst); |
| 80 } else { |
| 81 dst->moveTo(end); |
| 82 } |
| 83 |
| 84 interval_accum = interval_accum - current_length; |
| 85 } |
| 86 } |
OLD | NEW |