android.text.TextPaint#setTextSkewX ( )源码实例Demo

下面列出了android.text.TextPaint#setTextSkewX ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mongol-library   文件: MongolTypefaceSpan.java
private void apply(TextPaint paint) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }
    final int fakeStyle = oldStyle & ~typeface.getStyle();

    if ((fakeStyle & Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fakeStyle & Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(typeface);
}
 
private void applyCustomTypeFace(TextPaint paint) {
    final Typeface old = paint.getTypeface();
    final int oldStyle = (old == null) ? 0 : old.getStyle();

    Typeface typeface = this.typeface;
    int fake = oldStyle & ~typeface.getStyle();
    if ((fake & android.graphics.Typeface.BOLD) != 0) {
        paint.setFakeBoldText(true);
    }

    if ((fake & android.graphics.Typeface.ITALIC) != 0) {
        paint.setTextSkewX(-0.25f);
    }

    paint.setTypeface(typeface);
}
 
源代码3 项目: CodeEditor   文件: SyntaxHighlightSpan.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.setColor(color);
    tp.setFakeBoldText(bold);
    if(italics) {
        tp.setTextSkewX(-0.1f);
    }
}
 
源代码4 项目: styT   文件: PromptUtils.java
/**
 * Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source
 * Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
 */
public static void setTypeface(@NonNull TextPaint textPaint, @Nullable Typeface typeface, int style)
{
    if (style > 0)
    {
        if (typeface == null)
        {
            typeface = Typeface.defaultFromStyle(style);
        }
        else
        {
            typeface = Typeface.create(typeface, style);
        }

        textPaint.setTypeface(typeface);

        int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
        int need = style & ~typefaceStyle;
        textPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
        textPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    }
    else if (typeface != null)
    {
        textPaint.setTypeface(typeface);
    }
    else
    {
        textPaint.setTypeface(Typeface.defaultFromStyle(style));
    }
}
 
源代码5 项目: PowerFileExplorer   文件: TextAppearanceSpan.java
@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        int fake = style & ~tf.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
源代码6 项目: MaterialTapTargetPrompt   文件: PromptUtils.java
/**
 * Based on setTypeface in android TextView, Copyright (C) 2006 The Android Open Source
 * Project. https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/widget/TextView.java
 */
public static void setTypeface(@NonNull TextPaint textPaint, @Nullable Typeface typeface, int style)
{
    if (style > 0)
    {
        if (typeface == null)
        {
            typeface = Typeface.defaultFromStyle(style);
        }
        else
        {
            typeface = Typeface.create(typeface, style);
        }

        textPaint.setTypeface(typeface);

        int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
        int need = style & ~typefaceStyle;
        textPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
        textPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    }
    else if (typeface != null)
    {
        textPaint.setTypeface(typeface);
    }
    else
    {
        textPaint.setTypeface(Typeface.defaultFromStyle(style));
    }
}
 
/**
 * Applies the attributes that affect measurement from Typeface to the given TextPaint.
 *
 * @see android.text.style.TextAppearanceSpan#updateMeasureState(TextPaint)
 */
public void updateTextPaintMeasureState(
    @NonNull TextPaint textPaint, @NonNull Typeface typeface) {
  textPaint.setTypeface(typeface);

  int fake = textStyle & ~typeface.getStyle();
  textPaint.setFakeBoldText((fake & Typeface.BOLD) != 0);
  textPaint.setTextSkewX((fake & Typeface.ITALIC) != 0 ? -0.25f : 0f);

  textPaint.setTextSize(textSize);
}
 
源代码8 项目: md2tv   文件: TypefaceResourceSpan.java
@Override
public void updateMeasureState(TextPaint p) {
    Typeface old=p.getTypeface();
    if ( old != null && !old.isBold() && tf_.isBold() ) {
        p.setFakeBoldText(true);
    }
    if ( old != null && !old.isItalic() && tf_.isItalic() ) {
        p.setTextSkewX(-0.25f);
    }
    p.setTypeface(tf_);
}
 
源代码9 项目: md2tv   文件: TypefaceResourceSpan.java
@Override
public void updateDrawState(TextPaint tp) {
    Typeface old=tp.getTypeface();
    if ( old != null && !old.isBold() && tf_.isBold() ) {
        tp.setFakeBoldText(true);
    }
    if ( old != null && !old.isItalic() && tf_.isItalic() ) {
        tp.setTextSkewX(-0.25f);
    }
    tp.setTypeface(tf_);
}
 
源代码10 项目: JotaTextEditor   文件: TextAppearanceSpan.java
@Override
public void updateMeasureState(TextPaint ds) {
    if (mTypeface != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();
        int style = 0;

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mTypeface != null) {
            tf = Typeface.create(mTypeface, style);
        } else if (tf == null) {
            tf = Typeface.defaultFromStyle(style);
        } else {
            tf = Typeface.create(tf, style);
        }

        int fake = style & ~tf.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(tf);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
源代码11 项目: android_9.0.0_r45   文件: TextAppearanceSpan.java
@Override
public void updateMeasureState(TextPaint ds) {
    final Typeface styledTypeface;
    int style = 0;

    if (mTypeface != null) {
        style = mStyle;
        styledTypeface = Typeface.create(mTypeface, style);
    } else if (mFamilyName != null || mStyle != 0) {
        Typeface tf = ds.getTypeface();

        if (tf != null) {
            style = tf.getStyle();
        }

        style |= mStyle;

        if (mFamilyName != null) {
            styledTypeface = Typeface.create(mFamilyName, style);
        } else if (tf == null) {
            styledTypeface = Typeface.defaultFromStyle(style);
        } else {
            styledTypeface = Typeface.create(tf, style);
        }
    } else {
        styledTypeface = null;
    }

    if (styledTypeface != null) {
        int fake = style & ~styledTypeface.getStyle();

        if ((fake & Typeface.BOLD) != 0) {
            ds.setFakeBoldText(true);
        }

        if ((fake & Typeface.ITALIC) != 0) {
            ds.setTextSkewX(-0.25f);
        }

        ds.setTypeface(styledTypeface);
    }

    if (mTextSize > 0) {
        ds.setTextSize(mTextSize);
    }
}
 
源代码12 项目: imsdk-android   文件: WaterMarkTextUtil.java
/**
 * 生成水印文字图片
 */
public BitmapDrawable drawTextToBitmap(Context mContext, String gText) {

    try {
        TextPaint mTextPaint1 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint1.density = mContext.getResources().getDisplayMetrics().density;
        oneTextPx = Utils.sp2px(mContext, textSize);
        mTextPaint1.setTextSize(oneTextPx);
        //计算字长
        textLength = (int) mTextPaint1.measureText(gText);
        int stextLength = (int) mTextPaint1.measureText(sText);
        /**拿到字长之后,计算一下斜着显示文字的时候文字所占的长和高*/
        int witchPx = 0;
        int highPx = 0;
        /**默认一段文字的长和高计算*/
        if (sWitchPx == 0) {
            sWitchPx = measurementWitch(stextLength);
            sHigthPx = measurementHigth(stextLength);
        }
        /**传入的文字的长和高计算*/
        witchPx = measurementWitch(textLength);
        highPx = measurementHigth(textLength);
        /**计算显示完整所需占的画图长宽*/
        int bitmapWitch = witchPx + sWitchPx + 2 * oneTextPx + offset;
        int bitmaphigth = (highPx + oneTextPx) * 2;
        //设置画板的时候 增加一个字的长宽
        bitmap = Bitmap.createBitmap(bitmapWitch + right,
                bitmaphigth+(2*top), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(ContextCompat.getColor(mContext, R.color.atom_ui_chat_gray_bg));
        /**初始化画笔*/
        TextPaint mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        mTextPaint.density = mContext.getResources().getDisplayMetrics().density;
        mTextPaint.setColor(Color.parseColor("#C4C4C4"));
        mTextPaint.setAlpha(90);
        mTextPaint.setStyle(Paint.Style.FILL);
        mTextPaint.setAntiAlias(true);
        mTextPaint.setTextAlign(Paint.Align.LEFT);
        mTextPaint.setFakeBoldText(false);
        mTextPaint.setTextSkewX(0);
        mTextPaint.setTextSize(oneTextPx);
        /**
         * ——————————————————————————————————>
         * |    1号绘制区域    |  间  |  2号   |
         * |   gText         |      | appName |
         * |  ①号起点位置     |  隔  |  ②起   |
         * ———————————————————————————————————
         * | 3号      | 间   |   4号绘制区域    |
         * | appName   |      |   gText        |
         * |  ③起     | 隔   |   ④号起        |
         * |———————————————————————————————————
         * V
         */
        /**方式二利用画布平移和旋转绘制*/
        /**先移动到①起点位置*/
        canvas.translate(oneTextPx,highPx+oneTextPx+top);
        /**旋转一定度数 绘制文字*/
        canvas.rotate(-rotate);
        canvas.drawText(gText,0,0,mTextPaint);
        /**恢复原来的度数 再移动画布原点到②号位置*/
        canvas.rotate(rotate);
        canvas.translate(witchPx+offset+oneTextPx,0);
        /**旋转一定度数 绘制文字*/
        canvas.rotate(-rotate);
        canvas.drawText(sText,0,0,mTextPaint);
        /**恢复原来的度数 再移动画布原点到③号位置*/
        canvas.rotate(rotate);
        canvas.translate(-(witchPx+offset+oneTextPx),oneTextPx+highPx+top);
        /**旋转一定度数 绘制文字*/
        canvas.rotate(-rotate);
        canvas.drawText(sText,0,0,mTextPaint);
        /**恢复原来的度数 再移动画布原点到④号位置*/
        canvas.rotate(rotate);
        canvas.translate(sWitchPx+offset+oneTextPx,0);
        /**旋转一定度数 绘制文字*/
        canvas.rotate(-rotate);
        canvas.drawText(gText,0,0,mTextPaint);
        /**保存画布*/
        canvas.save(Canvas.ALL_SAVE_FLAG);
        canvas.restore();
        //生成平铺的bitmapDrawable
        BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmap);
        drawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        drawable.setDither(true);
        return drawable;
    } catch (Exception e) {

    }
    return null;

}
 
源代码13 项目: Markwon   文件: EmphasisSpan.java
@Override
public void updateMeasureState(TextPaint p) {
    p.setTextSkewX(-0.25F);
}
 
源代码14 项目: Markwon   文件: EmphasisSpan.java
@Override
public void updateDrawState(TextPaint tp) {
    tp.setTextSkewX(-0.25F);
}