Search in sources :

Example 46 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class BoringLayout method init.

/* package */
void init(CharSequence source, TextPaint paint, int outerwidth, Alignment align, float spacingmult, float spacingadd, BoringLayout.Metrics metrics, boolean includepad, boolean trustWidth) {
    int spacing;
    if (source instanceof String && align == Layout.Alignment.ALIGN_NORMAL) {
        mDirect = source.toString();
    } else {
        mDirect = null;
    }
    mPaint = paint;
    if (includepad) {
        spacing = metrics.bottom - metrics.top;
    } else {
        spacing = metrics.descent - metrics.ascent;
    }
    if (spacingmult != 1 || spacingadd != 0) {
        spacing = (int) (spacing * spacingmult + spacingadd + 0.5f);
    }
    mBottom = spacing;
    if (includepad) {
        mDesc = spacing + metrics.top;
    } else {
        mDesc = spacing + metrics.ascent;
    }
    if (trustWidth) {
        mMax = metrics.width;
    } else {
        /*
             * If we have ellipsized, we have to actually calculate the
             * width because the width that was passed in was for the
             * full text, not the ellipsized form.
             */
        TextLine line = TextLine.obtain();
        line.set(paint, source, 0, source.length(), Layout.DIR_LEFT_TO_RIGHT, Layout.DIRS_ALL_LEFT_TO_RIGHT, false, null);
        mMax = (int) FloatMath.ceil(line.metrics(null));
        TextLine.recycle(line);
    }
    if (includepad) {
        mTopPadding = metrics.top - metrics.ascent;
        mBottomPadding = metrics.bottom - metrics.descent;
    }
}
Also used : Paint(android.graphics.Paint)

Example 47 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class MeasuredText method addStyleRun.

float addStyleRun(TextPaint paint, int len, Paint.FontMetricsInt fm) {
    if (fm != null) {
        paint.getFontMetricsInt(fm);
    }
    int p = mPos;
    mPos = p + len;
    if (mEasy) {
        int flags = mDir == Layout.DIR_LEFT_TO_RIGHT ? Canvas.DIRECTION_LTR : Canvas.DIRECTION_RTL;
        return paint.getTextRunAdvances(mChars, p, len, p, len, flags, mWidths, p);
    }
    float totalAdvance = 0;
    int level = mLevels[p];
    for (int q = p, i = p + 1, e = p + len; ; ++i) {
        if (i == e || mLevels[i] != level) {
            int flags = (level & 0x1) == 0 ? Canvas.DIRECTION_LTR : Canvas.DIRECTION_RTL;
            totalAdvance += paint.getTextRunAdvances(mChars, q, i - q, q, i - q, flags, mWidths, q);
            if (i == e) {
                break;
            }
            q = i;
            level = mLevels[i];
        }
    }
    return totalAdvance;
}
Also used : Paint(android.graphics.Paint)

Example 48 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class SpannableStringBuilder method getTextWidths.

/**
     * Don't call this yourself -- exists for Paint to use internally.
     * {@hide}
     */
public int getTextWidths(int start, int end, float[] widths, Paint p) {
    checkRange("getTextWidths", start, end);
    int ret;
    if (end <= mGapStart) {
        ret = p.getTextWidths(mText, start, end - start, widths);
    } else if (start >= mGapStart) {
        ret = p.getTextWidths(mText, start + mGapLength, end - start, widths);
    } else {
        char[] buf = TextUtils.obtain(end - start);
        getChars(start, end, buf, 0);
        ret = p.getTextWidths(buf, 0, end - start, widths);
        TextUtils.recycle(buf);
    }
    return ret;
}
Also used : Paint(android.graphics.Paint)

Example 49 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class SpannableStringBuilder method drawTextRun.

/**
     * Don't call this yourself -- exists for Canvas to use internally.
     * {@hide}
     */
public void drawTextRun(Canvas c, int start, int end, int contextStart, int contextEnd, float x, float y, int flags, Paint p) {
    checkRange("drawTextRun", start, end);
    int contextLen = contextEnd - contextStart;
    int len = end - start;
    if (contextEnd <= mGapStart) {
        c.drawTextRun(mText, start, len, contextStart, contextLen, x, y, flags, p);
    } else if (contextStart >= mGapStart) {
        c.drawTextRun(mText, start + mGapLength, len, contextStart + mGapLength, contextLen, x, y, flags, p);
    } else {
        char[] buf = TextUtils.obtain(contextLen);
        getChars(contextStart, contextEnd, buf, 0);
        c.drawTextRun(buf, start - contextStart, len, 0, contextLen, x, y, flags, p);
        TextUtils.recycle(buf);
    }
}
Also used : Paint(android.graphics.Paint)

Example 50 with Paint

use of android.graphics.Paint in project android_frameworks_base by ParanoidAndroid.

the class MeasuredText method addStyleRun.

float addStyleRun(TextPaint paint, MetricAffectingSpan[] spans, int len, Paint.FontMetricsInt fm) {
    TextPaint workPaint = mWorkPaint;
    workPaint.set(paint);
    // XXX paint should not have a baseline shift, but...
    workPaint.baselineShift = 0;
    ReplacementSpan replacement = null;
    for (int i = 0; i < spans.length; i++) {
        MetricAffectingSpan span = spans[i];
        if (span instanceof ReplacementSpan) {
            replacement = (ReplacementSpan) span;
        } else {
            span.updateMeasureState(workPaint);
        }
    }
    float wid;
    if (replacement == null) {
        wid = addStyleRun(workPaint, len, fm);
    } else {
        // Use original text.  Shouldn't matter.
        wid = replacement.getSize(workPaint, mText, mTextStart + mPos, mTextStart + mPos + len, fm);
        float[] w = mWidths;
        w[mPos] = wid;
        for (int i = mPos + 1, e = mPos + len; i < e; i++) w[i] = 0;
        mPos += len;
    }
    if (fm != null) {
        if (workPaint.baselineShift < 0) {
            fm.ascent += workPaint.baselineShift;
            fm.top += workPaint.baselineShift;
        } else {
            fm.descent += workPaint.baselineShift;
            fm.bottom += workPaint.baselineShift;
        }
    }
    return wid;
}
Also used : ReplacementSpan(android.text.style.ReplacementSpan) Paint(android.graphics.Paint) MetricAffectingSpan(android.text.style.MetricAffectingSpan)

Aggregations

Paint (android.graphics.Paint)3611 Canvas (android.graphics.Canvas)815 Bitmap (android.graphics.Bitmap)735 RectF (android.graphics.RectF)484 Rect (android.graphics.Rect)400 Path (android.graphics.Path)281 TextPaint (android.text.TextPaint)269 PorterDuffXfermode (android.graphics.PorterDuffXfermode)232 Matrix (android.graphics.Matrix)173 SuppressLint (android.annotation.SuppressLint)148 Point (android.graphics.Point)147 TypedArray (android.content.res.TypedArray)134 BitmapShader (android.graphics.BitmapShader)117 View (android.view.View)103 Drawable (android.graphics.drawable.Drawable)99 BitmapDrawable (android.graphics.drawable.BitmapDrawable)92 ColorMatrix (android.graphics.ColorMatrix)76 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)66 Resources (android.content.res.Resources)65 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)57