Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 62901af5 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Add Paint.setTextLocale()"

parents f98c8b32 517825f1
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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);
+8 −0
Original line number Diff line number Diff line
@@ -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},
+41 −0
Original line number Diff line number Diff line
@@ -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 */
@@ -1044,6 +1052,36 @@ public class Paint {
        native_setTextAlign(mNativePaint, align.nativeInt);
    }

    /**
     * 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.
     *
@@ -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,