| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. |
| 3 * 2006 Rob Buis <buis@kde.org> | 3 * 2006 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
| 5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 6 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 6 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 7 * | 7 * |
| 8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
| 10 * are met: | 10 * are met: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 SkScalar length = 0; | 165 SkScalar length = 0; |
| 166 SkPathMeasure measure(m_path, false); | 166 SkPathMeasure measure(m_path, false); |
| 167 | 167 |
| 168 do { | 168 do { |
| 169 length += measure.getLength(); | 169 length += measure.getLength(); |
| 170 } while (measure.nextContour()); | 170 } while (measure.nextContour()); |
| 171 | 171 |
| 172 return SkScalarToFloat(length); | 172 return SkScalarToFloat(length); |
| 173 } | 173 } |
| 174 | 174 |
| 175 FloatPoint Path::pointAtLength(float length, bool& ok) const | 175 FloatPoint Path::pointAtLength(float length) const |
| 176 { | 176 { |
| 177 FloatPoint point; | 177 FloatPoint point; |
| 178 float normal; | 178 float normal; |
| 179 ok = pointAndNormalAtLength(length, point, normal); | 179 pointAndNormalAtLength(length, point, normal); |
| 180 return point; | 180 return point; |
| 181 } | 181 } |
| 182 | 182 |
| 183 static bool calculatePointAndNormalOnPath(SkPathMeasure& measure, SkScalar lengt
h, FloatPoint& point, float& normalAngle, SkScalar* accumulatedLength = 0) | 183 static bool calculatePointAndNormalOnPath(SkPathMeasure& measure, SkScalar lengt
h, FloatPoint& point, float& normalAngle, SkScalar* accumulatedLength = 0) |
| 184 { | 184 { |
| 185 do { | 185 do { |
| 186 SkScalar contourLength = measure.getLength(); | 186 SkScalar contourLength = measure.getLength(); |
| 187 if (length <= contourLength) { | 187 if (length <= contourLength) { |
| 188 SkVector tangent; | 188 SkVector tangent; |
| 189 SkPoint position; | 189 SkPoint position; |
| 190 | 190 |
| 191 if (measure.getPosTan(length, &position, &tangent)) { | 191 if (measure.getPosTan(length, &position, &tangent)) { |
| 192 normalAngle = rad2deg(SkScalarToFloat(SkScalarATan2(tangent.fY,
tangent.fX))); | 192 normalAngle = rad2deg(SkScalarToFloat(SkScalarATan2(tangent.fY,
tangent.fX))); |
| 193 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat
(position.fY)); | 193 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat
(position.fY)); |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 length -= contourLength; | 197 length -= contourLength; |
| 198 if (accumulatedLength) | 198 if (accumulatedLength) |
| 199 *accumulatedLength += contourLength; | 199 *accumulatedLength += contourLength; |
| 200 } while (measure.nextContour()); | 200 } while (measure.nextContour()); |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool Path::pointAndNormalAtLength(float length, FloatPoint& point, float& normal
) const | 204 void Path::pointAndNormalAtLength(float length, FloatPoint& point, float& normal
) const |
| 205 { | 205 { |
| 206 SkPathMeasure measure(m_path, false); | 206 SkPathMeasure measure(m_path, false); |
| 207 if (calculatePointAndNormalOnPath(measure, WebCoreFloatToSkScalar(length), p
oint, normal)) |
| 208 return; |
| 207 | 209 |
| 208 if (calculatePointAndNormalOnPath(measure, WebCoreFloatToSkScalar(length), p
oint, normal)) | 210 SkPoint position = m_path.getPoint(0); |
| 209 return true; | 211 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat(position.fY
)); |
| 210 | |
| 211 normal = 0; | 212 normal = 0; |
| 212 point = FloatPoint(0, 0); | |
| 213 return false; | |
| 214 } | 213 } |
| 215 | 214 |
| 216 Path::PositionCalculator::PositionCalculator(const Path& path) | 215 Path::PositionCalculator::PositionCalculator(const Path& path) |
| 217 : m_path(path.skPath()) | 216 : m_path(path.skPath()) |
| 218 , m_pathMeasure(path.skPath(), false) | 217 , m_pathMeasure(path.skPath(), false) |
| 219 , m_accumulatedLength(0) | 218 , m_accumulatedLength(0) |
| 220 { | 219 { |
| 221 } | 220 } |
| 222 | 221 |
| 223 bool Path::PositionCalculator::pointAndNormalAtLength(float length, FloatPoint&
point, float& normalAngle) | 222 void Path::PositionCalculator::pointAndNormalAtLength(float length, FloatPoint&
point, float& normalAngle) |
| 224 { | 223 { |
| 225 SkScalar skLength = WebCoreFloatToSkScalar(length); | 224 SkScalar skLength = WebCoreFloatToSkScalar(length); |
| 226 if (skLength >= 0) { | 225 if (skLength >= 0) { |
| 227 if (skLength < m_accumulatedLength) { | 226 if (skLength < m_accumulatedLength) { |
| 228 // Reset path measurer to rewind (and restart from 0). | 227 // Reset path measurer to rewind (and restart from 0). |
| 229 m_pathMeasure.setPath(&m_path, false); | 228 m_pathMeasure.setPath(&m_path, false); |
| 230 m_accumulatedLength = 0; | 229 m_accumulatedLength = 0; |
| 231 } else { | 230 } else { |
| 232 skLength -= m_accumulatedLength; | 231 skLength -= m_accumulatedLength; |
| 233 } | 232 } |
| 234 | 233 |
| 235 if (calculatePointAndNormalOnPath(m_pathMeasure, skLength, point, normal
Angle, &m_accumulatedLength)) | 234 if (calculatePointAndNormalOnPath(m_pathMeasure, skLength, point, normal
Angle, &m_accumulatedLength)) |
| 236 return true; | 235 return; |
| 237 } | 236 } |
| 238 | 237 |
| 238 SkPoint position = m_path.getPoint(0); |
| 239 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat(position.fY
)); |
| 239 normalAngle = 0; | 240 normalAngle = 0; |
| 240 point = FloatPoint(0, 0); | 241 return; |
| 241 return false; | |
| 242 } | 242 } |
| 243 | 243 |
| 244 void Path::clear() | 244 void Path::clear() |
| 245 { | 245 { |
| 246 m_path.reset(); | 246 m_path.reset(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 bool Path::isEmpty() const | 249 bool Path::isEmpty() const |
| 250 { | 250 { |
| 251 return m_path.isEmpty(); | 251 return m_path.isEmpty(); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 498 |
| 499 #if ENABLE(ASSERT) | 499 #if ENABLE(ASSERT) |
| 500 bool ellipseIsRenderable(float startAngle, float endAngle) | 500 bool ellipseIsRenderable(float startAngle, float endAngle) |
| 501 { | 501 { |
| 502 return (std::abs(endAngle - startAngle) < twoPiFloat) | 502 return (std::abs(endAngle - startAngle) < twoPiFloat) |
| 503 || WebCoreFloatNearlyEqual(std::abs(endAngle - startAngle), twoPiFloat); | 503 || WebCoreFloatNearlyEqual(std::abs(endAngle - startAngle), twoPiFloat); |
| 504 } | 504 } |
| 505 #endif | 505 #endif |
| 506 | 506 |
| 507 } // namespace blink | 507 } // namespace blink |
| OLD | NEW |