| 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 "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 const char* lastText = text; | 312 const char* lastText = text; |
| 313 // the last 2 parameters are ignored | 313 // the last 2 parameters are ignored |
| 314 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 314 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 315 | 315 |
| 316 if (glyph.fWidth) { | 316 if (glyph.fWidth) { |
| 317 SkScalar x = offset.x() + pos[0]; | 317 SkScalar x = offset.x() + pos[0]; |
| 318 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 318 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; |
| 319 | 319 |
| 320 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 320 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 321 glyph.getSubXFixed(), | 321 glyph.getSubXFixed(), |
| 322 glyph.getSubYFixed(), | 322 glyph.getSubYFixed()), |
| 323 GrGlyph::kDistance_MaskStyl
e), | |
| 324 x, y, fontScaler)) { | 323 x, y, fontScaler)) { |
| 325 // couldn't append, send to fallback | 324 // couldn't append, send to fallback |
| 326 fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); | 325 fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); |
| 327 fallbackPos.push_back(pos[0]); | 326 fallbackPos.push_back(pos[0]); |
| 328 if (2 == scalarsPerPosition) { | 327 if (2 == scalarsPerPosition) { |
| 329 fallbackPos.push_back(pos[1]); | 328 fallbackPos.push_back(pos[1]); |
| 330 } | 329 } |
| 331 } | 330 } |
| 332 } | 331 } |
| 333 pos += scalarsPerPosition; | 332 pos += scalarsPerPosition; |
| 334 } | 333 } |
| 335 } else { | 334 } else { |
| 336 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ?
SK_ScalarHalf | 335 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ?
SK_ScalarHalf |
| 337 :
SK_Scalar1; | 336 :
SK_Scalar1; |
| 338 while (text < stop) { | 337 while (text < stop) { |
| 339 const char* lastText = text; | 338 const char* lastText = text; |
| 340 // the last 2 parameters are ignored | 339 // the last 2 parameters are ignored |
| 341 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 340 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 342 | 341 |
| 343 if (glyph.fWidth) { | 342 if (glyph.fWidth) { |
| 344 SkScalar x = offset.x() + pos[0]; | 343 SkScalar x = offset.x() + pos[0]; |
| 345 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 344 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; |
| 346 | 345 |
| 347 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT
extRatio; | 346 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT
extRatio; |
| 348 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT
extRatio; | 347 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT
extRatio; |
| 349 | 348 |
| 350 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 349 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 351 glyph.getSubXFixed(), | 350 glyph.getSubXFixed(), |
| 352 glyph.getSubYFixed(), | 351 glyph.getSubYFixed()), |
| 353 GrGlyph::kDistance_MaskStyl
e), | |
| 354 x - advanceX, y - advanceY, fontScaler))
{ | 352 x - advanceX, y - advanceY, fontScaler))
{ |
| 355 // couldn't append, send to fallback | 353 // couldn't append, send to fallback |
| 356 fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); | 354 fallbackTxt.push_back_n(SkToInt(text-lastText), lastText); |
| 357 fallbackPos.push_back(pos[0]); | 355 fallbackPos.push_back(pos[0]); |
| 358 if (2 == scalarsPerPosition) { | 356 if (2 == scalarsPerPosition) { |
| 359 fallbackPos.push_back(pos[1]); | 357 fallbackPos.push_back(pos[1]); |
| 360 } | 358 } |
| 361 } | 359 } |
| 362 } | 360 } |
| 363 pos += scalarsPerPosition; | 361 pos += scalarsPerPosition; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // Returns true if this method handled the glyph, false if needs to be passed to
fallback | 502 // Returns true if this method handled the glyph, false if needs to be passed to
fallback |
| 505 // | 503 // |
| 506 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, | 504 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 507 SkScalar sx, SkScalar sy, | 505 SkScalar sx, SkScalar sy, |
| 508 GrFontScaler* scaler) { | 506 GrFontScaler* scaler) { |
| 509 if (NULL == fDrawTarget) { | 507 if (NULL == fDrawTarget) { |
| 510 return true; | 508 return true; |
| 511 } | 509 } |
| 512 | 510 |
| 513 if (NULL == fStrike) { | 511 if (NULL == fStrike) { |
| 514 fStrike = fContext->getFontCache()->getStrike(scaler); | 512 fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 515 } | 513 } |
| 516 | 514 |
| 517 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 515 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 518 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 516 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 519 return true; | 517 return true; |
| 520 } | 518 } |
| 521 | 519 |
| 522 // fallback to color glyph support | 520 // fallback to color glyph support |
| 523 if (kA8_GrMaskFormat != glyph->fMaskFormat) { | 521 if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 524 return false; | 522 return false; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 } | 718 } |
| 721 } | 719 } |
| 722 | 720 |
| 723 inline void GrDistanceFieldTextContext::finish() { | 721 inline void GrDistanceFieldTextContext::finish() { |
| 724 this->flush(); | 722 this->flush(); |
| 725 fTotalVertexCount = 0; | 723 fTotalVertexCount = 0; |
| 726 | 724 |
| 727 GrTextContext::finish(); | 725 GrTextContext::finish(); |
| 728 } | 726 } |
| 729 | 727 |
| OLD | NEW |