OLD | NEW |
1 // Copyright (C) 2013 Google Inc. All rights reserved. | 1 // Copyright (C) 2013 Google Inc. All rights reserved. |
2 // | 2 // |
3 // Redistribution and use in source and binary forms, with or without | 3 // Redistribution and use in source and binary forms, with or without |
4 // modification, are permitted provided that the following conditions are | 4 // modification, are permitted provided that the following conditions are |
5 // met: | 5 // met: |
6 // | 6 // |
7 // * Redistributions of source code must retain the above copyright | 7 // * Redistributions of source code must retain the above copyright |
8 // notice, this list of conditions and the following disclaimer. | 8 // notice, this list of conditions and the following disclaimer. |
9 // * Redistributions in binary form must reproduce the above | 9 // * Redistributions in binary form must reproduce the above |
10 // copyright notice, this list of conditions and the following disclaimer | 10 // copyright notice, this list of conditions and the following disclaimer |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 size_t count = !(dashLength % 2) ? dashLength : dashLength * 2; | 51 size_t count = !(dashLength % 2) ? dashLength : dashLength * 2; |
52 OwnPtr<SkScalar[]> intervals = adoptArrayPtr(new SkScalar[count]); | 52 OwnPtr<SkScalar[]> intervals = adoptArrayPtr(new SkScalar[count]); |
53 | 53 |
54 for (unsigned i = 0; i < count; i++) | 54 for (unsigned i = 0; i < count; i++) |
55 intervals[i] = dashes[i % dashLength]; | 55 intervals[i] = dashes[i % dashLength]; |
56 | 56 |
57 m_dash = adoptRef(new SkDashPathEffect(intervals.get(), count, dashOffset)); | 57 m_dash = adoptRef(new SkDashPathEffect(intervals.get(), count, dashOffset)); |
58 } | 58 } |
59 | 59 |
60 float StrokeData::setupPaint(SkPaint* paint, int length) const | 60 void StrokeData::setupPaint(SkPaint* paint, int length) const |
61 { | 61 { |
62 float width = m_thickness; | |
63 | |
64 paint->setStyle(SkPaint::kStroke_Style); | 62 paint->setStyle(SkPaint::kStroke_Style); |
65 paint->setStrokeWidth(SkFloatToScalar(width)); | 63 paint->setStrokeWidth(SkFloatToScalar(m_thickness)); |
66 paint->setStrokeCap(m_lineCap); | 64 paint->setStrokeCap(m_lineCap); |
67 paint->setStrokeJoin(m_lineJoin); | 65 paint->setStrokeJoin(m_lineJoin); |
68 paint->setStrokeMiter(SkFloatToScalar(m_miterLimit)); | 66 paint->setStrokeMiter(SkFloatToScalar(m_miterLimit)); |
69 | 67 |
| 68 setupPaintDashPathEffect(paint, length); |
| 69 } |
| 70 |
| 71 void StrokeData::setupPaintDashPathEffect(SkPaint* paint, int length) const |
| 72 { |
| 73 float width = m_thickness; |
70 if (m_dash) { | 74 if (m_dash) { |
71 paint->setPathEffect(m_dash.get()); | 75 paint->setPathEffect(m_dash.get()); |
72 } else { | 76 } else { |
73 switch (m_style) { | 77 switch (m_style) { |
74 case NoStroke: | 78 case NoStroke: |
75 case SolidStroke: | 79 case SolidStroke: |
76 case DoubleStroke: | 80 case DoubleStroke: |
77 case WavyStroke: // FIXME: https://code.google.com/p/chromium/issues/det
ail?id=229574 | 81 case WavyStroke: // FIXME: https://code.google.com/p/chromium/issues/det
ail?id=229574 |
78 break; | 82 paint->setPathEffect(0); |
| 83 return; |
79 case DashedStroke: | 84 case DashedStroke: |
80 width = dashRatio * width; | 85 width = dashRatio * width; |
81 // Fall through. | 86 // Fall through. |
82 case DottedStroke: | 87 case DottedStroke: |
83 // Truncate the width, since we don't want fuzzy dots or dashes. | 88 // Truncate the width, since we don't want fuzzy dots or dashes. |
84 int dashLength = static_cast<int>(width); | 89 int dashLength = static_cast<int>(width); |
85 // Subtract off the endcaps, since they're rendered separately. | 90 // Subtract off the endcaps, since they're rendered separately. |
86 int distance = length - 2 * static_cast<int>(m_thickness); | 91 int distance = length - 2 * static_cast<int>(m_thickness); |
87 int phase = 1; | 92 int phase = 1; |
88 if (dashLength > 1) { | 93 if (dashLength > 1) { |
89 // Determine how many dashes or dots we should have. | 94 // Determine how many dashes or dots we should have. |
90 int numDashes = distance / dashLength; | 95 int numDashes = distance / dashLength; |
91 int remainder = distance % dashLength; | 96 int remainder = distance % dashLength; |
92 // Adjust the phase to center the dashes within the line. | 97 // Adjust the phase to center the dashes within the line. |
93 if (numDashes % 2) { | 98 if (numDashes % 2) { |
94 // Odd: shift right a full dash, minus half the remainder. | 99 // Odd: shift right a full dash, minus half the remainder. |
95 phase = dashLength - remainder / 2; | 100 phase = dashLength - remainder / 2; |
96 } else { | 101 } else { |
97 // Even: shift right half a dash, minus half the remainder. | 102 // Even: shift right half a dash, minus half the remainder. |
98 phase = (dashLength - remainder) / 2; | 103 phase = (dashLength - remainder) / 2; |
99 } | 104 } |
100 } | 105 } |
101 SkScalar dashLengthSk = SkIntToScalar(dashLength); | 106 SkScalar dashLengthSk = SkIntToScalar(dashLength); |
102 SkScalar intervals[2] = { dashLengthSk, dashLengthSk }; | 107 SkScalar intervals[2] = { dashLengthSk, dashLengthSk }; |
103 RefPtr<SkDashPathEffect> pathEffect = adoptRef(new SkDashPathEffect(
intervals, 2, SkIntToScalar(phase))); | 108 RefPtr<SkDashPathEffect> pathEffect = adoptRef(new SkDashPathEffect(
intervals, 2, SkIntToScalar(phase))); |
104 paint->setPathEffect(pathEffect.get()); | 109 paint->setPathEffect(pathEffect.get()); |
105 } | 110 } |
106 } | 111 } |
107 | |
108 return width; | |
109 } | 112 } |
110 | 113 |
111 } // namespace | 114 } // namespace |
OLD | NEW |