Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: src/gpu/GrTextContext.cpp

Issue 653133004: Change drawText() to generate positions and send to drawPosText() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add ignored GMs Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextContext.cpp
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 94c05a712439a8c8498c899a0059574df4c9e187..869706e6527aee6adf5c55d2747cf083b613702c 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -44,16 +44,63 @@ bool GrTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength,
SkScalar x, SkScalar y) {
- GrTextContext* textContext = this;
- do {
- if (textContext->canDraw(skPaint)) {
- textContext->onDrawText(paint, skPaint, text, byteLength, x, y);
- return true;
- }
- textContext = textContext->fFallbackTextContext;
- } while (textContext);
+ SkASSERT(byteLength == 0 || text != NULL);
- return false;
+ // nothing to draw
+ if (text == NULL || byteLength == 0) {
+ return true;
+ }
+
+ SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc();
+ SkAutoGlyphCache autoCache(skPaint, &fDeviceProperties, NULL);
+ SkGlyphCache* cache = autoCache.getCache();
+
+ SkTArray<SkScalar> positions;
+
+ const char* textPtr = text;
+ SkFixed stopX = 0;
+ SkFixed stopY = 0;
+ SkFixed origin;
+ switch (skPaint.getTextAlign()) {
+ case SkPaint::kRight_Align: origin = SK_Fixed1; break;
+ case SkPaint::kCenter_Align: origin = SK_FixedHalf; break;
+ case SkPaint::kLeft_Align: origin = 0; break;
+ default: SkFAIL("Invalid paint origin"); return false;
+ }
+
+ SkAutoKern autokern;
+ const char* stop = text + byteLength;
+ while (textPtr < stop) {
+ // don't need x, y here, since all subpixel variants will have the
+ // same advance
+ const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0);
+
+ SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph);
+ positions.push_back(SkFixedToScalar(stopX + SkFixedMul_portable(origin, width)));
+
+ SkFixed height = glyph.fAdvanceY;
+ positions.push_back(SkFixedToScalar(stopY + SkFixedMul_portable(origin, height)));
+
+ stopX += width;
+ stopY += height;
+ }
+ SkASSERT(textPtr == stop);
+
+ // now adjust starting point depending on alignment
+ SkScalar alignX = SkFixedToScalar(stopX);
+ SkScalar alignY = SkFixedToScalar(stopY);
+ if (skPaint.getTextAlign() == SkPaint::kCenter_Align) {
+ alignX = SkScalarHalf(alignX);
+ alignY = SkScalarHalf(alignY);
+ } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
+ alignX = 0;
+ alignY = 0;
+ }
+ x -= alignX;
+ y -= alignY;
+ SkPoint offset = SkPoint::Make(x, y);
+
+ return this->drawPosText(paint, skPaint, text, byteLength, positions.begin(), 2, offset);
}
bool GrTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
« no previous file with comments | « src/gpu/GrTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698