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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); | 450 SkPaint::GlyphCacheProc glyphCacheProc = fFont.getGlyphCacheProc(true); |
451 | 451 |
452 fTotalGlyphCount = fFont.countText(text, byteLength); | 452 fTotalGlyphCount = fFont.countText(text, byteLength); |
453 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, | 453 fInstanceData.reset(InstanceData::Alloc(GrPathRendering::kTranslate_PathTran
sformType, |
454 fTotalGlyphCount)); | 454 fTotalGlyphCount)); |
455 | 455 |
456 const char* stop = text + byteLength; | 456 const char* stop = text + byteLength; |
457 | 457 |
458 // Measure first if needed. | 458 // Measure first if needed. |
459 if (fFont.getTextAlign() != SkPaint::kLeft_Align) { | 459 if (fFont.getTextAlign() != SkPaint::kLeft_Align) { |
460 SkFixed stopX = 0; | 460 SkScalar stopX = 0; |
461 SkFixed stopY = 0; | 461 SkScalar stopY = 0; |
462 | 462 |
463 const char* textPtr = text; | 463 const char* textPtr = text; |
464 while (textPtr < stop) { | 464 while (textPtr < stop) { |
465 // We don't need x, y here, since all subpixel variants will have th
e | 465 // We don't need x, y here, since all subpixel variants will have th
e |
466 // same advance. | 466 // same advance. |
467 const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr); | 467 const SkGlyph& glyph = glyphCacheProc(glyphCache, &textPtr); |
468 | 468 |
469 stopX += glyph.fAdvanceX; | 469 stopX += SkFloatToScalar(glyph.fAdvanceX); |
470 stopY += glyph.fAdvanceY; | 470 stopY += SkFloatToScalar(glyph.fAdvanceY); |
471 } | 471 } |
472 SkASSERT(textPtr == stop); | 472 SkASSERT(textPtr == stop); |
473 | 473 |
474 SkScalar alignX = SkFixedToScalar(stopX) * fTextRatio; | 474 SkScalar alignX = stopX * fTextRatio; |
475 SkScalar alignY = SkFixedToScalar(stopY) * fTextRatio; | 475 SkScalar alignY = stopY * fTextRatio; |
476 | 476 |
477 if (fFont.getTextAlign() == SkPaint::kCenter_Align) { | 477 if (fFont.getTextAlign() == SkPaint::kCenter_Align) { |
478 alignX = SkScalarHalf(alignX); | 478 alignX = SkScalarHalf(alignX); |
479 alignY = SkScalarHalf(alignY); | 479 alignY = SkScalarHalf(alignY); |
480 } | 480 } |
481 | 481 |
482 x -= alignX; | 482 x -= alignX; |
483 y -= alignY; | 483 y -= alignY; |
484 } | 484 } |
485 | 485 |
486 SkAutoKern autokern; | 486 SkAutoKern autokern; |
487 | 487 |
488 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); | |
489 | |
490 SkFixed fx = SkScalarToFixed(x); | |
491 SkFixed fy = SkScalarToFixed(y); | |
492 FallbackBlobBuilder fallback; | 488 FallbackBlobBuilder fallback; |
493 while (text < stop) { | 489 while (text < stop) { |
494 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); | 490 const SkGlyph& glyph = glyphCacheProc(glyphCache, &text); |
495 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); | 491 x += autokern.adjust(glyph) * fTextRatio; |
496 if (glyph.fWidth) { | 492 if (glyph.fWidth) { |
497 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT
oScalar(fy)), | 493 this->appendGlyph(glyph, SkPoint::Make(x, y), &fallback); |
498 &fallback); | |
499 } | 494 } |
500 | 495 |
501 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); | 496 x += SkFloatToScalar(glyph.fAdvanceX) * fTextRatio; |
502 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); | 497 y += SkFloatToScalar(glyph.fAdvanceY) * fTextRatio; |
503 } | 498 } |
504 | 499 |
505 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); | 500 fFallbackTextBlob.reset(fallback.buildIfNeeded(&fFallbackGlyphCount)); |
506 } | 501 } |
507 | 502 |
508 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t
byteLength, | 503 void GrStencilAndCoverTextContext::TextRun::setPosText(const char text[], size_t
byteLength, |
509 const SkScalar pos[], int
scalarsPerPosition, | 504 const SkScalar pos[], int
scalarsPerPosition, |
510 const SkPoint& offset) { | 505 const SkPoint& offset) { |
511 SkASSERT(byteLength == 0 || text != nullptr); | 506 SkASSERT(byteLength == 0 || text != nullptr); |
512 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 507 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 } | 699 } |
705 | 700 |
706 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { | 701 const SkTextBlob* GrStencilAndCoverTextContext::FallbackBlobBuilder::buildIfNeed
ed(int *count) { |
707 *count = fCount; | 702 *count = fCount; |
708 if (fCount) { | 703 if (fCount) { |
709 this->flush(); | 704 this->flush(); |
710 return fBuilder->build(); | 705 return fBuilder->build(); |
711 } | 706 } |
712 return nullptr; | 707 return nullptr; |
713 } | 708 } |
OLD | NEW |