| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007 Eric Seidel <eric@webkit.org> | 2 * Copyright (C) 2006, 2007 Eric Seidel <eric@webkit.org> |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 */ | 18 */ |
| 19 | 19 |
| 20 #include "config.h" | 20 #include "config.h" |
| 21 #include "core/platform/graphics/PathTraversalState.h" | 21 #include "platform/graphics/PathTraversalState.h" |
| 22 | 22 |
| 23 #include "wtf/MathExtras.h" | 23 #include "wtf/MathExtras.h" |
| 24 #include "wtf/Vector.h" | 24 #include "wtf/Vector.h" |
| 25 | 25 |
| 26 namespace WebCore { | 26 namespace WebCore { |
| 27 | 27 |
| 28 static const float kPathSegmentLengthTolerance = 0.00001f; | 28 static const float kPathSegmentLengthTolerance = 0.00001f; |
| 29 | 29 |
| 30 static inline FloatPoint midPoint(const FloatPoint& first, const FloatPoint& sec
ond) | 30 static inline FloatPoint midPoint(const FloatPoint& first, const FloatPoint& sec
ond) |
| 31 { | 31 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 FloatPoint start; | 104 FloatPoint start; |
| 105 FloatPoint control1; | 105 FloatPoint control1; |
| 106 FloatPoint control2; | 106 FloatPoint control2; |
| 107 FloatPoint end; | 107 FloatPoint end; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // FIXME: This function is possibly very slow due to the ifs required for proper
path measuring | 110 // FIXME: This function is possibly very slow due to the ifs required for proper
path measuring |
| 111 // A simple speed-up would be to use an additional boolean template parameter to
control whether | 111 // A simple speed-up would be to use an additional boolean template parameter to
control whether |
| 112 // to use the "fast" version of this function with no PathTraversalState updatin
g, vs. the slow | 112 // to use the "fast" version of this function with no PathTraversalState updatin
g, vs. the slow |
| 113 // version which does update the PathTraversalState. We'll have to shark it to
see if that's necessary. | 113 // version which does update the PathTraversalState. We'll have to shark it to s
ee if that's necessary. |
| 114 // Another check which is possible up-front (to send us down the fast path) woul
d be to check if | 114 // Another check which is possible up-front (to send us down the fast path) woul
d be to check if |
| 115 // approximateDistance() + current total distance > desired distance | 115 // approximateDistance() + current total distance > desired distance |
| 116 template<class CurveType> | 116 template<class CurveType> |
| 117 static float curveLength(PathTraversalState& traversalState, CurveType curve) | 117 static float curveLength(PathTraversalState& traversalState, CurveType curve) |
| 118 { | 118 { |
| 119 static const unsigned curveStackDepthLimit = 20; | 119 static const unsigned curveStackDepthLimit = 20; |
| 120 | 120 |
| 121 Vector<CurveType> curveStack; | 121 Vector<CurveType> curveStack; |
| 122 curveStack.append(curve); | 122 curveStack.append(curve); |
| 123 | 123 |
| 124 float totalLength = 0; | 124 float totalLength = 0; |
| 125 do { | 125 do { |
| 126 float length = curve.approximateDistance(); | 126 float length = curve.approximateDistance(); |
| 127 if ((length - distanceLine(curve.start, curve.end)) > kPathSegmentLength
Tolerance && curveStack.size() <= curveStackDepthLimit) { | 127 if ((length - distanceLine(curve.start, curve.end)) > kPathSegmentLength
Tolerance && curveStack.size() <= curveStackDepthLimit) { |
| 128 CurveType leftCurve; | 128 CurveType leftCurve; |
| 129 CurveType rightCurve; | 129 CurveType rightCurve; |
| 130 curve.split(leftCurve, rightCurve); | 130 curve.split(leftCurve, rightCurve); |
| 131 curve = leftCurve; | 131 curve = leftCurve; |
| 132 curveStack.append(rightCurve); | 132 curveStack.append(rightCurve); |
| 133 } else { | 133 } else { |
| 134 totalLength += length; | 134 totalLength += length; |
| 135 if (traversalState.m_action == PathTraversalState::TraversalPointAtL
ength | 135 if (traversalState.m_action == PathTraversalState::TraversalPointAtL
ength || traversalState.m_action == PathTraversalState::TraversalNormalAngleAtLe
ngth) { |
| 136 || traversalState.m_action == PathTraversalState::TraversalNormalAn
gleAtLength) { | |
| 137 traversalState.m_previous = curve.start; | 136 traversalState.m_previous = curve.start; |
| 138 traversalState.m_current = curve.end; | 137 traversalState.m_current = curve.end; |
| 139 if (traversalState.m_totalLength + totalLength > traversalState.
m_desiredLength) | 138 if (traversalState.m_totalLength + totalLength > traversalState.
m_desiredLength) |
| 140 return totalLength; | 139 return totalLength; |
| 141 } | 140 } |
| 142 curve = curveStack.last(); | 141 curve = curveStack.last(); |
| 143 curveStack.removeLast(); | 142 curveStack.removeLast(); |
| 144 } | 143 } |
| 145 } while (!curveStack.isEmpty()); | 144 } while (!curveStack.isEmpty()); |
| 146 | 145 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void PathTraversalState::processSegment() | 205 void PathTraversalState::processSegment() |
| 207 { | 206 { |
| 208 if (m_action == TraversalSegmentAtLength && m_totalLength >= m_desiredLength
) | 207 if (m_action == TraversalSegmentAtLength && m_totalLength >= m_desiredLength
) |
| 209 m_success = true; | 208 m_success = true; |
| 210 | 209 |
| 211 if ((m_action == TraversalPointAtLength || m_action == TraversalNormalAngleA
tLength) && m_totalLength >= m_desiredLength) { | 210 if ((m_action == TraversalPointAtLength || m_action == TraversalNormalAngleA
tLength) && m_totalLength >= m_desiredLength) { |
| 212 float slope = FloatPoint(m_current - m_previous).slopeAngleRadians(); | 211 float slope = FloatPoint(m_current - m_previous).slopeAngleRadians(); |
| 213 if (m_action == TraversalPointAtLength) { | 212 if (m_action == TraversalPointAtLength) { |
| 214 float offset = m_desiredLength - m_totalLength; | 213 float offset = m_desiredLength - m_totalLength; |
| 215 m_current.move(offset * cosf(slope), offset * sinf(slope)); | 214 m_current.move(offset * cosf(slope), offset * sinf(slope)); |
| 216 } else | 215 } else { |
| 217 m_normalAngle = rad2deg(slope); | 216 m_normalAngle = rad2deg(slope); |
| 217 } |
| 218 m_success = true; | 218 m_success = true; |
| 219 } | 219 } |
| 220 m_previous = m_current; | 220 m_previous = m_current; |
| 221 } | 221 } |
| 222 | 222 |
| 223 } | 223 } |
| 224 | 224 |
| OLD | NEW |