Chromium Code Reviews| 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(), |
|
jvanverth1
2014/10/30 16:37:16
There is another call to appendGlyph here.
| |
| 348 glyph.getSubXFixed(), | 346 glyph.getSubXFixed(), |
| 349 glyph.getSubYFixed()), | 347 glyph.getSubYFixed()), |
| 350 SkScalarToFixed(x - advanceX), | 348 SkScalarToFixed(x - advanceX), |
| 351 SkScalarToFixed(y - advanceY), | 349 SkScalarToFixed(y - advanceY), |
| 352 fontScaler)) { | 350 fontScaler)) { |
| 353 // couldn't append, send to fallback | 351 // couldn't append, send to fallback |
| 354 fallbackTxt.push_back_n(text-lastText, lastText); | 352 fallbackTxt.push_back_n(text-lastText, lastText); |
| 355 fallbackPos.push_back(pos[0]); | 353 fallbackPos.push_back(pos[0]); |
| 356 if (2 == scalarsPerPosition) { | 354 if (2 == scalarsPerPosition) { |
| 357 fallbackPos.push_back(pos[1]); | 355 fallbackPos.push_back(pos[1]); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 fEffectTextureUniqueID = textureUniqueID; | 443 fEffectTextureUniqueID = textureUniqueID; |
| 446 fEffectColor = filteredColor; | 444 fEffectColor = filteredColor; |
| 447 fEffectFlags = flags; | 445 fEffectFlags = flags; |
| 448 } | 446 } |
| 449 | 447 |
| 450 } | 448 } |
| 451 | 449 |
| 452 // Returns true if this method handled the glyph, false if needs to be passed to fallback | 450 // Returns true if this method handled the glyph, false if needs to be passed to fallback |
| 453 // | 451 // |
| 454 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, | 452 bool GrDistanceFieldTextContext::appendGlyph(GrGlyph::PackedID packed, |
| 455 SkFixed vx, SkFixed vy, | 453 SkScalar sx, SkScalar sy, |
| 456 GrFontScaler* scaler) { | 454 GrFontScaler* scaler) { |
| 457 if (NULL == fDrawTarget) { | 455 if (NULL == fDrawTarget) { |
| 458 return true; | 456 return true; |
| 459 } | 457 } |
| 460 | 458 |
| 461 if (NULL == fStrike) { | 459 if (NULL == fStrike) { |
| 462 fStrike = fContext->getFontCache()->getStrike(scaler, true); | 460 fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 463 } | 461 } |
| 464 | 462 |
| 465 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 463 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 466 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 464 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 467 return true; | 465 return true; |
| 468 } | 466 } |
| 469 | 467 |
| 470 // fallback to color glyph support | 468 // fallback to color glyph support |
| 471 if (kA8_GrMaskFormat != glyph->fMaskFormat) { | 469 if (kA8_GrMaskFormat != glyph->fMaskFormat) { |
| 472 return false; | 470 return false; |
| 473 } | 471 } |
| 474 | 472 |
| 475 SkScalar sx = SkFixedToScalar(vx); | |
| 476 SkScalar sy = SkFixedToScalar(vy); | |
| 477 /* | 473 /* |
| 478 // not valid, need to find a different solution for this | 474 // not valid, need to find a different solution for this |
| 479 vx += SkIntToFixed(glyph->fBounds.fLeft); | 475 vx += SkIntToFixed(glyph->fBounds.fLeft); |
| 480 vy += SkIntToFixed(glyph->fBounds.fTop); | 476 vy += SkIntToFixed(glyph->fBounds.fTop); |
| 481 | 477 |
| 482 // keep them as ints until we've done the clip-test | 478 // keep them as ints until we've done the clip-test |
| 483 GrFixed width = glyph->fBounds.width(); | 479 GrFixed width = glyph->fBounds.width(); |
| 484 GrFixed height = glyph->fBounds.height(); | 480 GrFixed height = glyph->fBounds.height(); |
| 485 | 481 |
| 486 // check if we clipped out | 482 // check if we clipped out |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 } | 693 } |
| 698 } | 694 } |
| 699 | 695 |
| 700 inline void GrDistanceFieldTextContext::finish() { | 696 inline void GrDistanceFieldTextContext::finish() { |
| 701 this->flush(); | 697 this->flush(); |
| 702 fTotalVertexCount = 0; | 698 fTotalVertexCount = 0; |
| 703 | 699 |
| 704 GrTextContext::finish(); | 700 GrTextContext::finish(); |
| 705 } | 701 } |
| 706 | 702 |
| OLD | NEW |