[FOray-commit] SF.net SVN: foray:[12379] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-01-11 13:32:54
|
Revision: 12379
http://sourceforge.net/p/foray/code/12379
Author: victormote
Date: 2022-01-11 13:32:51 +0000 (Tue, 11 Jan 2022)
Log Message:
-----------
Conform to aXSL changes: For text areas backed by word-based Fo Text classes, use location scheme to mark the bounds of text on a given line.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/LineArea4a.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoTextWords4a.java
trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/FoTextWordsPnr.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AbstractAncestralInlineArea.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -92,8 +92,9 @@
}
@Override
- public GlyphAreaSequenceG5 makeGlyphAreaSequence(final FoTextWords paragraph, final int startLeaf,
- final int sizeInLeaves, final boolean hasFauxSmallCaps) {
+ public GlyphAreaSequenceG5 makeGlyphAreaSequence(final FoTextWords paragraph,
+ final FoTextWords.Location startLocation, final FoTextWords.Location endLocation,
+ final boolean hasFauxSmallCaps) {
throw new UnsupportedOperationException();
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/LineArea4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/LineArea4a.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/LineArea4a.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -1014,9 +1014,10 @@
}
@Override
- public GlyphAreaSequenceG5 makeGlyphAreaSequence(final FoTextWords paragraph, final int startLeaf,
- final int sizeInLeaves, final boolean hasFauxSmallCaps) {
- final TextAreaWords newTextArea = TextAreaWords.makeTextArea(paragraph, this, startLeaf, sizeInLeaves);
+ public GlyphAreaSequenceG5 makeGlyphAreaSequence(final FoTextWords paragraph,
+ final FoTextWords.Location startLocation, final FoTextWords.Location endLocation,
+ final boolean hasFauxSmallCaps) {
+ final TextAreaWords newTextArea = TextAreaWords.makeTextArea(paragraph, this, startLocation, endLocation);
this.children.add(newTextArea);
return newTextArea;
}
@@ -1127,12 +1128,13 @@
@Override
public void addParaBranch(final ParaBranch branch, final int offset, final int length) {
- if (branch instanceof FoTextWords) {
- final FoTextWords foTextWords = (FoTextWords) branch;
- makeGlyphAreaSequence(foTextWords, offset, length, false);
- return;
- }
- throw new IllegalArgumentException();
+// if (branch instanceof FoTextWords) {
+// final FoTextWords foTextWords = (FoTextWords) branch;
+// makeGlyphAreaSequence(foTextWords, offset, length, false);
+// return;
+// }
+// throw new IllegalArgumentException();
+ throw new UnsupportedOperationException();
}
/**
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextArea.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -329,53 +329,15 @@
* rendered as spaces in the output.
* @return The numbers of spaces in this text.
*/
- public int countSpaces() {
- int spaceCount = 0;
- final CharSequence text = this.getText();
- /* Cache the length to avoid recomputing it on every iteration. */
- final int length = text.length();
- for (int i = 0; i < length; i++) {
- final char c = text.charAt(i);
- if (wordSpacingApplies(c)) {
- spaceCount ++;
- }
- }
- return spaceCount;
- }
+ public abstract int countSpaces();
/**
- * Indicates whether word-spacing should be applied to a given character.
- * @param c The character to be tested.
- * @return True if and only if word-spacing should be added for this character.
- */
- private boolean wordSpacingApplies(final int c) {
- switch (c) {
- case ' ': {
- return true;
- }
- default: {
- return false;
- }
- }
- }
-
- /**
* Counts the number of characters in this text that will have
* letter-spacing applied to them.
* @return The numbers of characters in this text to which letter-spacing
* will be applied.
*/
- public int countLetterSpacingChars() {
- /* TODO: The theory here is that all characters except those that have
- * word-spacing applied should have letter-spacing applied, including
- * the last one. I'm not sure this is right. Needs to be tested. Also,
- * letter-spacing may need to be turned off for spaces with specific
- * widths, like the 1/3 em space, etc. */
- int letterCount = 0;
- letterCount += this.getText().length();
- letterCount -= this.countSpaces();
- return letterCount;
- }
+ public abstract int countLetterSpacingChars();
/**
* Returns the resolved letter-spacing, in millipoints.
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaCharacters.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -446,4 +446,57 @@
return this.foLink.getGenerator();
}
+ /**
+ * Counts the number of space-like characters in this text that should be
+ * rendered as spaces in the output.
+ * @return The numbers of spaces in this text.
+ */
+ public int countSpaces() {
+ int spaceCount = 0;
+ final CharSequence text = this.getText();
+ /* Cache the length to avoid recomputing it on every iteration. */
+ final int length = text.length();
+ for (int i = 0; i < length; i++) {
+ final char c = text.charAt(i);
+ if (wordSpacingApplies(c)) {
+ spaceCount ++;
+ }
+ }
+ return spaceCount;
+ }
+
+ /**
+ * Indicates whether word-spacing should be applied to a given character.
+ * @param c The character to be tested.
+ * @return True if and only if word-spacing should be added for this character.
+ */
+ private boolean wordSpacingApplies(final int c) {
+ switch (c) {
+ case ' ': {
+ return true;
+ }
+ default: {
+ return false;
+ }
+ }
+ }
+
+ /**
+ * Counts the number of characters in this text that will have
+ * letter-spacing applied to them.
+ * @return The numbers of characters in this text to which letter-spacing
+ * will be applied.
+ */
+ public int countLetterSpacingChars() {
+ /* TODO: The theory here is that all characters except those that have
+ * word-spacing applied should have letter-spacing applied, including
+ * the last one. I'm not sure this is right. Needs to be tested. Also,
+ * letter-spacing may need to be turned off for spaces with specific
+ * widths, like the 1/3 em space, etc. */
+ int letterCount = 0;
+ letterCount += this.getText().length();
+ letterCount -= this.countSpaces();
+ return letterCount;
+ }
+
}
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/TextAreaWords.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -30,7 +30,6 @@
import org.foray.area.link.Link;
-import org.axsl.common.para.ParaLeaf;
import org.axsl.fotree.fo.FoTextWords;
public class TextAreaWords extends TextArea {
@@ -38,27 +37,25 @@
/** The link to the FO tree. */
private Link<FoTextWords> foLink;
- /** The first leaf index into the backing for {@link #foLink} that is part of this text area. */
- private int startingLeafIndex;
+ /** The starting location in {@link #foLink#traitGeneratedBy()} for the text in this area, inclusive. */
+ private FoTextWords.Location startLocation;
- /** The number of leaf indexes in the backing for {@link #foLink} that are part of this text area. */
- private int qtyLeaves;
+ /** The ending location in {@link #foLink#traitGeneratedBy()} for the text in this area, exclusive. */
+ private FoTextWords.Location endLocation;
/**
* Constructor.
* @param parentArea The parent area.
* @param generatedBy The FO tree linkage.
- * @param startingLeafIndex The first leaf index into the backing for {@code #generatedBy} that is part of this text
- * area.
- * @param qtyLeaves The number of leaf indexes in the backing for {@code #generatedBy} that are part of this text
- * area.
+ * @param startLocation The starting location in {@code generatedBy} for the text in this area, inclusive.
+ * @param endLocation The ending location in {@code generatedBy} for the text in this area, exclusive.
*/
- public TextAreaWords(final LineArea4a parentArea, final Link<FoTextWords> generatedBy, final int startingLeafIndex,
- final int qtyLeaves) {
+ public TextAreaWords(final LineArea4a parentArea, final Link<FoTextWords> generatedBy,
+ final FoTextWords.Location startLocation, final FoTextWords.Location endLocation) {
super(parentArea);
this.foLink = generatedBy;
- this.startingLeafIndex = startingLeafIndex;
- this.qtyLeaves = qtyLeaves;
+ this.startLocation = startLocation;
+ this.endLocation = endLocation;
}
/**
@@ -65,16 +62,14 @@
* Package-visible factory method.
* @param generatedBy The FO node generating this area.
* @param parentArea The parent area.
- * @param startingLeafIndex The first leaf index into the backing for {@code #generatedBy} that is part of this text
- * area.
- * @param qtyLeaves The number of leaf indexes in the backing for {@code #generatedBy} that are part of this text
- * area.
+ * @param startLocation The starting location in {@code generatedBy} for the text in this area, inclusive.
+ * @param endLocation The ending location in {@code generatedBy} for the text in this area, exclusive.
* @return The newly-created TextArea.
*/
static TextAreaWords makeTextArea(final FoTextWords generatedBy, final LineArea4a parentArea,
- final int startingLeafIndex, final int qtyLeaves) {
+ final FoTextWords.Location startLocation, final FoTextWords.Location endLocation) {
final Link<FoTextWords> linkage = parentArea.getLink(generatedBy);
- final TextAreaWords newTextArea = new TextAreaWords(parentArea, linkage, startingLeafIndex, qtyLeaves);
+ final TextAreaWords newTextArea = new TextAreaWords(parentArea, linkage, startLocation, endLocation);
newTextArea.registerLink(generatedBy);
return newTextArea;
}
@@ -86,13 +81,8 @@
@Override
public CharSequence getText() {
- final StringBuilder builder = new StringBuilder();
- final FoTextWords words = this.foLink.getGenerator();
- for (int index = this.startingLeafIndex; index < (this.startingLeafIndex + this.qtyLeaves); index ++) {
- final ParaLeaf leaf = words.paraLeafAt(index);
- builder.append(leaf.getText());
- }
- return builder.toString();
+ final FoTextWords generator = this.foLink.getGenerator();
+ return generator.extract(this.startLocation, this.endLocation, this);
}
@Override
@@ -112,4 +102,16 @@
return this.getFoLink().getGenerator();
}
+ @Override
+ public int countSpaces() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int countLetterSpacingChars() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoTextWords4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoTextWords4a.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoTextWords4a.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -185,8 +185,13 @@
@Override
public CharSequence extract(final TokenFlow.Location startLocation, final TokenFlow.Location endLocation,
final TextModifiers textModifiers) {
- // TODO Auto-generated method stub
- return null;
+ final StringBuilder builder = new StringBuilder();
+ /* TODO: Handle the segment and character indexes as well. */
+ for (int tokenIndex = startLocation.getTokenIndex(); tokenIndex < endLocation.getTokenIndex(); tokenIndex ++) {
+ final FoToken token = tokenAt(tokenIndex);
+ builder.append(token.getText());
+ }
+ return builder.toString();
}
@Override
Modified: trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/FoTextWordsPnr.java
===================================================================
--- trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/FoTextWordsPnr.java 2022-01-10 22:11:20 UTC (rev 12378)
+++ trunk/foray/foray-pioneer/src/main/java/org/foray/pioneer/FoTextWordsPnr.java 2022-01-11 13:32:51 UTC (rev 12379)
@@ -28,6 +28,8 @@
package org.foray.pioneer;
+import org.foray.common.para.ParaBranch4aIterator;
+
import org.axsl.area.AreaNode;
import org.axsl.area.AreaTreeException;
import org.axsl.area.LineArea;
@@ -73,12 +75,26 @@
final LineBreaker lb = areaNode.getAreaTree().getLineBreaker();
final LineBreakResult result = lb.breakIntoLines(this.node, (ParaConfig) this.node, paraContext);
- int lastLeafIndex = 0;
+ FoTextWords.Location startLocation = this.node.markLocation(0, (byte) -1, (byte) -1);
+ /* Run a leaf iterator alongside the iteration of the line-break results, so that we can conveniently retrieve
+ * the branch indexes. */
+ final ParaBranch4aIterator iterator = new ParaBranch4aIterator(this.node);
for (int index = 0; index < result.getQtyLines(); index ++) {
final int currentLeafIndex = result.getBreakPosition(index);
final LineArea lineArea = normalBlockArea.makeLineArea(true);
- lineArea.makeGlyphAreaSequence(this.node, lastLeafIndex, currentLeafIndex - lastLeafIndex, false);
- lastLeafIndex = currentLeafIndex;
+ while (iterator.nextIndex() < currentLeafIndex) {
+ if (iterator.hasNext()) {
+ iterator.next();
+ } else {
+ throw new IllegalStateException("Iterator cannot go past last element.");
+ }
+ }
+ /* Element 0 should be the token index. If there is an element 1, it should be the segment index. */
+ final int tokenIndex = iterator.branchIndexAt(0);
+ final byte segmentIndex = iterator.depth() > 1 ? (byte) iterator.branchIndexAt(1) : -1;
+ final FoTextWords.Location endLocation = this.node.markLocation(tokenIndex, segmentIndex, (byte) -1);
+ lineArea.makeGlyphAreaSequence(this.node, startLocation, endLocation, false);
+ startLocation = endLocation;
}
return Status.OK;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|