1/*
2 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#pragma once
22
23#include "FloatPoint.h"
24#include "SVGPathByteStream.h"
25#include "SVGPathConsumer.h"
26#include <wtf/text/WTFString.h>
27
28namespace WebCore {
29
30class SVGPathByteStreamBuilder final : public SVGPathConsumer {
31public:
32 SVGPathByteStreamBuilder(SVGPathByteStream&);
33
34private:
35 void incrementPathSegmentCount() final { }
36 bool continueConsuming() final { return true; }
37
38 // Used in UnalteredParsing/NormalizedParsing modes.
39 void moveTo(const FloatPoint&, bool closed, PathCoordinateMode) final;
40 void lineTo(const FloatPoint&, PathCoordinateMode) final;
41 void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode) final;
42 void closePath() final;
43
44 // Only used in UnalteredParsing mode.
45 void lineToHorizontal(float, PathCoordinateMode) final;
46 void lineToVertical(float, PathCoordinateMode) final;
47 void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) final;
48 void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) final;
49 void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) final;
50 void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode) final;
51
52 template<typename ByteType>
53 void writeType(const ByteType& type)
54 {
55 size_t typeSize = sizeof(ByteType);
56 for (size_t i = 0; i < typeSize; ++i)
57 m_byteStream.append(type.bytes[i]);
58 }
59
60 void writeFlag(bool value)
61 {
62 BoolByte data;
63 data.value = value;
64 writeType(data);
65 }
66
67 void writeFloat(float value)
68 {
69 FloatByte data;
70 data.value = value;
71 writeType(data);
72 }
73
74 void writeFloatPoint(const FloatPoint& point)
75 {
76 writeFloat(point.x());
77 writeFloat(point.y());
78 }
79
80 void writeSegmentType(unsigned short value)
81 {
82 UnsignedShortByte data;
83 data.value = value;
84 writeType(data);
85 }
86
87 SVGPathByteStream& m_byteStream;
88};
89
90} // namespace WebCore
91