FileDocCategorySizeDatePackage
Paint_Delegate.javaAPI DocAndroid 5.1 API40858Thu Mar 12 22:22:44 GMT 2015android.graphics

Paint_Delegate

public class Paint_Delegate extends Object
Delegate implementing the native methods of android.graphics.Paint Through the layoutlib_create tool, the original native methods of Paint have been replaced by calls to methods of the same name in this delegate class. This class behaves like the original native implementation, but in Java, keeping previously native data into its own objects and mapping them to int that are sent back and forth between it and the original Paint class.
see
DelegateManager

Fields Summary
private static final com.android.layoutlib.bridge.impl.DelegateManager
sManager
private List
mFonts
private int
mFlags
private int
mColor
private int
mStyle
private int
mCap
private int
mJoin
private int
mTextAlign
private Typeface_Delegate
mTypeface
private float
mStrokeWidth
private float
mStrokeMiter
private float
mTextSize
private float
mTextScaleX
private float
mTextSkewX
private int
mHintingMode
private android.graphics.FontFamily_Delegate.FontVariant
mFontVariant
private Xfermode_Delegate
mXfermode
private ColorFilter_Delegate
mColorFilter
private Shader_Delegate
mShader
private PathEffect_Delegate
mPathEffect
private MaskFilter_Delegate
mMaskFilter
private Rasterizer_Delegate
mRasterizer
private Locale
mLocale
public long
mNativeTypeface
Constructors Summary
Paint_Delegate()

        reset();
    
private Paint_Delegate(Paint_Delegate paint)

        set(paint);
    
Methods Summary
static floatascent(Paint thisPaint)

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        if (delegate.mFonts.size() > 0) {
            java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics;
            // Android expects negative ascent so we invert the value from Java.
            return - javaMetrics.getAscent();
        }

        return 0;
    
static floatdescent(Paint thisPaint)

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        if (delegate.mFonts.size() > 0) {
            java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics;
            return javaMetrics.getDescent();
        }

        return 0;

    
static voidfinalizer(long nativePaint)

        sManager.removeJavaReferenceFor(nativePaint);
    
static intgetAlpha(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        return delegate.getAlpha();
    
public intgetAlpha()

        return mColor >>> 24;
    
static intgetColor(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        return delegate.mColor;
    
public intgetColor()

        return mColor;
    
public ColorFilter_DelegategetColorFilter()
Returns the {@link ColorFilter} delegate or null if none have been set

return
the delegate or null.

        return mColorFilter;
    
public static android.graphics.Paint_DelegategetDelegate(long native_paint)


    // ---- Public Helper methods ----

         
        return sManager.getDelegate(native_paint);
    
static intgetFlags(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        return delegate.mFlags;
    
private floatgetFontMetrics(android.graphics.Paint.FontMetrics metrics)

        if (mFonts.size() > 0) {
            java.awt.FontMetrics javaMetrics = mFonts.get(0).mMetrics;
            if (metrics != null) {
                // Android expects negative ascent so we invert the value from Java.
                metrics.top = - javaMetrics.getMaxAscent();
                metrics.ascent = - javaMetrics.getAscent();
                metrics.descent = javaMetrics.getDescent();
                metrics.bottom = javaMetrics.getMaxDescent();
                metrics.leading = javaMetrics.getLeading();
            }

            return javaMetrics.getHeight();
        }

        return 0;
    
static floatgetFontMetrics(Paint thisPaint, android.graphics.Paint.FontMetrics metrics)

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        return delegate.getFontMetrics(metrics);
    
static intgetFontMetricsInt(Paint thisPaint, android.graphics.Paint.FontMetricsInt fmi)

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        if (delegate.mFonts.size() > 0) {
            java.awt.FontMetrics javaMetrics = delegate.mFonts.get(0).mMetrics;
            if (fmi != null) {
                // Android expects negative ascent so we invert the value from Java.
                fmi.top = - javaMetrics.getMaxAscent();
                fmi.ascent = - javaMetrics.getAscent();
                fmi.descent = javaMetrics.getDescent();
                fmi.bottom = javaMetrics.getMaxDescent();
                fmi.leading = javaMetrics.getLeading();
            }

            return javaMetrics.getHeight();
        }

        return 0;
    
public java.util.ListgetFonts()
Returns the list of {@link Font} objects.

        return mFonts;
    
static intgetHinting(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return Paint.HINTING_ON;
        }

        return delegate.mHintingMode;
    
public intgetJavaCap()

        switch (Paint.sCapArray[mCap]) {
            case BUTT:
                return BasicStroke.CAP_BUTT;
            case ROUND:
                return BasicStroke.CAP_ROUND;
            default:
            case SQUARE:
                return BasicStroke.CAP_SQUARE;
        }
    
public intgetJavaJoin()

        switch (Paint.sJoinArray[mJoin]) {
            default:
            case MITER:
                return BasicStroke.JOIN_MITER;
            case ROUND:
                return BasicStroke.JOIN_ROUND;
            case BEVEL:
                return BasicStroke.JOIN_BEVEL;
        }
    
public java.awt.StrokegetJavaStroke()

        if (mPathEffect != null) {
            if (mPathEffect.isSupported()) {
                Stroke stroke = mPathEffect.getStroke(this);
                assert stroke != null;
                if (stroke != null) {
                    return stroke;
                }
            } else {
                Bridge.getLog().fidelityWarning(LayoutLog.TAG_PATHEFFECT,
                        mPathEffect.getSupportMessage(),
                        null, null /*data*/);
            }
        }

        // if no custom stroke as been set, set the default one.
        return new BasicStroke(
                    getStrokeWidth(),
                    getJavaCap(),
                    getJavaJoin(),
                    getJavaStrokeMiter());
    
public floatgetJavaStrokeMiter()
returns the value of stroke miter needed by the java api.

        float miter = mStrokeMiter * mStrokeWidth;
        if (miter < 1.f) {
            miter = 1.f;
        }
        return miter;
    
public MaskFilter_DelegategetMaskFilter()
Returns the {@link MaskFilter} delegate or null if none have been set

return
the delegate or null.

        return mMaskFilter;
    
public Rasterizer_DelegategetRasterizer()
Returns the {@link Rasterizer} delegate or null if none have been set

return
the delegate or null.

        return mRasterizer;
    
public Shader_DelegategetShader()
Returns the {@link Shader} delegate or null if none have been set

return
the delegate or null.

        return mShader;
    
static floatgetStrokeMiter(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 1.f;
        }

        return delegate.mStrokeMiter;
    
public floatgetStrokeWidth()

        return mStrokeWidth;
    
static floatgetStrokeWidth(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 1.f;
        }

        return delegate.mStrokeWidth;
    
public intgetStyle()

        return mStyle;
    
public intgetTextAlign()

        return mTextAlign;
    
static floatgetTextScaleX(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 1.f;
        }

        return delegate.mTextScaleX;
    
static floatgetTextSize(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 1.f;
        }

        return delegate.mTextSize;
    
static floatgetTextSkewX(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 1.f;
        }

        return delegate.mTextSkewX;
    
public Xfermode_DelegategetXfermode()
Returns the {@link Xfermode} delegate or null if none have been set

return
the delegate or null.

        return mXfermode;
    
public booleanisAntiAliased()

        return (mFlags & Paint.ANTI_ALIAS_FLAG) != 0;
    
static booleanisElegantTextHeight(Paint thisPaint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        return delegate != null && delegate.mFontVariant == FontVariant.ELEGANT;
    
public booleanisFilterBitmap()

        return (mFlags & Paint.FILTER_BITMAP_FLAG) != 0;
    
RectFmeasureText(char[] text, int index, int count, float[] advances, int advancesIndex, int bidiFlags)

        return new BidiRenderer(null, this, text)
                .renderText(index, index + count, bidiFlags, advances, advancesIndex, false);
    
RectFmeasureText(char[] text, int index, int count, float[] advances, int advancesIndex, boolean isRtl)

        return new BidiRenderer(null, this, text)
                .renderText(index, index + count, isRtl, advances, advancesIndex, false);
    
static voidnativeGetCharArrayBounds(long nativePaint, long native_typeface, char[] text, int index, int count, int bidiFlags, Rect bounds)


        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(nativePaint);
        if (delegate == null) {
            return;
        }

        // assert that the typeface passed is actually the one that we had stored.
        assert (native_typeface == delegate.mNativeTypeface);

        delegate.measureText(text, index, count, null, 0, bidiFlags).roundOut(bounds);
    
static voidnativeGetStringBounds(long nativePaint, long native_typeface, java.lang.String text, int start, int end, int bidiFlags, Rect bounds)

        nativeGetCharArrayBounds(nativePaint, native_typeface, text.toCharArray(), start,
                end - start, bidiFlags, bounds);
    
static intnative_breakText(long nativePaint, long nativeTypeface, char[] text, int index, int count, float maxWidth, int bidiFlags, float[] measuredWidth)


        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(nativePaint);
        if (delegate == null) {
            return 0;
        }

        int inc = count > 0 ? 1 : -1;

        int measureIndex = 0;
        for (int i = index; i != index + count; i += inc, measureIndex++) {
            int start, end;
            if (i < index) {
                start = i;
                end = index;
            } else {
                start = index;
                end = i;
            }

            // measure from start to end
            RectF bounds = delegate.measureText(text, start, end - start + 1, null, 0, bidiFlags);
            float res = bounds.right - bounds.left;

            if (measuredWidth != null) {
                measuredWidth[measureIndex] = res;
            }

            if (res > maxWidth) {
                // we should not return this char index, but since it's 0-based
                // and we need to return a count, we simply return measureIndex;
                return measureIndex;
            }

        }

        return measureIndex;
    
static intnative_breakText(long nativePaint, long nativeTypeface, java.lang.String text, boolean measureForwards, float maxWidth, int bidiFlags, float[] measuredWidth)

        return native_breakText(nativePaint, nativeTypeface, text.toCharArray(), 0, text.length(),
                maxWidth, bidiFlags, measuredWidth);
    
static booleannative_getFillPath(long native_object, long src, long dst)

        Paint_Delegate paint = sManager.getDelegate(native_object);
        if (paint == null) {
            return false;
        }

        Path_Delegate srcPath = Path_Delegate.getDelegate(src);
        if (srcPath == null) {
            return true;
        }

        Path_Delegate dstPath = Path_Delegate.getDelegate(dst);
        if (dstPath == null) {
            return true;
        }

        Stroke stroke = paint.getJavaStroke();
        Shape strokeShape = stroke.createStrokedShape(srcPath.getJavaShape());

        dstPath.setJavaShape(strokeShape);

        // FIXME figure out the return value?
        return true;
    
static floatnative_getLetterSpacing(long nativePaint)

        // TODO: throw a fidelity warning.
        return 0;
    
static intnative_getStrokeCap(long native_object)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        return delegate.mCap;
    
static intnative_getStrokeJoin(long native_object)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        return delegate.mJoin;
    
static intnative_getStyle(long native_object)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        return delegate.mStyle;
    
static intnative_getTextAlign(long native_object)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        return delegate.mTextAlign;
    
static intnative_getTextGlyphs(long native_object, java.lang.String text, int start, int end, int contextStart, int contextEnd, int flags, char[] glyphs)

        // FIXME
        return 0;
    
static voidnative_getTextPath(long native_object, long native_typeface, int bidiFlags, char[] text, int index, int count, float x, float y, long path)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextPath is not supported.", null, null /*data*/);
    
static voidnative_getTextPath(long native_object, long native_typeface, int bidiFlags, java.lang.String text, int start, int end, float x, float y, long path)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextPath is not supported.", null, null /*data*/);
    
static floatnative_getTextRunAdvances(long native_object, long native_typeface, char[] text, int index, int count, int contextIndex, int contextCount, boolean isRtl, float[] advances, int advancesIndex)


        if (advances != null)
            for (int i = advancesIndex; i< advancesIndex+count; i++)
                advances[i]=0;
        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0.f;
        }

        // native_typeface is passed here since Framework's old implementation did not have the
        // typeface object associated with the Paint. Since, we follow the new framework way,
        // we store the typeface with the paint and use it directly.
        assert (native_typeface == delegate.mNativeTypeface);

        RectF bounds = delegate.measureText(text, index, count, advances, advancesIndex, isRtl);
        return bounds.right - bounds.left;
    
static floatnative_getTextRunAdvances(long native_object, long native_typeface, java.lang.String text, int start, int end, int contextStart, int contextEnd, boolean isRtl, float[] advances, int advancesIndex)

        // FIXME: support contextStart and contextEnd
        int count = end - start;
        char[] buffer = TemporaryBuffer.obtain(count);
        TextUtils.getChars(text, start, end, buffer, 0);

        return native_getTextRunAdvances(native_object, native_typeface, buffer, 0, count,
                contextStart, contextEnd - contextStart, isRtl, advances, advancesIndex);
    
static intnative_getTextRunCursor(Paint thisPaint, long native_object, char[] text, int contextStart, int contextLength, int flags, int offset, int cursorOpt)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextRunCursor is not supported.", null, null /*data*/);
        return 0;
    
static intnative_getTextRunCursor(Paint thisPaint, long native_object, java.lang.String text, int contextStart, int contextEnd, int flags, int offset, int cursorOpt)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.getTextRunCursor is not supported.", null, null /*data*/);
        return 0;
    
static intnative_getTextWidths(long native_object, long native_typeface, char[] text, int index, int count, int bidiFlags, float[] widths)


        if (widths != null) {
            for (int i = 0; i< count; i++) {
                widths[i]=0;
            }
        }
        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        // native_typeface is passed here since Framework's old implementation did not have the
        // typeface object associated with the Paint. Since, we follow the new framework way,
        // we store the typeface with the paint and use it directly.
        assert (native_typeface == delegate.mNativeTypeface);

        RectF bounds = delegate.measureText(text, index, count, widths, 0, bidiFlags);
        return ((int) (bounds.right - bounds.left));
    
static intnative_getTextWidths(long native_object, long native_typeface, java.lang.String text, int start, int end, int bidiFlags, float[] widths)

        return native_getTextWidths(native_object, native_typeface, text.toCharArray(), start,
                end - start, bidiFlags, widths);
    
static booleannative_hasShadowLayer(long paint)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.hasShadowLayer is not supported.", null, null /*data*/);
        return false;
    
static longnative_init()

        Paint_Delegate newDelegate = new Paint_Delegate();
        return sManager.addNewDelegate(newDelegate);
    
static longnative_initWithPaint(long paint)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(paint);
        if (delegate == null) {
            return 0;
        }

        Paint_Delegate newDelegate = new Paint_Delegate(delegate);
        return sManager.addNewDelegate(newDelegate);
    
static floatnative_measureText(Paint thisPaint, char[] text, int index, int count, int bidiFlags)

        // get the delegate
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return 0;
        }

        RectF bounds = delegate.measureText(text, index, count, null, 0, bidiFlags);
        return bounds.right - bounds.left;
    
static floatnative_measureText(Paint thisPaint, java.lang.String text, int start, int end, int bidiFlags)

        return native_measureText(thisPaint, text.toCharArray(), start, end - start, bidiFlags);
    
static floatnative_measureText(Paint thisPaint, java.lang.String text, int bidiFlags)

        return native_measureText(thisPaint, text.toCharArray(), 0, text.length(), bidiFlags);
    
static voidnative_reset(long native_object)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.reset();
    
static voidnative_set(long native_dst, long native_src)

        // get the delegate from the native int.
        Paint_Delegate delegate_dst = sManager.getDelegate(native_dst);
        if (delegate_dst == null) {
            return;
        }

        // get the delegate from the native int.
        Paint_Delegate delegate_src = sManager.getDelegate(native_src);
        if (delegate_src == null) {
            return;
        }

        delegate_dst.set(delegate_src);
    
static longnative_setColorFilter(long native_object, long filter)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return filter;
        }

        delegate.mColorFilter = ColorFilter_Delegate.getDelegate(filter);

        // Log warning if it's not supported.
        if (delegate.mColorFilter != null && !delegate.mColorFilter.isSupported()) {
            Bridge.getLog().fidelityWarning(LayoutLog.TAG_COLORFILTER,
                    delegate.mColorFilter.getSupportMessage(), null, null /*data*/);
        }

        return filter;
    
static voidnative_setFontFeatureSettings(long nativePaint, java.lang.String settings)

        // pass.
    
static voidnative_setLetterSpacing(long nativePaint, float letterSpacing)

        // pass.
    
static longnative_setMaskFilter(long native_object, long maskfilter)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return maskfilter;
        }

        delegate.mMaskFilter = MaskFilter_Delegate.getDelegate(maskfilter);

        // since none of those are supported, display a fidelity warning right away
        if (delegate.mMaskFilter != null && !delegate.mMaskFilter.isSupported()) {
            Bridge.getLog().fidelityWarning(LayoutLog.TAG_MASKFILTER,
                    delegate.mMaskFilter.getSupportMessage(), null, null /*data*/);
        }

        return maskfilter;
    
static longnative_setPathEffect(long native_object, long effect)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return effect;
        }

        delegate.mPathEffect = PathEffect_Delegate.getDelegate(effect);

        return effect;
    
static longnative_setRasterizer(long native_object, long rasterizer)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return rasterizer;
        }

        delegate.mRasterizer = Rasterizer_Delegate.getDelegate(rasterizer);

        // since none of those are supported, display a fidelity warning right away
        if (delegate.mRasterizer != null && !delegate.mRasterizer.isSupported()) {
            Bridge.getLog().fidelityWarning(LayoutLog.TAG_RASTERIZER,
                    delegate.mRasterizer.getSupportMessage(), null, null /*data*/);
        }

        return rasterizer;
    
static longnative_setShader(long native_object, long shader)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return shader;
        }

        delegate.mShader = Shader_Delegate.getDelegate(shader);

        return shader;
    
static voidnative_setShadowLayer(long paint, float radius, float dx, float dy, int color)

        // FIXME
        Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
                "Paint.setShadowLayer is not supported.", null, null /*data*/);
    
static voidnative_setStrokeCap(long native_object, int cap)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.mCap = cap;
    
static voidnative_setStrokeJoin(long native_object, int join)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.mJoin = join;
    
static voidnative_setStyle(long native_object, int style)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.mStyle = style;
    
static voidnative_setTextAlign(long native_object, int align)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.mTextAlign = align;
    
static voidnative_setTextLocale(long native_object, java.lang.String locale)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return;
        }

        delegate.setTextLocale(locale);
    
static longnative_setTypeface(long native_object, long typeface)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return 0;
        }

        delegate.mTypeface = Typeface_Delegate.getDelegate(typeface);
        delegate.mNativeTypeface = typeface;
        delegate.updateFontObject();
        return typeface;
    
static longnative_setXfermode(long native_object, long xfermode)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(native_object);
        if (delegate == null) {
            return xfermode;
        }

        delegate.mXfermode = Xfermode_Delegate.getDelegate(xfermode);

        return xfermode;
    
private voidreset()

        mFlags = Paint.DEFAULT_PAINT_FLAGS;
        mColor = 0xFF000000;
        mStyle = Paint.Style.FILL.nativeInt;
        mCap = Paint.Cap.BUTT.nativeInt;
        mJoin = Paint.Join.MITER.nativeInt;
        mTextAlign = 0;
        mTypeface = Typeface_Delegate.getDelegate(Typeface.sDefaults[0].native_instance);
        mNativeTypeface = 0;
        mStrokeWidth = 1.f;
        mStrokeMiter = 4.f;
        mTextSize = 20.f;
        mTextScaleX = 1.f;
        mTextSkewX = 0.f;
        mXfermode = null;
        mColorFilter = null;
        mShader = null;
        mPathEffect = null;
        mMaskFilter = null;
        mRasterizer = null;
        updateFontObject();
        mHintingMode = Paint.HINTING_ON;
    
private voidset(android.graphics.Paint_Delegate paint)

        mFlags = paint.mFlags;
        mColor = paint.mColor;
        mStyle = paint.mStyle;
        mCap = paint.mCap;
        mJoin = paint.mJoin;
        mTextAlign = paint.mTextAlign;
        mTypeface = paint.mTypeface;
        mNativeTypeface = paint.mNativeTypeface;
        mStrokeWidth = paint.mStrokeWidth;
        mStrokeMiter = paint.mStrokeMiter;
        mTextSize = paint.mTextSize;
        mTextScaleX = paint.mTextScaleX;
        mTextSkewX = paint.mTextSkewX;
        mXfermode = paint.mXfermode;
        mColorFilter = paint.mColorFilter;
        mShader = paint.mShader;
        mPathEffect = paint.mPathEffect;
        mMaskFilter = paint.mMaskFilter;
        mRasterizer = paint.mRasterizer;
        mHintingMode = paint.mHintingMode;
        updateFontObject();
    
static voidsetAlpha(Paint thisPaint, int a)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.setAlpha(a);
    
public voidsetAlpha(int alpha)

        mColor = (alpha << 24) | (mColor & 0x00FFFFFF);
    
static voidsetAntiAlias(Paint thisPaint, boolean aa)

        setFlag(thisPaint, Paint.ANTI_ALIAS_FLAG, aa);
    
static voidsetColor(Paint thisPaint, int color)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mColor = color;
    
static voidsetDither(Paint thisPaint, boolean dither)

        setFlag(thisPaint, Paint.DITHER_FLAG, dither);
    
static voidsetElegantTextHeight(Paint thisPaint, boolean elegant)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mFontVariant = elegant ? FontVariant.ELEGANT : FontVariant.COMPACT;
    
static voidsetFakeBoldText(Paint thisPaint, boolean fakeBoldText)

        setFlag(thisPaint, Paint.FAKE_BOLD_TEXT_FLAG, fakeBoldText);
    
static voidsetFilterBitmap(Paint thisPaint, boolean filter)

        setFlag(thisPaint, Paint.FILTER_BITMAP_FLAG, filter);
    
private static voidsetFlag(Paint thisPaint, int flagMask, boolean flagValue)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        if (flagValue) {
            delegate.mFlags |= flagMask;
        } else {
            delegate.mFlags &= ~flagMask;
        }
    
static voidsetFlags(Paint thisPaint, int flags)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mFlags = flags;
    
static voidsetHinting(Paint thisPaint, int mode)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mHintingMode = mode;
    
static voidsetLinearText(Paint thisPaint, boolean linearText)

        setFlag(thisPaint, Paint.LINEAR_TEXT_FLAG, linearText);
    
static voidsetStrikeThruText(Paint thisPaint, boolean strikeThruText)

        setFlag(thisPaint, Paint.STRIKE_THRU_TEXT_FLAG, strikeThruText);
    
static voidsetStrokeMiter(Paint thisPaint, float miter)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mStrokeMiter = miter;
    
static voidsetStrokeWidth(Paint thisPaint, float width)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mStrokeWidth = width;
    
static voidsetSubpixelText(Paint thisPaint, boolean subpixelText)

        setFlag(thisPaint, Paint.SUBPIXEL_TEXT_FLAG, subpixelText);
    
private voidsetTextLocale(java.lang.String locale)

        mLocale = new Locale(locale);
    
static voidsetTextScaleX(Paint thisPaint, float scaleX)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mTextScaleX = scaleX;
        delegate.updateFontObject();
    
static voidsetTextSize(Paint thisPaint, float textSize)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mTextSize = textSize;
        delegate.updateFontObject();
    
static voidsetTextSkewX(Paint thisPaint, float skewX)

        // get the delegate from the native int.
        Paint_Delegate delegate = sManager.getDelegate(thisPaint.mNativePaint);
        if (delegate == null) {
            return;
        }

        delegate.mTextSkewX = skewX;
        delegate.updateFontObject();
    
static voidsetUnderlineText(Paint thisPaint, boolean underlineText)

        setFlag(thisPaint, Paint.UNDERLINE_TEXT_FLAG, underlineText);
    
private voidupdateFontObject()
Update the {@link Font} object from the typeface, text size and scaling

        if (mTypeface != null) {
            // Get the fonts from the TypeFace object.
            List<Font> fonts = mTypeface.getFonts(mFontVariant);

            // create new font objects as well as FontMetrics, based on the current text size
            // and skew info.
            ArrayList<FontInfo> infoList = new ArrayList<FontInfo>(fonts.size());
            for (Font font : fonts) {
                if (font == null) {
                    // If the font is null, add null to infoList. When rendering the text, if this
                    // null is reached, a warning will be logged.
                    infoList.add(null);
                    continue;
                }
                FontInfo info = new FontInfo();
                info.mFont = font.deriveFont(mTextSize);
                if (mTextScaleX != 1.0 || mTextSkewX != 0) {
                    // TODO: support skew
                    info.mFont = info.mFont.deriveFont(new AffineTransform(
                            mTextScaleX, mTextSkewX, 0, 1, 0, 0));
                }
                // The metrics here don't have anti-aliasing set.
                info.mMetrics = Toolkit.getDefaultToolkit().getFontMetrics(info.mFont);

                infoList.add(info);
            }

            mFonts = Collections.unmodifiableList(infoList);
        }