下面列出了android.graphics.Paint#setStrikeThruText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
public static Bitmap getBitmap(final String text, int fillColor, final String arrow, final int width, final int height, final int margin, final boolean strike_through, boolean expandable, final boolean shadow) {
{
if ((text == null) || (text.length() > 4)) return null;
try {
if ((width > 2000) || height > 2000 || height < 16 || width < 16) return null;
final Paint paint = new Paint();
paint.setStrikeThruText(strike_through);
paint.setStyle(Paint.Style.FILL);
paint.setColor(fillColor);
paint.setAntiAlias(true);
//paint.setTypeface(Typeface.MONOSPACE);
paint.setTypeface(Typeface.SANS_SERIF); // TODO BEST?
paint.setTextAlign(Paint.Align.LEFT);
float paintTs = (arrow == null ? 17 : 17 - arrow.length());
paint.setTextSize(paintTs);
final Rect bounds = new Rect();
final String fullText = text + (arrow != null ? arrow : "");
paint.getTextBounds(fullText, 0, fullText.length(), bounds);
float textsize = ((paintTs - 1) * (width - margin)) / bounds.width();
paint.setTextSize(textsize);
paint.getTextBounds(fullText, 0, fullText.length(), bounds);
// cannot be Config.ALPHA_8 as it doesn't work on Samsung
final Bitmap bitmap = Bitmap.createBitmap(width, expandable ? Math.max(height, bounds.height() + 30) : height, Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(bitmap);
if (shadow) {
paint.setShadowLayer(10, 0, 0, getCol(ColorCache.X.color_number_wall_shadow));
}
c.drawText(fullText, 0, (height / 2) + (bounds.height() / 2), paint);
return bitmap;
} catch (Exception e) {
if (JoH.ratelimit("icon-failure", 60)) {
UserError.Log.e(TAG, "Cannot create number icon: " + e);
}
return null;
}
}
}
public static Bitmap getBitmap(final String text, int fillColor, final String arrow, final int width, final int height, final int margin, final boolean strike_through, boolean expandable, final boolean shadow) {
{
if ((text == null) || (text.length() > 4)) return null;
try {
if ((width > 2000) || height > 2000 || height < 16 || width < 16) return null;
final Paint paint = new Paint();
paint.setStrikeThruText(strike_through);
paint.setStyle(Paint.Style.FILL);
paint.setColor(fillColor);
paint.setAntiAlias(true);
//paint.setTypeface(Typeface.MONOSPACE);
paint.setTypeface(Typeface.SANS_SERIF); // TODO BEST?
paint.setTextAlign(Paint.Align.LEFT);
float paintTs = (arrow == null ? 17 : 17 - arrow.length());
paint.setTextSize(paintTs);
final Rect bounds = new Rect();
final String fullText = text + (arrow != null ? arrow : "");
paint.getTextBounds(fullText, 0, fullText.length(), bounds);
float textsize = ((paintTs - 1) * (width - margin)) / bounds.width();
paint.setTextSize(textsize);
paint.getTextBounds(fullText, 0, fullText.length(), bounds);
// cannot be Config.ALPHA_8 as it doesn't work on Samsung
final Bitmap bitmap = Bitmap.createBitmap(width, expandable ? Math.max(height, bounds.height() + 30) : height, Bitmap.Config.ARGB_8888);
final Canvas c = new Canvas(bitmap);
if (shadow) {
paint.setShadowLayer(10, 0, 0, getCol(ColorCache.X.color_number_wall_shadow));
}
c.drawText(fullText, 0, (height / 2) + (bounds.height() / 2), paint);
return bitmap;
} catch (Exception e) {
if (JoH.ratelimit("icon-failure", 60)) {
UserError.Log.e(TAG, "Cannot create number icon: " + e);
}
return null;
}
}
}