Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/core/SkTextBlob.cpp

Issue 1283853002: Revert of [TextBlob] Fall back to TightRunBounds when the font bounds are empty (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698