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 |
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 | 21 |
22 #include "core/svg/SVGPathUtilities.h" | 22 #include "core/svg/SVGPathUtilities.h" |
23 | 23 |
24 #include "core/svg/SVGPathBlender.h" | 24 #include "core/svg/SVGPathBlender.h" |
25 #include "core/svg/SVGPathBuilder.h" | 25 #include "core/svg/SVGPathBuilder.h" |
26 #include "core/svg/SVGPathByteStreamBuilder.h" | 26 #include "core/svg/SVGPathByteStreamBuilder.h" |
27 #include "core/svg/SVGPathByteStreamSource.h" | 27 #include "core/svg/SVGPathByteStreamSource.h" |
| 28 #include "core/svg/SVGPathElement.h" |
28 #include "core/svg/SVGPathParser.h" | 29 #include "core/svg/SVGPathParser.h" |
29 #include "core/svg/SVGPathSegListBuilder.h" | 30 #include "core/svg/SVGPathSegListBuilder.h" |
30 #include "core/svg/SVGPathSegListSource.h" | 31 #include "core/svg/SVGPathSegListSource.h" |
31 #include "core/svg/SVGPathStringBuilder.h" | 32 #include "core/svg/SVGPathStringBuilder.h" |
32 #include "core/svg/SVGPathStringSource.h" | 33 #include "core/svg/SVGPathStringSource.h" |
33 #include "core/svg/SVGPathTraversalStateBuilder.h" | 34 #include "core/svg/SVGPathTraversalStateBuilder.h" |
34 #include "platform/graphics/PathTraversalState.h" | 35 #include "platform/graphics/PathTraversalState.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 static SVGPathBuilder* globalSVGPathBuilder(Path& result) | 39 static SVGPathBuilder* globalSVGPathBuilder(Path& result) |
39 { | 40 { |
40 static SVGPathBuilder* s_builder = 0; | 41 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathBuilder>, pathBuilder, (ad
optPtrWillBeNoop(new SVGPathBuilder()))); |
41 if (!s_builder) | 42 pathBuilder->setCurrentPath(&result); |
42 s_builder = new SVGPathBuilder; | 43 return pathBuilder.get(); |
43 | |
44 s_builder->setCurrentPath(&result); | |
45 return s_builder; | |
46 } | 44 } |
47 | 45 |
48 static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStrea
m* result) | 46 static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStrea
m* result) |
49 { | 47 { |
50 static SVGPathByteStreamBuilder* s_builder = 0; | 48 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathByteStreamBuilder>, pathBu
ilder, (adoptPtrWillBeNoop(new SVGPathByteStreamBuilder()))); |
51 if (!s_builder) | 49 pathBuilder->setCurrentByteStream(result); |
52 s_builder = new SVGPathByteStreamBuilder; | 50 return pathBuilder.get(); |
53 | |
54 s_builder->setCurrentByteStream(result); | |
55 return s_builder; | |
56 } | 51 } |
57 | 52 |
58 static SVGPathStringBuilder* globalSVGPathStringBuilder() | 53 static SVGPathStringBuilder* globalSVGPathStringBuilder() |
59 { | 54 { |
60 static SVGPathStringBuilder* s_builder = 0; | 55 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathStringBuilder>, pathBuilde
r, (adoptPtrWillBeNoop(new SVGPathStringBuilder()))); |
61 if (!s_builder) | 56 return pathBuilder.get(); |
62 s_builder = new SVGPathStringBuilder; | |
63 | |
64 return s_builder; | |
65 } | 57 } |
66 | 58 |
67 static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTrav
ersalState& traversalState, float length) | 59 static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTrav
ersalState& traversalState, float length) |
68 { | 60 { |
69 static SVGPathTraversalStateBuilder* s_builder = 0; | 61 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathTraversalStateBuilder>, pa
thBuilder, (adoptPtrWillBeNoop(new SVGPathTraversalStateBuilder()))); |
70 if (!s_builder) | 62 pathBuilder->setCurrentTraversalState(&traversalState); |
71 s_builder = new SVGPathTraversalStateBuilder; | 63 pathBuilder->setDesiredLength(length); |
72 | 64 return pathBuilder.get(); |
73 s_builder->setCurrentTraversalState(&traversalState); | |
74 s_builder->setDesiredLength(length); | |
75 return s_builder; | |
76 } | 65 } |
77 | 66 |
78 static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer
* consumer) | 67 static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer
* consumer) |
79 { | 68 { |
80 static SVGPathParser* s_parser = 0; | 69 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathParser>, pathParser, (adop
tPtrWillBeNoop(new SVGPathParser()))); |
81 if (!s_parser) | 70 pathParser->setCurrentSource(source); |
82 s_parser = new SVGPathParser; | 71 pathParser->setCurrentConsumer(consumer); |
83 | 72 return pathParser.get(); |
84 s_parser->setCurrentSource(source); | |
85 s_parser->setCurrentConsumer(consumer); | |
86 return s_parser; | |
87 } | 73 } |
88 | 74 |
89 static SVGPathBlender* globalSVGPathBlender() | 75 static SVGPathBlender* globalSVGPathBlender() |
90 { | 76 { |
91 static SVGPathBlender* s_blender = 0; | 77 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<SVGPathBlender>, pathBlender, (ad
optPtrWillBeNoop(new SVGPathBlender()))); |
92 if (!s_blender) | 78 return pathBlender.get(); |
93 s_blender = new SVGPathBlender; | |
94 | |
95 return s_blender; | |
96 } | 79 } |
97 | 80 |
98 bool buildPathFromString(const String& d, Path& result) | 81 bool buildPathFromString(const String& d, Path& result) |
99 { | 82 { |
100 if (d.isEmpty()) | 83 if (d.isEmpty()) |
101 return true; | 84 return true; |
102 | 85 |
103 SVGPathBuilder* builder = globalSVGPathBuilder(result); | 86 SVGPathBuilder* builder = globalSVGPathBuilder(result); |
104 | 87 |
105 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); | 88 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create
(d); |
106 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 89 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); |
107 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 90 bool ok = parser->parsePathDataFromSource(NormalizedParsing); |
108 parser->cleanup(); | 91 parser->cleanup(); |
109 return ok; | 92 return ok; |
110 } | 93 } |
111 | 94 |
112 bool buildPathFromByteStream(const SVGPathByteStream* stream, Path& result) | 95 bool buildPathFromByteStream(const SVGPathByteStream* stream, Path& result) |
113 { | 96 { |
114 ASSERT(stream); | 97 ASSERT(stream); |
115 if (stream->isEmpty()) | 98 if (stream->isEmpty()) |
(...skipping 29 matching lines...) Expand all Loading... |
145 ASSERT(result); | 128 ASSERT(result); |
146 result->clear(); | 129 result->clear(); |
147 if (d.isEmpty()) | 130 if (d.isEmpty()) |
148 return true; | 131 return true; |
149 | 132 |
150 // The string length is typically a minor overestimate of eventual byte stre
am size, so it avoids us a lot of reallocs. | 133 // 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()); | 134 result->reserveInitialCapacity(d.length()); |
152 | 135 |
153 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); | 136 SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(result); |
154 | 137 |
155 OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d); | 138 OwnPtrWillBeRawPtr<SVGPathStringSource> source = SVGPathStringSource::create
(d); |
156 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); | 139 SVGPathParser* parser = globalSVGPathParser(source.get(), builder); |
157 bool ok = parser->parsePathDataFromSource(parsingMode); | 140 bool ok = parser->parsePathDataFromSource(parsingMode); |
158 parser->cleanup(); | 141 parser->cleanup(); |
159 | 142 |
160 result->shrinkToFit(); | 143 result->shrinkToFit(); |
161 | 144 |
162 return ok; | 145 return ok; |
163 } | 146 } |
164 | 147 |
165 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, const SVGPathByteStre
am* byStream, unsigned repeatCount) | 148 bool addToSVGPathByteStream(SVGPathByteStream* fromStream, const SVGPathByteStre
am* byStream, unsigned repeatCount) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 210 |
228 SVGPathByteStreamSource source(stream); | 211 SVGPathByteStreamSource source(stream); |
229 SVGPathParser* parser = globalSVGPathParser(&source, builder); | 212 SVGPathParser* parser = globalSVGPathParser(&source, builder); |
230 bool ok = parser->parsePathDataFromSource(NormalizedParsing); | 213 bool ok = parser->parsePathDataFromSource(NormalizedParsing); |
231 point = builder->currentPoint(); | 214 point = builder->currentPoint(); |
232 parser->cleanup(); | 215 parser->cleanup(); |
233 return ok; | 216 return ok; |
234 } | 217 } |
235 | 218 |
236 } | 219 } |
OLD | NEW |