Merge "Fix text corruption when rendering RTL enabled text."

This commit is contained in:
Romain Guy
2010-07-26 11:39:27 -07:00
committed by Android (Google) Code Review
3 changed files with 10 additions and 6 deletions

View File

@@ -151,7 +151,7 @@ jint TextLayout::layoutLine(const jchar* text, jint len, jint flags, int &dir, j
}
bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags,
const jchar** outText, int32_t* outBytes) {
const jchar** outText, int32_t* outBytes, jchar** outBuffer) {
const jchar *workText = text;
jchar *buffer = NULL;
int dir = kDirection_LTR;
@@ -196,8 +196,8 @@ bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint
*outBytes = (workLimit - workText) << 1;
*outText = workText;
free(buffer);
*outBuffer = buffer;
return true;
}
@@ -207,8 +207,9 @@ bool TextLayout::prepareText(SkPaint *paint, const jchar* text, jsize len, jint
void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len,
jint bidiFlags, jfloat x, jfloat y,SkCanvas *canvas, SkPath *path) {
const jchar *workText;
jchar *buffer = NULL;
int32_t workBytes;
if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes)) {
if (prepareText(paint, text, len, bidiFlags, &workText, &workBytes, &buffer)) {
SkScalar x_ = SkFloatToScalar(x);
SkScalar y_ = SkFloatToScalar(y);
if (canvas) {
@@ -216,6 +217,7 @@ void TextLayout::handleText(SkPaint *paint, const jchar* text, jsize len,
} else {
paint->getTextPath(workText, workBytes, x_, y_, path);
}
free(buffer);
}
}

View File

@@ -65,7 +65,7 @@ public:
SkPath* path, SkCanvas* canvas);
static bool prepareText(SkPaint *paint, const jchar* text, jsize len, jint bidiFlags,
const jchar** outText, int32_t* outBytes);
const jchar** outText, int32_t* outBytes, jchar** outBuffer);
private:
static bool needsLayout(const jchar* text, jint len, jint bidiFlags);

View File

@@ -256,9 +256,11 @@ static void android_view_GLES20Canvas_setupLinearShader(JNIEnv* env, jobject can
static void renderText(OpenGLRenderer* renderer, const jchar* text, int count,
jfloat x, jfloat y, int flags, SkPaint* paint) {
const jchar *workText;
jchar* buffer = NULL;
int32_t workBytes;
if (TextLayout::prepareText(paint, text, count, flags, &workText, &workBytes)) {
if (TextLayout::prepareText(paint, text, count, flags, &workText, &workBytes, &buffer)) {
renderer->drawText((const char*) workText, workBytes, count, x, y, paint);
free(buffer);
}
}