From 18934c653fd6f31fd464dc7db83d583c864884dc Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Mon, 21 May 2018 13:46:38 -0400 Subject: Simplify aligment for DFT drawText The original code had to compensate for the alignment that was passed in throught the paint. You can simplifiy the code by just changing the paint to left alignment. Change-Id: I532ae5224ea5de078c6cd6255f03fc1db06baa83 Reviewed-on: https://skia-review.googlesource.com/129360 Reviewed-by: Jim Van Verth Commit-Queue: Herb Derby --- src/gpu/text/GrAtlasTextContext.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp index dfa0da83cd..1086bc4894 100644 --- a/src/gpu/text/GrAtlasTextContext.cpp +++ b/src/gpu/text/GrAtlasTextContext.cpp @@ -687,12 +687,6 @@ void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex, const char* textPtr = text; SkScalar stopX = 0; SkScalar stopY = 0; - SkScalar origin = 0; - switch (skPaint.getTextAlign()) { - case SkPaint::kRight_Align: origin = SK_Scalar1; break; - case SkPaint::kCenter_Align: origin = SK_ScalarHalf; break; - case SkPaint::kLeft_Align: origin = 0; break; - } SkAutoDescriptor desc; SkScalerContextEffects effects; @@ -712,14 +706,11 @@ void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex, // same advance const SkGlyph& glyph = glyphCacheProc(origPaintCache.get(), &textPtr); - SkScalar width = SkFloatToScalar(glyph.fAdvanceX); - positions.push_back(stopX + origin * width); - - SkScalar height = SkFloatToScalar(glyph.fAdvanceY); - positions.push_back(stopY + origin * height); + positions.push_back(stopX); + positions.push_back(stopY); - stopX += width; - stopY += height; + stopX += SkFloatToScalar(glyph.fAdvanceX); + stopY += SkFloatToScalar(glyph.fAdvanceY); } SkASSERT(textPtr == stop); } @@ -738,8 +729,13 @@ void GrAtlasTextContext::drawDFText(GrAtlasTextBlob* blob, int runIndex, y -= alignY; SkPoint offset = SkPoint::Make(x, y); - this->drawDFPosText(blob, runIndex, glyphCache, props, paint, scalerContextFlags, viewMatrix, - text, byteLength, positions.begin(), 2, offset); + SkPaint leftAlignedSkPaint(skPaint); + leftAlignedSkPaint.setTextAlign(SkPaint::kLeft_Align); + + GrTextUtils::Paint leftAlignedPaint(&leftAlignedSkPaint, paint.dstColorSpaceInfo()); + + this->drawDFPosText(blob, runIndex, glyphCache, props, leftAlignedPaint, scalerContextFlags, + viewMatrix, text, byteLength, positions.begin(), 2, offset); } void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex, -- cgit v1.2.3