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

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

Issue 1722483003: make transformed rrect radii fit rectangle (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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/SkRRect.h ('k') | no next file » | 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 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 <cmath> 8 #include <cmath>
9 #include "SkRRect.h" 9 #include "SkRRect.h"
10 #include "SkMatrix.h" 10 #include "SkMatrix.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } else { 151 } else {
152 allCornersSquare = false; 152 allCornersSquare = false;
153 } 153 }
154 } 154 }
155 155
156 if (allCornersSquare) { 156 if (allCornersSquare) {
157 this->setRect(rect); 157 this->setRect(rect);
158 return; 158 return;
159 } 159 }
160 160
161 this->scaleRadii();
162 }
163
164 void SkRRect::scaleRadii() {
165
161 // Proportionally scale down all radii to fit. Find the minimum ratio 166 // Proportionally scale down all radii to fit. Find the minimum ratio
162 // of a side and the radii on that side (for all four sides) and use 167 // of a side and the radii on that side (for all four sides) and use
163 // that to scale down _all_ the radii. This algorithm is from the 168 // that to scale down _all_ the radii. This algorithm is from the
164 // W3 spec (http://www.w3.org/TR/css3-background/) section 5.5 - Overlapping 169 // W3 spec (http://www.w3.org/TR/css3-background/) section 5.5 - Overlapping
165 // Curves: 170 // Curves:
166 // "Let f = min(Li/Si), where i is one of { top, right, bottom, left }, 171 // "Let f = min(Li/Si), where i is one of { top, right, bottom, left },
167 // Si is the sum of the two corresponding radii of the corners on side i, 172 // Si is the sum of the two corresponding radii of the corners on side i,
168 // and Ltop = Lbottom = the width of the box, 173 // and Ltop = Lbottom = the width of the box,
169 // and Lleft = Lright = the height of the box. 174 // and Lleft = Lright = the height of the box.
170 // If f < 1, then all corner radii are reduced by multiplying them by f." 175 // If f < 1, then all corner radii are reduced by multiplying them by f."
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // Only swap in x 418 // Only swap in x
414 SkTSwap(dst->fRadii[kUpperRight_Corner], dst->fRadii[kUpperLeft_Corn er]); 419 SkTSwap(dst->fRadii[kUpperRight_Corner], dst->fRadii[kUpperLeft_Corn er]);
415 SkTSwap(dst->fRadii[kLowerRight_Corner], dst->fRadii[kLowerLeft_Corn er]); 420 SkTSwap(dst->fRadii[kLowerRight_Corner], dst->fRadii[kLowerLeft_Corn er]);
416 } 421 }
417 } else if (flipY) { 422 } else if (flipY) {
418 // Only swap in y 423 // Only swap in y
419 SkTSwap(dst->fRadii[kUpperLeft_Corner], dst->fRadii[kLowerLeft_Corner]); 424 SkTSwap(dst->fRadii[kUpperLeft_Corner], dst->fRadii[kLowerLeft_Corner]);
420 SkTSwap(dst->fRadii[kUpperRight_Corner], dst->fRadii[kLowerRight_Corner] ); 425 SkTSwap(dst->fRadii[kUpperRight_Corner], dst->fRadii[kLowerRight_Corner] );
421 } 426 }
422 427
423 SkDEBUGCODE(dst->validate();) 428 dst->scaleRadii();
424 429
425 return true; 430 return true;
426 } 431 }
427 432
428 /////////////////////////////////////////////////////////////////////////////// 433 ///////////////////////////////////////////////////////////////////////////////
429 434
430 void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const { 435 void SkRRect::inset(SkScalar dx, SkScalar dy, SkRRect* dst) const {
431 const SkRect r = fRect.makeInset(dx, dy); 436 const SkRect r = fRect.makeInset(dx, dy);
432 437
433 if (r.isEmpty()) { 438 if (r.isEmpty()) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 569 }
565 570
566 for (int i = 0; i < 4; ++i) { 571 for (int i = 0; i < 4; ++i) {
567 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight ); 572 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight );
568 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom ); 573 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom );
569 } 574 }
570 } 575 }
571 #endif // SK_DEBUG 576 #endif // SK_DEBUG
572 577
573 /////////////////////////////////////////////////////////////////////////////// 578 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « include/core/SkRRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698