OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkParse.h" | 8 #include "SkParse.h" |
9 #include "SkSVGAttributeParser.h" | 9 #include "SkSVGAttributeParser.h" |
10 #include "SkSVGTypes.h" | 10 #include "SkSVGTypes.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 break; | 142 break; |
143 default: | 143 default: |
144 return false; | 144 return false; |
145 } | 145 } |
146 | 146 |
147 *c = v | 0xff000000; | 147 *c = v | 0xff000000; |
148 return true; | 148 return true; |
149 } | 149 } |
150 | 150 |
151 // https://www.w3.org/TR/SVG/types.html#DataTypeColor | 151 // https://www.w3.org/TR/SVG/types.html#DataTypeColor |
152 bool SkSVGAttributeParser::parseColor(SkSVGColor* color) { | 152 bool SkSVGAttributeParser::parseColor(SkSVGColorType* color) { |
153 SkColor c; | 153 SkColor c; |
154 | 154 |
155 // TODO: rgb(...) | 155 // TODO: rgb(...) |
156 if (this->parseHexColorToken(&c) || this->parseNamedColorToken(&c)) { | 156 if (this->parseHexColorToken(&c) || this->parseNamedColorToken(&c)) { |
157 *color = SkSVGColor(c); | 157 *color = SkSVGColorType(c); |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 return false; | 161 return false; |
162 } | 162 } |
163 | 163 |
164 // https://www.w3.org/TR/SVG/types.html#DataTypeNumber | 164 // https://www.w3.org/TR/SVG/types.html#DataTypeNumber |
165 bool SkSVGAttributeParser::parseNumber(SkSVGNumber* number) { | 165 bool SkSVGAttributeParser::parseNumber(SkSVGNumberType* number) { |
166 // consume WS | 166 // consume WS |
167 this->parseWSToken(); | 167 this->parseWSToken(); |
168 | 168 |
169 SkScalar s; | 169 SkScalar s; |
170 if (this->parseScalarToken(&s)) { | 170 if (this->parseScalarToken(&s)) { |
171 *number = SkSVGNumber(s); | 171 *number = SkSVGNumberType(s); |
172 // consume trailing separators | 172 // consume trailing separators |
173 this->parseSepToken(); | 173 this->parseSepToken(); |
174 return true; | 174 return true; |
175 } | 175 } |
176 | 176 |
177 return false; | 177 return false; |
178 } | 178 } |
179 | 179 |
180 // https://www.w3.org/TR/SVG/types.html#DataTypeLength | 180 // https://www.w3.org/TR/SVG/types.html#DataTypeLength |
181 bool SkSVGAttributeParser::parseLength(SkSVGLength* length) { | 181 bool SkSVGAttributeParser::parseLength(SkSVGLength* length) { |
182 SkScalar s; | 182 SkScalar s; |
183 SkSVGLength::Unit u = SkSVGLength::Unit::kNumber; | 183 SkSVGLength::Unit u = SkSVGLength::Unit::kNumber; |
184 | 184 |
185 if (this->parseScalarToken(&s) && | 185 if (this->parseScalarToken(&s) && |
186 (this->parseLengthUnitToken(&u) || this->parseSepToken() || this->parseE
OSToken())) { | 186 (this->parseLengthUnitToken(&u) || this->parseSepToken() || this->parseE
OSToken())) { |
187 *length = SkSVGLength(s, u); | 187 *length = SkSVGLength(s, u); |
188 // consume trailing separators | 188 // consume trailing separators |
189 this->parseSepToken(); | 189 this->parseSepToken(); |
190 return true; | 190 return true; |
191 } | 191 } |
192 | 192 |
193 return false; | 193 return false; |
194 } | 194 } |
| 195 |
| 196 // https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute |
| 197 bool SkSVGAttributeParser::parseViewBox(SkSVGViewBoxType* vb) { |
| 198 SkScalar x, y, w, h; |
| 199 this->parseWSToken(); |
| 200 |
| 201 bool parsedValue = false; |
| 202 if (this->parseScalarToken(&x) && this->parseSepToken() && |
| 203 this->parseScalarToken(&y) && this->parseSepToken() && |
| 204 this->parseScalarToken(&w) && this->parseSepToken() && |
| 205 this->parseScalarToken(&h)) { |
| 206 |
| 207 *vb = SkSVGViewBoxType(SkRect::MakeXYWH(x, y, w, h)); |
| 208 parsedValue = true; |
| 209 // consume trailing whitespace |
| 210 this->parseWSToken(); |
| 211 } |
| 212 return parsedValue && this->parseEOSToken(); |
| 213 } |
OLD | NEW |