diff --git a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java index 9e9e2a44..c402e24f 100644 --- a/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java +++ b/library/src/main/java/ru/noties/markwon/spans/SpannableTheme.java @@ -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; diff --git a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java index c0dcb8c8..552af486 100644 --- a/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java +++ b/library/src/main/java/ru/noties/markwon/spans/TableRowSpan.java @@ -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);