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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #include "config.h" | 30 #include "config.h" |
31 #include "platform/graphics/Path.h" | 31 #include "platform/graphics/Path.h" |
32 | 32 |
33 #include <math.h> | 33 #include <math.h> |
34 #include "platform/geometry/FloatPoint.h" | 34 #include "platform/geometry/FloatPoint.h" |
35 #include "platform/geometry/FloatRect.h" | 35 #include "platform/geometry/FloatRect.h" |
36 #include "platform/graphics/GraphicsContext.h" | 36 #include "platform/graphics/GraphicsContext.h" |
37 #include "platform/graphics/skia/SkiaUtils.h" | 37 #include "platform/graphics/skia/SkiaUtils.h" |
38 #include "platform/transforms/AffineTransform.h" | 38 #include "platform/transforms/AffineTransform.h" |
39 #include "third_party/skia/include/core/SkPathMeasure.h" | |
40 #include "third_party/skia/include/pathops/SkPathOps.h" | 39 #include "third_party/skia/include/pathops/SkPathOps.h" |
41 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
42 | 41 |
43 namespace WebCore { | 42 namespace WebCore { |
44 | 43 |
45 Path::Path() | 44 Path::Path() |
46 : m_path() | 45 : m_path() |
47 { | 46 { |
48 } | 47 } |
49 | 48 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 169 } |
171 | 170 |
172 float Path::normalAngleAtLength(float length, bool& ok) const | 171 float Path::normalAngleAtLength(float length, bool& ok) const |
173 { | 172 { |
174 FloatPoint point; | 173 FloatPoint point; |
175 float normal; | 174 float normal; |
176 ok = pointAndNormalAtLength(length, point, normal); | 175 ok = pointAndNormalAtLength(length, point, normal); |
177 return normal; | 176 return normal; |
178 } | 177 } |
179 | 178 |
180 bool Path::pointAndNormalAtLength(float length, FloatPoint& point, float& normal
) const | 179 static bool calculatePointAndNormalOnPath(SkPathMeasure& measure, SkScalar lengt
h, FloatPoint& point, float& normalAngle, SkScalar* accumulatedLength = 0) |
181 { | 180 { |
182 SkPathMeasure measure(m_path, false); | |
183 | |
184 do { | 181 do { |
185 SkScalar contourLength = measure.getLength(); | 182 SkScalar contourLength = measure.getLength(); |
186 if (length <= contourLength) { | 183 if (length <= contourLength) { |
187 SkVector tangent; | 184 SkVector tangent; |
188 SkPoint position; | 185 SkPoint position; |
189 | 186 |
190 if (measure.getPosTan(length, &position, &tangent)) { | 187 if (measure.getPosTan(length, &position, &tangent)) { |
191 normal = rad2deg(SkScalarToFloat(SkScalarATan2(tangent.fY, tange
nt.fX))); | 188 normalAngle = rad2deg(SkScalarToFloat(SkScalarATan2(tangent.fY,
tangent.fX))); |
192 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat
(position.fY)); | 189 point = FloatPoint(SkScalarToFloat(position.fX), SkScalarToFloat
(position.fY)); |
193 return true; | 190 return true; |
194 } | 191 } |
195 } | 192 } |
196 length -= contourLength; | 193 length -= contourLength; |
| 194 if (accumulatedLength) |
| 195 *accumulatedLength += contourLength; |
197 } while (measure.nextContour()); | 196 } while (measure.nextContour()); |
| 197 return false; |
| 198 } |
| 199 |
| 200 bool Path::pointAndNormalAtLength(float length, FloatPoint& point, float& normal
) const |
| 201 { |
| 202 SkPathMeasure measure(m_path, false); |
| 203 |
| 204 if (calculatePointAndNormalOnPath(measure, WebCoreFloatToSkScalar(length), p
oint, normal)) |
| 205 return true; |
198 | 206 |
199 normal = 0; | 207 normal = 0; |
200 point = FloatPoint(0, 0); | 208 point = FloatPoint(0, 0); |
201 return false; | 209 return false; |
202 } | 210 } |
203 | 211 |
| 212 Path::PositionCalculator::PositionCalculator(const Path& path) |
| 213 : m_path(path.skPath()) |
| 214 , m_pathMeasure(path.skPath(), false) |
| 215 , m_accumulatedLength(0) |
| 216 { |
| 217 } |
| 218 |
| 219 bool Path::PositionCalculator::pointAndNormalAtLength(float length, FloatPoint&
point, float& normalAngle) |
| 220 { |
| 221 SkScalar skLength = WebCoreFloatToSkScalar(length); |
| 222 if (skLength >= 0) { |
| 223 if (skLength < m_accumulatedLength) { |
| 224 // Reset path measurer to rewind (and restart from 0). |
| 225 m_pathMeasure.setPath(&m_path, false); |
| 226 m_accumulatedLength = 0; |
| 227 } else { |
| 228 skLength -= m_accumulatedLength; |
| 229 } |
| 230 |
| 231 if (calculatePointAndNormalOnPath(m_pathMeasure, skLength, point, normal
Angle, &m_accumulatedLength)) |
| 232 return true; |
| 233 } |
| 234 |
| 235 normalAngle = 0; |
| 236 point = FloatPoint(0, 0); |
| 237 return false; |
| 238 } |
| 239 |
204 void Path::clear() | 240 void Path::clear() |
205 { | 241 { |
206 m_path.reset(); | 242 m_path.reset(); |
207 } | 243 } |
208 | 244 |
209 bool Path::isEmpty() const | 245 bool Path::isEmpty() const |
210 { | 246 { |
211 return m_path.isEmpty(); | 247 return m_path.isEmpty(); |
212 } | 248 } |
213 | 249 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 484 |
449 #if !ASSERT_DISABLED | 485 #if !ASSERT_DISABLED |
450 bool ellipseIsRenderable(float startAngle, float endAngle) | 486 bool ellipseIsRenderable(float startAngle, float endAngle) |
451 { | 487 { |
452 return (std::abs(endAngle - startAngle) < 2 * piFloat) | 488 return (std::abs(endAngle - startAngle) < 2 * piFloat) |
453 || WebCoreFloatNearlyEqual(std::abs(endAngle - startAngle), 2 * piFloat)
; | 489 || WebCoreFloatNearlyEqual(std::abs(endAngle - startAngle), 2 * piFloat)
; |
454 } | 490 } |
455 #endif | 491 #endif |
456 | 492 |
457 } | 493 } |
OLD | NEW |