Chromium Code Reviews| Index: src/core/SkBBoxRecord.cpp |
| diff --git a/src/core/SkBBoxRecord.cpp b/src/core/SkBBoxRecord.cpp |
| index 366808703f6a97ef74987fde48a4a7d7f1bac818..16c5f04d73ff28fd3936b16f8fc1ad47a85845c7 100644 |
| --- a/src/core/SkBBoxRecord.cpp |
| +++ b/src/core/SkBBoxRecord.cpp |
| @@ -179,35 +179,45 @@ void SkBBoxRecord::drawPosText(const void* text, size_t byteLength, |
| void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], |
| SkScalar constY, const SkPaint& paint) { |
| - SkRect bbox; |
| size_t numChars = paint.countText(text, byteLength); |
| - if (numChars > 0) { |
| - bbox.fLeft = xpos[0]; |
| - bbox.fRight = xpos[numChars - 1]; |
| - // if we had a guarantee that these will be monotonically increasing, this could be sped up |
| - for (size_t i = 1; i < numChars; ++i) { |
| - if (xpos[i] < bbox.fLeft) { |
| - bbox.fLeft = xpos[i]; |
| - } |
| - if (xpos[i] > bbox.fRight) { |
| - bbox.fRight = xpos[i]; |
| - } |
| + if (numChars == 0) { |
| + return; |
| + } |
| + |
| + const SkFlatData* flatPaintData = this->getFlatPaintData(paint); |
| + WriteTopBot(paint, *flatPaintData); |
| + |
| + SkScalar top = flatPaintData->topBot()[0]; |
| + SkScalar bottom = flatPaintData->topBot()[1]; |
| + SkScalar pad = top - bottom; |
| + |
| + SkRect bbox; |
| + bbox.fLeft = SkMinScalar(xpos[0], xpos[numChars - 1]); |
| + bbox.fRight = SkMaxScalar(xpos[0], xpos[numChars - 1]); |
| + |
|
sglez
2013/08/21 19:33:28
I think that calling min and max fixes the bug.
caryclark
2013/08/21 19:58:01
It works. I would have written it as
bbox.fLeft =
|
| + for (size_t i = 1; i < numChars; ++i) { |
| + if (xpos[i] < bbox.fLeft) { |
| + bbox.fLeft = xpos[i]; |
| } |
| - SkPaint::FontMetrics metrics; |
| - paint.getFontMetrics(&metrics); |
| - |
| - // pad horizontally by max glyph height |
| - SkScalar pad = (metrics.fTop - metrics.fBottom); |
| - bbox.fLeft += pad; |
| - bbox.fRight -= pad; |
| - |
| - bbox.fTop = metrics.fTop + constY; |
| - bbox.fBottom = metrics.fBottom + constY; |
| - if (!this->transformBounds(bbox, &paint)) { |
| - return; |
| + if (xpos[i] > bbox.fRight) { |
| + bbox.fRight = xpos[i]; |
| } |
| } |
| - INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); |
| + |
| + // pad horizontally by max glyph height |
| + bbox.fLeft += pad; |
| + bbox.fRight -= pad; |
| + |
| + bbox.fTop = top + constY; |
| + bbox.fBottom = bottom + constY; |
| + |
| + if (!this->transformBounds(bbox, &paint)) { |
| + return; |
| + } |
| + // This is the equivalent of calling: |
| + // INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); |
| + // but we filled our flat paint beforehand so that we could get font metrics. |
| + drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); |
| } |
| void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |