From: Joerg Pietschmann Date: Sat, 10 Aug 2002 20:09:40 +0000 (+0000) Subject: Better fix for setting TextDecoration. X-Git-Tag: fop-0_20_5rc~105 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d38ec8086d79c1b82a4e00f90d38c21bf717c453;p=xmlgraphics-fop.git Better fix for setting TextDecoration. Changed error handling and detection of markers which are not initial children of their parent. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_20_2-maintain@195076 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/FONode.java b/src/org/apache/fop/fo/FONode.java index 78a6f8b22..03828659e 100644 --- a/src/org/apache/fop/fo/FONode.java +++ b/src/org/apache/fop/fo/FONode.java @@ -202,4 +202,9 @@ abstract public class FONode { ((FONode)children.get(this.marker)).rollback(snapshot); } + + public boolean mayPrecedeMarker() { + return false; + } + } diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index dd01555c3..f03cbea50 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -22,53 +22,38 @@ import org.apache.fop.apps.FOPException; */ public class FOText extends FONode { - protected char[] ca; - protected int length; + private char[] ca; - FontState fs; - float red; - float green; - float blue; - int wrapOption; - int whiteSpaceCollapse; - int verticalAlign; + private FontState fs; + private float red; + private float green; + private float blue; + private int wrapOption; + private int whiteSpaceCollapse; + private int verticalAlign; // Textdecoration - protected boolean underlined = false; - protected boolean overlined = false; - protected boolean lineThrough = false; - - TextState ts; + private TextState ts; public FOText(StringBuffer b, FObj parent) { super(parent); - this.length = b.length(); - this.ca = new char[this.length]; - b.getChars(0,length,ca,0); - } - - public void setUnderlined(boolean ul) { - this.underlined = ul; + this.ca = new char[b.length()]; + b.getChars(0,b.length(),ca,0); } - public void setOverlined(boolean ol) { - this.overlined = ol; + public void setTextState(TextState ts) { + this.ts = ts; } - public void setLineThrough(boolean lt) { - this.lineThrough = lt; - } - - public boolean willCreateArea() { this.whiteSpaceCollapse = this.parent.properties.get("white-space-collapse").getEnum(); if (this.whiteSpaceCollapse == WhiteSpaceCollapse.FALSE - && length > 0) { + && ca.length > 0) { return true; } - for (int i = 0; i < length; i++) { + for (int i = 0; i < ca.length; i++) { char ch = ca[i]; if (!((ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t'))) { // whitespace @@ -78,10 +63,21 @@ public class FOText extends FONode { return false; } + public boolean mayPrecedeMarker() { + for (int i = 0; i < ca.length; i++) { + char ch = ca[i]; + if ((ch != ' ') || (ch != '\n') || (ch != '\r') + || (ch != '\t')) { // whitespace + return true; + } + } + return false; + } + public Status layout(Area area) throws FOPException { if (!(area instanceof BlockArea)) { log.error("text outside block area" - + new String(ca, 0, length)); + + new String(ca, 0, ca.length)); return new Status(Status.OK); } if (this.marker == START) { @@ -116,17 +112,12 @@ public class FOText extends FONode { this.parent.properties.get("wrap-option").getEnum(); this.whiteSpaceCollapse = this.parent.properties.get("white-space-collapse").getEnum(); - this.ts = new TextState(); - ts.setUnderlined(underlined); - ts.setOverlined(overlined); - ts.setLineThrough(lineThrough); - this.marker = 0; } int orig_start = this.marker; this.marker = addText((BlockArea)area, fs, red, green, blue, wrapOption, this.getLinkSet(), - whiteSpaceCollapse, ca, this.marker, length, + whiteSpaceCollapse, ca, this.marker, ca.length, ts, verticalAlign); if (this.marker == -1) { diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index 86e15b479..a6f2b73ea 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -27,10 +27,6 @@ public abstract class FObj extends FONode { PropertyList propertyList) throws FOPException; } -// public static Maker maker() { -// return new Maker(); -// } - // protected PropertyList properties; public PropertyList properties; protected PropertyManager propMgr; @@ -38,8 +34,6 @@ public abstract class FObj extends FONode { // markers private HashMap markers; -// protected String name; - protected FObj(FObj parent, PropertyList propertyList) { super(parent); this.properties = propertyList; // TO BE REMOVED!!! @@ -159,9 +153,14 @@ public abstract class FObj extends FONode { public void addMarker(Marker marker) throws FOPException { String mcname = marker.getMarkerClassName(); - if (!children.isEmpty()) { - throw new FOPException("A fo:marker must be an initial child of '" - + getName()); + if (children != null) { + for (int i = 0; i < children.size(); i++) { + FONode child = (FONode)children.get(i); + if (!child.mayPrecedeMarker()) { + throw new FOPException("A fo:marker must be an initial child of '" + + getName()+"'"); + } + } } if (markers==null) { markers = new HashMap(); diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java index 1b45a88e9..2d2a55f11 100644 --- a/src/org/apache/fop/fo/FObjMixed.java +++ b/src/org/apache/fop/fo/FObjMixed.java @@ -18,16 +18,19 @@ import org.apache.fop.apps.FOPException; public abstract class FObjMixed extends FObj { // Textdecoration - protected TextState ts; + protected TextState textState; private StringBuffer textBuffer; - protected FObjMixed(FObj parent, PropertyList propertyList) { + protected FObjMixed(FObj parent, PropertyList propertyList) + throws FOPException { super(parent, propertyList); + textState = propMgr.getTextDecoration(parent); + } public TextState getTextState() { - return ts; + return textState; } protected void addCharacters(char data[], int start, int length) { @@ -40,12 +43,7 @@ public abstract class FObjMixed extends FObj { private final void finalizeText() { if (textBuffer!=null) { FOText ft = new FOText(textBuffer, this); - ft.setLogger(log); - if (ts != null) { - ft.setUnderlined(ts.getUnderlined()); - ft.setOverlined(ts.getOverlined()); - ft.setLineThrough(ts.getLineThrough()); - } + ft.setTextState(textState); super.addChild(ft); textBuffer.setLength(0); } diff --git a/src/org/apache/fop/fo/PropertyManager.java b/src/org/apache/fop/fo/PropertyManager.java index cd6b57d9e..c63be2dd5 100644 --- a/src/org/apache/fop/fo/PropertyManager.java +++ b/src/org/apache/fop/fo/PropertyManager.java @@ -12,6 +12,7 @@ import java.text.FieldPosition; import java.text.MessageFormat; import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.flow.AbstractFlow; import org.apache.fop.fo.properties.BreakAfter; import org.apache.fop.fo.properties.BreakBefore; import org.apache.fop.fo.properties.Constants; @@ -300,10 +301,9 @@ public class PropertyManager { boolean found = false; do { - String fname = parent.getName(); - if (fname.equals("fo:flow") || fname.equals("fo:static-content")) { + if (parent instanceof AbstractFlow) { found = true; - } else if (fname.equals("fo:block") || fname.equals("fo:inline")) { + } else if (parent instanceof FObjMixed) { FObjMixed fom = (FObjMixed) parent; tsp = fom.getTextState(); found = true; diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index 95de87212..c130235f5 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -68,7 +68,6 @@ public class Block extends FObjMixed { super(parent, propertyList); this.span = this.properties.get("span").getEnum(); - ts = propMgr.getTextDecoration(parent); } public String getName() { diff --git a/src/org/apache/fop/fo/flow/Inline.java b/src/org/apache/fop/fo/flow/Inline.java index 1418ce863..943d183db 100644 --- a/src/org/apache/fop/fo/flow/Inline.java +++ b/src/org/apache/fop/fo/flow/Inline.java @@ -69,9 +69,6 @@ public class Inline extends FObjMixed { // this.properties.get("visibility"); // this.properties.get("z-index"); - // Text Decoration Properties - ts = propMgr.getTextDecoration(parent); - } public String getName() { diff --git a/src/org/apache/fop/fo/flow/Leader.java b/src/org/apache/fop/fo/flow/Leader.java index 55b08acba..53a3d6436 100644 --- a/src/org/apache/fop/fo/flow/Leader.java +++ b/src/org/apache/fop/fo/flow/Leader.java @@ -38,7 +38,8 @@ public class Leader extends FObjMixed { return new Leader.Maker(); } - public Leader(FObj parent, PropertyList propertyList) { + public Leader(FObj parent, PropertyList propertyList) + throws FOPException { super(parent, propertyList); } diff --git a/src/org/apache/fop/fo/flow/Marker.java b/src/org/apache/fop/fo/flow/Marker.java index 0b3ffdcc9..3773d3c45 100644 --- a/src/org/apache/fop/fo/flow/Marker.java +++ b/src/org/apache/fop/fo/flow/Marker.java @@ -31,7 +31,8 @@ public class Marker extends FObjMixed { return new Marker.Maker(); } - public Marker(FObj parent, PropertyList propertyList) { + public Marker(FObj parent, PropertyList propertyList) + throws FOPException { super(parent, propertyList); // do check to see that 'this' is under fo:flow @@ -41,13 +42,7 @@ public class Marker extends FObjMixed { // check to ensure that no other marker with same parent // has this 'marker-class-name' is in addMarker() method - try { - parent.addMarker(this); - } catch (FOPException fopex) { - // log is null in constructor - //log.error("marker cannot be added to '" + parent - // + "'"); - } + parent.addMarker(this); } public String getName() { @@ -89,4 +84,7 @@ public class Marker extends FObjMixed { return registryArea; } + public boolean mayPrecedeMarker() { + return true; + } } diff --git a/src/org/apache/fop/fo/flow/Wrapper.java b/src/org/apache/fop/fo/flow/Wrapper.java index 14510be93..1e7c39ab1 100644 --- a/src/org/apache/fop/fo/flow/Wrapper.java +++ b/src/org/apache/fop/fo/flow/Wrapper.java @@ -42,7 +42,6 @@ public class Wrapper extends FObjMixed { throws FOPException { super(parent, propertyList); // check that this occurs inside an fo:flow - ts = propMgr.getTextDecoration(parent); } }