| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // the last 2 parameters are ignored | 309 // the last 2 parameters are ignored |
| 310 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 310 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 311 | 311 |
| 312 if (glyph.fWidth) { | 312 if (glyph.fWidth) { |
| 313 SkScalar x = offset.x() + pos[0]; | 313 SkScalar x = offset.x() + pos[0]; |
| 314 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 314 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; |
| 315 | 315 |
| 316 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 316 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 317 glyph.getSubXFixed(), | 317 glyph.getSubXFixed(), |
| 318 glyph.getSubYFixed()), | 318 glyph.getSubYFixed()), |
| 319 SkScalarToFixed(x), | 319 x, y, fontScaler)) { |
| 320 SkScalarToFixed(y), | |
| 321 fontScaler)) { | |
| 322 // couldn't append, send to fallback | 320 // couldn't append, send to fallback |
| 323 fallbackTxt.push_back_n(text-lastText, lastText); | 321 fallbackTxt.push_back_n(text-lastText, lastText); |
| 324 fallbackPos.push_back(pos[0]); | 322 fallbackPos.push_back(pos[0]); |
| 325 if (2 == scalarsPerPosition) { | 323 if (2 == scalarsPerPosition) { |
| 326 fallbackPos.push_back(pos[1]); | 324 fallbackPos.push_back(pos[1]); |
| 327 } | 325 } |
| 328 } | 326 } |
| 329 } | 327 } |
| 330 pos += scalarsPerPosition; | 328 pos += scalarsPerPosition; |
| 331 } | 329 } |
| 332 } else { | 330 } else { |
| 333 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ?
SK_ScalarHalf | 331 SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ?
SK_ScalarHalf |
| 334 :
SK_Scalar1; | 332 :
SK_Scalar1; |
| 335 while (text < stop) { | 333 while (text < stop) { |
| 336 const char* lastText = text; | 334 const char* lastText = text; |
| 337 // the last 2 parameters are ignored | 335 // the last 2 parameters are ignored |
| 338 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 336 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 339 | 337 |
| 340 if (glyph.fWidth) { | 338 if (glyph.fWidth) { |
| 341 SkScalar x = offset.x() + pos[0]; | 339 SkScalar x = offset.x() + pos[0]; |
| 342 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; | 340 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0)
; |
| 343 | 341 |
| 344 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT
extRatio; | 342 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fT
extRatio; |
| 345 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT
extRatio; | 343 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fT
extRatio; |
| 346 | 344 |
| 347 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), | 345 if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(), |
| 348 glyph.getSubXFixed(), | 346 glyph.getSubXFixed(), |
| 349 glyph.getSubYFixed()), | 347 glyph.getSubYFixed()), |
| 350 SkScalarToFixed(x - advanceX), | 348 x - advanceX, y - advanceY, fontScaler))
{ |
| 351 SkScalarToFixed(y - advanceY), | |
| 352 fontScaler)) { | |
| 353 // couldn't append, send to fallback | 349 // couldn't append, send to fallback |
| 354 fallbackTxt.push_back_n(text-lastText, lastText); | 350 fallbackTxt.push_back_n(text-lastText, lastText); |
| 355 fallbackPos.push_back(pos[0]); | 351 fallbackPos.push_back(pos[0]); |
| 356 if (2 == scalarsPerPosition) { | 352 if (2 == scalarsPerPosition) { |
| 357 fallbackPos.push_back(pos[1]); | 353 fallbackPos.push_back(pos[1]); |
| 358 } | 354 } |
| 359 } | 355 } |
| 360 } | 356 } |
| 361 pos += scalarsPerPosition; | 357 pos += scalarsPerPosition; |
| 362 } | 358 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 fEffectTextureUniqueID = textureUniqueID; | 441 fEffectTextureUniqueID = textureUniqueID; |
| 446 fEffectColor = filteredColor; | 442 fEffectColor = filteredColor; |
| 447 fEffectFlags = flags; | 443 fEffectFlags = flags; |
| 448 } | 444 } |
| 449 | 445 |
| 450 } | 446 } |
| 451 | 447 |
| 452 // Returns true if this method handled the glyph, false if needs to be passed to
fallback | 448 // Returns true if this method handled the glyph, false if needs to be passed to
fallback |
| 453 // | 449 // |
| 454 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, | 450 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 455 SkFixed vx, SkFixed vy, | 451 SkScalar sx, SkScalar sy, |
| 456 GrFontScaler* scaler) { | 452 GrFontScaler* scaler) { |
| 457 if (NULL == fDrawTarget) { | 453 if (NULL == fDrawTarget) { |
| 458 return true; | 454 return true; |
| 459 } | 455 } |
| 460 | 456 |
| 461 if (NULL == fStrike) { | 457 if (NULL == fStrike) { |
| 462 fStrike = fContext->getFontCache()->getStrike(scaler, true); | 458 fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 463 } | 459 } |
| 464 | 460 |
| 465 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 461 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 466 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 462 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 467 return true; | 463 return true; |
| 468 } | 464 } |
| 469 | 465 |
| 470 // fallback to color glyph support | 466 // fallback to color glyph support |
| 471 if (kA8_GrMaskFormat != glyph->fMaskFormat) { | 467 if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 472 return false; | 468 return false; |
| 473 } | 469 } |
| 474 | 470 |
| 475 SkScalar sx = SkFixedToScalar(vx); | |
| 476 SkScalar sy = SkFixedToScalar(vy); | |
| 477 /* | 471 /* |
| 478 // not valid, need to find a different solution for this | 472 // not valid, need to find a different solution for this |
| 479 vx += SkIntToFixed(glyph->fBounds.fLeft); | 473 vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 480 vy += SkIntToFixed(glyph->fBounds.fTop); | 474 vy += SkIntToFixed(glyph->fBounds.fTop); |
| 481 | 475 |
| 482 // keep them as ints until we've done the clip-test | 476 // keep them as ints until we've done the clip-test |
| 483 GrFixed width = glyph->fBounds.width(); | 477 GrFixed width = glyph->fBounds.width(); |
| 484 GrFixed height = glyph->fBounds.height(); | 478 GrFixed height = glyph->fBounds.height(); |
| 485 | 479 |
| 486 // check if we clipped out | 480 // check if we clipped out |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 691 } |
| 698 } | 692 } |
| 699 | 693 |
| 700 inline void GrDistanceFieldTextContext::finish() { | 694 inline void GrDistanceFieldTextContext::finish() { |
| 701 this->flush(); | 695 this->flush(); |
| 702 fTotalVertexCount = 0; | 696 fTotalVertexCount = 0; |
| 703 | 697 |
| 704 GrTextContext::finish(); | 698 GrTextContext::finish(); |
| 705 } | 699 } |
| 706 | 700 |
| OLD | NEW |