Search in sources :

Example 41 with Paint

use of android.graphics.Paint in project playn by threerings.

the class AndroidTextLayout method layoutText.

public static TextLayout[] layoutText(String text, TextFormat format, TextWrap wrap) {
    AndroidFont font = (format.font == null) ? AndroidFont.DEFAULT : (AndroidFont) format.font;
    Paint paint = new Paint(format.antialias ? Paint.ANTI_ALIAS_FLAG : 0);
    paint.setTypeface(font.typeface);
    paint.setTextSize(font.size());
    paint.setSubpixelText(true);
    Paint.FontMetrics metrics = paint.getFontMetrics();
    List<TextLayout> layouts = new ArrayList<TextLayout>();
    float[] measuredWidth = new float[1];
    for (String ltext : AbstractTextLayout.normalizeEOL(text).split("\\n")) {
        // if we're only wrapping on newlines, then just add the whole line now
        if (wrap.width <= 0 || wrap.width == Float.MAX_VALUE) {
            layouts.add(new AndroidTextLayout(ltext, format, font, metrics, paint.measureText(ltext)));
        } else {
            int start = 0, end = ltext.length();
            while (start < end) {
                // breakText only breaks on characters; we want to break on word boundaries
                int count = paint.breakText(ltext, start, end, true, wrap.width, measuredWidth);
                // breakText exhibits a bug where ligaturized text sequences (e.g. "fi") are counted as a
                // single character in the returned count when in reality they consume multiple
                // characters of the source text; so we use a hacky table of known ligatures for the font
                // in question to adjust the count if the text passed to breakText contains any known
                // ligatures
                int lineEnd = start + count;
                if (lineEnd < end && font.ligatureHacks.length > 0) {
                    int adjust = accountForLigatures(ltext, start, count, font.ligatureHacks);
                    count += adjust;
                    lineEnd += adjust;
                }
                // if we matched the rest of the line, things are simple
                if (lineEnd == end) {
                    layouts.add(new AndroidTextLayout(ltext.substring(start, lineEnd), format, font, metrics, measuredWidth[0]));
                    start += count;
                } else {
                    // if we ended in the middle of a word, back up until we hit whitespace
                    if (!Character.isWhitespace(ltext.charAt(lineEnd - 1)) && !Character.isWhitespace(ltext.charAt(lineEnd))) {
                        do {
                            --lineEnd;
                        } while (lineEnd > start && !Character.isWhitespace(ltext.charAt(lineEnd)));
                    }
                    // if there is no whitespace on the line, then we hard-break in the middle of the word
                    if (lineEnd == start) {
                        layouts.add(new AndroidTextLayout(ltext.substring(start, start + count), format, font, metrics, measuredWidth[0]));
                        start += count;
                    } else {
                        // otherwise we're now positioned on some sort of whitespace; trim it
                        while (Character.isWhitespace(ltext.charAt(lineEnd - 1))) {
                            --lineEnd;
                        }
                        String line = ltext.substring(start, lineEnd);
                        float size = paint.measureText(line);
                        layouts.add(new AndroidTextLayout(line, format, font, metrics, size));
                        start = lineEnd;
                    }
                    // now trim any whitespace from start to the first non-whitespace character
                    while (start < end && Character.isWhitespace(ltext.charAt(start))) {
                        start++;
                    }
                }
            }
        }
    }
    return layouts.toArray(new TextLayout[layouts.size()]);
}
Also used : ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Paint(android.graphics.Paint) AbstractTextLayout(playn.core.AbstractTextLayout) TextLayout(playn.core.TextLayout)

Example 42 with Paint

use of android.graphics.Paint in project QiDict by timqi.

the class CirclesProgress method initCirclesProgress.

private void initCirclesProgress(int[] colors) {
    initColors(colors);
    mPath = new Path();
    Paint basePaint = new Paint();
    basePaint.setAntiAlias(true);
    mFstHalfPaint = new Paint(basePaint);
    mScndHalfPaint = new Paint(basePaint);
    mAbovePaint = new Paint(basePaint);
    // init alpha and color filter
    setAlpha(mAlpha);
    setColorFilter(mColorFilter);
}
Also used : Path(android.graphics.Path) Paint(android.graphics.Paint)

Example 43 with Paint

use of android.graphics.Paint in project Shuttle by timusus.

the class IntroductoryOverlay method setupHolePaint.

private void setupHolePaint() {
    PorterDuffXfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY);
    mHolePaint = new Paint();
    mHolePaint.setColor(0xFFFFFF);
    mHolePaint.setAlpha(0);
    mHolePaint.setXfermode(xfermode);
    mHolePaint.setAntiAlias(true);
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint)

Example 44 with Paint

use of android.graphics.Paint in project CalendarListview by traex.

the class SimpleMonthView method initView.

protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mMonthTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);
    mMonthTitleBGPaint = new Paint();
    mMonthTitleBGPaint.setFakeBoldText(true);
    mMonthTitleBGPaint.setAntiAlias(true);
    mMonthTitleBGPaint.setColor(mMonthTitleBGColor);
    mMonthTitleBGPaint.setTextAlign(Align.CENTER);
    mMonthTitleBGPaint.setStyle(Style.FILL);
    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mSelectedDaysColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);
    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mDayTextColor);
    mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);
    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
}
Also used : Paint(android.graphics.Paint)

Example 45 with Paint

use of android.graphics.Paint in project glitch-hq-android by tinyspeck.

the class BitmapUtil method CreateTransparentOvalBitmap.

public static Bitmap CreateTransparentOvalBitmap(int nBitmapW, int nBitmapH, RectF r, int nInColor, int nOutColor) {
    Bitmap bmMask = Bitmap.createBitmap(nBitmapW, nBitmapH, Bitmap.Config.ARGB_8888);
    Canvas cvsMask = new Canvas(bmMask);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);
    paint.setColor(nOutColor);
    cvsMask.drawRect(0, 0, nBitmapW, nBitmapH, paint);
    paint.setColor(nInColor);
    cvsMask.drawOval(r, paint);
    return bmMask;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2248 Canvas (android.graphics.Canvas)466 Bitmap (android.graphics.Bitmap)415 Rect (android.graphics.Rect)267 RectF (android.graphics.RectF)231 TextPaint (android.text.TextPaint)178 PorterDuffXfermode (android.graphics.PorterDuffXfermode)124 Path (android.graphics.Path)120 Matrix (android.graphics.Matrix)105 TypedArray (android.content.res.TypedArray)81 BitmapDrawable (android.graphics.drawable.BitmapDrawable)75 Drawable (android.graphics.drawable.Drawable)65 BitmapShader (android.graphics.BitmapShader)63 Point (android.graphics.Point)60 SuppressLint (android.annotation.SuppressLint)57 View (android.view.View)54 Resources (android.content.res.Resources)42 Test (org.junit.Test)40 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)39 Typeface (android.graphics.Typeface)39