diff options
| author | 2010-07-23 18:55:21 -0700 | |
|---|---|---|
| committer | 2010-07-23 18:55:21 -0700 | |
| commit | e8e62a4a032a80409114a37908b5f18ab0080848 (patch) | |
| tree | 7bd5be7505e21861a02dda702e24f94d8e9b24cc /libs/hwui/OpenGLRenderer.cpp | |
| parent | 9e05ed2f6860a2d34c339a1755dbb5f68081c62e (diff) | |
Add text alignment support to drawText().
This change also integrates better support for RTL text.
Change-Id: I6da8f5cf5dc28ca7cf1b22e27b0d853c919e8481
Diffstat (limited to 'libs/hwui/OpenGLRenderer.cpp')
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index c6a2e33cff78..d30d7180028e 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -525,7 +525,26 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom, drawColorRect(left, top, right, bottom, color, mode); } -void OpenGLRenderer::drawText(const char* text, int count, float x, float y, SkPaint* paint) { +void OpenGLRenderer::drawText(const char* text, int bytesCount, int count, + float x, float y, SkPaint* paint) { + if (text == NULL || count == 0 || (paint->getAlpha() == 0 && paint->getXfermode() == NULL)) { + return; + } + + float length; + switch (paint->getTextAlign()) { + case SkPaint::kCenter_Align: + length = paint->measureText(text, bytesCount); + x -= length / 2.0f; + break; + case SkPaint::kRight_Align: + length = paint->measureText(text, bytesCount); + x -= length; + break; + default: + break; + } + int alpha; SkXfermode::Mode mode; getAlphaAndMode(paint, &alpha, &mode); @@ -551,7 +570,7 @@ void OpenGLRenderer::drawText(const char* text, int count, float x, float y, SkP const Rect& clip = mSnapshot->getLocalClip(); mFontRenderer.setFont(SkTypeface::UniqueID(paint->getTypeface()), paint->getTextSize()); - mFontRenderer.renderText(paint, &clip, text, 0, count, count, x, y); + mFontRenderer.renderText(paint, &clip, text, 0, bytesCount, count, x, y); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } |