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

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

Issue 789793004: Revert of Use SkPaint::getFontBounds() for text bounding boxes in pictures. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | tests/RecordDrawTest.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 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 "SkLayerInfo.h" 8 #include "SkLayerInfo.h"
9 #include "SkRecordDraw.h" 9 #include "SkRecordDraw.h"
10 #include "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 left = SkMinScalar(left, op.xpos[i]); 480 left = SkMinScalar(left, op.xpos[i]);
481 right = SkMaxScalar(right, op.xpos[i]); 481 right = SkMaxScalar(right, op.xpos[i]);
482 } 482 }
483 SkRect dst = { left, op.y, right, op.y }; 483 SkRect dst = { left, op.y, right, op.y };
484 AdjustTextForFontMetrics(&dst, op.paint); 484 AdjustTextForFontMetrics(&dst, op.paint);
485 return this->adjustAndMap(dst, &op.paint); 485 return this->adjustAndMap(dst, &op.paint);
486 } 486 }
487 Bounds bounds(const DrawTextOnPath& op) const { 487 Bounds bounds(const DrawTextOnPath& op) const {
488 SkRect dst = op.path.getBounds(); 488 SkRect dst = op.path.getBounds();
489 489
490 // We don't know how the text will curve around the path, so 490 // Pad all sides by the maximum padding in any direction we'd normally a pply.
491 // pad all sides by the maximum padding in any direction we'd normally a pply.
492 SkRect pad = { 0, 0, 0, 0}; 491 SkRect pad = { 0, 0, 0, 0};
493 AdjustTextForFontMetrics(&pad, op.paint); 492 AdjustTextForFontMetrics(&pad, op.paint);
494 SkScalar max = SkTMax(SkTMax(-pad.fLeft, pad.fRight), 493
495 SkTMax(-pad.fTop, pad.fBottom)); 494 // That maximum padding happens to always be the right pad today.
496 dst.outset(max, max); 495 SkASSERT(pad.fLeft == -pad.fRight);
496 SkASSERT(pad.fTop == -pad.fBottom);
497 SkASSERT(pad.fRight > pad.fBottom);
498 dst.outset(pad.fRight, pad.fRight);
499
497 return this->adjustAndMap(dst, &op.paint); 500 return this->adjustAndMap(dst, &op.paint);
498 } 501 }
499 502
500 Bounds bounds(const DrawTextBlob& op) const { 503 Bounds bounds(const DrawTextBlob& op) const {
501 SkRect dst = op.blob->bounds(); 504 SkRect dst = op.blob->bounds();
502 dst.offset(op.x, op.y); 505 dst.offset(op.x, op.y);
503 return this->adjustAndMap(dst, &op.paint); 506 return this->adjustAndMap(dst, &op.paint);
504 } 507 }
505 508
506 Bounds bounds(const DrawDrawable& op) const { 509 Bounds bounds(const DrawDrawable& op) const {
507 return this->adjustAndMap(op.worstCaseBounds, NULL); 510 return this->adjustAndMap(op.worstCaseBounds, NULL);
508 } 511 }
509 512
510 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { 513 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
511 // rect was built from only the text's origin points, so we need to 514 #ifdef SK_DEBUG
512 // outset it by the worst-case bounds of the font. 515 SkRect correct = *rect;
513 const SkRect bounds = paint.getFontBounds(); 516 #endif
514 rect->fLeft += bounds.fLeft; 517 // crbug.com/373785 ~~> xPad = 4x yPad
515 rect->fRight += bounds.fRight; 518 // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x
516 rect->fTop += bounds.fTop; 519 const SkScalar yPad = 2.5f * paint.getTextSize(),
517 rect->fBottom += bounds.fBottom; 520 xPad = 4.0f * yPad;
521 rect->outset(xPad, yPad);
518 #ifdef SK_DEBUG 522 #ifdef SK_DEBUG
519 SkPaint::FontMetrics metrics; 523 SkPaint::FontMetrics metrics;
520 paint.getFontMetrics(&metrics); 524 paint.getFontMetrics(&metrics);
521 const SkRect correct = { metrics.fXMin, metrics.fTop, metrics.fXMax, met rics.fBottom }; 525 correct.fLeft += metrics.fXMin;
526 correct.fTop += metrics.fTop;
527 correct.fRight += metrics.fXMax;
528 correct.fBottom += metrics.fBottom;
522 // See skia:2862 for why we ignore small text sizes. 529 // See skia:2862 for why we ignore small text sizes.
523 SkASSERTF(paint.getTextSize() < 0.001f || bounds.contains(correct), 530 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct),
524 "%f %f %f %f vs. %f %f %f %f\n", 531 "%f %f %f %f vs. %f %f %f %f\n",
525 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, 532 -xPad, -yPad, +xPad, +yPad,
526 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom); 533 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom);
527 #endif 534 #endif
528 } 535 }
529 536
530 // Returns true if rect was meaningfully adjusted for the effects of paint, 537 // Returns true if rect was meaningfully adjusted for the effects of paint,
531 // false if the paint could affect the rect in unknown ways. 538 // false if the paint could affect the rect in unknown ways.
532 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { 539 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) {
533 if (paint) { 540 if (paint) {
534 if (paint->canComputeFastBounds()) { 541 if (paint->canComputeFastBounds()) {
535 *rect = paint->computeFastBounds(*rect, rect); 542 *rect = paint->computeFastBounds(*rect, rect);
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); 786 SkRecords::CollectLayers visitor(cullRect, record, pictList, data);
780 787
781 for (unsigned curOp = 0; curOp < record.count(); curOp++) { 788 for (unsigned curOp = 0; curOp < record.count(); curOp++) {
782 visitor.setCurrentOp(curOp); 789 visitor.setCurrentOp(curOp);
783 record.visit<void>(curOp, visitor); 790 record.visit<void>(curOp, visitor);
784 } 791 }
785 792
786 visitor.cleanUp(bbh); 793 visitor.cleanUp(bbh);
787 } 794 }
788 795
OLDNEW
« no previous file with comments | « no previous file | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698