OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTextBlob.h" | 8 #include "SkTextBlob.h" |
9 | 9 |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &b
ounds); | 375 paint.measureText(run.glyphBuffer(), run.glyphCount() * sizeof(uint16_t), &b
ounds); |
376 | 376 |
377 return bounds.makeOffset(run.offset().x(), run.offset().y()); | 377 return bounds.makeOffset(run.offset().x(), run.offset().y()); |
378 } | 378 } |
379 | 379 |
380 SkRect SkTextBlobBuilder::ConservativeRunBounds(const SkTextBlob::RunRecord& run
) { | 380 SkRect SkTextBlobBuilder::ConservativeRunBounds(const SkTextBlob::RunRecord& run
) { |
381 SkASSERT(run.glyphCount() > 0); | 381 SkASSERT(run.glyphCount() > 0); |
382 SkASSERT(SkTextBlob::kFull_Positioning == run.positioning() || | 382 SkASSERT(SkTextBlob::kFull_Positioning == run.positioning() || |
383 SkTextBlob::kHorizontal_Positioning == run.positioning()); | 383 SkTextBlob::kHorizontal_Positioning == run.positioning()); |
384 | 384 |
385 // First, compute the glyph position bbox. | 385 SkPaint paint; |
| 386 run.font().applyToPaint(&paint); |
| 387 const SkRect fontBounds = paint.getFontBounds(); |
| 388 if (fontBounds.isEmpty()) { |
| 389 // Empty font bounds are likely a font bug. TightBounds has a better ch
ance of |
| 390 // producing useful results in this case. |
| 391 return TightRunBounds(run); |
| 392 } |
| 393 |
| 394 // Compute the glyph position bbox. |
386 SkRect bounds; | 395 SkRect bounds; |
387 switch (run.positioning()) { | 396 switch (run.positioning()) { |
388 case SkTextBlob::kHorizontal_Positioning: { | 397 case SkTextBlob::kHorizontal_Positioning: { |
389 const SkScalar* glyphPos = run.posBuffer(); | 398 const SkScalar* glyphPos = run.posBuffer(); |
390 SkASSERT((void*)(glyphPos + run.glyphCount()) <= SkTextBlob::RunRecord::
Next(&run)); | 399 SkASSERT((void*)(glyphPos + run.glyphCount()) <= SkTextBlob::RunRecord::
Next(&run)); |
391 | 400 |
392 SkScalar minX = *glyphPos; | 401 SkScalar minX = *glyphPos; |
393 SkScalar maxX = *glyphPos; | 402 SkScalar maxX = *glyphPos; |
394 for (unsigned i = 1; i < run.glyphCount(); ++i) { | 403 for (unsigned i = 1; i < run.glyphCount(); ++i) { |
395 SkScalar x = glyphPos[i]; | 404 SkScalar x = glyphPos[i]; |
396 minX = SkMinScalar(x, minX); | 405 minX = SkMinScalar(x, minX); |
397 maxX = SkMaxScalar(x, maxX); | 406 maxX = SkMaxScalar(x, maxX); |
398 } | 407 } |
399 | 408 |
400 bounds.setLTRB(minX, 0, maxX, 0); | 409 bounds.setLTRB(minX, 0, maxX, 0); |
401 } break; | 410 } break; |
402 case SkTextBlob::kFull_Positioning: { | 411 case SkTextBlob::kFull_Positioning: { |
403 const SkPoint* glyphPosPts = reinterpret_cast<const SkPoint*>(run.posBuf
fer()); | 412 const SkPoint* glyphPosPts = reinterpret_cast<const SkPoint*>(run.posBuf
fer()); |
404 SkASSERT((void*)(glyphPosPts + run.glyphCount()) <= SkTextBlob::RunRecor
d::Next(&run)); | 413 SkASSERT((void*)(glyphPosPts + run.glyphCount()) <= SkTextBlob::RunRecor
d::Next(&run)); |
405 | 414 |
406 bounds.setBounds(glyphPosPts, run.glyphCount()); | 415 bounds.setBounds(glyphPosPts, run.glyphCount()); |
407 } break; | 416 } break; |
408 default: | 417 default: |
409 SkFAIL("unsupported positioning mode"); | 418 SkFAIL("unsupported positioning mode"); |
410 } | 419 } |
411 | 420 |
412 // Expand by typeface glyph bounds. | 421 // Expand by typeface glyph bounds. |
413 SkPaint paint; | |
414 run.font().applyToPaint(&paint); | |
415 const SkRect fontBounds = paint.getFontBounds(); | |
416 bounds.fLeft += fontBounds.left(); | 422 bounds.fLeft += fontBounds.left(); |
417 bounds.fTop += fontBounds.top(); | 423 bounds.fTop += fontBounds.top(); |
418 bounds.fRight += fontBounds.right(); | 424 bounds.fRight += fontBounds.right(); |
419 bounds.fBottom += fontBounds.bottom(); | 425 bounds.fBottom += fontBounds.bottom(); |
420 | 426 |
421 // Offset by run position. | 427 // Offset by run position. |
422 return bounds.makeOffset(run.offset().x(), run.offset().y()); | 428 return bounds.makeOffset(run.offset().x(), run.offset().y()); |
423 } | 429 } |
424 | 430 |
425 void SkTextBlobBuilder::updateDeferredBounds() { | 431 void SkTextBlobBuilder::updateDeferredBounds() { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 | 606 |
601 fStorageUsed = 0; | 607 fStorageUsed = 0; |
602 fStorageSize = 0; | 608 fStorageSize = 0; |
603 fRunCount = 0; | 609 fRunCount = 0; |
604 fLastRun = 0; | 610 fLastRun = 0; |
605 fBounds.setEmpty(); | 611 fBounds.setEmpty(); |
606 | 612 |
607 return blob; | 613 return blob; |
608 } | 614 } |
609 | 615 |
OLD | NEW |