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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 static SVGPathBlender* s_blender = 0; | 91 static SVGPathBlender* s_blender = 0; |
92 if (!s_blender) | 92 if (!s_blender) |
93 s_blender = new SVGPathBlender; | 93 s_blender = new SVGPathBlender; |
94 | 94 |
95 return s_blender; | 95 return s_blender; |
96 } | 96 } |
97 | 97 |
98 bool buildPathFromString(const String& d, Path& result) | 98 bool buildPathFromString(const String& d, Path& result) |
99 { | 99 { |
100 if (d.isEmpty()) | 100 if (d.isEmpty()) |
101 return false; | 101 return true; |
102 | 102 |
103 SVGPathBuilder* builder = globalSVGPathBuilder(result); | 103 SVGPathBuilder* builder = globalSVGPathBuilder(result); |
104 | 104 |
105 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); | 105 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); |
106 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 106 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); |
107 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 107 bool ok = parser->parsePathDataFromSource(NormalizedParsing); |
108 parser->cleanup(); | 108 parser->cleanup(); |
109 return ok; | 109 return ok; |
110 } | 110 } |
111 | 111 |
112 bool buildPathFromByteStream(const SVGPathByteStream* stream, Path& result) | 112 bool buildPathFromByteStream(const SVGPathByteStream* stream, Path& result) |
113 { | 113 { |
114 ASSERT(stream); | 114 ASSERT(stream); |
115 if (stream->isEmpty()) | 115 if (stream->isEmpty()) |
116 return false; | 116 return true; |
117 | 117 |
118 SVGPathBuilder* builder = globalSVGPathBuilder(result); | 118 SVGPathBuilder* builder = globalSVGPathBuilder(result); |
119 | 119 |
120 SVGPathByteStreamSource source(stream); | 120 SVGPathByteStreamSource source(stream); |
121 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 121 SVGPathParser* parser = globalSVGPathParser(&source, builder); |
122 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 122 bool ok = parser->parsePathDataFromSource(NormalizedParsing); |
123 parser->cleanup(); | 123 parser->cleanup(); |
124 return ok; | 124 return ok; |
125 } | 125 } |
126 | 126 |
127 bool buildStringFromByteStream(const SVGPathByteStream* stream, String& result,
PathParsingMode parsingMode) | 127 bool buildStringFromByteStream(const SVGPathByteStream* stream, String& result,
PathParsingMode parsingMode) |
128 { | 128 { |
129 ASSERT(stream); | 129 ASSERT(stream); |
130 if (stream->isEmpty()) | 130 if (stream->isEmpty()) |
131 return false; | 131 return true; |
132 | 132 |
133 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); | 133 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); |
134 | 134 |
135 SVGPathByteStreamSource source(stream); | 135 SVGPathByteStreamSource source(stream); |
136 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 136 SVGPathParser* parser = globalSVGPathParser(&source, builder); |
137 bool ok = parser->parsePathDataFromSource(parsingMode); | 137 bool ok = parser->parsePathDataFromSource(parsingMode); |
138 result = builder->result(); | 138 result = builder->result(); |
139 parser->cleanup(); | 139 parser->cleanup(); |
140 return ok; | 140 return ok; |
141 } | 141 } |
142 | 142 |
143 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream* result
, PathParsingMode parsingMode) | 143 bool buildSVGPathByteStreamFromString(const String& d, SVGPathByteStream* result
, PathParsingMode parsingMode) |
144 { | 144 { |
145 ASSERT(result); | 145 ASSERT(result); |
146 result->clear(); | 146 result->clear(); |
147 if (d.isEmpty()) | 147 if (d.isEmpty()) |
148 return false; | 148 return true; |
149 | 149 |
150 // The string length is typically a minor overestimate of eventual byte stre
am size, so it avoids us a lot of reallocs. | 150 // The string length is typically a minor overestimate of eventual byte stre
am size, so it avoids us a lot of reallocs. |
151 result->reserveInitialCapacity(d.length()); | 151 result->reserveInitialCapacity(d.length()); |
152 | 152 |
153 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); | 153 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); |
154 | 154 |
155 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); | 155 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); |
156 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 156 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); |
157 bool ok = parser->parsePathDataFromSource(parsingMode); | 157 bool ok = parser->parsePathDataFromSource(parsingMode); |
158 parser->cleanup(); | 158 parser->cleanup(); |
159 | 159 |
160 result->shrinkToFit(); | 160 result->shrinkToFit(); |
161 | 161 |
162 return ok; | 162 return ok; |
163 } | 163 } |
164 | 164 |
165 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, const SVGPathByteStre
am* byStream, unsigned repeatCount) | 165 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, const SVGPathByteStre
am* byStream, unsigned repeatCount) |
166 { | 166 { |
167 ASSERT(fromStream); | 167 ASSERT(fromStream); |
168 ASSERT(byStream); | 168 ASSERT(byStream); |
169 if (fromStream->isEmpty() || byStream->isEmpty()) | 169 if (fromStream->isEmpty() || byStream->isEmpty()) |
170 return false; | 170 return true; |
171 | 171 |
172 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStrea
m); | 172 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(fromStrea
m); |
173 | 173 |
174 OwnPtr<SVGPathByteStream> fromStreamCopy = fromStream->copy(); | 174 OwnPtr<SVGPathByteStream> fromStreamCopy = fromStream->copy(); |
175 fromStream->clear(); | 175 fromStream->clear(); |
176 | 176 |
177 SVGPathByteStreamSource fromSource(fromStreamCopy.get()); | 177 SVGPathByteStreamSource fromSource(fromStreamCopy.get()); |
178 SVGPathByteStreamSource bySource(byStream); | 178 SVGPathByteStreamSource bySource(byStream); |
179 SVGPathBlender* blender = globalSVGPathBlender(); | 179 SVGPathBlender* blender = globalSVGPathBlender(); |
180 bool ok = blender->addAnimatedPath(&fromSource, &bySource, builder, repeatCo
unt); | 180 bool ok = blender->addAnimatedPath(&fromSource, &bySource, builder, repeatCo
unt); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 227 |
228 SVGPathByteStreamSource source(stream); | 228 SVGPathByteStreamSource source(stream); |
229 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 229 SVGPathParser* parser = globalSVGPathParser(&source, builder); |
230 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 230 bool ok = parser->parsePathDataFromSource(NormalizedParsing); |
231 point = builder->currentPoint(); | 231 point = builder->currentPoint(); |
232 parser->cleanup(); | 232 parser->cleanup(); |
233 return ok; | 233 return ok; |
234 } | 234 } |
235 | 235 |
236 } | 236 } |
OLD | NEW |