Tables can have no borders (0)

This commit is contained in:
Dimitry Ivanov 2017-11-22 15:34:08 +03:00
parent 59f647e5cc
commit 43cf000339
2 changed files with 21 additions and 8 deletions

View File

@ -384,6 +384,16 @@ public class SpannableTheme {
return tableCellPadding;
}
public int tableBorderWidth(@NonNull Paint paint) {
final int out;
if (tableBorderWidth == -1) {
out = (int) (paint.getStrokeWidth() + .5F);
} else {
out = tableBorderWidth;
}
return out;
}
public void applyTableBorderStyle(@NonNull Paint paint) {
final int color;
@ -393,10 +403,6 @@ public class SpannableTheme {
color = tableBorderColor;
}
if (tableBorderWidth != 0) {
paint.setStrokeWidth(tableBorderWidth);
}
paint.setColor(color);
paint.setStyle(Paint.Style.STROKE);
}
@ -442,7 +448,7 @@ public class SpannableTheme {
private int thematicBreakHeight = -1;
private int tableCellPadding;
private int tableBorderColor;
private int tableBorderWidth;
private int tableBorderWidth = -1;
private int tableOddRowBackgroundColor;
private Drawable taskListDrawable;

View File

@ -169,10 +169,14 @@ public class TableRowSpan extends ReplacementSpan {
}
}
rect.set(0, 0, w, bottom - top);
theme.applyTableBorderStyle(this.paint);
final int borderWidth = theme.tableBorderWidth(paint);
final boolean drawBorder = borderWidth > 0;
if (drawBorder) {
rect.set(0, 0, w, bottom - top);
}
StaticLayout layout;
for (int i = 0; i < size; i++) {
layout = layouts.get(i);
@ -180,7 +184,10 @@ public class TableRowSpan extends ReplacementSpan {
try {
canvas.translate(x + (i * w), top - heightDiff);
canvas.drawRect(rect, this.paint);
if (drawBorder) {
canvas.drawRect(rect, this.paint);
}
canvas.translate(padding, padding + heightDiff);
layout.draw(canvas);