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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 } | 352 } |
353 | 353 |
354 this->parseWSToken(); | 354 this->parseWSToken(); |
355 if (!parsed || !this->parseEOSToken()) { | 355 if (!parsed || !this->parseEOSToken()) { |
356 return false; | 356 return false; |
357 } | 357 } |
358 | 358 |
359 *t = SkSVGTransformType(matrix); | 359 *t = SkSVGTransformType(matrix); |
360 return true; | 360 return true; |
361 } | 361 } |
| 362 |
| 363 // https://www.w3.org/TR/SVG/painting.html#SpecifyingPaint |
| 364 bool SkSVGAttributeParser::parsePaint(SkSVGPaint* paint) { |
| 365 SkSVGColorType c; |
| 366 bool parsedValue = false; |
| 367 if (this->parseColor(&c)) { |
| 368 *paint = SkSVGPaint(c); |
| 369 parsedValue = true; |
| 370 } else if (this->parseExpectedStringToken("none")) { |
| 371 *paint = SkSVGPaint(SkSVGPaint::Type::kNone); |
| 372 parsedValue = true; |
| 373 } else if (this->parseExpectedStringToken("currentColor")) { |
| 374 *paint = SkSVGPaint(SkSVGPaint::Type::kCurrentColor); |
| 375 parsedValue = true; |
| 376 } else if (this->parseExpectedStringToken("inherit")) { |
| 377 *paint = SkSVGPaint(SkSVGPaint::Type::kInherit); |
| 378 parsedValue = true; |
| 379 } |
| 380 return parsedValue && this->parseEOSToken(); |
| 381 } |
| 382 |
| 383 // https://www.w3.org/TR/SVG/painting.html#StrokeLinecapProperty |
| 384 bool SkSVGAttributeParser::parseLineCap(SkSVGLineCap* cap) { |
| 385 static const struct { |
| 386 SkSVGLineCap::Type fType; |
| 387 const char* fName; |
| 388 } gCapInfo[] = { |
| 389 { SkSVGLineCap::Type::kButt , "butt" }, |
| 390 { SkSVGLineCap::Type::kRound , "round" }, |
| 391 { SkSVGLineCap::Type::kSquare , "square" }, |
| 392 { SkSVGLineCap::Type::kInherit, "inherit" }, |
| 393 }; |
| 394 |
| 395 bool parsedValue = false; |
| 396 for (size_t i = 0; i < SK_ARRAY_COUNT(gCapInfo); ++i) { |
| 397 if (this->parseExpectedStringToken(gCapInfo[i].fName)) { |
| 398 *cap = SkSVGLineCap(gCapInfo[i].fType); |
| 399 parsedValue = true; |
| 400 break; |
| 401 } |
| 402 } |
| 403 |
| 404 return parsedValue && this->parseEOSToken(); |
| 405 } |
| 406 |
| 407 // https://www.w3.org/TR/SVG/painting.html#StrokeLinejoinProperty |
| 408 bool SkSVGAttributeParser::parseLineJoin(SkSVGLineJoin* join) { |
| 409 static const struct { |
| 410 SkSVGLineJoin::Type fType; |
| 411 const char* fName; |
| 412 } gJoinInfo[] = { |
| 413 { SkSVGLineJoin::Type::kMiter , "miter" }, |
| 414 { SkSVGLineJoin::Type::kRound , "round" }, |
| 415 { SkSVGLineJoin::Type::kBevel , "bevel" }, |
| 416 { SkSVGLineJoin::Type::kInherit, "inherit" }, |
| 417 }; |
| 418 |
| 419 bool parsedValue = false; |
| 420 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoinInfo); ++i) { |
| 421 if (this->parseExpectedStringToken(gJoinInfo[i].fName)) { |
| 422 *join = SkSVGLineJoin(gJoinInfo[i].fType); |
| 423 parsedValue = true; |
| 424 break; |
| 425 } |
| 426 } |
| 427 |
| 428 return parsedValue && this->parseEOSToken(); |
| 429 } |
OLD | NEW |