diff --git a/CHANGELOG.md b/CHANGELOG.md index d927b16e9..7d6a3ea3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## CHANGELOG ### head - 1.0.1-SNAPSHOT ++ [#403](https://github.com/danfickle/openhtmltopdf/issues/403) Soft hyphen support. Soft hyphens are now replaced with hard hyphens when used as line ending character. Thanks @sbrunecker. + [#408](https://github.com/danfickle/openhtmltopdf/issues/408) Fix for bookmarks not working with HTML5 parsers such as JSoup. Thanks @syjer for investigating and fixing and @Milchreis for reporting. + [#404](https://github.com/danfickle/openhtmltopdf/issues/404) Upgrade Batik to 1.12 and xmlgraphics-common to 2.4 (both used in SVG module) to avoid CVE in one or both. Thanks @avoiculet. + [#396](https://github.com/danfickle/openhtmltopdf/issues/396) Much faster rendering of boxes using border-radius properties. Thanks @mndzielski. diff --git a/README.md b/README.md index ec4ecec08..f4d79224e 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ from ````/openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/Testc ## CHANGELOG ### head - 1.0.1-SNAPSHOT ++ [#403](https://github.com/danfickle/openhtmltopdf/issues/403) Soft hyphen support. Soft hyphens are now replaced with hard hyphens when used as line ending character. Thanks @sbrunecker. + [#408](https://github.com/danfickle/openhtmltopdf/issues/408) Fix for bookmarks not working with HTML5 parsers such as JSoup. Thanks @syjer for investigating and fixing and @Milchreis for reporting. + [#404](https://github.com/danfickle/openhtmltopdf/issues/404) Upgrade Batik to 1.12 and xmlgraphics-common to 2.4 (both used in SVG module) to avoid CVE in one or both. Thanks @avoiculet. + [#396](https://github.com/danfickle/openhtmltopdf/issues/396) Much faster rendering of boxes using border-radius properties. Thanks @mndzielski. diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java index 5f5a230c1..13fc033e7 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java @@ -418,6 +418,29 @@ public final class CSSName implements Comparable { new PrimitivePropertyBuilders.FSPageBreakMinHeight() ); + /** + * The max extra spacing for space characters when text-align: justify is in use. + */ + public final static CSSName FS_MAX_JUSTIFICATION_INTER_WORD = + addProperty( + "-fs-max-justification-inter-word", + PRIMITIVE, + "2cm", + INHERITS, + new PrimitivePropertyBuilders.FSMaxJustificationInterWord() + ); + /** + * The max extra spacing for non-space characters when text-align: justify is in use. + */ + public final static CSSName FS_MAX_JUSTIFICATION_INTER_CHAR = + addProperty( + "-fs-max-justification-inter-char", + PRIMITIVE, + "0.5mm", + INHERITS, + new PrimitivePropertyBuilders.FSMaxJustificationInterChar() + ); + /** * Unique CSSName instance for CSS2 property. */ diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java index c41cb6b34..64033a895 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java @@ -1258,6 +1258,12 @@ public static class MinWidth extends NonNegativeLengthLike { public static class FSPageBreakMinHeight extends NonNegativeLengthLike { } + + public static class FSMaxJustificationInterWord extends NonNegativeLengthLike { + } + + public static class FSMaxJustificationInterChar extends NonNegativeLengthLike { + } public static class Orphans extends PlainInteger { protected boolean isNegativeValuesAllowed() { diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/LineBox.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/LineBox.java index aa978917b..335509d01 100755 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/LineBox.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/LineBox.java @@ -228,6 +228,9 @@ public void justify(CssContext c) { leftFloatDistance - rightFloatDistance - getContentStart(); if (available > getContentWidth()) { + float maxInterChar = getParent().getStyle().getFloatPropertyProportionalWidth(CSSName.FS_MAX_JUSTIFICATION_INTER_CHAR, getParent().getWidth(), c); + float maxInterWord = getParent().getStyle().getFloatPropertyProportionalWidth(CSSName.FS_MAX_JUSTIFICATION_INTER_WORD, getParent().getWidth(), c); + int toAdd = available - getContentWidth(); CharCounts counts = countJustifiableChars(); @@ -236,20 +239,19 @@ public void justify(CssContext c) { if (counts.getSpaceCount() > 0) { if (counts.getNonSpaceCount() > 1) { - info.setNonSpaceAdjust((float)toAdd * JUSTIFY_NON_SPACE_SHARE / (counts.getNonSpaceCount()-1)); + info.setNonSpaceAdjust(Math.min((float)toAdd * JUSTIFY_NON_SPACE_SHARE / (counts.getNonSpaceCount()-1), maxInterChar)); } else { info.setNonSpaceAdjust(0.0f); } if (counts.getSpaceCount() > 0) { - info.setSpaceAdjust((float)toAdd * JUSTIFY_SPACE_SHARE / counts.getSpaceCount()); + info.setSpaceAdjust(Math.min((float)toAdd * JUSTIFY_SPACE_SHARE / counts.getSpaceCount(), maxInterWord)); } else { info.setSpaceAdjust(0.0f); } } else { info.setSpaceAdjust(0f); - // TODO: Configure the maximum gap between characters for justification through CSS. - info.setNonSpaceAdjust(Math.min((float) toAdd / (counts.getNonSpaceCount() - 1), 150)); + info.setNonSpaceAdjust(Math.min((float) toAdd / (counts.getNonSpaceCount() - 1), maxInterChar)); } adjustChildren(info); diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-floats-unbalanced.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-floats-unbalanced.pdf index 54bc6f095..0e3175423 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-floats-unbalanced.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-floats-unbalanced.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-nested-unbalanced.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-nested-unbalanced.pdf index 1d75ad5b9..fae21776f 100644 Binary files a/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-nested-unbalanced.pdf and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/columns-nested-unbalanced.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 new file mode 100644 index 000000000..100cf11ae Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/text/soft-hyphens.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/soft-hyphens.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/soft-hyphens.html index 474d106a6..116faf7f9 100644 --- a/openhtmltopdf-examples/src/main/resources/visualtest/html/text/soft-hyphens.html +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/text/soft-hyphens.html @@ -10,6 +10,8 @@ body { padding: 0; margin: 0; + -fs-max-justification-inter-char: 1cm; + -fs-max-justification-inter-word: 3cm; } table { border-collapse: collapse; diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java index 945126bd7..dea5c5d88 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/TextVisualRegressionTest.java @@ -620,7 +620,6 @@ public void testJustifySpaceAtEnd() throws IOException { * Issue 403. */ @Test - @Ignore // Need to work on configurable text justification. public void testSoftHyphens() throws IOException { assertTrue(vtester.runTest("soft-hyphens", WITH_COLLAPSED_LINE_BREAKER)); } @@ -638,7 +637,6 @@ public void testColumnsSimpleUnbalanced() throws IOException { * Tests columns with nested content such as paragraphs, lists and span. */ @Test - @Ignore // Need to work on configurable text justification. public void testColumnsNestedUnbalanced() throws IOException { assertTrue(run("columns-nested-unbalanced")); } @@ -648,7 +646,6 @@ public void testColumnsNestedUnbalanced() throws IOException { * Also tests explicit column breaks. */ @Test - @Ignore // Need to work on configurable text justification. public void testColumnsFloatsUnbalanced() throws IOException { assertTrue(run("columns-floats-unbalanced")); }