| 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 "GrStencilAndCoverTextContext.h" | 8 #include "GrStencilAndCoverTextContext.h" |
| 9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 | 433 |
| 434 GrStencilAndCoverTextContext::TextRun::~TextRun() { | 434 GrStencilAndCoverTextContext::TextRun::~TextRun() { |
| 435 this->releaseGlyphCache(); | 435 this->releaseGlyphCache(); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by
teLength, | 438 void GrStencilAndCoverTextContext::TextRun::setText(const char text[], size_t by
teLength, |
| 439 SkScalar x, SkScalar y) { | 439 SkScalar x, SkScalar y) { |
| 440 SkASSERT(byteLength == 0 || text != nullptr); | 440 SkASSERT(byteLength == 0 || text != nullptr); |
| 441 | 441 |
| 442 SkGlyphCache* glyphCache = this->getGlyphCache(); | 442 SkGlyphCache* glyphCache = this->getGlyphCache(); |
| 443 SkDrawCacheProc glyphCacheProc = fFont.getDrawCacheProc(); | 443 SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); |
| 444 | 444 |
| 445 fTotalGlyphCount = fFont.countText(text, byteLength); | 445 fTotalGlyphCount = fFont.countText(text, byteLength); |
| 446 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, | 446 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, |
| 447 fTotalGlyphCount)); | 447 fTotalGlyphCount)); |
| 448 | 448 |
| 449 const char* stop = text + byteLength; | 449 const char* stop = text + byteLength; |
| 450 | 450 |
| 451 // Measure first if needed. | 451 // Measure first if needed. |
| 452 if (fFont.getTextAlign() != SkPaint::kLeft_Align) { | 452 if (fFont.getTextAlign() != SkPaint::kLeft_Align) { |
| 453 SkFixed stopX = 0; | 453 SkFixed stopX = 0; |
| 454 SkFixed stopY = 0; | 454 SkFixed stopY = 0; |
| 455 | 455 |
| 456 const char* textPtr = text; | 456 const char* textPtr = text; |
| 457 while (textPtr < stop) { | 457 while (textPtr < stop) { |
| 458 // We don't need x, y here, since all subpixel variants will have th
e | 458 // We don't need x, y here, since all subpixel variants will have th
e |
| 459 // same advance. | 459 // same advance. |
| 460 const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr, 0, 0); | 460 const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr); |
| 461 | 461 |
| 462 stopX += glyph.fAdvanceX; | 462 stopX += glyph.fAdvanceX; |
| 463 stopY += glyph.fAdvanceY; | 463 stopY += glyph.fAdvanceY; |
| 464 } | 464 } |
| 465 SkASSERT(textPtr == stop); | 465 SkASSERT(textPtr == stop); |
| 466 | 466 |
| 467 SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio; | 467 SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio; |
| 468 SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio; | 468 SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio; |
| 469 | 469 |
| 470 if (fFont.getTextAlign() == SkPaint::kCenter_Align) { | 470 if (fFont.getTextAlign() == SkPaint::kCenter_Align) { |
| 471 alignX = SkScalarHalf(alignX); | 471 alignX = SkScalarHalf(alignX); |
| 472 alignY = SkScalarHalf(alignY); | 472 alignY = SkScalarHalf(alignY); |
| 473 } | 473 } |
| 474 | 474 |
| 475 x -= alignX; | 475 x -= alignX; |
| 476 y -= alignY; | 476 y -= alignY; |
| 477 } | 477 } |
| 478 | 478 |
| 479 SkAutoKern autokern; | 479 SkAutoKern autokern; |
| 480 | 480 |
| 481 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); | 481 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); |
| 482 | 482 |
| 483 SkFixed fx = SkScalarToFixed(x); | 483 SkFixed fx = SkScalarToFixed(x); |
| 484 SkFixed fy = SkScalarToFixed(y); | 484 SkFixed fy = SkScalarToFixed(y); |
| 485 FallbackBlobBuilder fallback; | 485 FallbackBlobBuilder fallback; |
| 486 while (text < stop) { | 486 while (text < stop) { |
| 487 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text, 0, 0); | 487 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); |
| 488 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); | 488 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); |
| 489 if (glyph.fWidth) { | 489 if (glyph.fWidth) { |
| 490 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT
oScalar(fy)), | 490 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT
oScalar(fy)), |
| 491 &fallback); | 491 &fallback); |
| 492 } | 492 } |
| 493 | 493 |
| 494 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); | 494 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); |
| 495 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); | 495 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); |
| 496 } | 496 } |
| 497 | 497 |
| 498 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); | 498 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t
byteLength, | 501 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t
byteLength, |
| 502 const SkScalar pos[], int
scalarsPerPosition, | 502 const SkScalar pos[], int
scalarsPerPosition, |
| 503 const SkPoint& offset) { | 503 const SkPoint& offset) { |
| 504 SkASSERT(byteLength == 0 || text != nullptr); | 504 SkASSERT(byteLength == 0 || text != nullptr); |
| 505 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 505 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 506 | 506 |
| 507 SkGlyphCache* glyphCache = this->getGlyphCache(); | 507 SkGlyphCache* glyphCache = this->getGlyphCache(); |
| 508 SkDrawCacheProc glyphCacheProc = fFont.getDrawCacheProc(); | 508 SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); |
| 509 | 509 |
| 510 fTotalGlyphCount = fFont.countText(text, byteLength); | 510 fTotalGlyphCount = fFont.countText(text, byteLength); |
| 511 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, | 511 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, |
| 512 fTotalGlyphCount)); | 512 fTotalGlyphCount)); |
| 513 | 513 |
| 514 const char* stop = text + byteLength; | 514 const char* stop = text + byteLength; |
| 515 | 515 |
| 516 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); | 516 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
| 517 SkTextAlignProc alignProc(fFont.getTextAlign()); | 517 SkTextAlignProc alignProc(fFont.getTextAlign()); |
| 518 FallbackBlobBuilder fallback; | 518 FallbackBlobBuilder fallback; |
| 519 while (text < stop) { | 519 while (text < stop) { |
| 520 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text, 0, 0); | 520 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); |
| 521 if (glyph.fWidth) { | 521 if (glyph.fWidth) { |
| 522 SkPoint tmsLoc; | 522 SkPoint tmsLoc; |
| 523 tmsProc(pos, &tmsLoc); | 523 tmsProc(pos, &tmsLoc); |
| 524 SkPoint loc; | 524 SkPoint loc; |
| 525 alignProc(tmsLoc, glyph, &loc); | 525 alignProc(tmsLoc, glyph, &loc); |
| 526 | 526 |
| 527 this->appendGlyph(glyph, loc, &fallback); | 527 this->appendGlyph(glyph, loc, &fallback); |
| 528 } | 528 } |
| 529 pos += scalarsPerPosition; | 529 pos += scalarsPerPosition; |
| 530 } | 530 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 697 } |
| 698 | 698 |
| 699 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 699 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
| 700 *count = fCount; | 700 *count = fCount; |
| 701 if (fCount) { | 701 if (fCount) { |
| 702 this->flush(); | 702 this->flush(); |
| 703 return fBuilder->build(); | 703 return fBuilder->build(); |
| 704 } | 704 } |
| 705 return nullptr; | 705 return nullptr; |
| 706 } | 706 } |
| OLD | NEW |