| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Setup any DashPathEffect on the paint. If a non-zero length is provided, | 80 // Setup any DashPathEffect on the paint. If a non-zero length is provided, |
| 81 // and no line dash has been set, the number of dashes/dots on a dashed/dotted | 81 // and no line dash has been set, the number of dashes/dots on a dashed/dotted |
| 82 // line will be adjusted to start and end that length with a dash/dot. | 82 // line will be adjusted to start and end that length with a dash/dot. |
| 83 void setupPaintDashPathEffect(PaintFlags*, int) const; | 83 void setupPaintDashPathEffect(PaintFlags*, int) const; |
| 84 | 84 |
| 85 // Determine whether a stroked line should be drawn using dashes. In practice, | 85 // Determine whether a stroked line should be drawn using dashes. In practice, |
| 86 // we draw dashes when a dashed stroke is specified or when a dotted stroke | 86 // we draw dashes when a dashed stroke is specified or when a dotted stroke |
| 87 // is specified but the line width is too small to draw circles. | 87 // is specified but the line width is too small to draw circles. |
| 88 static bool strokeIsDashed(float width, StrokeStyle); | 88 static bool strokeIsDashed(float width, StrokeStyle); |
| 89 | 89 |
| 90 // The length of the dash relative to the line thickness for dashed stroking. |
| 91 // A different dash length may be used when dashes are adjusted to better |
| 92 // fit a given length path. Thin lines need longer dashes to avoid |
| 93 // looking like dots when drawn. |
| 94 static float dashLengthRatio(float thickness) { |
| 95 return thickness >= 3 ? 2.0 : 3.0; |
| 96 } |
| 97 |
| 98 // The length of the gap between dashes relative to the line thickness for |
| 99 // dashed stroking. A different gap may be used when dashes are adjusted to |
| 100 // better fit a given length path. Thin lines need longer gaps to avoid |
| 101 // looking like a continuous line when drawn. |
| 102 static float dashGapRatio(float thickness) { |
| 103 return thickness >= 3 ? 1.0 : 2.0; |
| 104 } |
| 105 |
| 106 // Return a dash gap size that places dashes at each end of a stroke that is |
| 107 // strokeLength long, given preferred dash and gap sizes. The gap returned is |
| 108 // the one that minimizes deviation from the preferred gap length. |
| 109 static float selectBestDashGap(float strokeLength, |
| 110 float dashLength, |
| 111 float gapLength); |
| 112 |
| 90 private: | 113 private: |
| 91 StrokeStyle m_style; | 114 StrokeStyle m_style; |
| 92 float m_thickness; | 115 float m_thickness; |
| 93 PaintFlags::Cap m_lineCap; | 116 PaintFlags::Cap m_lineCap; |
| 94 PaintFlags::Join m_lineJoin; | 117 PaintFlags::Join m_lineJoin; |
| 95 float m_miterLimit; | 118 float m_miterLimit; |
| 96 sk_sp<SkPathEffect> m_dash; | 119 sk_sp<SkPathEffect> m_dash; |
| 97 }; | 120 }; |
| 98 | 121 |
| 99 } // namespace blink | 122 } // namespace blink |
| 100 | 123 |
| 101 #endif // StrokeData_h | 124 #endif // StrokeData_h |
| OLD | NEW |