1/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
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
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#pragma once
21
22#include "FloatPoint.h"
23#include "SVGPathByteStream.h"
24#include "SVGPathSource.h"
25
26namespace WebCore {
27
28class SVGPathByteStreamSource final : public SVGPathSource {
29public:
30 explicit SVGPathByteStreamSource(const SVGPathByteStream&);
31
32private:
33 bool hasMoreData() const final;
34 bool moveToNextToken() final { return true; }
35 bool parseSVGSegmentType(SVGPathSegType&) final;
36 SVGPathSegType nextCommand(SVGPathSegType) final;
37
38 bool parseMoveToSegment(FloatPoint&) final;
39 bool parseLineToSegment(FloatPoint&) final;
40 bool parseLineToHorizontalSegment(float&) final;
41 bool parseLineToVerticalSegment(float&) final;
42 bool parseCurveToCubicSegment(FloatPoint&, FloatPoint&, FloatPoint&) final;
43 bool parseCurveToCubicSmoothSegment(FloatPoint&, FloatPoint&) final;
44 bool parseCurveToQuadraticSegment(FloatPoint&, FloatPoint&) final;
45 bool parseCurveToQuadraticSmoothSegment(FloatPoint&) final;
46 bool parseArcToSegment(float&, float&, float&, bool&, bool&, FloatPoint&) final;
47
48#if COMPILER(MSVC)
49#pragma warning(disable: 4701)
50#endif
51 template<typename DataType, typename ByteType>
52 DataType readType()
53 {
54 ByteType data;
55 size_t typeSize = sizeof(ByteType);
56
57 for (size_t i = 0; i < typeSize; ++i) {
58 ASSERT_WITH_SECURITY_IMPLICATION(m_streamCurrent < m_streamEnd);
59 data.bytes[i] = *m_streamCurrent;
60 ++m_streamCurrent;
61 }
62
63 return data.value;
64 }
65
66 bool readFlag()
67 {
68 return readType<bool, BoolByte>();
69 }
70
71 float readFloat()
72 {
73 return readType<float, FloatByte>();
74 }
75
76 unsigned short readSVGSegmentType()
77 {
78 return readType<unsigned short, UnsignedShortByte>();
79 }
80
81 FloatPoint readFloatPoint()
82 {
83 float x = readType<float, FloatByte>();
84 float y = readType<float, FloatByte>();
85 return FloatPoint(x, y);
86 }
87
88 SVGPathByteStream::DataIterator m_streamCurrent;
89 SVGPathByteStream::DataIterator m_streamEnd;
90};
91
92} // namespace WebCore
93