[FOray-commit] SF.net SVN: foray:[12390] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-01-13 17:29:52
|
Revision: 12390
http://sourceforge.net/p/foray/code/12390
Author: victormote
Date: 2022-01-13 17:29:49 +0000 (Thu, 13 Jan 2022)
Log Message:
-----------
1. Conform to and use results of aXSL change: Add the hyphenation character as part of the TextModifiers. 2. Add test of hyphenated line.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java
trunk/foray/foray-orthography/src/main/java/org/foray/orthography/TokenFlow4a.java
trunk/foray/foray-orthography/src/test/java/org/foray/orthography/TokenFlow4aTests.java
trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2022-01-13 14:33:00 UTC (rev 12389)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2022-01-13 17:29:49 UTC (rev 12390)
@@ -43,6 +43,7 @@
import org.axsl.fotree.fo.GraftingPoint;
import org.axsl.fotree.fo.Table;
import org.axsl.fotree.fo.prop.ColorPa;
+import org.axsl.fotree.fo.prop.CommonHyphenationPa;
import org.axsl.galley.AreaNodeG5;
import org.axsl.galley.Galley;
import org.axsl.orthography.Orthography;
@@ -766,4 +767,21 @@
final Block block = nearestBlockArea.traitGeneratedBy();
return block.traitWhiteSpaceCollapse(nearestBlockArea);
}
+
+ @Override
+ public int traitHyphenationCharacter() {
+ AreaNode4a areaNode = this;
+ Fo generator = traitGeneratedBy();
+ while (areaNode != null
+ && ! (generator instanceof CommonHyphenationPa)) {
+ areaNode = areaNode.getParent();
+ generator = areaNode.traitGeneratedBy();
+ }
+ if (areaNode == null) {
+ throw new IllegalStateException(this.getClass().getName() + " unable to find hyphenation character");
+ }
+ final CommonHyphenationPa fo = (CommonHyphenationPa) generator;
+ return fo.traitHyphenationCharacter(this);
+ }
+
}
Modified: trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java
===================================================================
--- trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java 2022-01-13 14:33:00 UTC (rev 12389)
+++ trunk/foray/foray-fotree/src/test/java/org/foray/fotree/AbstractPropertyTest.java 2022-01-13 17:29:49 UTC (rev 12390)
@@ -100,6 +100,10 @@
public WhiteSpaceTreatment traitWhiteSpaceTreatment() {
return WhiteSpaceTreatment.IGNORE_IF_SURROUNDING_LINEFEED;
}
+ @Override
+ public int traitHyphenationCharacter() {
+ return '-';
+ }
};
/** Constant providing a standard, but completely bogus context to be
Modified: trunk/foray/foray-orthography/src/main/java/org/foray/orthography/TokenFlow4a.java
===================================================================
--- trunk/foray/foray-orthography/src/main/java/org/foray/orthography/TokenFlow4a.java 2022-01-13 14:33:00 UTC (rev 12389)
+++ trunk/foray/foray-orthography/src/main/java/org/foray/orthography/TokenFlow4a.java 2022-01-13 17:29:49 UTC (rev 12390)
@@ -261,10 +261,33 @@
currentLocation.markTokenComplete();
}
+ if (isHyphenNeeded(isEndOfLine, endLocation)) {
+ builder.append(Character.toChars(textModifiers.traitHyphenationCharacter()));
+ }
+
applyWhiteSpaceTreatmentToLine(builder, textModifiers.traitWhiteSpaceTreatment(), isStartOfLine, isEndOfLine);
return builder.toString();
}
+ private boolean isHyphenNeeded(final boolean isEndOfLine, final TokenFlow.Location endLocation) {
+ if (! isEndOfLine) {
+ return false;
+ }
+ if (endLocation.getTokenIndex() >= this.qtyTokens()) {
+ /* The token marked as being the end of the token flow is past the end, indicating that all of the last
+ * token was included. */
+ return false;
+ }
+ final FoToken lastToken = this.tokenAt(endLocation.getTokenIndex());
+ if (lastToken instanceof FoWord) {
+ final FoWord word = (FoWord) lastToken;
+ final int qtySegments = word.qtyWordSegments();
+ return endLocation.getSegmentIndex() < qtySegments;
+ } else {
+ return false;
+ }
+ }
+
/**
* For tokens where it matters, computes the whitespace Unicode codepoint, if any, immediately before that token.
* This computation is only relevant for contiguous whitespace tokens, so that white-space-collapse can be properly
Modified: trunk/foray/foray-orthography/src/test/java/org/foray/orthography/TokenFlow4aTests.java
===================================================================
--- trunk/foray/foray-orthography/src/test/java/org/foray/orthography/TokenFlow4aTests.java 2022-01-13 14:33:00 UTC (rev 12389)
+++ trunk/foray/foray-orthography/src/test/java/org/foray/orthography/TokenFlow4aTests.java 2022-01-13 17:29:49 UTC (rev 12390)
@@ -34,6 +34,7 @@
import org.axsl.common.value.WhiteSpaceTreatment;
import org.axsl.fotree.text.FoTokenFlow;
import org.axsl.orthography.TokenFlow;
+import org.axsl.unicode.block.Basic_Latin_Block;
import org.junit.Assert;
import org.junit.Test;
@@ -189,6 +190,7 @@
Mockito.when(textModifiers.traitWhiteSpaceTreatment()).thenReturn(
WhiteSpaceTreatment.IGNORE_IF_SURROUNDING_LINEFEED);
Mockito.when(textModifiers.traitWhiteSpaceCollapse()).thenReturn(true);
+ Mockito.when(textModifiers.traitHyphenationCharacter()).thenReturn((int) Basic_Latin_Block.HYPHEN_MINUS);
/* Test extract starting at the start. */
TokenFlow.Location start = out.markLocation(0, 0, 0);
@@ -208,6 +210,18 @@
start = out.markLocation(12, 1, 0);
end = out.markLocation(18, 0, 0);
Assert.assertEquals("gainst than sinning.", out.extract(start, end, textModifiers, false, false));
+
+ /* Test extract starting in the middle of a word and ending in the middle of a word, where the text is not at
+ * the end of the line. */
+ start = out.markLocation(12, 1, 0);
+ end = out.markLocation(16, 1, 0);
+ Assert.assertEquals("gainst than sin", out.extract(start, end, textModifiers, false, false));
+
+ /* Test extract starting in the middle of a word and ending in the middle of a word, where the text IS at the
+ * end of the line, i.e. where a discretionary hyphen should be added. */
+ start = out.markLocation(12, 1, 0);
+ end = out.markLocation(16, 1, 0);
+ Assert.assertEquals("gainst than sin-", out.extract(start, end, textModifiers, false, true));
}
}
Modified: trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java
===================================================================
--- trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java 2022-01-13 14:33:00 UTC (rev 12389)
+++ trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/OverrideGraftingContext.java 2022-01-13 17:29:49 UTC (rev 12390)
@@ -140,4 +140,9 @@
return this.wrappedContext.traitWhiteSpaceTreatment();
}
+ @Override
+ public int traitHyphenationCharacter() {
+ return this.wrappedContext.traitHyphenationCharacter();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|