Java Code Examples for android.graphics.Paint.setTextSkewX()

The following are Jave code examples for showing how to use setTextSkewX() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AndroidUtilCode-master   File: SpanUtils.java   View Source Code Vote up 7 votes
private void apply(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.getShader();

    paint.setTypeface(tf);
}
 
Example 2
Project: GitHub   File: SpanUtils.java   View Source Code Vote up 6 votes
private void apply(final Paint paint, final Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.getShader();

    paint.setTypeface(tf);
}
 
Example 3
Project: android_ui   File: TextAppearance.java   View Source Code Vote up 6 votes
/**
 * Updates typeface setting for the given <var>paint</var> to the specified one.
 *
 * @param paint    The paint to be updated.
 * @param typeface The desired typeface. May be {@code null} to resolve instance of typeface
 *                 from the specified style.
 * @param style    The desired text style used to resolve proper instance of typeface.
 * @return {@code True} if paint's typeface setting has changed, {@code false} otherwise.
 * @see Paint#setTypeface(Typeface)
 */
public static boolean updatePaintTypeface(@NonNull Paint paint, @Nullable Typeface typeface, @TextStyle int style) {
	if (style > 0) {
		if (typeface == null) {
			typeface = Typeface.defaultFromStyle(style);
		} else {
			typeface = Typeface.create(typeface, style);
		}
		final int typefaceStyle = typeface != null ? typeface.getStyle() : 0;
		final int need = style & ~typefaceStyle;
		paint.setFakeBoldText((need & Typeface.BOLD) != 0);
		paint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
		paint.setTypeface(typeface);
	} else {
		paint.setFakeBoldText(false);
		paint.setTextSkewX(0);
		paint.setTypeface(typeface);
	}
	return true;
}
 
Example 4
Project: Android-UtilCode   File: SpannableStringUtils.java   View Source Code Vote up 6 votes
private static void apply(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 5
Project: EsperantoRadio   File: EgenTypefaceSpan.java   View Source Code Vote up 6 votes
private void applyCustomTypeFace(Paint paint, Typeface tf) {
  int oldStyle;
  Typeface old = paint.getTypeface();
  if (old == null) {
    oldStyle = 0;
  } else {
    oldStyle = old.getStyle();
  }

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

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

  paint.setTypeface(tf);
}
 
Example 6
Project: LuaViewPlayground   File: CustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 7
Project: HeadlineNews   File: SpanUtils.java   View Source Code Vote up 6 votes
private void apply(final Paint paint, final Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.getShader();

    paint.setTypeface(tf);
}
 
Example 8
Project: qmui   File: QMUICustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, @Nullable Typeface tf) {
    if (tf == null) {
        return;
    }

    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 9
Project: MobileMedia   File: Icon.java   View Source Code Vote up 6 votes
public static void applyTypeface(Context context, Paint v) {
    if (v.getTypeface() == null) {
        v.setTypeface(getNormal(context));
        return;
    }
    switch (v.getTypeface().getStyle()) {
        case Typeface.BOLD:
            v.setTypeface(getNormal(context));
            v.setFakeBoldText(true);
            break;
        default:
            v.setTypeface(getNormal(context));
            break;
        case Typeface.ITALIC:
            v.setTypeface(getNormal(context));
            v.setTextSkewX(-0.25f);
            break;
        case Typeface.BOLD_ITALIC:
            v.setTypeface(getNormal(context));
            v.setFakeBoldText(true);
            v.setTextSkewX(-0.25f);
            break;
    }
}
 
Example 10
Project: Cook-It-Android-XML-Template   File: CustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 11
Project: SDHtmlTextView   File: FontFamilySpan.java   View Source Code Vote up 6 votes
private void applyCustomTypeFace(Paint paint, FontFamily tf) {

		paint.setAntiAlias(true);
		
		paint.setTypeface(tf.getDefaultTypeface());

		if (bold) {
			if (tf.isFakeBold()) {
				paint.setFakeBoldText(true);
			} else {
				paint.setTypeface(tf.getBoldTypeface());
			}
		}

		if (italic) {
			if (tf.isFakeItalic()) {
				paint.setTextSkewX(-0.25f);
			} else {
				paint.setTypeface(tf.getItalicTypeface());
			}
		}

		if (bold && italic && tf.getBoldItalicTypeface() != null) {
			paint.setTypeface(tf.getBoldItalicTypeface());
		}
	}
 
Example 12
Project: Expert-Android-Programming   File: CustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 13
Project: DeviceInfo   File: CustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, Typeface tf) {
    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 14
Project: QMUI_Android   File: QMUICustomTypefaceSpan.java   View Source Code Vote up 6 votes
private static void applyCustomTypeFace(Paint paint, @Nullable Typeface tf) {
    if (tf == null) {
        return;
    }

    int oldStyle;
    Typeface old = paint.getTypeface();
    if (old == null) {
        oldStyle = 0;
    } else {
        oldStyle = old.getStyle();
    }

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

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

    paint.setTypeface(tf);
}
 
Example 15
Project: starcor.xul   File: XulSpannedLabelRender.java   View Source Code Vote up 5 votes
private Paint _getTextPaint(float fontSizeScale) {
	Paint defPaint = _ctx.getTextPaintByName(_fontFace);

	if (!(_fontShadowSize == 0 || (_fontShadowColor & 0xFF000000) == 0)) {
		defPaint = _ctx.getShadowTextPaintByName(_fontFace);
		defPaint.setShadowLayer(_fontShadowSize, _fontShadowX, _fontShadowY, _fontShadowColor);
	}

	defPaint.setColor(_fontColor);
	if (Math.abs(fontSizeScale - 1.0f) > 0.01f) {
		defPaint.setTextSize(_fontSize * fontSizeScale);
	} else {
		defPaint.setTextSize(_fontSize);
	}

	//defPaint.setStrokeWidth(_fontWeight / 2.0f);

	if (_fontWeight > 1.0) {
		defPaint.setFakeBoldText(true);
	} else {
		defPaint.setFakeBoldText(false);
	}
	defPaint.setUnderlineText(_fontUnderline);
	defPaint.setTextSkewX(_fontItalic ? -0.25f : 0);
	defPaint.setTextAlign(Paint.Align.LEFT);
	return defPaint;
}
 
Example 16
Project: starcor.xul   File: XulBasicTextRenderer.java   View Source Code Vote up 5 votes
protected Paint _getTextPaint(float fontSizeScale) {
	XulRenderContext ctx = _render.getRenderContext();
	Paint defPaint = ctx.getTextPaintByName(_fontFace);

	if (!(_fontShadowSize == 0 || (_fontShadowColor & 0xFF000000) == 0)) {
		defPaint = ctx.getShadowTextPaintByName(_fontFace);
		defPaint.setShadowLayer(_fontShadowSize, _fontShadowX, _fontShadowY, _fontShadowColor);
	}

	defPaint.setColor(_fontColor);
	if (Math.abs(fontSizeScale - 1.0f) > 0.01f) {
		defPaint.setTextSize(_fontSize * fontSizeScale);
	} else {
		defPaint.setTextSize(_fontSize);
	}

	if (_fontWeight > 1.0) {
		if (_fontWeight > 2.5) {
			defPaint.setStrokeWidth(_fontWeight*fontSizeScale/2);
		} else {
			defPaint.setFakeBoldText(true);
		}
	} else {
		defPaint.setFakeBoldText(false);
	}
	defPaint.setTextScaleX(_fontScaleX);
	defPaint.setUnderlineText(_fontUnderline);
	defPaint.setStrikeThruText(_fontStrikeThrough);
	defPaint.setTextSkewX(_fontItalic ? -0.25f : 0);
	defPaint.setTextAlign(Paint.Align.LEFT);
	return defPaint;
}
 
Example 17
Project: SmingZZick_App   File: TextMakingInfo.java   View Source Code Vote up 5 votes
public Paint getPaint(Context context, float scale, boolean outline) {
    float textSize = TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            this.textSize,
            context.getResources().getDisplayMetrics()) * scale;

    Paint textPaint = new Paint();

    if (typeface != null) {
        textPaint.setTypeface(typeface);
    }

    textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
    textPaint.setTextSize(textSize);
    textPaint.setAntiAlias(true);

    if (outline == false) {
        textPaint.setStrokeWidth(textSize * textStrokeRatio);
        textPaint.setColor(textColor);
    } else {
        textPaint.setStrokeWidth(textSize * textStrokeRatio + textSize * textOutlineRatio);
        textPaint.setColor(outlineColor);
    }


    // skew
    textPaint.setTextSkewX(skewX);


    // scaleX
    textPaint.setTextScaleX(scaleX);

    if (Build.VERSION.SDK_INT >= 21) {
        textPaint.setLetterSpacing(letterSpacing);
    }

    return textPaint;
}
 
Example 18
Project: FastTextView   File: ItalicReplacementSpan.java   View Source Code Vote up 5 votes
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
  canvas.save();
  float preTextSkewX = paint.getTextSkewX();
  paint.setTextSkewX(mTextSkewX);
  canvas.drawText(text, start, end, x, y, paint);
  paint.setTextSkewX(preTextSkewX);
  canvas.restore();
}
 
Example 19
Project: shareNote   File: CodeUtils.java   View Source Code Vote up 5 votes
private void randomTextStyle(Paint paint) {
        int color = randomColor();
        paint.setColor(color);
        paint.setFakeBoldText(mRandom.nextBoolean());  //true为粗体,false为非粗体
        float skewX = mRandom.nextInt(11) / 10;
        skewX = mRandom.nextBoolean() ? skewX : -skewX;
        paint.setTextSkewX(skewX); //float类型参数,负数表示右斜,整数左斜
//        paint.setUnderlineText(true); //true为下划线,false为非下划线
//        paint.setStrikeThruText(true); //true为删除线,false为非删除线
    }
 
Example 20
Project: FastTextView   File: ItalicReplacementSpan.java   View Source Code Vote up 3 votes
/**
 * Returns the width of the span. Extending classes can set the height of the span by updating
 * attributes of {@link android.graphics.Paint.FontMetricsInt}. If the span covers the whole
 * text, and the height is not set,
 * {@link #draw(Canvas, CharSequence, int, int, float, int, int, int, Paint)} will not be
 * called for the span.
 *
 * @param paint Paint instance.
 * @param text  Current text.
 * @param start Start character index for span.
 * @param end   End character index for span.
 * @param fm    Font metrics, can be null.
 * @return Width of the span.
 */
@Override
public int getSize(@NonNull Paint paint, CharSequence text, @IntRange(from = 0) int start, @IntRange(from = 0) int end, @Nullable Paint.FontMetricsInt fm) {
  float preTextSkewX = paint.getTextSkewX();
  paint.setTextSkewX(mTextSkewX);
  TextMeasureUtil.getTextBounds(paint, text, start, end, mRect);
  paint.setTextSkewX(preTextSkewX);
  setHeightIfNeed(text, start, end, fm);
  return mRect.width();
}