Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: third_party/WebKit/Source/core/svg/SVGPathUtilities.cpp

Issue 1471943003: Introduce SVGPathQuery to hold SVG path query methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Const-qualify. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "core/svg/SVGPathUtilities.h" 21 #include "core/svg/SVGPathUtilities.h"
22 22
23 #include "core/svg/SVGPathBuilder.h" 23 #include "core/svg/SVGPathBuilder.h"
24 #include "core/svg/SVGPathByteStreamBuilder.h" 24 #include "core/svg/SVGPathByteStreamBuilder.h"
25 #include "core/svg/SVGPathByteStreamSource.h" 25 #include "core/svg/SVGPathByteStreamSource.h"
26 #include "core/svg/SVGPathParser.h" 26 #include "core/svg/SVGPathParser.h"
27 #include "core/svg/SVGPathStringBuilder.h" 27 #include "core/svg/SVGPathStringBuilder.h"
28 #include "core/svg/SVGPathStringSource.h" 28 #include "core/svg/SVGPathStringSource.h"
29 #include "core/svg/SVGPathTraversalStateBuilder.h"
30 #include "platform/graphics/PathTraversalState.h"
31 29
32 namespace blink { 30 namespace blink {
33 31
34 bool buildPathFromString(const String& d, Path& result) 32 bool buildPathFromString(const String& d, Path& result)
35 { 33 {
36 if (d.isEmpty()) 34 if (d.isEmpty())
37 return true; 35 return true;
38 36
39 SVGPathBuilder builder(result); 37 SVGPathBuilder builder(result);
40 SVGPathStringSource source(d); 38 SVGPathStringSource source(d);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 result.reserveInitialCapacity(d.length()); 74 result.reserveInitialCapacity(d.length());
77 75
78 SVGPathByteStreamBuilder builder(result); 76 SVGPathByteStreamBuilder builder(result);
79 SVGPathStringSource source(d); 77 SVGPathStringSource source(d);
80 SVGPathParser parser(&source, &builder); 78 SVGPathParser parser(&source, &builder);
81 bool ok = parser.parsePathDataFromSource(parsingMode); 79 bool ok = parser.parsePathDataFromSource(parsingMode);
82 result.shrinkToFit(); 80 result.shrinkToFit();
83 return ok; 81 return ok;
84 } 82 }
85 83
86 unsigned getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& str eam, float length)
87 {
88 if (stream.isEmpty())
89 return 0;
90
91 SVGPathTraversalStateBuilder builder(PathTraversalState::TraversalSegmentAtL ength, length);
92 SVGPathByteStreamSource source(stream);
93 SVGPathParser parser(&source, &builder);
94 parser.parsePathDataFromSource(NormalizedParsing);
95 return builder.pathSegmentIndex();
96 } 84 }
97
98 float getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream)
99 {
100 if (stream.isEmpty())
101 return 0;
102
103 SVGPathTraversalStateBuilder builder(PathTraversalState::TraversalTotalLengt h);
104 SVGPathByteStreamSource source(stream);
105 SVGPathParser parser(&source, &builder);
106 parser.parsePathDataFromSource(NormalizedParsing);
107 return builder.totalLength();
108 }
109
110 FloatPoint getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length)
111 {
112 if (stream.isEmpty())
113 return FloatPoint();
114
115 SVGPathTraversalStateBuilder builder(PathTraversalState::TraversalPointAtLen gth, length);
116 SVGPathByteStreamSource source(stream);
117 SVGPathParser parser(&source, &builder);
118 parser.parsePathDataFromSource(NormalizedParsing);
119 return builder.currentPoint();
120 }
121
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698