Skip to content

Commit

Permalink
#403 Configurable text justification and proof for soft hyphen test.
Browse files Browse the repository at this point in the history
Also, new proofs for column tests which use justified text as we have tweaked the justification algorithm.

Properties introduced to configure text justification are:
+ -fs-max-justification-inter-word
+ -fs-max-justification-inter-char

These properties can only be used on block and block-like (table cells) elements.

This commit should finish the soft-hyphen support which is now supported for normal, justified and custom letter-spacing.
  • Loading branch information
danfickle committed Nov 16, 2019
1 parent 55bb59b commit f02682c
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,29 @@ public final class CSSName implements Comparable<CSSName> {
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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"));
}
Expand All @@ -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"));
}
Expand Down

0 comments on commit f02682c

Please sign in to comment.