aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRecordDraw.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-12-16 06:17:54 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-16 06:17:54 -0800
commit02d2b9831579173e783569530ab7bae08de907e9 (patch)
tree329d2b021276aa17970a4e09ce569541139f20f5 /src/core/SkRecordDraw.cpp
parentbc02bf0ee4221604796cd6d0394ca3af60c0a579 (diff)
Use SkPaint::getFontBounds() for text bounding boxes in pictures.
Now that SkTextBlobs have landed, this is a perf no-op, but it at least lets us eliminate a bunch of questionable hacks. CQ_EXTRA_TRYBOTS=client.skia:Test-Win7-ShuttleA-HD2000-x86-Debug-Trybot,Test-Mac10.8-MacMini4.1-GeForce320M-x86_64-Debug-Trybot BUG=skia: Review URL: https://codereview.chromium.org/805983003
Diffstat (limited to 'src/core/SkRecordDraw.cpp')
-rw-r--r--src/core/SkRecordDraw.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 86621f2170..ba401005fa 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -487,16 +487,13 @@ private:
Bounds bounds(const DrawTextOnPath& op) const {
SkRect dst = op.path.getBounds();
- // Pad all sides by the maximum padding in any direction we'd normally apply.
+ // We don't know how the text will curve around the path, so
+ // pad all sides by the maximum padding in any direction we'd normally apply.
SkRect pad = { 0, 0, 0, 0};
AdjustTextForFontMetrics(&pad, op.paint);
-
- // That maximum padding happens to always be the right pad today.
- SkASSERT(pad.fLeft == -pad.fRight);
- SkASSERT(pad.fTop == -pad.fBottom);
- SkASSERT(pad.fRight > pad.fBottom);
- dst.outset(pad.fRight, pad.fRight);
-
+ SkScalar max = SkTMax(SkTMax(-pad.fLeft, pad.fRight),
+ SkTMax(-pad.fTop, pad.fBottom));
+ dst.outset(max, max);
return this->adjustAndMap(dst, &op.paint);
}
@@ -511,25 +508,21 @@ private:
}
static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
-#ifdef SK_DEBUG
- SkRect correct = *rect;
-#endif
- // crbug.com/373785 ~~> xPad = 4x yPad
- // crbug.com/424824 ~~> bump yPad from 2x text size to 2.5x
- const SkScalar yPad = 2.5f * paint.getTextSize(),
- xPad = 4.0f * yPad;
- rect->outset(xPad, yPad);
+ // rect was built from only the text's origin points, so we need to
+ // outset it by the worst-case bounds of the font.
+ const SkRect bounds = paint.getFontBounds();
+ rect->fLeft += bounds.fLeft;
+ rect->fRight += bounds.fRight;
+ rect->fTop += bounds.fTop;
+ rect->fBottom += bounds.fBottom;
#ifdef SK_DEBUG
SkPaint::FontMetrics metrics;
paint.getFontMetrics(&metrics);
- correct.fLeft += metrics.fXMin;
- correct.fTop += metrics.fTop;
- correct.fRight += metrics.fXMax;
- correct.fBottom += metrics.fBottom;
+ const SkRect correct = { metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom };
// See skia:2862 for why we ignore small text sizes.
- SkASSERTF(paint.getTextSize() < 0.001f || rect->contains(correct),
+ SkASSERTF(paint.getTextSize() < 0.001f || bounds.contains(correct),
"%f %f %f %f vs. %f %f %f %f\n",
- -xPad, -yPad, +xPad, +yPad,
+ bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom,
metrics.fXMin, metrics.fTop, metrics.fXMax, metrics.fBottom);
#endif
}