Skip to content

Commit 11d06a7

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Fix text encoding when drawing with drawPosText in software"
2 parents 7c0f282 + 62b6eaa commit 11d06a7

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

core/jni/android/graphics/Canvas.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,12 @@ class SkCanvasGlue {
820820
posPtr[indx].fX = SkFloatToScalar(posArray[indx << 1]);
821821
posPtr[indx].fY = SkFloatToScalar(posArray[(indx << 1) + 1]);
822822
}
823+
824+
SkPaint::TextEncoding encoding = paint->getTextEncoding();
825+
paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
823826
canvas->drawPosText(textArray + index, count << 1, posPtr, *paint);
827+
paint->setTextEncoding(encoding);
828+
824829
if (text) {
825830
env->ReleaseCharArrayElements(text, textArray, 0);
826831
}
@@ -844,7 +849,12 @@ class SkCanvasGlue {
844849
posPtr[indx].fX = SkFloatToScalar(posArray[indx << 1]);
845850
posPtr[indx].fY = SkFloatToScalar(posArray[(indx << 1) + 1]);
846851
}
852+
853+
SkPaint::TextEncoding encoding = paint->getTextEncoding();
854+
paint->setTextEncoding(SkPaint::kUTF16_TextEncoding);
847855
canvas->drawPosText(text_, byteLength << 1, posPtr, *paint);
856+
paint->setTextEncoding(encoding);
857+
848858
if (text) {
849859
env->ReleaseStringChars(text, (const jchar*) text_);
850860
}

graphics/java/android/graphics/Canvas.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,9 @@ public void drawTextRun(CharSequence text, int start, int end,
15161516
/**
15171517
* Draw the text in the array, with each character's origin specified by
15181518
* the pos array.
1519+
*
1520+
* This method does not support glyph composition and decomposition and
1521+
* should therefore not be used to render complex scripts.
15191522
*
15201523
* @param text The text to be drawn
15211524
* @param index The index of the first character to draw
@@ -1536,6 +1539,9 @@ public void drawPosText(char[] text, int index, int count, float[] pos,
15361539
/**
15371540
* Draw the text in the array, with each character's origin specified by
15381541
* the pos array.
1542+
*
1543+
* This method does not support glyph composition and decomposition and
1544+
* should therefore not be used to render complex scripts.
15391545
*
15401546
* @param text The text to be drawn
15411547
* @param pos Array of [x,y] positions, used to position each character

tests/HwAccelerationTest/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,16 @@
465465
</intent-filter>
466466
</activity>
467467

468+
<activity
469+
android:name="PosTextActivity"
470+
android:label="_PosText"
471+
android:theme="@android:style/Theme.NoTitleBar">
472+
<intent-filter>
473+
<action android:name="android.intent.action.MAIN" />
474+
<category android:name="android.intent.category.LAUNCHER" />
475+
</intent-filter>
476+
</activity>
477+
468478
<activity
469479
android:name="ListActivity"
470480
android:label="__List">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<resources>
18+
<string name="complex_string">"ตำแหน่งของตัวชี้"</string>
19+
</resources>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2010 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.android.test.hwui;
18+
19+
import android.app.Activity;
20+
import android.content.Context;
21+
import android.graphics.Canvas;
22+
import android.graphics.Paint;
23+
import android.os.Bundle;
24+
import android.view.View;
25+
26+
@SuppressWarnings({"UnusedDeclaration"})
27+
public class PosTextActivity extends Activity {
28+
@Override
29+
protected void onCreate(Bundle savedInstanceState) {
30+
super.onCreate(savedInstanceState);
31+
32+
setContentView(new CustomTextView(this));
33+
}
34+
35+
static class CustomTextView extends View {
36+
private final Paint mLargePaint;
37+
private final String mText;
38+
private final float[] mPos;
39+
40+
CustomTextView(Context c) {
41+
super(c);
42+
43+
mText = c.getResources().getString(R.string.complex_string);
44+
mPos = new float[mText.length() * 2];
45+
for (int i = 0; i < mPos.length; i += 2) {
46+
mPos[i] = i * 30.0f;
47+
mPos[i + 1] = i * 10.0f;
48+
}
49+
50+
mLargePaint = new Paint();
51+
mLargePaint.setAntiAlias(true);
52+
mLargePaint.setTextSize(36.0f);
53+
}
54+
55+
@Override
56+
protected void onDraw(Canvas canvas) {
57+
super.onDraw(canvas);
58+
canvas.drawRGB(255, 255, 255);
59+
60+
canvas.save();
61+
canvas.translate(100.0f, 100.0f);
62+
canvas.drawPosText(mText, mPos, mLargePaint);
63+
canvas.restore();
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)