2121import android .text .SpannedString ;
2222import android .text .TextUtils ;
2323
24+ import java .util .Locale ;
25+
2426/**
2527 * The Paint class holds the style and color information about how to draw
2628 * geometries, text and bitmaps.
@@ -44,6 +46,8 @@ public class Paint {
4446 private float mCompatScaling ;
4547 private float mInvCompatScaling ;
4648
49+ private Locale mLocale ;
50+
4751 /**
4852 * @hide
4953 */
@@ -348,6 +352,7 @@ public Paint(int flags) {
348352 // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV
349353 // ? HINTING_OFF : HINTING_ON);
350354 mCompatScaling = mInvCompatScaling = 1 ;
355+ mLocale = Locale .getDefault ();
351356 }
352357
353358 /**
@@ -360,6 +365,7 @@ public Paint(int flags) {
360365 public Paint (Paint paint ) {
361366 mNativePaint = native_initWithPaint (paint .mNativePaint );
362367 setClassVariablesFrom (paint );
368+ mLocale = paint .mLocale ;
363369 }
364370
365371 /** Restores the paint to its default settings. */
@@ -373,6 +379,7 @@ public void reset() {
373379 mHasCompatScaling = false ;
374380 mCompatScaling = mInvCompatScaling = 1 ;
375381 mBidiFlags = BIDI_DEFAULT_LTR ;
382+ mLocale = Locale .getDefault ();
376383 }
377384
378385 /**
@@ -412,6 +419,7 @@ private void setClassVariablesFrom(Paint paint) {
412419 shadowColor = paint .shadowColor ;
413420
414421 mBidiFlags = paint .mBidiFlags ;
422+ mLocale = paint .mLocale ;
415423 }
416424
417425 /** @hide */
@@ -1044,6 +1052,36 @@ public void setTextAlign(Align align) {
10441052 native_setTextAlign (mNativePaint , align .nativeInt );
10451053 }
10461054
1055+ /**
1056+ * Get the text Locale.
1057+ *
1058+ * @return the paint's Locale used for drawing text, never null.
1059+ */
1060+ public Locale getTextLocale () {
1061+ return mLocale ;
1062+ }
1063+
1064+ /**
1065+ * Set the text locale.
1066+ *
1067+ * This controls how the text will be drawn. Providing the ROOT Locale (default case)
1068+ * means that the text will be drawn with the font corresponding to its script.
1069+ *
1070+ * Using the CHINESE or CHINA Locale means that the text will be drawn with a Chinese font.
1071+ * Using the JAPANESE or JAPAN Locale means that the text will be drawn with a Japanese font.
1072+ * Using the KOREAN or KOREA Locale means that the text will be drawn with a Korean font.
1073+ *
1074+ * @param locale the paint's locale value for drawing text, must not be null.
1075+ */
1076+ public void setTextLocale (Locale locale ) {
1077+ if (locale == null ) {
1078+ throw new IllegalArgumentException ("locale cannot be null" );
1079+ }
1080+ if (locale .equals (mLocale )) return ;
1081+ mLocale = locale ;
1082+ native_setTextLocale (mNativePaint , locale .toString ());
1083+ }
1084+
10471085 /**
10481086 * Return the paint's text size.
10491087 *
@@ -2144,6 +2182,9 @@ private static native int native_setRasterizer(int native_object,
21442182 private static native void native_setTextAlign (int native_object ,
21452183 int align );
21462184
2185+ private static native void native_setTextLocale (int native_object ,
2186+ String locale );
2187+
21472188 private static native int native_getTextWidths (int native_object ,
21482189 char [] text , int index , int count , float [] widths );
21492190 private static native int native_getTextWidths (int native_object ,
0 commit comments