| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkBBoxRecord.h" | 9 #include "SkBBoxRecord.h" |
| 10 | 10 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 bbox.fLeft += pad; | 172 bbox.fLeft += pad; |
| 173 bbox.fRight -= pad; | 173 bbox.fRight -= pad; |
| 174 | 174 |
| 175 if (this->transformBounds(bbox, &paint)) { | 175 if (this->transformBounds(bbox, &paint)) { |
| 176 INHERITED::drawPosText(text, byteLength, pos, paint); | 176 INHERITED::drawPosText(text, byteLength, pos, paint); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], | 180 void SkBBoxRecord::drawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], |
| 181 SkScalar constY, const SkPaint& paint) { | 181 SkScalar constY, const SkPaint& paint) { |
| 182 size_t numChars = paint.countText(text, byteLength); |
| 183 if (numChars == 0) { |
| 184 return; |
| 185 } |
| 186 |
| 187 const SkFlatData* flatPaintData = this->getFlatPaintData(paint); |
| 188 WriteTopBot(paint, *flatPaintData); |
| 189 |
| 190 SkScalar top = flatPaintData->topBot()[0]; |
| 191 SkScalar bottom = flatPaintData->topBot()[1]; |
| 192 SkScalar pad = top - bottom; |
| 193 |
| 182 SkRect bbox; | 194 SkRect bbox; |
| 183 size_t numChars = paint.countText(text, byteLength); | 195 bbox.fLeft = SK_ScalarMax; |
| 184 if (numChars > 0) { | 196 bbox.fRight = SK_ScalarMin; |
| 185 bbox.fLeft = xpos[0]; | 197 |
| 186 bbox.fRight = xpos[numChars - 1]; | 198 for (size_t i = 0; i < numChars; ++i) { |
| 187 // if we had a guarantee that these will be monotonically increasing, th
is could be sped up | 199 if (xpos[i] < bbox.fLeft) { |
| 188 for (size_t i = 1; i < numChars; ++i) { | 200 bbox.fLeft = xpos[i]; |
| 189 if (xpos[i] < bbox.fLeft) { | |
| 190 bbox.fLeft = xpos[i]; | |
| 191 } | |
| 192 if (xpos[i] > bbox.fRight) { | |
| 193 bbox.fRight = xpos[i]; | |
| 194 } | |
| 195 } | 201 } |
| 196 SkPaint::FontMetrics metrics; | 202 if (xpos[i] > bbox.fRight) { |
| 197 paint.getFontMetrics(&metrics); | 203 bbox.fRight = xpos[i]; |
| 198 | |
| 199 // pad horizontally by max glyph height | |
| 200 SkScalar pad = (metrics.fTop - metrics.fBottom); | |
| 201 bbox.fLeft += pad; | |
| 202 bbox.fRight -= pad; | |
| 203 | |
| 204 bbox.fTop = metrics.fTop + constY; | |
| 205 bbox.fBottom = metrics.fBottom + constY; | |
| 206 if (!this->transformBounds(bbox, &paint)) { | |
| 207 return; | |
| 208 } | 204 } |
| 209 } | 205 } |
| 210 INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); | 206 |
| 207 // pad horizontally by max glyph height |
| 208 bbox.fLeft += pad; |
| 209 bbox.fRight -= pad; |
| 210 |
| 211 bbox.fTop = top + constY; |
| 212 bbox.fBottom = bottom + constY; |
| 213 |
| 214 if (!this->transformBounds(bbox, &paint)) { |
| 215 return; |
| 216 } |
| 217 // This is the equivalent of calling: |
| 218 // INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); |
| 219 // but we filled our flat paint beforehand so that we could get font metrics
. |
| 220 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); |
| 211 } | 221 } |
| 212 | 222 |
| 213 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, | 223 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
| 214 const SkPaint* paint) { | 224 const SkPaint* paint) { |
| 215 SkRect bbox; | 225 SkRect bbox; |
| 216 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); | 226 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); |
| 217 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored | 227 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored |
| 218 INHERITED::drawSprite(bitmap, left, top, paint); | 228 INHERITED::drawSprite(bitmap, left, top, paint); |
| 219 } | 229 } |
| 220 | 230 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 286 } |
| 277 | 287 |
| 278 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { | 288 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { |
| 279 this->getTotalMatrix().mapRect(&outBounds); | 289 this->getTotalMatrix().mapRect(&outBounds); |
| 280 this->handleBBox(outBounds); | 290 this->handleBBox(outBounds); |
| 281 return true; | 291 return true; |
| 282 } | 292 } |
| 283 | 293 |
| 284 return false; | 294 return false; |
| 285 } | 295 } |
| OLD | NEW |