下面列出了android.graphics.Paint#getStrokeWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void draw(@NonNull Rect outRect, @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) {
float oldStrokeWidth = paint.getStrokeWidth();
Paint.Style oldStyle = paint.getStyle();
int oldColor = paint.getColor();
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);
paint.setColor(color);
canvas.save();
if (includePad) {
canvas.translate(x + strokeWidth / 2, strokeWidth / 2);
} else {
canvas.translate(x + strokeWidth / 2, fontMetricsInt.ascent - fontMetricsInt.top + strokeWidth / 2);
}
shape.draw(canvas, paint);
canvas.restore();
paint.setColor(oldColor);
paint.setStyle(oldStyle);
paint.setStrokeWidth(oldStrokeWidth);
float oldTextSize = paint.getTextSize();
paint.setTextSize(oldTextSize * 0.8f);
super.draw(outRect, canvas, text, start, end, x, top, y, bottom, paint);
paint.setTextSize(oldTextSize);
}
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);
}
@Override
public void drawBackground(Canvas c, Paint p, int left, int right, int top, int baseline, int bottom, CharSequence text, int start, int end, int lnum) {
//h1 h2 和最后一行
if (level <= 2 && (((Spanned) text).getSpanEnd(this) == end - 1)) {
int color = p.getColor();
float width = p.getStrokeWidth();
p.setColor(0xffeeeeee);
p.setStrokeWidth(HtmlView.FONT_SIZE / 14);
c.drawLine(left, baseline + HtmlView.FONT_SIZE / 2,
right, baseline + HtmlView.FONT_SIZE / 2, p);
p.setColor(color);
p.setStrokeWidth(width);
}
}
@Override
public void drawBackground(Canvas canvas, Paint paint, int left, int right, int top, int baseline, int bottom, CharSequence charSequence, int start, int end, int num) {
Paint.Style ostyle = paint.getStyle();
int oColor = paint.getColor();
float oWidth = paint.getStrokeWidth();
paint.setStyle(Paint.Style.FILL);
paint.setStrokeWidth(HEIGHT);
paint.setColor(COLOR);
canvas.drawLine(left, (top + bottom - 5) / 2.0f, right, (top + bottom - 5) / 2.0f, paint);
paint.setStrokeWidth(oWidth);
paint.setStyle(ostyle);
paint.setColor(oColor);
}
public void draw(Canvas g2, float x, float y) {
box.draw(g2, x + space + thickness, y);
Paint st = AjLatexMath.getPaint();
float w = st.getStrokeWidth();
st.setStrokeWidth(thickness);
Style s = st.getStyle();
st.setStyle(Style.STROKE);
float th = thickness / 2;
float r = 0.5f * Math
.min(width - thickness, height + depth - thickness);
g2.drawRoundRect(new RectF(x + th, y - height + th, x + th + width
- thickness, y - height + th + height + depth - thickness), r,
r, st);
st.setStrokeWidth(w);
st.setStyle(s);
// drawDebug(g2, x, y);
}
/**
* 绘制按下状态的点
*
* @param point 单位点
* @param canvas 画布
* @param pressPaint 按下状态画笔
*/
@Override
public void drawPressPoint(Point point, Canvas canvas, Paint pressPaint) {
// 1.记录画笔的原始属性(绘制过程中需要修改的属性),绘制结束时进行还原
Paint.Style style = pressPaint.getStyle();
float originStrokeWidth = pressPaint.getStrokeWidth();
// 2.绘制实心点
pressPaint.setStyle(Paint.Style.FILL);
canvas.drawCircle(point.x, point.y, point.radius / 3, pressPaint);
// 3.绘制空心圆边界
pressPaint.setStyle(Paint.Style.STROKE);
pressPaint.setStrokeWidth(point.radius / 16);
canvas.drawCircle(point.x, point.y, point.radius, pressPaint);
// 4.结束绘制,还原画笔属性
pressPaint.setStyle(style);
pressPaint.setStrokeWidth(originStrokeWidth);
}
@Override
public void draw(@NonNull Rect outRect, @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) {
float oldStrokeWidth = paint.getStrokeWidth();
Paint.Style oldStyle = paint.getStyle();
int oldColor = paint.getColor();
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);
paint.setColor(color);
canvas.save();
if (includePad) {
canvas.translate(x + strokeWidth / 2, strokeWidth / 2);
} else {
canvas.translate(x + strokeWidth / 2, fontMetricsInt.ascent - fontMetricsInt.top + strokeWidth / 2);
}
shape.draw(canvas, paint);
canvas.restore();
paint.setColor(oldColor);
paint.setStyle(oldStyle);
paint.setStrokeWidth(oldStrokeWidth);
float oldTextSize = paint.getTextSize();
paint.setTextSize(oldTextSize * 0.8f);
super.draw(outRect, canvas, text, start, end, x, top, y, bottom, paint);
paint.setTextSize(oldTextSize);
}
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, @NonNull Paint paint) {
int ypos = (top + bottom) / 2;
int c = paint.getColor();
float s = paint.getStrokeWidth();
paint.setColor(lineColor);
paint.setStrokeWidth(strokeWidth);
canvas.drawLine(0, ypos, canvas.getWidth(), ypos, paint);
paint.setColor(c);
paint.setStrokeWidth(s);
}
@Override
public void draw(Canvas canvas, Paint paint) {
final float size = paint.getStrokeWidth();
if (mDirection == 3) {
canvas.drawLine(size, size, getWidth() - size, getHeight() / 2, paint);
canvas.drawLine(size, getHeight() - size, getWidth() - size, getHeight() / 2, paint);
}
}
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
int y, int bottom, Paint paint) {
canvas.save();
canvas.translate(x, (bottom + top) / 2 - height);
final int c = paint.getColor();
final float w = paint.getStrokeWidth();
final Style s = paint.getStyle();
final PathEffect e = paint.getPathEffect();
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(height);
paint.setPathEffect(effe);
path.moveTo(x, 0);
path.lineTo(x + width, 0);
canvas.drawPath(path, paint);
paint.setColor(c);
paint.setStyle(s);
paint.setStrokeWidth(w);
paint.setPathEffect(e);
canvas.restore();
}
@Override
public void drawMajorLatitudes(Canvas c, int w, int h, double[] mid, WorldMapTask.WorldMapOptions options)
{
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setXfermode(options.hasTransparentBaseMap ? new PorterDuffXfermode(PorterDuff.Mode.DST_OVER) : new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
Paint.Style prevStyle = p.getStyle();
PathEffect prevEffect = p.getPathEffect();
float prevStrokeWidth = p.getStrokeWidth();
double equator = mid[1] * r_equator;
double tropics = mid[1] * r_tropics;
double polar = mid[1] * r_polar;
float strokeWidth = sunStroke(c, options) * options.latitudeLineScale;
p.setStrokeWidth(strokeWidth);
p.setStyle(Paint.Style.STROKE);
p.setStrokeCap(Paint.Cap.ROUND);
p.setColor(options.latitudeColors[0]);
p.setPathEffect((options.latitudeLinePatterns[0][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[0], 0) : null);
c.drawCircle((int)mid[0], (int)mid[1], (int)equator, p);
p.setColor(options.latitudeColors[1]);
p.setPathEffect((options.latitudeLinePatterns[1][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[1], 0) : null);
c.drawCircle((int)mid[0], (int)mid[1], (int)(equator + tropics), p);
c.drawCircle((int)mid[0], (int)mid[1], (int)(equator - tropics), p);
p.setColor(options.latitudeColors[2]);
p.setPathEffect((options.latitudeLinePatterns[2][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[2], 0) : null);
c.drawCircle((int)mid[0], (int)mid[1], (int)(equator + polar), p);
c.drawCircle((int)mid[0], (int)mid[1], (int)(equator - polar), p);
p.setStyle(prevStyle);
p.setPathEffect(prevEffect);
p.setStrokeWidth(prevStrokeWidth);
}
@Override
public void drawMajorLatitudes(Canvas c, int w, int h, double[] mid, WorldMapTask.WorldMapOptions options)
{
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setXfermode(new PorterDuffXfermode( options.hasTransparentBaseMap ? PorterDuff.Mode.DST_OVER : PorterDuff.Mode.SRC_OVER ));
Paint.Style prevStyle = p.getStyle();
PathEffect prevEffect = p.getPathEffect();
float prevStrokeWidth = p.getStrokeWidth();
float strokeWidth = sunStroke(c, options) * options.latitudeLineScale;
p.setStrokeWidth(strokeWidth);
p.setColor(options.latitudeColors[0]); // equator
p.setPathEffect((options.latitudeLinePatterns[0][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[0], 0) : null);
c.drawLine(0, (int)mid[1], w, (int)mid[1], p);
double tropics = r_tropics * mid[1];
int tropicsY0 = (int)(mid[1] + tropics);
int tropicsY1 = (int)(mid[1] - tropics);
p.setColor(options.latitudeColors[1]); // tropics
p.setPathEffect((options.latitudeLinePatterns[1][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[1], 0) : null);
c.drawLine(0, tropicsY0, w, tropicsY0, p);
c.drawLine(0, tropicsY1, w, tropicsY1, p);
double polar = r_polar * mid[1];
int polarY0 = (int)(mid[1] + polar);
int polarY1 = (int)(mid[1] - polar);
p.setColor(options.latitudeColors[2]); // polar
p.setPathEffect((options.latitudeLinePatterns[2][0] > 0) ? new DashPathEffect(options.latitudeLinePatterns[2], 0) : null);
c.drawLine(0, polarY0, w, polarY0, p);
c.drawLine(0, polarY1, w, polarY1, p);
p.setStyle(prevStyle);
p.setPathEffect(prevEffect);
p.setStrokeWidth(prevStrokeWidth);
p.setXfermode(new PorterDuffXfermode( PorterDuff.Mode.SRC_OVER) );
}
public void draw(Canvas g2, float x, float y) {
Paint st = AjLatexMath.getPaint();
float w = st.getStrokeWidth();
Style s = st.getStyle();
int c = st.getColor();
st.setStrokeWidth(thickness);
st.setStyle(Style.FILL_AND_STROKE);
float th = thickness / 2;
if (bg != null) {
st.setColor(bg);
g2.drawRect(x + th, y - height + th, x + th + width - thickness, y
+ th + depth - thickness, st);
}
st.setStyle(Style.STROKE);
if (line != null) {
st.setColor(line);
g2.drawRect(x + th, y - height + th, x + th + width - thickness, y
+ th + depth - thickness, st);
} else {
g2.drawRect(x + th, y - height + th, x + th + width - thickness, y
+ th + depth - thickness, st);
}
// drawDebug(g2, x, y);
st.setStrokeWidth(w);
st.setStyle(s);
box.draw(g2, x + space + thickness, y);
// st.setStyle(s);
st.setColor(c);
}
private static void drawMountBoundsBorder(Canvas canvas, Paint paint, Rect bounds) {
final int inset = (int) paint.getStrokeWidth() / 2;
canvas.drawRect(
bounds.left + inset,
bounds.top + inset,
bounds.right - inset,
bounds.bottom - inset,
paint);
}
@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) {
drawDebugLines(canvas, x, top, y, bottom, paint);
float oldStrokeWidth = paint.getStrokeWidth();
Paint.Style oldStyle = paint.getStyle();
int oldColor = paint.getColor();
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);
paint.setColor(color);
canvas.save();
canvas.translate(x + strokeWidth / 2, fontMetricsInt.ascent - fontMetricsInt.top + strokeWidth / 2);
shape.draw(canvas, paint);
canvas.restore();
paint.setColor(oldColor);
paint.setStyle(oldStyle);
paint.setStrokeWidth(oldStrokeWidth);
int width = frame.width();
paint.setTextSize(paint.getTextSize() * 0.8f);
if (drawText) {
if (false) {
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text, start, end, frame.centerX(), y, paint);
} else {
canvas.drawText(text, start, end, x + (width * 0.2f) / 2, y, paint);
}
}
}
public int tableBorderWidth(@NonNull Paint paint) {
final int out;
if (tableBorderWidth == -1) {
out = (int) (paint.getStrokeWidth() + .5F);
} else {
out = tableBorderWidth;
}
return out;
}
@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) {
drawDebugLines(canvas, x, top, y, bottom, paint);
float oldStrokeWidth = paint.getStrokeWidth();
Paint.Style oldStyle = paint.getStyle();
int oldColor = paint.getColor();
paint.setStrokeWidth(strokeWidth);
paint.setStyle(style);
paint.setColor(color);
canvas.save();
canvas.translate(x + strokeWidth / 2, fontMetricsInt.ascent - fontMetricsInt.top + strokeWidth / 2);
shape.draw(canvas, paint);
canvas.restore();
paint.setColor(oldColor);
paint.setStyle(oldStyle);
paint.setStrokeWidth(oldStrokeWidth);
int width = frame.width();
paint.setTextSize(paint.getTextSize() * 0.8f);
if (drawText) {
if (false) {
paint.setTextAlign(Paint.Align.CENTER);
canvas.drawText(text, start, end, frame.centerX(), y, paint);
} else {
canvas.drawText(text, start, end, x + (width * 0.2f) / 2, y, paint);
}
}
}
public RouteOverlay(final Route route)
{
super();
this.route = route;
bitmaps = new WeakHashMap<Waypoint, Bitmap>();
Resources resources = application.getResources();
linePaint = new Paint();
linePaint.setAntiAlias(true);
linePaint.setStrokeWidth(routeWidth);
linePaint.setStyle(Paint.Style.STROKE);
linePaint.setColor(resources.getColor(R.color.routeline));
fillPaint = new Paint();
fillPaint.setAntiAlias(false);
fillPaint.setStrokeWidth(1);
fillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
fillPaint.setColor(resources.getColor(R.color.routewaypoint));
borderPaint = new Paint();
borderPaint.setAntiAlias(false);
borderPaint.setStrokeWidth(1);
borderPaint.setStyle(Paint.Style.STROKE);
borderPaint.setColor(resources.getColor(R.color.routeline));
textPaint = new Paint();
textPaint.setAntiAlias(true);
textPaint.setStrokeWidth(2);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextAlign(Align.LEFT);
textPaint.setTextSize(pointWidth * 1.5f);
textPaint.setTypeface(Typeface.SANS_SERIF);
textPaint.setColor(resources.getColor(R.color.routewaypointtext));
textFillPaint = new Paint();
textFillPaint.setAntiAlias(false);
textFillPaint.setStrokeWidth(1);
textFillPaint.setStyle(Paint.Style.FILL_AND_STROKE);
textFillPaint.setColor(resources.getColor(R.color.routeline));
onPreferencesChanged(PreferenceManager.getDefaultSharedPreferences(application));
enabled = true;
if (route.width <= 0)
route.width = (int) linePaint.getStrokeWidth();
if (route.lineColor == -1)
route.lineColor = linePaint.getColor();
onRoutePropertiesChanged();
}
private float determineLineWidth(@NonNull Paint paint, float factor) {
float width = paint.getStrokeWidth();
width = Math.min(width, MAX_LINE_WIDTH);
width = Math.max(width, MIN_LINE_WIDTH);
return width * factor;
}
@Override
public void drawBackground(Canvas c, Paint p,
int left, int right,
int top, int baseline, int bottom,
CharSequence text, int start, int end,
int lnum) {
int baseMargin = 0;
if ( style.getMarginLeft() != null ) {
StyleValue styleValue = style.getMarginLeft();
if ( styleValue.getUnit() == StyleValue.Unit.PX ) {
if ( styleValue.getIntValue() > 0 ) {
baseMargin = styleValue.getIntValue();
}
} else if ( styleValue.getFloatValue() > 0f ) {
baseMargin = (int) (styleValue.getFloatValue() * HtmlSpanner.HORIZONTAL_EM_WIDTH);
}
//Leave a little bit of room
baseMargin--;
}
if ( baseMargin > 0 ) {
left = left + baseMargin;
}
int originalColor = p.getColor();
float originalStrokeWidth = p.getStrokeWidth();
p.setColor(Color.parseColor("#000000"));
if (style.getBorderColor() != null ) {
p.setColor( style.getBorderColor() );
}
int strokeWidth;
if ( style.getBorderWidth() != null && style.getBorderWidth().getUnit() == StyleValue.Unit.PX ) {
strokeWidth = style.getBorderWidth().getIntValue();
} else {
strokeWidth = 1;
}
p.setStrokeWidth( strokeWidth );
right -= strokeWidth;
p.setStyle(Paint.Style.STROKE);
Log.d("HorizontalSpan", "Drawing line");
int center=(bottom+top)/2;
c.drawLine(left, center, right, center, p);
p.setColor(originalColor);
p.setStrokeWidth(originalStrokeWidth);
}