Chromium Code Reviews| 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 class CORE_EXPORT SVGPathParser { |
|
f(malita)
2016/01/28 16:34:06
Nit: class -> namespace?
fs
2016/01/28 19:09:37
Sure, unless pdr minds.
| |
| 37 WTF_MAKE_NONCOPYABLE(SVGPathParser); | 36 STATIC_ONLY(SVGPathParser); |
| 38 STACK_ALLOCATED(); | |
| 39 public: | 37 public: |
| 40 SVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer) | 38 template<typename SourceType, typename ConsumerType> |
| 41 : m_source(source) | 39 static bool parsePath(SourceType&, ConsumerType&); |
| 42 , m_consumer(consumer) | |
| 43 { | |
| 44 ASSERT(m_source); | |
| 45 ASSERT(m_consumer); | |
| 46 } | |
| 47 | |
| 48 bool parsePathDataFromSource(bool checkForInitialMoveTo = true) | |
| 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 }; | 40 }; |
| 64 | 41 |
| 65 class SVGPathNormalizer { | 42 class SVGPathNormalizer { |
| 66 STACK_ALLOCATED(); | 43 STACK_ALLOCATED(); |
| 67 public: | 44 public: |
| 68 SVGPathNormalizer(SVGPathConsumer* consumer) | 45 SVGPathNormalizer(SVGPathConsumer* consumer) |
| 69 : m_consumer(consumer) | 46 : m_consumer(consumer) |
| 70 , m_lastCommand(PathSegUnknown) | 47 , m_lastCommand(PathSegUnknown) |
| 71 { | 48 { |
| 72 ASSERT(m_consumer); | 49 ASSERT(m_consumer); |
| 73 } | 50 } |
| 74 | 51 |
| 75 void emitSegment(const PathSegmentData&); | 52 void emitSegment(const PathSegmentData&); |
| 76 | 53 |
| 77 private: | 54 private: |
| 78 bool decomposeArcToCubic(const FloatPoint& currentPoint, const PathSegmentDa ta&); | 55 bool decomposeArcToCubic(const FloatPoint& currentPoint, const PathSegmentDa ta&); |
| 79 | 56 |
| 80 SVGPathConsumer* m_consumer; | 57 SVGPathConsumer* m_consumer; |
| 81 FloatPoint m_controlPoint; | 58 FloatPoint m_controlPoint; |
| 82 FloatPoint m_currentPoint; | 59 FloatPoint m_currentPoint; |
| 83 FloatPoint m_subPathPoint; | 60 FloatPoint m_subPathPoint; |
| 84 SVGPathSegType m_lastCommand; | 61 SVGPathSegType m_lastCommand; |
| 85 }; | 62 }; |
| 86 | 63 |
| 64 template<typename SourceType, typename ConsumerType> | |
| 65 bool SVGPathParser::parsePath(SourceType& source, ConsumerType& consumer) | |
| 66 { | |
| 67 while (source.hasMoreData()) { | |
| 68 PathSegmentData segment = source.parseSegment(); | |
| 69 if (segment.command == PathSegUnknown) | |
| 70 return false; | |
| 71 | |
| 72 consumer.emitSegment(segment); | |
| 73 } | |
| 74 return true; | |
| 75 } | |
| 76 | |
| 87 } // namespace blink | 77 } // namespace blink |
| 88 | 78 |
| 89 #endif // SVGPathParser_h | 79 #endif // SVGPathParser_h |
| OLD | NEW |