Chromium Code Reviews| Index: src/core/SkBBoxRecord.cpp |
| diff --git a/src/core/SkBBoxRecord.cpp b/src/core/SkBBoxRecord.cpp |
| index 366808703f6a97ef74987fde48a4a7d7f1bac818..e83535b9ac03aa272aced4c04198983543d5bb2a 100644 |
| --- a/src/core/SkBBoxRecord.cpp |
| +++ b/src/core/SkBBoxRecord.cpp |
| @@ -179,35 +179,44 @@ 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 = xpos[0]; |
| + bbox.fRight = xpos[numChars - 1]; |
| + for (size_t i = 1; i < numChars; ++i) { |
|
caryclark
2013/08/21 17:54:09
what if xpos[0] > bbox.fRight ?
sglez
2013/08/21 18:11:56
i starts at 1.
If numChars == 1, then fLeft == fR
caryclark
2013/08/21 18:27:55
suppose numChars == 2, xpos[0] = 3, xpos[1] = 2:
sglez
2013/08/21 18:43:17
Assuming bbox.fLeft == bbox.fRight,
And assuming p
|
| + 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, |