Java Code Examples for android.text.TextPaint#setTextSkewX()
The following examples show how to use
android.text.TextPaint#setTextSkewX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongolTypefaceSpan.java From mongol-library with MIT License | 6 votes |
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); }
Example 2
Source File: CustomTypefaceSpan.java From tns-core-modules-widgets with Apache License 2.0 | 6 votes |
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); }
Example 3
Source File: SyntaxHighlightSpan.java From CodeEditor with Apache License 2.0 | 5 votes |
@Override public void updateDrawState(TextPaint tp) { tp.setColor(color); tp.setFakeBoldText(bold); if(italics) { tp.setTextSkewX(-0.1f); } }
Example 4
Source File: PromptUtils.java From styT with Apache License 2.0 | 5 votes |
/** * 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)); } }
Example 5
Source File: TextAppearanceSpan.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
@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); } }
Example 6
Source File: PromptUtils.java From MaterialTapTargetPrompt with Apache License 2.0 | 5 votes |
/** * 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)); } }
Example 7
Source File: TextAppearance.java From material-components-android with Apache License 2.0 | 5 votes |
/** * 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); }
Example 8
Source File: TypefaceResourceSpan.java From md2tv with MIT License | 5 votes |
@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_); }
Example 9
Source File: TypefaceResourceSpan.java From md2tv with MIT License | 5 votes |
@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_); }
Example 10
Source File: TextAppearanceSpan.java From JotaTextEditor with Apache License 2.0 | 5 votes |
@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); } }
Example 11
Source File: TextAppearanceSpan.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@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); } }
Example 12
Source File: WaterMarkTextUtil.java From imsdk-android with MIT License | 4 votes |
/** * 生成水印文字图片 */ 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; }
Example 13
Source File: EmphasisSpan.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void updateMeasureState(TextPaint p) { p.setTextSkewX(-0.25F); }
Example 14
Source File: EmphasisSpan.java From Markwon with Apache License 2.0 | 4 votes |
@Override public void updateDrawState(TextPaint tp) { tp.setTextSkewX(-0.25F); }