本文整理汇总了Java中android.graphics.Paint.setTypeface方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.setTypeface方法的具体用法?Java Paint.setTypeface怎么用?Java Paint.setTypeface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.Paint
的用法示例。
在下文中一共展示了Paint.setTypeface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: draw
import android.graphics.Paint; //导入方法依赖的package包/类
public void draw(Canvas g2, float x, float y) {
drawDebug(g2, x, y);
// Paint st=AjLatexMath.getPaint();
// st.setTextSize(AjLatexMath.getTextSize());
Paint st =new Paint();
float w = st.getStrokeWidth();
Style s = st.getStyle();
Typeface f = st.getTypeface();
st.setStrokeWidth(0);//
st.setStyle(Style.FILL_AND_STROKE);
st.setTypeface(font);
g2.save();
g2.translate(x, y);
g2.scale(0.5f * size, 0.5f * size);
// g2.drawText(str, x, y, st);
g2.drawText(str, 0, 0, st);
g2.restore();
st.setStyle(s);
st.setStrokeWidth(w);
st.setTypeface(f);
}
示例2: createBall
import android.graphics.Paint; //导入方法依赖的package包/类
public static Bitmap createBall(int radius, int ballColor, int letterColor, String letter) {
letter = letter.toUpperCase();
Bitmap bitmap = Bitmap.createBitmap(radius*2, radius*2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint2 = new Paint();
paint2.setColor(ballColor);
canvas.drawCircle(radius, radius, (float) radius, paint2);
Paint paint = new Paint();
paint.setColor(letterColor);
paint.setTextSize(120);
paint.setTypeface(Typeface.create("sans-serif-light", Typeface.NORMAL));
Rect textBounds = new Rect();
paint.getTextBounds(letter, 0, letter.length(), textBounds);
canvas.drawText(letter, radius - textBounds.exactCenterX(), radius - textBounds.exactCenterY(), paint);
return bitmap;
}
示例3: applyCustomTypeFace
import android.graphics.Paint; //导入方法依赖的package包/类
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);
}
示例4: applyCustomTypeFace
import android.graphics.Paint; //导入方法依赖的package包/类
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);
}
示例5: c
import android.graphics.Paint; //导入方法依赖的package包/类
protected float c(Paint paint) {
float f = 0.0f;
if (!TextUtils.isEmpty(this.text)) {
Typeface d = d(paint);
if ((this.useDefaultFont || !this.useHanyiColorFont) && (paint instanceof ETPaint)) {
paint = ((ETPaint) paint).a();
}
int length = this.text.length();
int i = 0;
while (i < length) {
int charCount = Character.charCount(this.text.codePointAt(i));
float measureText = paint.measureText(this.text, i, i + charCount) + f;
i += charCount;
f = measureText;
}
if (d != null) {
paint.setTypeface(d);
}
}
return f;
}
示例6: getShadowTextPaintByName
import android.graphics.Paint; //导入方法依赖的package包/类
static public Paint getShadowTextPaintByName(String name) {
if (name == null) {
return getDefShadowTextPaint();
}
TypefaceInfo typefaceInfo = _font_map.get(name);
if (typefaceInfo == null) {
return getDefShadowTextPaint();
}
Paint paint = typefaceInfo.paint;
if (paint == null) {
typefaceInfo.paint = paint = new Paint();
paint.setTypeface(typefaceInfo.typeface);
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setShadowLayer(3, 0, 0, Color.BLACK);
}
return paint;
}
示例7: TabSwitcherDrawable
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Creates a new drawable, which allows to display the number of tabs, which are currently
* contained by a {@link TabSwitcher}.
*
* @param context
* The context, which should be used by the drawable, as an instance of the class {@link
* Context}. The context may not be null
*/
public TabSwitcherDrawable(@NonNull final Context context) {
ensureNotNull(context, "The context may not be null");
Resources resources = context.getResources();
size = resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_size);
textSizeNormal =
resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_normal);
textSizeSmall =
resources.getDimensionPixelSize(R.dimen.tab_switcher_drawable_font_size_small);
background =
ContextCompat.getDrawable(context, R.drawable.tab_switcher_drawable_background)
.mutate();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(textSizeNormal);
paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
label = Integer.toString(0);
int tint = ThemeUtil.getColor(context, android.R.attr.textColorPrimary);
setColorFilter(tint, PorterDuff.Mode.MULTIPLY);
}
示例8: initPaints
import android.graphics.Paint; //导入方法依赖的package包/类
private void initPaints() {
paintOuterText = new Paint();
paintOuterText.setAntiAlias(true);
paintOuterText.setColor(textColorOuter);
paintOuterText.setTypeface(typeface);
paintOuterText.setTextSize(textSize);
paintCenterText = new Paint();
paintCenterText.setAntiAlias(true);
paintCenterText.setColor(textColorCenter);
paintCenterText.setTextScaleX(1.1F);
paintCenterText.setTypeface(typeface);
paintCenterText.setTextSize(textSize);
paintIndicator = new Paint();
paintIndicator.setAntiAlias(true);
paintIndicator.setColor(dividerConfig.color);
paintIndicator.setStrokeWidth(dividerConfig.thick);
paintIndicator.setAlpha(dividerConfig.alpha);
paintShadow = new Paint();
paintShadow.setAntiAlias(true);
paintShadow.setColor(dividerConfig.shadowColor);
paintShadow.setAlpha(dividerConfig.shadowAlpha);
setLayerType(LAYER_TYPE_SOFTWARE, null);
}
示例9: BadgeDrawable
import android.graphics.Paint; //导入方法依赖的package包/类
public BadgeDrawable(Context context) {
mTextSize = 15F;
myColor = context.getResources().getColor(R.color.theme_primary_dark_badge);
mBadgePaint = new Paint();
mBadgePaint.setColor(myColor);
mBadgePaint.setAntiAlias(true);
mBadgePaint.setStyle(Paint.Style.FILL);
mTextPaint = new Paint();
mTextPaint.setColor(Color.YELLOW);
mTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
mTextPaint.setTextSize(mTextSize);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextAlign(Paint.Align.CENTER);
}
示例10: createTextPaint
import android.graphics.Paint; //导入方法依赖的package包/类
private Paint createTextPaint(int textColor) {
Paint paint = new Paint();
paint.setColor(textColor);
paint.setTypeface(NORMAL_TYPEFACE);
paint.setAntiAlias(true);
return paint;
}
示例11: drawIconGlyph
import android.graphics.Paint; //导入方法依赖的package包/类
private static void drawIconGlyph(Context context, String iconChar, int size, Canvas canvas, int color) {
Paint textPaint = new Paint();
textPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setColor(color);
textPaint.setTextSize(size);
textPaint.setTypeface(Typeface.createFromAsset(context.getResources().getAssets(), "SalesforceDesignSystemIcons.ttf"));
float y = (size / 2.0f) - ((textPaint.descent() + textPaint.ascent()) / 2.0f);
canvas.drawText(iconChar, (size / 2.0f), y, textPaint);
}
示例12: drawTextElements
import android.graphics.Paint; //导入方法依赖的package包/类
/**
* Draw the 12 text values at the positions specified by the textGrid parameters.
*/
private void drawTextElements(Canvas canvas, float textSize, Typeface typeface,
ColorStateList textColor, String[] texts, float[] textX, float[] textY, Paint paint,
int alpha, boolean showActivated, int activatedDegrees, boolean activatedOnly) {
paint.setTextSize(textSize);
paint.setTypeface(typeface);
// The activated index can touch a range of elements.
final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS);
final int activatedFloor = (int) activatedIndex;
final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS;
for (int i = 0; i < 12; i++) {
final boolean activated = (activatedFloor == i || activatedCeil == i);
if (activatedOnly && !activated) {
continue;
}
final int stateMask = StateSet.VIEW_STATE_ENABLED
| (showActivated && activated ? StateSet.VIEW_STATE_ACTIVATED : 0);
final int color = textColor.getColorForState(StateSet.get(stateMask), 0);
paint.setColor(color);
paint.setAlpha(getMultipliedAlpha(color, alpha));
canvas.drawText(texts[i], textX[i], textY[i], paint);
}
}
示例13: apply
import android.graphics.Paint; //导入方法依赖的package包/类
private static void apply(
Paint paint,
int style,
int weight,
@Nullable String family,
AssetManager assetManager) {
int oldStyle;
Typeface typeface = paint.getTypeface();
if (typeface == null) {
oldStyle = 0;
} else {
oldStyle = typeface.getStyle();
}
int want = 0;
if ((weight == Typeface.BOLD) ||
((oldStyle & Typeface.BOLD) != 0 && weight == ReactTextShadowNode.UNSET)) {
want |= Typeface.BOLD;
}
if ((style == Typeface.ITALIC) ||
((oldStyle & Typeface.ITALIC) != 0 && style == ReactTextShadowNode.UNSET)) {
want |= Typeface.ITALIC;
}
if (family != null) {
typeface = ReactFontManager.getInstance().getTypeface(family, want, assetManager);
} else if (typeface != null) {
// TODO(t9055065): Fix custom fonts getting applied to text children with different style
typeface = Typeface.create(typeface, want);
}
if (typeface != null) {
paint.setTypeface(typeface);
} else {
paint.setTypeface(Typeface.defaultFromStyle(want));
}
}
示例14: applyFontStyle
import android.graphics.Paint; //导入方法依赖的package包/类
public static void applyFontStyle(Paint paint, int style, int weight, String family) {
int oldStyle;
Typeface typeface = paint.getTypeface();
if (typeface == null) {
oldStyle = 0;
} else {
oldStyle = typeface.getStyle();
}
int want = 0;
if ((weight == Typeface.BOLD)
|| ((oldStyle & Typeface.BOLD) != 0 && weight == WXStyle.UNSET)) {
want |= Typeface.BOLD;
}
if ((style == Typeface.ITALIC)
|| ((oldStyle & Typeface.ITALIC) != 0 && style == WXStyle.UNSET)) {
want |= Typeface.ITALIC;
}
if (family != null) {
typeface = getOrCreateTypeface(family, want);
}
if (typeface != null) {
paint.setTypeface(Typeface.create(typeface, want));
} else {
paint.setTypeface(Typeface.defaultFromStyle(want));
}
}
示例15: drawLanguageOnSpacebar
import android.graphics.Paint; //导入方法依赖的package包/类
private void drawLanguageOnSpacebar(final Key key, final Canvas canvas, final Paint paint) {
final Keyboard keyboard = getKeyboard();
if (keyboard == null) {
return;
}
final int width = key.getWidth();
final int height = key.getHeight();
paint.setTextAlign(Align.CENTER);
paint.setTypeface(Typeface.DEFAULT);
paint.setTextSize(mLanguageOnSpacebarTextSize);
final String language = layoutLanguageOnSpacebar(paint, keyboard.mId.mSubtype, width);
// Draw language text with shadow
final float descent = paint.descent();
final float textHeight = -paint.ascent() + descent;
final float baseline = height / 2 + textHeight / 2;
if (mLanguageOnSpacebarTextShadowRadius > 0.0f) {
paint.setShadowLayer(mLanguageOnSpacebarTextShadowRadius, 0, 0,
mLanguageOnSpacebarTextShadowColor);
} else {
paint.clearShadowLayer();
}
paint.setColor(mLanguageOnSpacebarTextColor);
paint.setAlpha(mLanguageOnSpacebarAnimAlpha);
canvas.drawText(language, width / 2, baseline - descent, paint);
paint.clearShadowLayer();
paint.setTextScaleX(1.0f);
}