- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGPathByteStreamBuilder.cpp
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 #include "config.h"
21
22 #include "core/svg/SVGPathByteStreamBuilder.h"
23
24 #include "core/svg/SVGPathSeg.h"
25 #include "wtf/OwnPtr.h"
26
27 namespace WebCore {
28
29 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder()
30     : m_byteStream(0)
31 {
32 }
33
34 void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
35 {
36     ASSERT(m_byteStream);
37     writeSegmentType(mode == RelativeCoordinates ?  PathSegMoveToRel : PathSegMoveToAbs);
38     writeFloatPoint(targetPoint);
39 }
40
41 void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
42 {
43     ASSERT(m_byteStream);
44     writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs);
45     writeFloatPoint(targetPoint);
46 }
47
48 void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
49 {
50     ASSERT(m_byteStream);
51     writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs);
52     writeFloat(x);
53 }
54
55 void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode)
56 {
57     ASSERT(m_byteStream);
58     writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs);
59     writeFloat(y);
60 }
61
62 void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
63 {
64     ASSERT(m_byteStream);
65     writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs);
66     writeFloatPoint(point1);
67     writeFloatPoint(point2);
68     writeFloatPoint(targetPoint);
69 }
70
71 void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
72 {
73     ASSERT(m_byteStream);
74     writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs);
75     writeFloatPoint(point2);
76     writeFloatPoint(targetPoint);
77 }
78
79 void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
80 {
81     ASSERT(m_byteStream);
82     writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs);
83     writeFloatPoint(point1);
84     writeFloatPoint(targetPoint);
85 }
86
87 void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
88 {
89     ASSERT(m_byteStream);
90     writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs);
91     writeFloatPoint(targetPoint);
92 }
93
94 void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
95 {
96     ASSERT(m_byteStream);
97     writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs);
98     writeFloat(r1);
99     writeFloat(r2);
100     writeFloat(angle);
101     writeFlag(largeArcFlag);
102     writeFlag(sweepFlag);
103     writeFloatPoint(targetPoint);
104 }
105
106 void SVGPathByteStreamBuilder::closePath()
107 {
108     ASSERT(m_byteStream);
109     writeSegmentType(PathSegClosePath);
110 }
111
112 } // namespace WebCore