diff options
-rw-r--r-- | api/current.txt | 2 | ||||
-rw-r--r-- | core/jni/android/graphics/Paint.cpp | 8 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 41 |
3 files changed, 51 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index 53bd92f..b2a8b2d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8492,6 +8492,7 @@ package android.graphics { method public android.graphics.Paint.Align getTextAlign(); method public void getTextBounds(java.lang.String, int, int, android.graphics.Rect); method public void getTextBounds(char[], int, int, android.graphics.Rect); + method public java.util.Locale getTextLocale(); method public void getTextPath(char[], int, int, float, float, android.graphics.Path); method public void getTextPath(java.lang.String, int, int, float, float, android.graphics.Path); method public float getTextScaleX(); @@ -8541,6 +8542,7 @@ package android.graphics { method public void setStyle(android.graphics.Paint.Style); method public void setSubpixelText(boolean); method public void setTextAlign(android.graphics.Paint.Align); + method public void setTextLocale(java.util.Locale); method public void setTextScaleX(float); method public void setTextSize(float); method public void setTextSkewX(float); diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 376c841..a65262c 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -254,6 +254,13 @@ public: obj->setTextAlign(align); } + static void setTextLocale(JNIEnv* env, jobject clazz, SkPaint* obj, jstring locale) { + const char* localeArray = env->GetStringUTFChars(locale, NULL); + SkString skLocale(localeArray); + obj->setTextLocale(skLocale); + env->ReleaseStringUTFChars(locale, localeArray); + } + static jfloat getTextSize(JNIEnv* env, jobject paint) { NPE_CHECK_RETURN_ZERO(env, paint); return SkScalarToFloat(GraphicsJNI::getNativePaint(env, paint)->getTextSize()); @@ -817,6 +824,7 @@ static JNINativeMethod methods[] = { {"native_setRasterizer","(II)I", (void*) SkPaintGlue::setRasterizer}, {"native_getTextAlign","(I)I", (void*) SkPaintGlue::getTextAlign}, {"native_setTextAlign","(II)V", (void*) SkPaintGlue::setTextAlign}, + {"native_setTextLocale","(ILjava/lang/String;)V", (void*) SkPaintGlue::setTextLocale}, {"getTextSize","()F", (void*) SkPaintGlue::getTextSize}, {"setTextSize","(F)V", (void*) SkPaintGlue::setTextSize}, {"getTextScaleX","()F", (void*) SkPaintGlue::getTextScaleX}, 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, |