OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "core/svg/SVGPathStringBuilder.h" | 21 #include "core/svg/SVGPathStringBuilder.h" |
22 | 22 |
23 #include "core/svg/SVGPathSeg.h" | |
23 #include "wtf/text/WTFString.h" | 24 #include "wtf/text/WTFString.h" |
24 | 25 |
25 namespace blink { | 26 namespace blink { |
26 | 27 |
27 String SVGPathStringBuilder::result() | 28 String SVGPathStringBuilder::result() |
28 { | 29 { |
29 unsigned size = m_stringBuilder.length(); | 30 unsigned size = m_stringBuilder.length(); |
30 if (!size) | 31 if (!size) |
31 return String(); | 32 return String(); |
32 | 33 |
(...skipping 13 matching lines...) Expand all Loading... | |
46 stringBuilder.append(' '); | 47 stringBuilder.append(' '); |
47 stringBuilder.appendNumber(value); | 48 stringBuilder.appendNumber(value); |
48 } | 49 } |
49 | 50 |
50 static void appendPoint(StringBuilder& stringBuilder, const FloatPoint& point) | 51 static void appendPoint(StringBuilder& stringBuilder, const FloatPoint& point) |
51 { | 52 { |
52 appendFloat(stringBuilder, point.x()); | 53 appendFloat(stringBuilder, point.x()); |
53 appendFloat(stringBuilder, point.y()); | 54 appendFloat(stringBuilder, point.y()); |
54 } | 55 } |
55 | 56 |
56 static void emitCommand1Arg(StringBuilder& stringBuilder, char commandChar, floa t argument) | 57 // FIXME: Centralized location for this (SVGPathSeg.h?) |
Stephen Chennney
2015/03/25 15:05:25
FIXMEs now must be TODO(name). See thread on blink
Stephen Chennney
2015/03/25 15:05:25
Is this a repeat of some other block? I recall see
fs
2015/03/25 17:08:14
I don't _think_ this exact block exists somewhere
| |
58 static const char pathSegmentCharacter[] = { | |
59 0, // PathSegUnknown | |
60 'Z', // PathSegClosePath | |
61 'M', // PathSegMoveToAbs | |
62 'm', // PathSegMoveToRel | |
63 'L', // PathSegLineToAbs | |
64 'l', // PathSegLineToRel | |
65 'C', // PathSegCurveToCubicAbs | |
66 'c', // PathSegCurveToCubicRel | |
67 'Q', // PathSegCurveToQuadraticAbs | |
68 'q', // PathSegCurveToQuadraticRel | |
69 'A', // PathSegArcAbs | |
70 'a', // PathSegArcRel | |
71 'H', // PathSegLineToHorizontalAbs | |
72 'h', // PathSegLineToHorizontalRel | |
73 'V', // PathSegLineToVerticalAbs | |
74 'v', // PathSegLineToVerticalRel | |
75 'S', // PathSegCurveToCubicSmoothAbs | |
76 's', // PathSegCurveToCubicSmoothRel | |
77 'T', // PathSegCurveToQuadraticSmoothAbs | |
78 't', // PathSegCurveToQuadraticSmoothRel | |
79 }; | |
80 | |
81 void SVGPathStringBuilder::emitSegment(const PathSegmentData& segment) | |
57 { | 82 { |
58 stringBuilder.append(commandChar); | 83 ASSERT(segment.command > PathSegUnknown && segment.command <= PathSegCurveTo QuadraticSmoothRel); |
59 appendFloat(stringBuilder, argument); | 84 m_stringBuilder.append(pathSegmentCharacter[segment.command]); |
60 stringBuilder.append(' '); | |
61 } | |
62 | 85 |
63 static void emitCommand1Arg(StringBuilder& stringBuilder, char commandChar, cons t FloatPoint& argumentPoint) | 86 switch (segment.command) { |
64 { | 87 case PathSegMoveToRel: |
65 stringBuilder.append(commandChar); | 88 case PathSegMoveToAbs: |
66 appendPoint(stringBuilder, argumentPoint); | 89 case PathSegLineToRel: |
67 stringBuilder.append(' '); | 90 case PathSegLineToAbs: |
68 } | 91 case PathSegCurveToQuadraticSmoothRel: |
69 | 92 case PathSegCurveToQuadraticSmoothAbs: |
70 static void emitCommand2Arg(StringBuilder& stringBuilder, char commandChar, cons t FloatPoint& argument1Point, const FloatPoint& argument2Point) | 93 appendPoint(m_stringBuilder, segment.targetPoint); |
71 { | 94 break; |
72 stringBuilder.append(commandChar); | 95 case PathSegLineToHorizontalRel: |
73 appendPoint(stringBuilder, argument1Point); | 96 case PathSegLineToHorizontalAbs: |
74 appendPoint(stringBuilder, argument2Point); | 97 appendFloat(m_stringBuilder, segment.targetPoint.x()); |
75 stringBuilder.append(' '); | 98 break; |
76 } | 99 case PathSegLineToVerticalRel: |
77 | 100 case PathSegLineToVerticalAbs: |
78 void SVGPathStringBuilder::moveTo(const FloatPoint& targetPoint, PathCoordinateM ode mode) | 101 appendFloat(m_stringBuilder, segment.targetPoint.y()); |
79 { | 102 break; |
80 emitCommand1Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'M' : 'm', targetPoint); | 103 case PathSegClosePath: |
81 } | 104 break; |
82 | 105 case PathSegCurveToCubicRel: |
83 void SVGPathStringBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateM ode mode) | 106 case PathSegCurveToCubicAbs: |
84 { | 107 appendPoint(m_stringBuilder, segment.point1); |
85 emitCommand1Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'L' : 'l', targetPoint); | 108 appendPoint(m_stringBuilder, segment.point2); |
86 } | 109 appendPoint(m_stringBuilder, segment.targetPoint); |
87 | 110 break; |
88 void SVGPathStringBuilder::lineToHorizontal(float x, PathCoordinateMode mode) | 111 case PathSegCurveToCubicSmoothRel: |
89 { | 112 case PathSegCurveToCubicSmoothAbs: |
90 emitCommand1Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'H' : 'h', x); | 113 appendPoint(m_stringBuilder, segment.point2); |
91 } | 114 appendPoint(m_stringBuilder, segment.targetPoint); |
92 | 115 break; |
93 void SVGPathStringBuilder::lineToVertical(float y, PathCoordinateMode mode) | 116 case PathSegCurveToQuadraticRel: |
94 { | 117 case PathSegCurveToQuadraticAbs: |
95 emitCommand1Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'V' : 'v', y); | 118 appendPoint(m_stringBuilder, segment.point1); |
96 } | 119 appendPoint(m_stringBuilder, segment.targetPoint); |
97 | 120 break; |
98 void SVGPathStringBuilder::curveToCubic(const FloatPoint& point1, const FloatPoi nt& point2, const FloatPoint& targetPoint, PathCoordinateMode mode) | 121 case PathSegArcRel: |
99 { | 122 case PathSegArcAbs: |
100 m_stringBuilder.append((mode == AbsoluteCoordinates) ? 'C' : 'c'); | 123 appendPoint(m_stringBuilder, segment.point1); |
101 appendPoint(m_stringBuilder, point1); | 124 appendFloat(m_stringBuilder, segment.point2.x()); |
102 appendPoint(m_stringBuilder, point2); | 125 appendBool(m_stringBuilder, segment.arcLarge); |
103 appendPoint(m_stringBuilder, targetPoint); | 126 appendBool(m_stringBuilder, segment.arcSweep); |
127 appendPoint(m_stringBuilder, segment.targetPoint); | |
128 break; | |
129 default: | |
130 ASSERT_NOT_REACHED(); | |
131 } | |
104 m_stringBuilder.append(' '); | 132 m_stringBuilder.append(' '); |
105 } | 133 } |
106 | 134 |
107 void SVGPathStringBuilder::curveToCubicSmooth(const FloatPoint& point2, const Fl oatPoint& targetPoint, PathCoordinateMode mode) | |
108 { | |
109 emitCommand2Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'S' : 's', point2, targetPoint); | |
110 } | |
111 | |
112 void SVGPathStringBuilder::curveToQuadratic(const FloatPoint& point1, const Floa tPoint& targetPoint, PathCoordinateMode mode) | |
113 { | |
114 emitCommand2Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'Q' : 'q', point1, targetPoint); | |
115 } | |
116 | |
117 void SVGPathStringBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode) | |
118 { | |
119 emitCommand1Arg(m_stringBuilder, (mode == AbsoluteCoordinates) ? 'T' : 't', targetPoint); | |
120 } | |
121 | |
122 void SVGPathStringBuilder::arcTo(float r1, float r2, float angle, bool largeArcF lag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode) | |
123 { | |
124 m_stringBuilder.append((mode == AbsoluteCoordinates) ? 'A' : 'a'); | |
125 appendFloat(m_stringBuilder, r1); | |
126 appendFloat(m_stringBuilder, r2); | |
127 appendFloat(m_stringBuilder, angle); | |
128 appendBool(m_stringBuilder, largeArcFlag); | |
129 appendBool(m_stringBuilder, sweepFlag); | |
130 appendPoint(m_stringBuilder, targetPoint); | |
131 m_stringBuilder.append(' '); | |
132 } | |
133 | |
134 void SVGPathStringBuilder::closePath() | |
135 { | |
136 m_stringBuilder.appendLiteral("Z "); | |
137 } | |
138 | |
139 } // namespace blink | 135 } // namespace blink |
OLD | NEW |