OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010, 2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010, 2012. 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 |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "core/svg/SVGPathParser.h" | 29 #include "core/svg/SVGPathParser.h" |
30 #include "core/svg/SVGPathSegListBuilder.h" | 30 #include "core/svg/SVGPathSegListBuilder.h" |
31 #include "core/svg/SVGPathSegListSource.h" | 31 #include "core/svg/SVGPathSegListSource.h" |
32 #include "core/svg/SVGPathStringBuilder.h" | 32 #include "core/svg/SVGPathStringBuilder.h" |
33 #include "core/svg/SVGPathStringSource.h" | 33 #include "core/svg/SVGPathStringSource.h" |
34 #include "core/svg/SVGPathTraversalStateBuilder.h" | 34 #include "core/svg/SVGPathTraversalStateBuilder.h" |
35 #include "platform/graphics/PathTraversalState.h" | 35 #include "platform/graphics/PathTraversalState.h" |
36 | 36 |
37 namespace blink { | 37 namespace blink { |
38 | 38 |
39 static SVGPathBuilder* globalSVGPathBuilder(Path& result) | |
40 { | |
41 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathBuilder>, pathBuilder, (ad optPtrWillBeNoop(new SVGPathBuilder()))); | |
42 pathBuilder->setCurrentPath(&result); | |
43 return pathBuilder.get(); | |
44 } | |
45 | |
46 static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStrea m* result) | |
47 { | |
48 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathByteStreamBuilder>, pathBu ilder, (adoptPtrWillBeNoop(new SVGPathByteStreamBuilder()))); | |
49 pathBuilder->setCurrentByteStream(result); | |
50 return pathBuilder.get(); | |
51 } | |
52 | |
53 static SVGPathStringBuilder* globalSVGPathStringBuilder() | |
54 { | |
55 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathStringBuilder>, pathBuilde r, (adoptPtrWillBeNoop(new SVGPathStringBuilder()))); | |
56 return pathBuilder.get(); | |
57 } | |
58 | |
59 static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTrav ersalState& traversalState, float length) | |
60 { | |
61 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathTraversalStateBuilder>, pa thBuilder, (adoptPtrWillBeNoop(new SVGPathTraversalStateBuilder()))); | |
62 pathBuilder->setCurrentTraversalState(&traversalState); | |
63 pathBuilder->setDesiredLength(length); | |
64 return pathBuilder.get(); | |
65 } | |
66 | |
67 static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer * consumer) | |
68 { | |
69 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathParser>, pathParser, (adop tPtrWillBeNoop(new SVGPathParser()))); | |
70 pathParser->setCurrentSource(source); | |
71 pathParser->setCurrentConsumer(consumer); | |
72 return pathParser.get(); | |
73 } | |
74 | |
75 static SVGPathBlender* globalSVGPathBlender() | |
76 { | |
77 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathBlender>, pathBlender, (ad optPtrWillBeNoop(new SVGPathBlender()))); | |
78 return pathBlender.get(); | |
79 } | |
80 | |
81 bool buildPathFromString(const String& d, Path& result) | 39 bool buildPathFromString(const String& d, Path& result) |
82 { | 40 { |
83 if (d.isEmpty()) | 41 if (d.isEmpty()) |
84 return true; | 42 return true; |
85 | 43 |
86 SVGPathBuilder* builder = globalSVGPathBuilder(result); | 44 SVGPathBuilder builder(result); |
45 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create (d); | |
f(malita)
2014/11/24 16:56:57
We don't have to address it in this CL, but is the
| |
46 SVGPathParser parser(source.get(), &builder); | |
47 return parser.parsePathDataFromSource(NormalizedParsing); | |
48 } | |
87 | 49 |
88 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create (d); | 50 bool buildPathFromByteStream(const SVGPathByteStream& stream, Path& result) |
89 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 51 { |
90 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 52 if (stream.isEmpty()) |
91 parser->cleanup(); | 53 return true; |
54 | |
55 SVGPathBuilder builder(result); | |
56 SVGPathByteStreamSource source(stream); | |
57 SVGPathParser parser(&source, &builder); | |
58 return parser.parsePathDataFromSource(NormalizedParsing); | |
59 } | |
60 | |
61 bool buildStringFromByteStream(const SVGPathByteStream& stream, String& result, PathParsingMode parsingMode) | |
62 { | |
63 if (stream.isEmpty()) | |
64 return true; | |
65 | |
66 SVGPathStringBuilder builder; | |
67 SVGPathByteStreamSource source(stream); | |
68 SVGPathParser parser(&source, &builder); | |
69 bool ok = parser.parsePathDataFromSource(parsingMode); | |
70 result = builder.result(); | |
92 return ok; | 71 return ok; |
93 } | 72 } |
94 | 73 |
95 bool buildPathFromByteStream(const SVGPathByteStream* stream, Path& result) | 74 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream& result , PathParsingMode parsingMode) |
96 { | 75 { |
97 ASSERT(stream); | 76 result.clear(); |
98 if (stream->isEmpty()) | |
99 return true; | |
100 | |
101 SVGPathBuilder* builder = globalSVGPathBuilder(result); | |
102 | |
103 SVGPathByteStreamSource source(stream); | |
104 SVGPathParser* parser = globalSVGPathParser(&source, builder); | |
105 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | |
106 parser->cleanup(); | |
107 return ok; | |
108 } | |
109 | |
110 bool buildStringFromByteStream(const SVGPathByteStream* stream, String& result, PathParsingMode parsingMode) | |
111 { | |
112 ASSERT(stream); | |
113 if (stream->isEmpty()) | |
114 return true; | |
115 | |
116 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); | |
117 | |
118 SVGPathByteStreamSource source(stream); | |
119 SVGPathParser* parser = globalSVGPathParser(&source, builder); | |
120 bool ok = parser->parsePathDataFromSource(parsingMode); | |
121 result = builder->result(); | |
122 parser->cleanup(); | |
123 return ok; | |
124 } | |
125 | |
126 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream* result , PathParsingMode parsingMode) | |
127 { | |
128 ASSERT(result); | |
129 result->clear(); | |
130 if (d.isEmpty()) | 77 if (d.isEmpty()) |
131 return true; | 78 return true; |
132 | 79 |
133 // The string length is typically a minor overestimate of eventual byte stre am size, so it avoids us a lot of reallocs. | 80 // The string length is typically a minor overestimate of eventual byte stre am size, so it avoids us a lot of reallocs. |
134 result->reserveInitialCapacity(d.length()); | 81 result.reserveInitialCapacity(d.length()); |
135 | 82 |
136 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); | 83 SVGPathByteStreamBuilder builder(result); |
137 | |
138 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create (d); | 84 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create (d); |
f(malita)
2014/11/24 16:56:57
Same follow-up idea: local ownptr -> stack object?
| |
139 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 85 SVGPathParser parser(source.get(), &builder); |
140 bool ok = parser->parsePathDataFromSource(parsingMode); | 86 bool ok = parser.parsePathDataFromSource(parsingMode); |
141 parser->cleanup(); | 87 result.shrinkToFit(); |
142 | |
143 result->shrinkToFit(); | |
144 | |
145 return ok; | 88 return ok; |
146 } | 89 } |
147 | 90 |
148 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, const SVGPathByteStre am* byStream, unsigned repeatCount) | 91 bool addToSVGPathByteStream(SVGPathByteStream& fromStream, const SVGPathByteStre am& byStream, unsigned repeatCount) |
149 { | 92 { |
150 ASSERT(fromStream); | 93 if (fromStream.isEmpty() || byStream.isEmpty()) |
151 ASSERT(byStream); | |
152 if (fromStream->isEmpty() || byStream->isEmpty()) | |
153 return true; | 94 return true; |
154 | 95 |
155 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStrea m); | 96 OwnPtr<SVGPathByteStream> fromStreamCopy = fromStream.copy(); |
97 fromStream.clear(); | |
156 | 98 |
157 OwnPtr<SVGPathByteStream> fromStreamCopy = fromStream->copy(); | 99 SVGPathByteStreamBuilder builder(fromStream); |
158 fromStream->clear(); | 100 SVGPathByteStreamSource fromSource(*fromStreamCopy); |
101 SVGPathByteStreamSource bySource(byStream); | |
102 SVGPathBlender blender(&fromSource, &bySource, &builder); | |
103 return blender.addAnimatedPath(repeatCount); | |
104 } | |
159 | 105 |
160 SVGPathByteStreamSource fromSource(fromStreamCopy.get()); | 106 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& stream, float length, unsigned& pathSeg) |
f(malita)
2014/11/24 16:56:57
Moar followup ideas: we don't even use the returne
| |
161 SVGPathByteStreamSource bySource(byStream); | 107 { |
162 SVGPathBlender* blender = globalSVGPathBlender(); | 108 if (stream.isEmpty()) |
163 bool ok = blender->addAnimatedPath(&fromSource, &bySource, builder, repeatCo unt); | 109 return false; |
164 blender->cleanup(); | 110 |
111 PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLeng th); | |
112 SVGPathTraversalStateBuilder builder(traversalState, length); | |
113 SVGPathByteStreamSource source(stream); | |
114 SVGPathParser parser(&source, &builder); | |
115 bool ok = parser.parsePathDataFromSource(NormalizedParsing); | |
116 pathSeg = builder.pathSegmentIndex(); | |
165 return ok; | 117 return ok; |
166 } | 118 } |
167 | 119 |
168 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream* stream, float length, unsigned& pathSeg) | 120 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float& t otalLength) |
f(malita)
2014/11/24 16:56:57
Ditto.
| |
169 { | 121 { |
170 ASSERT(stream); | 122 if (stream.isEmpty()) |
171 if (stream->isEmpty()) | |
172 return false; | 123 return false; |
173 | 124 |
174 PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLeng th); | 125 PathTraversalState traversalState(PathTraversalState::TraversalTotalLength); |
175 SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(t raversalState, length); | 126 SVGPathTraversalStateBuilder builder(traversalState); |
176 | |
177 SVGPathByteStreamSource source(stream); | 127 SVGPathByteStreamSource source(stream); |
178 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 128 SVGPathParser parser(&source, &builder); |
179 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 129 bool ok = parser.parsePathDataFromSource(NormalizedParsing); |
180 pathSeg = builder->pathSegmentIndex(); | 130 totalLength = builder.totalLength(); |
181 parser->cleanup(); | |
182 return ok; | 131 return ok; |
183 } | 132 } |
184 | 133 |
185 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream* stream, float& t otalLength) | 134 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length, FloatPoint& point) |
f(malita)
2014/11/24 16:56:57
Ditto.
| |
186 { | 135 { |
187 ASSERT(stream); | 136 if (stream.isEmpty()) |
188 if (stream->isEmpty()) | |
189 return false; | 137 return false; |
190 | 138 |
191 PathTraversalState traversalState(PathTraversalState::TraversalTotalLength); | 139 PathTraversalState traversalState(PathTraversalState::TraversalPointAtLength ); |
192 SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(t raversalState, 0); | 140 SVGPathTraversalStateBuilder builder(traversalState, length); |
193 | |
194 SVGPathByteStreamSource source(stream); | 141 SVGPathByteStreamSource source(stream); |
195 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 142 SVGPathParser parser(&source, &builder); |
196 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 143 bool ok = parser.parsePathDataFromSource(NormalizedParsing); |
197 totalLength = builder->totalLength(); | 144 point = builder.currentPoint(); |
198 parser->cleanup(); | |
199 return ok; | 145 return ok; |
200 } | 146 } |
201 | 147 |
202 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream* stream, float length, FloatPoint& point) | |
203 { | |
204 ASSERT(stream); | |
205 if (stream->isEmpty()) | |
206 return false; | |
207 | |
208 PathTraversalState traversalState(PathTraversalState::TraversalPointAtLength ); | |
209 SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(t raversalState, length); | |
210 | |
211 SVGPathByteStreamSource source(stream); | |
212 SVGPathParser* parser = globalSVGPathParser(&source, builder); | |
213 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | |
214 point = builder->currentPoint(); | |
215 parser->cleanup(); | |
216 return ok; | |
217 } | |
218 | |
219 } | 148 } |
OLD | NEW |