| 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 return; |
| 79 case DashedStroke: | 83 case DashedStroke: |
| 80 width = dashRatio * width; | 84 width = dashRatio * width; |
| 81 // Fall through. | 85 // Fall through. |
| 82 case DottedStroke: | 86 case DottedStroke: |
| 83 // Truncate the width, since we don't want fuzzy dots or dashes. | 87 // Truncate the width, since we don't want fuzzy dots or dashes. |
| 84 int dashLength = static_cast<int>(width); | 88 int dashLength = static_cast<int>(width); |
| 85 // Subtract off the endcaps, since they're rendered separately. | 89 // Subtract off the endcaps, since they're rendered separately. |
| 86 int distance = length - 2 * static_cast<int>(m_thickness); | 90 int distance = length - 2 * static_cast<int>(m_thickness); |
| 87 int phase = 1; | 91 int phase = 1; |
| 88 if (dashLength > 1) { | 92 if (dashLength > 1) { |
| 89 // Determine how many dashes or dots we should have. | 93 // Determine how many dashes or dots we should have. |
| 90 int numDashes = distance / dashLength; | 94 int numDashes = distance / dashLength; |
| 91 int remainder = distance % dashLength; | 95 int remainder = distance % dashLength; |
| 92 // Adjust the phase to center the dashes within the line. | 96 // Adjust the phase to center the dashes within the line. |
| 93 if (numDashes % 2) { | 97 if (numDashes % 2) { |
| 94 // Odd: shift right a full dash, minus half the remainder. | 98 // Odd: shift right a full dash, minus half the remainder. |
| 95 phase = dashLength - remainder / 2; | 99 phase = dashLength - remainder / 2; |
| 96 } else { | 100 } else { |
| 97 // Even: shift right half a dash, minus half the remainder. | 101 // Even: shift right half a dash, minus half the remainder. |
| 98 phase = (dashLength - remainder) / 2; | 102 phase = (dashLength - remainder) / 2; |
| 99 } | 103 } |
| 100 } | 104 } |
| 101 SkScalar dashLengthSk = SkIntToScalar(dashLength); | 105 SkScalar dashLengthSk = SkIntToScalar(dashLength); |
| 102 SkScalar intervals[2] = { dashLengthSk, dashLengthSk }; | 106 SkScalar intervals[2] = { dashLengthSk, dashLengthSk }; |
| 103 RefPtr<SkDashPathEffect> pathEffect = adoptRef(new SkDashPathEffect(
intervals, 2, SkIntToScalar(phase))); | 107 RefPtr<SkDashPathEffect> pathEffect = adoptRef(new SkDashPathEffect(
intervals, 2, SkIntToScalar(phase))); |
| 104 paint->setPathEffect(pathEffect.get()); | 108 paint->setPathEffect(pathEffect.get()); |
| 105 } | 109 } |
| 106 } | 110 } |
| 107 | |
| 108 return width; | |
| 109 } | 111 } |
| 110 | 112 |
| 111 } // namespace | 113 } // namespace |
| OLD | NEW |