diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java index 2cca61849..a4d2fe424 100755 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BorderPainter.java @@ -27,6 +27,7 @@ import java.awt.geom.Arc2D; import java.awt.geom.Area; import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; import com.openhtmltopdf.css.constants.IdentValue; import com.openhtmltopdf.css.parser.FSRGBColor; @@ -81,7 +82,37 @@ public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPrope public static Path2D generateBorderShape(Rectangle bounds, int side, BorderPropertySet border, boolean drawInterior, float scaledOffset) { return generateBorderShape(bounds, side, border, drawInterior, scaledOffset, 1); } - + + /** + * Generate a simple rectangle without beveling for a solid border side. + * Turning off beveling should disable anti-aliasing and work better with + * table cell borders. + * See https://github.com/danfickle/openhtmltopdf/issues/752 + */ + private static Shape generateSimpleBorderShape(Rectangle bounds, int currentSide, BorderPropertySet border) { + if (currentSide == TOP || currentSide == BOTTOM) { + double x = bounds.getX(); + double y = currentSide == TOP ? + bounds.getY() : + bounds.getY() + bounds.getHeight() - border.bottom(); + double w = bounds.getWidth(); + double h = currentSide == TOP ? + border.top() : border.bottom(); + + return new Rectangle2D.Double(x, y, w, h); + } else { + double x = currentSide == LEFT ? + bounds.getX() : + bounds.getX() + bounds.getWidth() - border.right(); + double y = bounds.getY(); + double w = currentSide == LEFT ? + border.left() : border.right(); + double h = bounds.getHeight(); + + return new Rectangle2D.Double(x, y, w, h); + } + } + /** * Generates one side of a border * @param bounds bounds of the container @@ -328,23 +359,30 @@ private static void paintBorderSide(OutputDevice outputDevice, 0, 1, sides, currentSide, bevel); } else if (borderSideStyle == IdentValue.SOLID) { outputDevice.setStroke(new BasicStroke(1f)); - if(currentSide == TOP) { + + switch (currentSide) { + case TOP: outputDevice.setColor(border.topColor()); - outputDevice.fill(generateBorderShape(bounds, TOP, border, true, 0, 1)); - } - if(currentSide == RIGHT) { + break; + case RIGHT: outputDevice.setColor(border.rightColor()); - outputDevice.fill(generateBorderShape(bounds, RIGHT, border, true, 0, 1)); - } - if(currentSide == BOTTOM) { + break; + case BOTTOM: outputDevice.setColor(border.bottomColor()); - outputDevice.fill(generateBorderShape(bounds, BOTTOM, border, true, 0, 1)); - } - if(currentSide == LEFT) { + break; + case LEFT: outputDevice.setColor(border.leftColor()); - outputDevice.fill(generateBorderShape(bounds, LEFT, border, true, 0, 1)); + break; + default: + return; } - + + Shape s = bevel || border.hasBorderRadius() ? + generateBorderShape(bounds, currentSide, border, true, 0, 1) : + generateSimpleBorderShape(bounds, currentSide, border); + + outputDevice.fill(s); + } else if (borderSideStyle == IdentValue.DOUBLE) { paintDoubleBorder(outputDevice, border, bounds, sides, currentSide, bevel); } else { diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-732-no-bfc.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-732-no-bfc.pdf index 8b0efd53c..e4c56d31a 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-732-no-bfc.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-732-no-bfc.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-752-table-border-strange.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-752-table-border-strange.pdf new file mode 100644 index 000000000..ab998668c Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-752-table-border-strange.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-plugin-latex.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-plugin-latex.pdf index 82df1ce47..6afdf449b 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-plugin-latex.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/replaced-plugin-latex.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/table-cell-borders.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/table-cell-borders.pdf index b05a35765..84f5f3862 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/table-cell-borders.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/table-cell-borders.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/soft-hyphens.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/soft-hyphens.pdf index d42dc0db9..3c0e2cd1b 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/soft-hyphens.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/soft-hyphens.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-non-paginated.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-non-paginated.pdf index 71a62ec93..14df54df2 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-non-paginated.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-non-paginated.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-paginated.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-paginated.pdf index 987ed580a..aa0c01117 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-paginated.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/table-paginated.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-752-table-border-strange.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-752-table-border-strange.html new file mode 100644 index 000000000..52b25cc17 --- /dev/null +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-752-table-border-strange.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + +
1234
5678
+ + + diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java index 18aec8735..6126d23b1 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -1450,6 +1450,17 @@ public void testIssue551PageBreakInsideAvoidDeep() throws IOException { assertTrue(vt.runTest("issue-551-page-break-inside-avoid-deep")); } + /** + * Test weirdness in table borders when PDF is zoomed. + * Apparently was caused by anti-aliasing selectively applied + * to beveled borders. + */ + @Test + public void testIssue752TableBorderInconcistency() throws IOException { + assertTrue(vt.runTest("issue-752-table-border-strange")); + } + + // TODO: // + Elements that appear just on generated overflow pages. // + content property (page counters, etc)