From 517825f1a9f14f92908bd7859b91b927c2eec6d9 Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Fri, 6 Apr 2012 16:53:48 -0700 Subject: Add Paint.setTextLocale() - will be used for better shaping CJK and other goodies Change-Id: If64945a337edd915f5ebb88f04b6fd18e92ca587 --- graphics/java/android/graphics/Paint.java | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'graphics') diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index c97785e..8cb8466 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -21,6 +21,8 @@ import android.text.SpannableString; import android.text.SpannedString; import android.text.TextUtils; +import java.util.Locale; + /** * The Paint class holds the style and color information about how to draw * geometries, text and bitmaps. @@ -44,6 +46,8 @@ public class Paint { private float mCompatScaling; private float mInvCompatScaling; + private Locale mLocale; + /** * @hide */ @@ -348,6 +352,7 @@ public class Paint { // setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV // ? HINTING_OFF : HINTING_ON); mCompatScaling = mInvCompatScaling = 1; + mLocale = Locale.getDefault(); } /** @@ -360,6 +365,7 @@ public class Paint { public Paint(Paint paint) { mNativePaint = native_initWithPaint(paint.mNativePaint); setClassVariablesFrom(paint); + mLocale = paint.mLocale; } /** Restores the paint to its default settings. */ @@ -373,6 +379,7 @@ public class Paint { mHasCompatScaling = false; mCompatScaling = mInvCompatScaling = 1; mBidiFlags = BIDI_DEFAULT_LTR; + mLocale = Locale.getDefault(); } /** @@ -412,6 +419,7 @@ public class Paint { shadowColor = paint.shadowColor; mBidiFlags = paint.mBidiFlags; + mLocale = paint.mLocale; } /** @hide */ @@ -1045,6 +1053,36 @@ public class Paint { } /** + * Get the text Locale. + * + * @return the paint's Locale used for drawing text, never null. + */ + public Locale getTextLocale() { + return mLocale; + } + + /** + * Set the text locale. + * + * This controls how the text will be drawn. Providing the ROOT Locale (default case) + * means that the text will be drawn with the font corresponding to its script. + * + * Using the CHINESE or CHINA Locale means that the text will be drawn with a Chinese font. + * Using the JAPANESE or JAPAN Locale means that the text will be drawn with a Japanese font. + * Using the KOREAN or KOREA Locale means that the text will be drawn with a Korean font. + * + * @param locale the paint's locale value for drawing text, must not be null. + */ + public void setTextLocale(Locale locale) { + if (locale == null) { + throw new IllegalArgumentException("locale cannot be null"); + } + if (locale.equals(mLocale)) return; + mLocale = locale; + native_setTextLocale(mNativePaint, locale.toString()); + } + + /** * Return the paint's text size. * * @return the paint's text size. @@ -2144,6 +2182,9 @@ public class Paint { private static native void native_setTextAlign(int native_object, int align); + private static native void native_setTextLocale(int native_object, + String locale); + private static native int native_getTextWidths(int native_object, char[] text, int index, int count, float[] widths); private static native int native_getTextWidths(int native_object, -- cgit v1.1