OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2002, 2003 The Karbon Developers | 2 * Copyright (C) 2002, 2003 The Karbon Developers |
3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> | 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> |
4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> | 4 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org> |
5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. | 5 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. |
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 13 matching lines...) Expand all Loading... |
24 #ifndef SVGPathParser_h | 24 #ifndef SVGPathParser_h |
25 #define SVGPathParser_h | 25 #define SVGPathParser_h |
26 | 26 |
27 #include "core/CoreExport.h" | 27 #include "core/CoreExport.h" |
28 #include "core/svg/SVGPathData.h" | 28 #include "core/svg/SVGPathData.h" |
29 #include "platform/heap/Handle.h" | 29 #include "platform/heap/Handle.h" |
30 | 30 |
31 namespace blink { | 31 namespace blink { |
32 | 32 |
33 class SVGPathConsumer; | 33 class SVGPathConsumer; |
34 class SVGPathSource; | |
35 | 34 |
36 class CORE_EXPORT SVGPathParser final { | 35 namespace SVGPathParser { |
37 WTF_MAKE_NONCOPYABLE(SVGPathParser); | 36 |
38 STACK_ALLOCATED(); | 37 template<typename SourceType, typename ConsumerType> |
39 public: | 38 inline bool parsePath(SourceType& source, ConsumerType& consumer) |
40 SVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer) | 39 { |
41 : m_source(source) | 40 while (source.hasMoreData()) { |
42 , m_consumer(consumer) | 41 PathSegmentData segment = source.parseSegment(); |
43 { | 42 if (segment.command == PathSegUnknown) |
44 ASSERT(m_source); | 43 return false; |
45 ASSERT(m_consumer); | 44 |
| 45 consumer.emitSegment(segment); |
46 } | 46 } |
| 47 return true; |
| 48 } |
47 | 49 |
48 bool parsePathDataFromSource(bool checkForInitialMoveTo = true) | 50 } // namespace SVGPathParser |
49 { | |
50 ASSERT(m_source); | |
51 ASSERT(m_consumer); | |
52 if (checkForInitialMoveTo && !initialCommandIsMoveTo()) | |
53 return false; | |
54 return parsePath(); | |
55 } | |
56 | |
57 private: | |
58 bool initialCommandIsMoveTo(); | |
59 bool parsePath(); | |
60 | |
61 SVGPathSource* m_source; | |
62 SVGPathConsumer* m_consumer; | |
63 }; | |
64 | 51 |
65 class SVGPathNormalizer { | 52 class SVGPathNormalizer { |
66 STACK_ALLOCATED(); | 53 STACK_ALLOCATED(); |
67 public: | 54 public: |
68 SVGPathNormalizer(SVGPathConsumer* consumer) | 55 SVGPathNormalizer(SVGPathConsumer* consumer) |
69 : m_consumer(consumer) | 56 : m_consumer(consumer) |
70 , m_lastCommand(PathSegUnknown) | 57 , m_lastCommand(PathSegUnknown) |
71 { | 58 { |
72 ASSERT(m_consumer); | 59 ASSERT(m_consumer); |
73 } | 60 } |
74 | 61 |
75 void emitSegment(const PathSegmentData&); | 62 void emitSegment(const PathSegmentData&); |
76 | 63 |
77 private: | 64 private: |
78 bool decomposeArcToCubic(const FloatPoint& currentPoint, const PathSegmentDa
ta&); | 65 bool decomposeArcToCubic(const FloatPoint& currentPoint, const PathSegmentDa
ta&); |
79 | 66 |
80 SVGPathConsumer* m_consumer; | 67 SVGPathConsumer* m_consumer; |
81 FloatPoint m_controlPoint; | 68 FloatPoint m_controlPoint; |
82 FloatPoint m_currentPoint; | 69 FloatPoint m_currentPoint; |
83 FloatPoint m_subPathPoint; | 70 FloatPoint m_subPathPoint; |
84 SVGPathSegType m_lastCommand; | 71 SVGPathSegType m_lastCommand; |
85 }; | 72 }; |
86 | 73 |
87 } // namespace blink | 74 } // namespace blink |
88 | 75 |
89 #endif // SVGPathParser_h | 76 #endif // SVGPathParser_h |
OLD | NEW |