| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 | 600 |
| 601 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); | 601 fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale); |
| 602 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); | 602 fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale); |
| 603 } | 603 } |
| 604 | 604 |
| 605 this->finish(); | 605 this->finish(); |
| 606 } | 606 } |
| 607 | 607 |
| 608 void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
& skPaint, | 608 void GrDistanceFieldTextContext::drawPosText(const GrPaint& paint, const SkPaint
& skPaint, |
| 609 const char text[], size_t byteLengt
h, | 609 const char text[], size_t byteLengt
h, |
| 610 const SkScalar pos[], int scalarsPe
rPosition, | 610 const SkScalar pos[], SkScalar cons
tY, |
| 611 const SkPoint& offset) { | 611 int scalarsPerPosition) { |
| 612 | 612 |
| 613 SkASSERT(byteLength == 0 || text != NULL); | 613 SkASSERT(byteLength == 0 || text != NULL); |
| 614 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 614 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 615 | 615 |
| 616 // nothing to draw | 616 // nothing to draw |
| 617 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ | 617 if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/)
{ |
| 618 return; | 618 return; |
| 619 } | 619 } |
| 620 | 620 |
| 621 this->init(paint, skPaint); | 621 this->init(paint, skPaint); |
| 622 | 622 |
| 623 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 623 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 624 | 624 |
| 625 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); | 625 SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL); |
| 626 SkGlyphCache* cache = autoCache.getCache(); | 626 SkGlyphCache* cache = autoCache.getCache(); |
| 627 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 627 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 628 | 628 |
| 629 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); | 629 setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture); |
| 630 | 630 |
| 631 const char* stop = text + byteLength; | 631 const char* stop = text + byteLength; |
| 632 | 632 |
| 633 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { | 633 if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) { |
| 634 while (text < stop) { | 634 while (text < stop) { |
| 635 // the last 2 parameters are ignored | 635 // the last 2 parameters are ignored |
| 636 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 636 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 637 | 637 |
| 638 if (glyph.fWidth) { | 638 if (glyph.fWidth) { |
| 639 SkScalar x = offset.x() + pos[0]; | 639 SkScalar x = pos[0]; |
| 640 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 640 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; |
| 641 | 641 |
| 642 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 642 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 643 glyph.getSubXFixed(), | 643 glyph.getSubXFixed(), |
| 644 glyph.getSubYFixed()), | 644 glyph.getSubYFixed()), |
| 645 SkScalarToFixed(x), | 645 SkScalarToFixed(x), |
| 646 SkScalarToFixed(y), | 646 SkScalarToFixed(y), |
| 647 fontScaler); | 647 fontScaler); |
| 648 } | 648 } |
| 649 pos += scalarsPerPosition; | 649 pos += scalarsPerPosition; |
| 650 } | 650 } |
| 651 } else { | 651 } else { |
| 652 int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 :
0; | 652 int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 :
0; |
| 653 while (text < stop) { | 653 while (text < stop) { |
| 654 // the last 2 parameters are ignored | 654 // the last 2 parameters are ignored |
| 655 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 655 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 656 | 656 |
| 657 if (glyph.fWidth) { | 657 if (glyph.fWidth) { |
| 658 SkScalar x = offset.x() + pos[0]; | 658 SkScalar x = pos[0]; |
| 659 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 659 SkScalar y = scalarsPerPosition == 1 ? constY : pos[1]; |
| 660 | 660 |
| 661 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 661 this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 662 glyph.getSubXFixed(), | 662 glyph.getSubXFixed(), |
| 663 glyph.getSubYFixed()), | 663 glyph.getSubYFixed()), |
| 664 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), | 664 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), |
| 665 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), | 665 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), |
| 666 fontScaler); | 666 fontScaler); |
| 667 } | 667 } |
| 668 pos += scalarsPerPosition; | 668 pos += scalarsPerPosition; |
| 669 } | 669 } |
| 670 } | 670 } |
| 671 | 671 |
| 672 this->finish(); | 672 this->finish(); |
| 673 } | 673 } |
| OLD | NEW |