Skip to content

Commit 8b4072d

Browse files
committed
Fix bug 6892600 Font (character pairs) rendering issue
Alignment on paint for actual glyph drawing needs to always be left, even when drawing centered or right aligned text. The x offset for alignment is applied by OpenGLRenderer::drawText (and needs to be early in the pipeline for quickReject to work). Similar change needed for drawing drop shadow. Also fixes bug with mispositioned underline (offset for alignment has already been applied once, no need to do it again in drawTextDecorations). Change-Id: Id3dcd62de5536a26b158d768889273a1492b35d6
1 parent e72a6e9 commit 8b4072d

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

libs/hwui/OpenGLRenderer.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,13 +2508,14 @@ status_t OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
25082508
#endif
25092509

25102510
bool status;
2511-
if (positions != NULL) {
2512-
status = fontRenderer.renderPosText(paint, clip, text, 0, bytesCount, count, x, y,
2511+
if (paint->getTextAlign() != SkPaint::kLeft_Align) {
2512+
SkPaint paintCopy(*paint);
2513+
paintCopy.setTextAlign(SkPaint::kLeft_Align);
2514+
status = fontRenderer.renderPosText(&paintCopy, clip, text, 0, bytesCount, count, x, y,
25132515
positions, hasActiveLayer ? &bounds : NULL);
25142516
} else {
2515-
// TODO: would it be okay to call renderPosText with null positions?
2516-
status = fontRenderer.renderText(paint, clip, text, 0, bytesCount, count, x, y,
2517-
hasActiveLayer ? &bounds : NULL);
2517+
status = fontRenderer.renderPosText(paint, clip, text, 0, bytesCount, count, x, y,
2518+
positions, hasActiveLayer ? &bounds : NULL);
25182519
}
25192520
if (status) {
25202521
#if RENDER_LAYERS_AS_REGIONS
@@ -2801,23 +2802,11 @@ void OpenGLRenderer::drawTextDecorations(const char* text, int bytesCount, float
28012802
underlineWidth = paintCopy.measureText(text, bytesCount);
28022803
}
28032804

2804-
float offsetX = 0;
2805-
switch (paintCopy.getTextAlign()) {
2806-
case SkPaint::kCenter_Align:
2807-
offsetX = underlineWidth * 0.5f;
2808-
break;
2809-
case SkPaint::kRight_Align:
2810-
offsetX = underlineWidth;
2811-
break;
2812-
default:
2813-
break;
2814-
}
2815-
28162805
if (CC_LIKELY(underlineWidth > 0.0f)) {
28172806
const float textSize = paintCopy.getTextSize();
28182807
const float strokeWidth = fmax(textSize * kStdUnderline_Thickness, 1.0f);
28192808

2820-
const float left = x - offsetX;
2809+
const float left = x;
28212810
float top = 0.0f;
28222811

28232812
int linesCount = 0;

libs/hwui/TextDropShadowCache.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ ShadowTexture* TextDropShadowCache::get(SkPaint* paint, const char* text, uint32
107107
ShadowTexture* texture = mCache.get(entry);
108108

109109
if (!texture) {
110-
FontRenderer::DropShadow shadow = mRenderer->renderDropShadow(paint, text, 0,
110+
SkPaint paintCopy(*paint);
111+
paintCopy.setTextAlign(SkPaint::kLeft_Align);
112+
FontRenderer::DropShadow shadow = mRenderer->renderDropShadow(&paintCopy, text, 0,
111113
len, numGlyphs, radius, positions);
112114

113115
texture = new ShadowTexture;

0 commit comments

Comments
 (0)