OLD | NEW |
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 Loading... |
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 // Pad all sides by the maximum padding in any direction we'd normally a
pply. | 490 // We don't know how the text will curve around the path, so |
| 491 // pad all sides by the maximum padding in any direction we'd normally a
pply. |
491 SkRect pad = { 0, 0, 0, 0}; | 492 SkRect pad = { 0, 0, 0, 0}; |
492 AdjustTextForFontMetrics(&pad, op.paint); | 493 AdjustTextForFontMetrics(&pad, op.paint); |
493 | 494 SkScalar max = SkTMax(SkTMax(-pad.fLeft, pad.fRight), |
494 // That maximum padding happens to always be the right pad today. | 495 SkTMax(-pad.fTop, pad.fBottom)); |
495 SkASSERT(pad.fLeft == -pad.fRight); | 496 dst.outset(max, max); |
496 SkASSERT(pad.fTop == -pad.fBottom); | |
497 SkASSERT(pad.fRight > pad.fBottom); | |
498 dst.outset(pad.fRight, pad.fRight); | |
499 | |
500 return this->adjustAndMap(dst, &op.paint); | 497 return this->adjustAndMap(dst, &op.paint); |
501 } | 498 } |
502 | 499 |
503 Bounds bounds(const DrawTextBlob& op) const { | 500 Bounds bounds(const DrawTextBlob& op) const { |
504 SkRect dst = op.blob->bounds(); | 501 SkRect dst = op.blob->bounds(); |
505 dst.offset(op.x, op.y); | 502 dst.offset(op.x, op.y); |
506 return this->adjustAndMap(dst, &op.paint); | 503 return this->adjustAndMap(dst, &op.paint); |
507 } | 504 } |
508 | 505 |
509 Bounds bounds(const DrawDrawable& op) const { | 506 Bounds bounds(const DrawDrawable& op) const { |
510 return this->adjustAndMap(op.worstCaseBounds, NULL); | 507 return this->adjustAndMap(op.worstCaseBounds, NULL); |
511 } | 508 } |
512 | 509 |
513 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { | 510 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { |
514 #ifdef SK_DEBUG | 511 // rect was built from only the text's origin points, so we need to |
515 SkRect correct = *rect; | 512 // outset it by the worst-case bounds of the font. |
516 #endif | 513 const SkRect bounds = paint.getFontBounds(); |
517 // crbug.com/373785 ~~> xPad = 4x yPad | 514 rect->fLeft += bounds.fLeft; |
518 // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x | 515 rect->fRight += bounds.fRight; |
519 const SkScalar yPad = 2.5f * paint.getTextSize(), | 516 rect->fTop += bounds.fTop; |
520 xPad = 4.0f * yPad; | 517 rect->fBottom += bounds.fBottom; |
521 rect->outset(xPad, yPad); | |
522 #ifdef SK_DEBUG | 518 #ifdef SK_DEBUG |
523 SkPaint::FontMetrics metrics; | 519 SkPaint::FontMetrics metrics; |
524 paint.getFontMetrics(&metrics); | 520 paint.getFontMetrics(&metrics); |
525 correct.fLeft += metrics.fXMin; | 521 const SkRect correct = { metrics.fXMin, metrics.fTop, metrics.fXMax, met
rics.fBottom }; |
526 correct.fTop += metrics.fTop; | |
527 correct.fRight += metrics.fXMax; | |
528 correct.fBottom += metrics.fBottom; | |
529 // See skia:2862 for why we ignore small text sizes. | 522 // See skia:2862 for why we ignore small text sizes. |
530 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct), | 523 SkASSERTF(paint.getTextSize() < 0.001f || bounds.contains(correct), |
531 "%f %f %f %f vs. %f %f %f %f\n", | 524 "%g %g %g %g vs. %g %g %g %g, size %g, scalex %g, skewx %g\n", |
532 -xPad, -yPad, +xPad, +yPad, | 525 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, |
533 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom); | 526 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom, |
| 527 paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX
()); |
534 #endif | 528 #endif |
535 } | 529 } |
536 | 530 |
537 // Returns true if rect was meaningfully adjusted for the effects of paint, | 531 // Returns true if rect was meaningfully adjusted for the effects of paint, |
538 // false if the paint could affect the rect in unknown ways. | 532 // false if the paint could affect the rect in unknown ways. |
539 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { | 533 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { |
540 if (paint) { | 534 if (paint) { |
541 if (paint->canComputeFastBounds()) { | 535 if (paint->canComputeFastBounds()) { |
542 *rect = paint->computeFastBounds(*rect, rect); | 536 *rect = paint->computeFastBounds(*rect, rect); |
543 return true; | 537 return true; |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); | 780 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); |
787 | 781 |
788 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 782 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
789 visitor.setCurrentOp(curOp); | 783 visitor.setCurrentOp(curOp); |
790 record.visit<void>(curOp, visitor); | 784 record.visit<void>(curOp, visitor); |
791 } | 785 } |
792 | 786 |
793 visitor.cleanUp(bbh); | 787 visitor.cleanUp(bbh); |
794 } | 788 } |
795 | 789 |
OLD | NEW |