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 SkPaint paint; | 385 // First, compute the glyph position bbox. |
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. | |
395 SkRect bounds; | 386 SkRect bounds; |
396 switch (run.positioning()) { | 387 switch (run.positioning()) { |
397 case SkTextBlob::kHorizontal_Positioning: { | 388 case SkTextBlob::kHorizontal_Positioning: { |
398 const SkScalar* glyphPos = run.posBuffer(); | 389 const SkScalar* glyphPos = run.posBuffer(); |
399 SkASSERT((void*)(glyphPos + run.glyphCount()) <= SkTextBlob::RunRecord::
Next(&run)); | 390 SkASSERT((void*)(glyphPos + run.glyphCount()) <= SkTextBlob::RunRecord::
Next(&run)); |
400 | 391 |
401 SkScalar minX = *glyphPos; | 392 SkScalar minX = *glyphPos; |
402 SkScalar maxX = *glyphPos; | 393 SkScalar maxX = *glyphPos; |
403 for (unsigned i = 1; i < run.glyphCount(); ++i) { | 394 for (unsigned i = 1; i < run.glyphCount(); ++i) { |
404 SkScalar x = glyphPos[i]; | 395 SkScalar x = glyphPos[i]; |
405 minX = SkMinScalar(x, minX); | 396 minX = SkMinScalar(x, minX); |
406 maxX = SkMaxScalar(x, maxX); | 397 maxX = SkMaxScalar(x, maxX); |
407 } | 398 } |
408 | 399 |
409 bounds.setLTRB(minX, 0, maxX, 0); | 400 bounds.setLTRB(minX, 0, maxX, 0); |
410 } break; | 401 } break; |
411 case SkTextBlob::kFull_Positioning: { | 402 case SkTextBlob::kFull_Positioning: { |
412 const SkPoint* glyphPosPts = reinterpret_cast<const SkPoint*>(run.posBuf
fer()); | 403 const SkPoint* glyphPosPts = reinterpret_cast<const SkPoint*>(run.posBuf
fer()); |
413 SkASSERT((void*)(glyphPosPts + run.glyphCount()) <= SkTextBlob::RunRecor
d::Next(&run)); | 404 SkASSERT((void*)(glyphPosPts + run.glyphCount()) <= SkTextBlob::RunRecor
d::Next(&run)); |
414 | 405 |
415 bounds.setBounds(glyphPosPts, run.glyphCount()); | 406 bounds.setBounds(glyphPosPts, run.glyphCount()); |
416 } break; | 407 } break; |
417 default: | 408 default: |
418 SkFAIL("unsupported positioning mode"); | 409 SkFAIL("unsupported positioning mode"); |
419 } | 410 } |
420 | 411 |
421 // Expand by typeface glyph bounds. | 412 // Expand by typeface glyph bounds. |
| 413 SkPaint paint; |
| 414 run.font().applyToPaint(&paint); |
| 415 const SkRect fontBounds = paint.getFontBounds(); |
422 bounds.fLeft += fontBounds.left(); | 416 bounds.fLeft += fontBounds.left(); |
423 bounds.fTop += fontBounds.top(); | 417 bounds.fTop += fontBounds.top(); |
424 bounds.fRight += fontBounds.right(); | 418 bounds.fRight += fontBounds.right(); |
425 bounds.fBottom += fontBounds.bottom(); | 419 bounds.fBottom += fontBounds.bottom(); |
426 | 420 |
427 // Offset by run position. | 421 // Offset by run position. |
428 return bounds.makeOffset(run.offset().x(), run.offset().y()); | 422 return bounds.makeOffset(run.offset().x(), run.offset().y()); |
429 } | 423 } |
430 | 424 |
431 void SkTextBlobBuilder::updateDeferredBounds() { | 425 void SkTextBlobBuilder::updateDeferredBounds() { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 600 |
607 fStorageUsed = 0; | 601 fStorageUsed = 0; |
608 fStorageSize = 0; | 602 fStorageSize = 0; |
609 fRunCount = 0; | 603 fRunCount = 0; |
610 fLastRun = 0; | 604 fLastRun = 0; |
611 fBounds.setEmpty(); | 605 fBounds.setEmpty(); |
612 | 606 |
613 return blob; | 607 return blob; |
614 } | 608 } |
615 | 609 |
OLD | NEW |