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 "SkRecordDraw.h" | 8 #include "SkRecordDraw.h" |
9 #include "SkPatchUtils.h" | 9 #include "SkPatchUtils.h" |
10 #include "SkTypeface.h" | |
10 | 11 |
11 void SkRecordDraw(const SkRecord& record, | 12 void SkRecordDraw(const SkRecord& record, |
12 SkCanvas* canvas, | 13 SkCanvas* canvas, |
13 const SkBBoxHierarchy* bbh, | 14 const SkBBoxHierarchy* bbh, |
14 SkDrawPictureCallback* callback) { | 15 SkDrawPictureCallback* callback) { |
15 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 16 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
16 | 17 |
17 if (bbh) { | 18 if (bbh) { |
18 // Draw only ops that affect pixels in the canvas's current clip. | 19 // Draw only ops that affect pixels in the canvas's current clip. |
19 // The SkRecord and BBH were recorded in identity space. This canvas | 20 // The SkRecord and BBH were recorded in identity space. This canvas |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 AdjustTextForFontMetrics(&dst, op.paint); | 442 AdjustTextForFontMetrics(&dst, op.paint); |
442 return this->adjustAndMap(dst, &op.paint); | 443 return this->adjustAndMap(dst, &op.paint); |
443 } | 444 } |
444 Bounds bounds(const DrawTextOnPath& op) const { | 445 Bounds bounds(const DrawTextOnPath& op) const { |
445 SkRect dst = op.path.getBounds(); | 446 SkRect dst = op.path.getBounds(); |
446 | 447 |
447 // Pad all sides by the maximum padding in any direction we'd normally a pply. | 448 // Pad all sides by the maximum padding in any direction we'd normally a pply. |
448 SkRect pad = { 0, 0, 0, 0}; | 449 SkRect pad = { 0, 0, 0, 0}; |
449 AdjustTextForFontMetrics(&pad, op.paint); | 450 AdjustTextForFontMetrics(&pad, op.paint); |
450 | 451 |
451 // That maximum padding happens to always be the right pad today. | 452 SkScalar max = SkTMax(SkTMax(-pad.fLeft, pad.fRight), |
reed1
2014/10/28 17:36:13
/* we take the max, instead of outsetting by each
| |
452 SkASSERT(pad.fLeft == -pad.fRight); | 453 SkTMax(-pad.fTop, pad.fBottom)); |
453 SkASSERT(pad.fTop == -pad.fBottom); | 454 dst.outset(max, max); |
454 SkASSERT(pad.fRight > pad.fBottom); | |
455 dst.outset(pad.fRight, pad.fRight); | |
456 | 455 |
457 return this->adjustAndMap(dst, &op.paint); | 456 return this->adjustAndMap(dst, &op.paint); |
458 } | 457 } |
459 | 458 |
460 Bounds bounds(const DrawTextBlob& op) const { | 459 Bounds bounds(const DrawTextBlob& op) const { |
461 SkRect dst = op.blob->bounds(); | 460 SkRect dst = op.blob->bounds(); |
462 dst.offset(op.x, op.y); | 461 dst.offset(op.x, op.y); |
463 return this->adjustAndMap(dst, &op.paint); | 462 return this->adjustAndMap(dst, &op.paint); |
464 } | 463 } |
465 | 464 |
466 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { | 465 static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) { |
467 #ifdef SK_DEBUG | 466 #ifdef SK_DEBUG |
468 SkRect correct = *rect; | 467 SkRect correct = *rect; |
469 #endif | 468 #endif |
470 // crbug.com/373785 ~~> xPad = 4x yPad | 469 SkAutoTUnref<SkTypeface> au; |
471 // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x | 470 SkTypeface* tf = paint.getTypeface(); |
472 const SkScalar yPad = 2.5f * paint.getTextSize(), | 471 if (!tf) { |
473 xPad = 4.0f * yPad; | 472 au.reset(SkTypeface::RefDefault()); |
474 rect->outset(xPad, yPad); | 473 tf = au.get(); |
474 } | |
475 const SkScalar size = paint.getTextSize(); | |
476 const SkRect tb = tf->getBounds(); | |
reed1
2014/10/28 17:36:13
// "outset" rect by the corresponding fields in th
| |
477 rect->fLeft += size * tb.fLeft; | |
478 rect->fRight += size * tb.fRight; | |
479 rect->fTop += size * tb.fTop; | |
480 rect->fBottom += size * tb.fBottom; | |
475 #ifdef SK_DEBUG | 481 #ifdef SK_DEBUG |
476 SkPaint::FontMetrics metrics; | 482 SkPaint::FontMetrics metrics; |
477 paint.getFontMetrics(&metrics); | 483 paint.getFontMetrics(&metrics); |
478 correct.fLeft += metrics.fXMin; | 484 correct.fLeft += metrics.fXMin; |
479 correct.fTop += metrics.fTop; | 485 correct.fTop += metrics.fTop; |
480 correct.fRight += metrics.fXMax; | 486 correct.fRight += metrics.fXMax; |
481 correct.fBottom += metrics.fBottom; | 487 correct.fBottom += metrics.fBottom; |
482 // See skia:2862 for why we ignore small text sizes. | 488 // See skia:2862 for why we ignore small text sizes. |
483 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct), | 489 SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct), |
484 "%f %f %f %f vs. %f %f %f %f\n", | 490 "%f %f %f %f vs. %f %f %f %f, text size %f\n", |
485 -xPad, -yPad, +xPad, +yPad, | 491 size*tb.fLeft, size*tb.fTop, size*tb.fRight, size*tb.fBottom, |
486 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom); | 492 metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom, |
493 paint.getTextSize()); | |
487 #endif | 494 #endif |
488 } | 495 } |
489 | 496 |
490 // Returns true if rect was meaningfully adjusted for the effects of paint, | 497 // Returns true if rect was meaningfully adjusted for the effects of paint, |
491 // false if the paint could affect the rect in unknown ways. | 498 // false if the paint could affect the rect in unknown ways. |
492 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { | 499 static bool AdjustForPaint(const SkPaint* paint, SkRect* rect) { |
493 if (paint) { | 500 if (paint) { |
494 if (paint->canComputeFastBounds()) { | 501 if (paint->canComputeFastBounds()) { |
495 *rect = paint->computeFastBounds(*rect, rect); | 502 *rect = paint->computeFastBounds(*rect, rect); |
496 return true; | 503 return true; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 // Used to track the bounds of Save/Restore blocks and the control ops insid e them. | 555 // Used to track the bounds of Save/Restore blocks and the control ops insid e them. |
549 SkTDArray<SaveBounds> fSaveStack; | 556 SkTDArray<SaveBounds> fSaveStack; |
550 SkTDArray<unsigned> fControlIndices; | 557 SkTDArray<unsigned> fControlIndices; |
551 }; | 558 }; |
552 | 559 |
553 } // namespace SkRecords | 560 } // namespace SkRecords |
554 | 561 |
555 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { | 562 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) { |
556 SkRecords::FillBounds(record, bbh); | 563 SkRecords::FillBounds(record, bbh); |
557 } | 564 } |
OLD | NEW |