Revision: 12318
http://sourceforge.net/p/foray/code/12318
Author: victormote
Date: 2022-01-01 14:58:57 +0000 (Sat, 01 Jan 2022)
Log Message:
-----------
Fix error in creation of text content.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Block4a.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoText4a.java
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-01-01 01:03:34 UTC (rev 12317)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2022-01-01 14:58:57 UTC (rev 12318)
@@ -44,10 +44,12 @@
import org.foray.fotree.fo.obj.Block4a;
import org.foray.fotree.fo.obj.Flow4a;
import org.foray.fotree.fo.obj.FoScaled4a;
+import org.foray.fotree.fo.obj.FoText4a;
import org.foray.fotree.fo.obj.FoTextCharacters4a;
import org.foray.fotree.fo.obj.Leader4a;
import org.foray.fotree.fo.obj.ListBlock4a;
import org.foray.fotree.fo.obj.ListItem4a;
+import org.foray.fotree.fo.obj.Marker4a;
import org.foray.fotree.fo.obj.Root4a;
import org.foray.fotree.fo.obj.StaticContent4a;
import org.foray.fotree.fo.obj.Table4a;
@@ -3234,6 +3236,34 @@
*/
public abstract boolean canHaveMarkerChildren();
+ /**
+ * Indicates whether it is valid to add fo:marker(s) to this FO.
+ * This method is generally only useful during FO tree construction.
+ * Markers can only be added at the beginning of FOs in which they are valid.
+ * However, if the FO so far contains only whitespace content, we treat that as ignorable whitespace, and
+ * allow markers to be added.
+ * @return True if and only if fo:marker(s) can be added to this FO.
+ */
+ protected boolean canAddMarkers() {
+ if (! canHaveMarkerChildren()) {
+ return false;
+ }
+ for (int index = 0; index < getChildren().size(); index ++) {
+ final FoObj child = getChildren().get(index);
+ if (child instanceof Marker4a) {
+ continue;
+ }
+ if (child instanceof FoText4a) {
+ final FoText4a text = (FoText4a) child;
+ if (text.isAllWhiteSpace()) {
+ continue;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
@Override
public int qtyMarkerChildren() {
int qtyMarkers = 0;
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java 2022-01-01 01:03:34 UTC (rev 12317)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/AbstractCharacterSequence.java 2022-01-01 14:58:57 UTC (rev 12318)
@@ -57,12 +57,6 @@
super(parent);
}
- /**
- * Indicates whether this text item is all whitespace.
- * @return True if and only if all of the text in this item is whitespace.
- */
- public abstract boolean isAllWhiteSpace();
-
@Override
public CharSequence inlineText(final TextModifiers textModifers) {
return inlineText(null);
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Block4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Block4a.java 2022-01-01 01:03:34 UTC (rev 12317)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Block4a.java 2022-01-01 14:58:57 UTC (rev 12318)
@@ -168,63 +168,73 @@
return true;
}
-// @Override
-// public void addChild(final FoObj fobj) throws FoTreeException {
-// if (fobj.isAlwaysBlockContent()) {
-// getChildren().add(fobj);
-// return;
-// }
-// if (fobj instanceof FoText4a) {
-// /* If we are still in a place where an fo:marker can be added (i.e. at the beginning of the block), and
-// * this text is all whitespace, it is not really part of the BlockDiscrete content.
-// * Place it directly into the block content so that fo:marker objecs can be added if needed. */
-// if (getChildren().size() < 1
-// || getChildren().get(getChildren().size() - 1) instanceof Marker4a) {
-// getChildren().add(fobj);
-// } else {
-// addBlockDiscreteContent(fobj);
-// }
-// return;
-// }
-// if (fobj.isAlwaysInlineContent()) {
-// addBlockDiscreteContent(fobj);
-// return;
-// }
-// if (fobj instanceof Marker4a) {
-// getChildren().add(fobj);
-// return;
-// }
-// if (fobj instanceof Footnote4a) {
-// addBlockDiscreteContent(fobj);
-// return;
-// }
-// if (fobj.isNeutralContainer()
-// || fobj.isOutOfLineAnyContent()
-// || fobj.isOutOfLineInlineContent()) {
-// /* If it is capable of containing block-level elements, but does not, it can be a child. */
-// if (! fobj.hasDescendantBlocks()) {
-// addBlockDiscreteContent(fobj);
-// } else {
-// getChildren().add(fobj);
-// }
-// return;
-// }
-// throwException("Unable to handle this kind of mixed content.");
-// }
-//
-// private void addBlockDiscreteContent(final FoObj fobj) throws FoTreeException {
-// final FoObj lastChild = this.getLastChild();
-// BlockDiscrete4a discrete = null;
-// if (lastChild == null) {
-// discrete = new BlockDiscrete4a(this);
-// getChildren().add(discrete);
-// } else if (lastChild instanceof BlockDiscrete4a) {
-// discrete = (BlockDiscrete4a) lastChild;
-// } else {
-// discrete = new BlockDiscrete4a(this);
-// getChildren().add(discrete);
-// }
-// discrete.addChild(fobj);
-// }
+ @Override
+ public void addChild(final FoObj fobj) throws FoTreeException {
+ /* TODO: The following code block should be removed when the BlockDiscrete logic is working properly. */
+ if ("block".equals(getName())) {
+ super.addChild(fobj);
+ return;
+ }
+ if (fobj.isAlwaysBlockContent()) {
+ getChildren().add(fobj);
+ return;
+ }
+ if (fobj instanceof FoText4a) {
+ final FoText4a text = (FoText4a) fobj;
+ /* If we are still in a place where an fo:marker can be added (i.e. at the beginning of the block), and
+ * this text is all whitespace, it is not really part of the BlockDiscrete content.
+ * Place it directly into the block content so that fo:marker objects can be added if needed. */
+ if (text.isAllWhiteSpace()
+ && canAddMarkers()) {
+ getChildren().add(fobj);
+ } else {
+ addBlockDiscreteContent(fobj);
+ }
+ return;
+ }
+ if (fobj.isAlwaysInlineContent()) {
+ addBlockDiscreteContent(fobj);
+ return;
+ }
+ if (fobj instanceof Marker4a) {
+ if (canAddMarkers()) {
+ getChildren().add(fobj);
+ } else {
+ throwExceptionContentModelViolation();
+ }
+ return;
+ }
+ if (fobj instanceof Footnote4a) {
+ addBlockDiscreteContent(fobj);
+ return;
+ }
+ if (fobj.isNeutralContainer()
+ || fobj.isOutOfLineAnyContent()
+ || fobj.isOutOfLineInlineContent()) {
+ /* If it is capable of containing block-level elements, but does not, it can be a child. */
+ if (! fobj.hasDescendantBlocks()) {
+ addBlockDiscreteContent(fobj);
+ } else {
+ getChildren().add(fobj);
+ }
+ return;
+ }
+ throwException("Unable to handle this kind of mixed content.");
+ }
+ private void addBlockDiscreteContent(final FoObj fobj) throws FoTreeException {
+ final FoObj lastChild = this.getLastChild();
+ BlockDiscrete4a discrete = null;
+ if (lastChild == null) {
+ discrete = new BlockDiscrete4a(this);
+ getChildren().add(discrete);
+ } else if (lastChild instanceof BlockDiscrete4a) {
+ discrete = (BlockDiscrete4a) lastChild;
+ } else {
+ discrete = new BlockDiscrete4a(this);
+ getChildren().add(discrete);
+ }
+ discrete.addChild(fobj);
+ }
+
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoText4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoText4a.java 2022-01-01 01:03:34 UTC (rev 12317)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/FoText4a.java 2022-01-01 14:58:57 UTC (rev 12318)
@@ -574,4 +574,10 @@
return newStringBuilder;
}
+ /**
+ * Indicates whether this text item is all whitespace.
+ * @return True if and only if all of the text in this item is whitespace.
+ */
+ public abstract boolean isAllWhiteSpace();
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|