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 = xpos[0]; |
184 if (numChars > 0) { | 196 bbox.fRight = xpos[numChars - 1]; |
185 bbox.fLeft = xpos[0]; | 197 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
| |
186 bbox.fRight = xpos[numChars - 1]; | 198 if (xpos[i] < bbox.fLeft) { |
187 // if we had a guarantee that these will be monotonically increasing, th is could be sped up | 199 bbox.fLeft = xpos[i]; |
188 for (size_t i = 1; i < numChars; ++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 } | 200 } |
196 SkPaint::FontMetrics metrics; | 201 if (xpos[i] > bbox.fRight) { |
197 paint.getFontMetrics(&metrics); | 202 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 } | 203 } |
209 } | 204 } |
210 INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); | 205 |
206 // pad horizontally by max glyph height | |
207 bbox.fLeft += pad; | |
208 bbox.fRight -= pad; | |
209 | |
210 bbox.fTop = top + constY; | |
211 bbox.fBottom = bottom + constY; | |
212 | |
213 if (!this->transformBounds(bbox, &paint)) { | |
214 return; | |
215 } | |
216 // This is the equivalent of calling: | |
217 // INHERITED::drawPosTextH(text, byteLength, xpos, constY, paint); | |
218 // but we filled our flat paint beforehand so that we could get font metrics . | |
219 drawPosTextHImpl(text, byteLength, xpos, constY, paint, flatPaintData); | |
211 } | 220 } |
212 | 221 |
213 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, | 222 void SkBBoxRecord::drawSprite(const SkBitmap& bitmap, int left, int top, |
214 const SkPaint* paint) { | 223 const SkPaint* paint) { |
215 SkRect bbox; | 224 SkRect bbox; |
216 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); | 225 bbox.set(SkIRect::MakeXYWH(left, top, bitmap.width(), bitmap.height())); |
217 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored | 226 this->handleBBox(bbox); // directly call handleBBox, matrix is ignored |
218 INHERITED::drawSprite(bitmap, left, top, paint); | 227 INHERITED::drawSprite(bitmap, left, top, paint); |
219 } | 228 } |
220 | 229 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 } | 285 } |
277 | 286 |
278 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { | 287 if (!outBounds.isEmpty() && !this->quickReject(outBounds)) { |
279 this->getTotalMatrix().mapRect(&outBounds); | 288 this->getTotalMatrix().mapRect(&outBounds); |
280 this->handleBBox(outBounds); | 289 this->handleBBox(outBounds); |
281 return true; | 290 return true; |
282 } | 291 } |
283 | 292 |
284 return false; | 293 return false; |
285 } | 294 } |
OLD | NEW |