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

Side by Side Diff: src/core/SkPath.cpp

Issue 151353006: Adding new 'extend' mode to SkPath::addPath (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added test and fix for empty path case Created 6 years, 10 months 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
« no previous file with comments | « include/core/SkPath.h ('k') | tests/PathTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBuffer.h" 10 #include "SkBuffer.h"
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 this->incReserve(count); 1436 this->incReserve(count);
1437 // [xx,yy] == pts[0] 1437 // [xx,yy] == pts[0]
1438 this->lineTo(xx, yy); 1438 this->lineTo(xx, yy);
1439 for (int i = 1; i < count; i += 2) { 1439 for (int i = 1; i < count; i += 2) {
1440 this->quadTo(pts[i], pts[i+1]); 1440 this->quadTo(pts[i], pts[i+1]);
1441 } 1441 }
1442 } 1442 }
1443 1443
1444 /////////////////////////////////////////////////////////////////////////////// 1444 ///////////////////////////////////////////////////////////////////////////////
1445 1445
1446 void SkPath::addPath(const SkPath& path, SkScalar dx, SkScalar dy) { 1446 void SkPath::addPath(const SkPath& path, SkScalar dx, SkScalar dy, AddPathMode m ode) {
1447 SkMatrix matrix; 1447 SkMatrix matrix;
1448 1448
1449 matrix.setTranslate(dx, dy); 1449 matrix.setTranslate(dx, dy);
1450 this->addPath(path, matrix); 1450 this->addPath(path, matrix, mode);
1451 } 1451 }
1452 1452
1453 void SkPath::addPath(const SkPath& path, const SkMatrix& matrix) { 1453 void SkPath::addPath(const SkPath& path, const SkMatrix& matrix, AddPathMode mod e) {
1454 SkPathRef::Editor(&fPathRef, path.countVerbs(), path.countPoints()); 1454 SkPathRef::Editor(&fPathRef, path.countVerbs(), path.countPoints());
1455 1455
1456 RawIter iter(path); 1456 RawIter iter(path);
1457 SkPoint pts[4]; 1457 SkPoint pts[4];
1458 Verb verb; 1458 Verb verb;
1459 1459
1460 SkMatrix::MapPtsProc proc = matrix.getMapPtsProc(); 1460 SkMatrix::MapPtsProc proc = matrix.getMapPtsProc();
1461 1461 bool firstVerb = true;
1462 while ((verb = iter.next(pts)) != kDone_Verb) { 1462 while ((verb = iter.next(pts)) != kDone_Verb) {
1463 switch (verb) { 1463 switch (verb) {
1464 case kMove_Verb: 1464 case kMove_Verb:
1465 proc(matrix, &pts[0], &pts[0], 1); 1465 proc(matrix, &pts[0], &pts[0], 1);
1466 this->moveTo(pts[0]); 1466 if (firstVerb && mode == kExtend_AddPathMode && !isEmpty()) {
1467 injectMoveToIfNeeded(); // In case last contour is closed
1468 this->lineTo(pts[0]);
1469 } else {
1470 this->moveTo(pts[0]);
1471 }
1467 break; 1472 break;
1468 case kLine_Verb: 1473 case kLine_Verb:
1469 proc(matrix, &pts[1], &pts[1], 1); 1474 proc(matrix, &pts[1], &pts[1], 1);
1470 this->lineTo(pts[1]); 1475 this->lineTo(pts[1]);
1471 break; 1476 break;
1472 case kQuad_Verb: 1477 case kQuad_Verb:
1473 proc(matrix, &pts[1], &pts[1], 2); 1478 proc(matrix, &pts[1], &pts[1], 2);
1474 this->quadTo(pts[1], pts[2]); 1479 this->quadTo(pts[1], pts[2]);
1475 break; 1480 break;
1476 case kConic_Verb: 1481 case kConic_Verb:
1477 proc(matrix, &pts[1], &pts[1], 2); 1482 proc(matrix, &pts[1], &pts[1], 2);
1478 this->conicTo(pts[1], pts[2], iter.conicWeight()); 1483 this->conicTo(pts[1], pts[2], iter.conicWeight());
1479 break; 1484 break;
1480 case kCubic_Verb: 1485 case kCubic_Verb:
1481 proc(matrix, &pts[1], &pts[1], 3); 1486 proc(matrix, &pts[1], &pts[1], 3);
1482 this->cubicTo(pts[1], pts[2], pts[3]); 1487 this->cubicTo(pts[1], pts[2], pts[3]);
1483 break; 1488 break;
1484 case kClose_Verb: 1489 case kClose_Verb:
1485 this->close(); 1490 this->close();
1486 break; 1491 break;
1487 default: 1492 default:
1488 SkDEBUGFAIL("unknown verb"); 1493 SkDEBUGFAIL("unknown verb");
1489 } 1494 }
1495 firstVerb = false;
1490 } 1496 }
1491 } 1497 }
1492 1498
1493 /////////////////////////////////////////////////////////////////////////////// 1499 ///////////////////////////////////////////////////////////////////////////////
1494 1500
1495 static int pts_in_verb(unsigned verb) { 1501 static int pts_in_verb(unsigned verb) {
1496 static const uint8_t gPtsInVerb[] = { 1502 static const uint8_t gPtsInVerb[] = {
1497 1, // kMove 1503 1, // kMove
1498 1, // kLine 1504 1, // kLine
1499 2, // kQuad 1505 2, // kQuad
(...skipping 1381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 switch (this->getFillType()) { 2887 switch (this->getFillType()) {
2882 case SkPath::kEvenOdd_FillType: 2888 case SkPath::kEvenOdd_FillType:
2883 case SkPath::kInverseEvenOdd_FillType: 2889 case SkPath::kInverseEvenOdd_FillType:
2884 w &= 1; 2890 w &= 1;
2885 break; 2891 break;
2886 default: 2892 default:
2887 break; 2893 break;
2888 } 2894 }
2889 return SkToBool(w); 2895 return SkToBool(w);
2890 } 2896 }
OLDNEW
« no previous file with comments | « include/core/SkPath.h ('k') | tests/PathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698