From: Karen Lease Date: Sun, 11 Nov 2001 22:09:37 +0000 (+0000) Subject: Move text layout code into TextLayoutManager; add generatesInlineAreas to FObj X-Git-Tag: fop-0_20_4-doc~204 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=452004701f4ec3dc20ba55bc132f28f3f841e099;p=xmlgraphics-fop.git Move text layout code into TextLayoutManager; add generatesInlineAreas to FObj git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194559 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/FOText.java b/src/org/apache/fop/fo/FOText.java index 8c02cc07e..84b9c667b 100644 --- a/src/org/apache/fop/fo/FOText.java +++ b/src/org/apache/fop/fo/FOText.java @@ -56,8 +56,7 @@ public class FOText extends FObj { super(null); this.start = 0; this.ca = new char[e - s]; - for (int i = s; i < e; i++) - ca[i - s] = chars[i]; + System.arraycopy(chars, s, ca, 0, e-s); this.length = e - s; textInfo = ti; } @@ -78,166 +77,19 @@ public class FOText extends FObj { return false; } - public Status layout(Area area) throws FOPException { - if (!(area instanceof BlockArea)) { - log.error("text outside block area" - + new String(ca, start, length)); - return new Status(Status.OK); - } - if (this.marker == START) { - this.ts = new TextState(); - ts.setUnderlined(textInfo.underlined); - ts.setOverlined(textInfo.overlined); - ts.setLineThrough(textInfo.lineThrough); - - this.marker = this.start; - } - int orig_start = this.marker; - this.marker = addText((BlockArea)area, textInfo.fs, textInfo.red, textInfo.green, textInfo.blue, - textInfo.wrapOption, this.getLinkSet(), - textInfo.whiteSpaceCollapse, ca, this.marker, length, - ts, textInfo.verticalAlign); - if (this.marker == -1) { - + // Just to keep PageNumber and PageNumber citation happy for now. + // The real code is moved to TextLayoutManager! - // commented out by Hani Elabed, 11/28/2000 - // if this object has been laid out - // successfully, leave it alone.... - // Now, to prevent the array index out of - // bound of LineArea.addText(), I have added - // the following test at the beginning of that method. - // if( start == -1 ) return -1; - // see LineArea.addText() - - // this.marker = 0; - return new Status(Status.OK); - } else if (this.marker != orig_start) { - return new Status(Status.AREA_FULL_SOME); - } else { - return new Status(Status.AREA_FULL_NONE); - } - } - - // font-variant support : addText is a wrapper for addRealText - // added by Eric SCHAEFFER public static int addText(BlockArea ba, FontState fontState, float red, float green, float blue, int wrapOption, LinkSet ls, int whiteSpaceCollapse, char data[], int start, int end, TextState textState, int vAlign) { - if (fontState.getFontVariant() == FontVariant.SMALL_CAPS) { - FontState smallCapsFontState; - try { - int smallCapsFontHeight = - (int)(((double)fontState.getFontSize()) * 0.8d); - smallCapsFontState = new FontState(fontState.getFontInfo(), - fontState.getFontFamily(), - fontState.getFontStyle(), - fontState.getFontWeight(), - smallCapsFontHeight, - FontVariant.NORMAL); - } catch (FOPException ex) { - smallCapsFontState = fontState; - //log.error("Error creating small-caps FontState: " - // + ex.getMessage()); - } - - // parse text for upper/lower case and call addRealText - char c; - boolean isLowerCase; - int caseStart; - FontState fontStateToUse; - for (int i = start; i < end; ) { - caseStart = i; - c = data[i]; - isLowerCase = (java.lang.Character.isLetter(c) - && java.lang.Character.isLowerCase(c)); - while (isLowerCase - == (java.lang.Character.isLetter(c) - && java.lang.Character.isLowerCase(c))) { - if (isLowerCase) { - data[i] = java.lang.Character.toUpperCase(c); - } - i++; - if (i == end) - break; - c = data[i]; - } - if (isLowerCase) { - fontStateToUse = smallCapsFontState; - } else { - fontStateToUse = fontState; - } - int index = addRealText(ba, fontStateToUse, red, green, blue, - wrapOption, ls, whiteSpaceCollapse, - data, caseStart, i, textState, - vAlign); - if (index != -1) { - return index; - } - } - - return -1; - } - - // font-variant normal - return addRealText(ba, fontState, red, green, blue, wrapOption, ls, - whiteSpaceCollapse, data, start, end, textState, - vAlign); - } - - protected static int addRealText(BlockArea ba, FontState fontState, - float red, float green, float blue, - int wrapOption, LinkSet ls, - int whiteSpaceCollapse, char data[], - int start, int end, TextState textState, - int vAlign) { - int ts, te; - char[] ca; - - ts = start; - te = end; - ca = data; - - LineArea la = ba.getCurrentLineArea(); - if (la == null) { - return start; - } - - la.changeFont(fontState); - la.changeColor(red, green, blue); - la.changeWrapOption(wrapOption); - la.changeWhiteSpaceCollapse(whiteSpaceCollapse); - la.changeVerticalAlign(vAlign); - // la.changeHyphenation(language, country, hyphenate, - // hyphenationChar, hyphenationPushCharacterCount, - // hyphenationRemainCharacterCount); - ba.setupLinkSet(ls); - - ts = la.addText(ca, ts, te, ls, textState); - // this.hasLines = true; - - while (ts != -1) { - la = ba.createNextLineArea(); - if (la == null) { - return ts; - } - la.changeFont(fontState); - la.changeColor(red, green, blue); - la.changeWrapOption(wrapOption); - la.changeWhiteSpaceCollapse(whiteSpaceCollapse); - // la.changeHyphenation(language, country, hyphenate, - // hyphenationChar, hyphenationPushCharacterCount, - // hyphenationRemainCharacterCount); - ba.setupLinkSet(ls); - - ts = la.addText(ca, ts, te, ls, textState); - } - return -1; + return 0; } public LayoutManager getLayoutManager() { - return new TextLayoutManager(this, ca); + return new TextLayoutManager(this, ca, textInfo); } } diff --git a/src/org/apache/fop/fo/FObj.java b/src/org/apache/fop/fo/FObj.java index f4b6b52e6..325a937c1 100644 --- a/src/org/apache/fop/fo/FObj.java +++ b/src/org/apache/fop/fo/FObj.java @@ -176,6 +176,11 @@ public class FObj extends FONode { return false; } + + public boolean generatesInlineAreas() { + return true; + } + /** * Set writing mode for this FO. * Find nearest ancestor, including self, which generates diff --git a/src/org/apache/fop/fo/FObjMixed.java b/src/org/apache/fop/fo/FObjMixed.java index 32eb46651..5a535be84 100644 --- a/src/org/apache/fop/fo/FObjMixed.java +++ b/src/org/apache/fop/fo/FObjMixed.java @@ -9,7 +9,9 @@ package org.apache.fop.fo; import org.apache.fop.layout.Area; import org.apache.fop.layout.FontState; +import org.apache.fop.layout.FontInfo; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.StreamRenderer; import org.apache.fop.datatypes.ColorType; /** @@ -18,30 +20,26 @@ import org.apache.fop.datatypes.ColorType; */ public class FObjMixed extends FObj { FOText.TextInfo textInfo = null; + FontInfo fontInfo=null; public FObjMixed(FONode parent) { super(parent); } + public void setStreamRenderer(StreamRenderer st) { + fontInfo = st.getFontInfo(); + } + protected void addCharacters(char data[], int start, int length) { if(textInfo == null) { textInfo = new FOText.TextInfo(); - String fontFamily = - getProperty("font-family").getString(); - String fontStyle = - getProperty("font-style").getString(); - String fontWeight = - getProperty("font-weight").getString(); - int fontSize = - getProperty("font-size").getLength().mvalue(); - // font-variant support - // added by Eric SCHAEFFER - int fontVariant = - getProperty("font-variant").getEnum(); - - //textInfo.fs = new FontState(area.getFontInfo(), fontFamily, - // fontStyle, fontWeight, fontSize, - // fontVariant); + + try { + textInfo.fs = propMgr.getFontState(fontInfo); + } catch (FOPException fopex) { + log.error("Error setting FontState for characters: " + + fopex.getMessage()); + } ColorType c = getProperty("color").getColorType(); textInfo.red = c.red(); diff --git a/src/org/apache/fop/fo/flow/Block.java b/src/org/apache/fop/fo/flow/Block.java index f548b9e1c..196cf6aa0 100644 --- a/src/org/apache/fop/fo/flow/Block.java +++ b/src/org/apache/fop/fo/flow/Block.java @@ -356,4 +356,8 @@ public class Block extends FObjMixed { return new BlockLayoutManager(this); } + + public boolean generatesInlineAreas() { + return false; + } } diff --git a/src/org/apache/fop/fo/flow/BlockContainer.java b/src/org/apache/fop/fo/flow/BlockContainer.java index fc218cb76..401506209 100644 --- a/src/org/apache/fop/fo/flow/BlockContainer.java +++ b/src/org/apache/fop/fo/flow/BlockContainer.java @@ -167,6 +167,10 @@ public class BlockContainer extends FObj { return true; } + public boolean generatesInlineAreas() { + return false; + } + public int getSpan() { return this.span; } diff --git a/src/org/apache/fop/fo/flow/ListBlock.java b/src/org/apache/fop/fo/flow/ListBlock.java index f66c7ab25..8c8d65d60 100644 --- a/src/org/apache/fop/fo/flow/ListBlock.java +++ b/src/org/apache/fop/fo/flow/ListBlock.java @@ -164,4 +164,9 @@ public class ListBlock extends FObj { return new Status(Status.OK); } + public boolean generatesInlineAreas() { + return false; + } + + } diff --git a/src/org/apache/fop/fo/flow/ListItem.java b/src/org/apache/fop/fo/flow/ListItem.java index e16d59ce2..68af21547 100644 --- a/src/org/apache/fop/fo/flow/ListItem.java +++ b/src/org/apache/fop/fo/flow/ListItem.java @@ -168,4 +168,8 @@ public class ListItem extends FObj { return 0; // not laid out yet } + public boolean generatesInlineAreas() { + return false; + } + } diff --git a/src/org/apache/fop/fo/flow/Table.java b/src/org/apache/fop/fo/flow/Table.java index 8ab0d3ce1..38e4a79af 100644 --- a/src/org/apache/fop/fo/flow/Table.java +++ b/src/org/apache/fop/fo/flow/Table.java @@ -511,6 +511,11 @@ public class Table extends FObj { return 0; // not laid out yet } + public boolean generatesInlineAreas() { + return false; + } + + /** * Initialize table inline-progression-properties values */ diff --git a/src/org/apache/fop/fo/flow/TableAndCaption.java b/src/org/apache/fop/fo/flow/TableAndCaption.java index 33dae362c..cca6c2ef7 100644 --- a/src/org/apache/fop/fo/flow/TableAndCaption.java +++ b/src/org/apache/fop/fo/flow/TableAndCaption.java @@ -48,4 +48,8 @@ public class TableAndCaption extends ToBeImplementedElement { return super.layout(area); } + + public boolean generatesInlineAreas() { + return false; + } } diff --git a/src/org/apache/fop/fo/pagination/PageSequence.java b/src/org/apache/fop/fo/pagination/PageSequence.java index da1e22883..1e05cef5c 100644 --- a/src/org/apache/fop/fo/pagination/PageSequence.java +++ b/src/org/apache/fop/fo/pagination/PageSequence.java @@ -21,6 +21,7 @@ import org.apache.fop.layout.PageMaster; import org.apache.fop.area.AreaTree; import org.apache.fop.area.PageViewport; import org.apache.fop.apps.FOPException; +import org.apache.fop.apps.StreamRenderer; import org.apache.fop.layoutmgr.PageLayoutManager; @@ -46,6 +47,10 @@ public class PageSequence extends FObj { // // associations // + /** + * Use to layout and render the page sequence. + */ + private StreamRenderer streamRenderer; /** * The parent root object @@ -266,12 +271,14 @@ public class PageSequence extends FObj { } } + + public void setStreamRenderer(StreamRenderer st) { + this.streamRenderer = st; + } + public void end() { try { - AreaTree at = new AreaTree(); - at.setTreeModel(AreaTree.createStorePagesModel()); - at.startPageSequence(null); - format(at); + this.streamRenderer.render(this); } catch (FOPException fopex) { log.error("Error in PageSequence.end(): " + fopex.getMessage()); @@ -314,6 +321,8 @@ public class PageSequence extends FObj { // If no main flow, nothing to layout! if (this.mainFlow == null) return; + areaTree.startPageSequence(null); + // Initialize if already used? this.layoutMasterSet.resetPageMasters(); diff --git a/src/org/apache/fop/fo/pagination/RegionBA.java b/src/org/apache/fop/fo/pagination/RegionBA.java index db526e765..7efb3c291 100644 --- a/src/org/apache/fop/fo/pagination/RegionBA.java +++ b/src/org/apache/fop/fo/pagination/RegionBA.java @@ -27,6 +27,7 @@ public abstract class RegionBA extends RegionBASE { } public void end() { + super.end(); bPrecedence = (this.properties.get("precedence").getEnum()==Precedence.TRUE); } diff --git a/src/org/apache/fop/fo/pagination/RegionBefore.java b/src/org/apache/fop/fo/pagination/RegionBefore.java index 0b33ccec1..f829ef6b5 100644 --- a/src/org/apache/fop/fo/pagination/RegionBefore.java +++ b/src/org/apache/fop/fo/pagination/RegionBefore.java @@ -22,9 +22,9 @@ public class RegionBefore extends RegionBA { super(parent); } - public void handleAttrs(Attributes attlist) throws FOPException { - super.handleAttrs(attlist); - } +// public void handleAttrs(Attributes attlist) throws FOPException { +// super.handleAttrs(attlist); +// } protected String getDefaultRegionName() {