From: Keiron Liddle Date: Fri, 9 Aug 2002 07:11:16 +0000 (+0000) Subject: removed old code, cleaned up a bit X-Git-Tag: Alt-Design-integration-base~461 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=33b00c53cdd2801ce341eae38ae35787599cbb48;p=xmlgraphics-fop.git removed old code, cleaned up a bit git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195072 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java index 57e7e69de..d63d1a66a 100644 --- a/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractBPLayoutManager.java @@ -58,9 +58,9 @@ public abstract class AbstractBPLayoutManager extends AbstractLayoutManager impl return m_curChildLM; } else { m_childLMiter.remove(); - System.err.println( - "WARNING: child LM not a BPLayoutManager: " + - obj.getClass().getName()); + //log.warn( + // "child LM not a BPLayoutManager: " + + // obj.getClass().getName()); } } return null; @@ -69,8 +69,8 @@ public abstract class AbstractBPLayoutManager extends AbstractLayoutManager impl protected boolean hasMoreLM(BPLayoutManager prevLM) { // prevLM should = m_curChildLM if (prevLM != m_curChildLM) { - System.err.println("AbstractBPLayoutManager.peekNextLM: " + - "passed LM is not current child LM!"); + //log.debug("AbstractBPLayoutManager.peekNextLM: " + + // "passed LM is not current child LM!"); return false; } return !m_childLMiter.hasNext(); @@ -92,7 +92,7 @@ public abstract class AbstractBPLayoutManager extends AbstractLayoutManager impl // ASSERT m_curChildLM == (BPLayoutManager)m_childLMiter.previous() if (m_curChildLM != (BPLayoutManager) m_childLMiter.previous()) { - System.err.println("LMiter problem!"); + //log.error("LMiter problem!"); } while (m_curChildLM != lm && m_childLMiter.hasPrevious()) { m_curChildLM.resetPosition(null); @@ -130,7 +130,7 @@ public abstract class AbstractBPLayoutManager extends AbstractLayoutManager impl * for the areas it will create, based on Properties set on its FO. */ protected void initProperties(PropertyManager pm) { - System.err.println("AbstractBPLayoutManager.initProperties"); + //log.debug("AbstractBPLayoutManager.initProperties"); } diff --git a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java index 50d4b643a..ccb642863 100644 --- a/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/AbstractLayoutManager.java @@ -41,34 +41,6 @@ public abstract class AbstractLayoutManager implements LayoutManager { return 0; } - /** - * Propagates to lower level layout managers. It iterates over the - * children of its FO, asks each for its LayoutManager and calls - * its generateAreas method. - */ - public boolean generateAreas() { - ArrayList lms = new ArrayList(); - if (fobj != null) { - ListIterator children = fobj.getChildren(); - while (children.hasNext()) { - FONode node = (FONode) children.next(); - if (node instanceof FObj) { - ((FObj) node).addLayoutManager(lms); - } - } - fobj = null; - } - - for (int count = 0; count < lms.size(); count++) { - LayoutManager lm = (LayoutManager) lms.get(count); - lm.setParentLM(this); - if (lm.generateAreas()) { - break; - } - } - return flush(); // Add last area to parent - } - // /** // * Ask the parent LayoutManager to add the current (full) area to the // * appropriate parent area. diff --git a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java index ad7372ab4..85a93b164 100644 --- a/src/org/apache/fop/layoutmgr/BlockLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockLayoutManager.java @@ -94,9 +94,9 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { return m_curChildLM; } else { m_childLMiter.remove(); - System.err.println( - "WARNING: child LM not a BPLayoutManager: " + - lm.getClass().getName()); + //log.warn( + // "child LM not a BPLayoutManager: " + + // lm.getClass().getName()); } } return null; @@ -159,72 +159,6 @@ public class BlockLayoutManager extends BlockStackingLayoutManager { flush(); } - - /** - * Generate areas by telling all layout managers for its FO's - * children to generate areas. - */ - public boolean generateAreas() { - ArrayList lms = new ArrayList(); - LayoutManager lm = null; - FObj curFobj = fobj; - if (fobj != null) { - ListIterator children = fobj.getChildren(); - while (children.hasNext()) { - Object childFO = children.next(); - if (childFO instanceof FObj) { - ((FObj) childFO).addLayoutManager(lms); - } - } - //fobj = null; - } - - ArrayList vecBreakPoss = new ArrayList(); - - BreakPoss bp; - LayoutContext childLC = new LayoutContext(0); - while (!isFinished()) { - if ((bp = getNextBreakPoss(childLC, null)) != null) { - vecBreakPoss.add(bp); - } - } - - addAreas( new BreakPossPosIter(vecBreakPoss, 0, - vecBreakPoss.size()), null); - - - /* - for (int count = 0; count < lms.size(); count++) { - lm = (LayoutManager) lms.get(count); - if (lm.generatesInlineAreas()) { - ArrayList inlines = new ArrayList(); - inlines.add(lm); - //lms.remove(count); - while (count + 1 < lms.size()) { - lm = (LayoutManager) lms.get(count + 1); - if (lm.generatesInlineAreas()) { - inlines.add(lm); - lms.remove(count + 1); - } else { - break; - } - } - lm = new LineBPLayoutManager(curFobj, inlines, - lineHeight, lead, follow); - lms.set(count, lm); - } - lm.setParentLM(this); - if (lm.generateAreas()) { - if (flush()) { - return true; - } - } - } - */ - return flush(); // Add last area to parent - } - - /** * Return an Area which can contain the passed childArea. The childArea * may not yet have any content, but it has essential traits set. diff --git a/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java b/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java index 2b05cdc82..b657b1005 100644 --- a/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/BlockStackingLayoutManager.java @@ -139,7 +139,7 @@ public abstract class BlockStackingLayoutManager extends AbstractBPLayoutManager BlockParent parentArea) { // This should be a block-level Area (Block in the generic sense) if (!(childArea instanceof Block)) { - System.err.println("Child not a Block in BlockStackingLM!"); + //log.error("Child not a Block in BlockStackingLM!"); return false; } diff --git a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java index ded7344d8..6919a71d5 100644 --- a/src/org/apache/fop/layoutmgr/FlowLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/FlowLayoutManager.java @@ -43,25 +43,6 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { super(fobj); } - public boolean generateAreas() { - - ArrayList vecBreakPoss = new ArrayList(); - - BreakPoss bp; - LayoutContext childLC = new LayoutContext(0); - while (!isFinished()) { - if ((bp = getNextBreakPoss(childLC, null)) != null) { - System.out.println("Flow Break: " + bp); - vecBreakPoss.add(bp); - } - } - - addAreas( new BreakPossPosIter(vecBreakPoss, 0, - vecBreakPoss.size()), null); - flush(); - return false; - } - public BreakPoss getNextBreakPoss(LayoutContext context, Position prevLineBP) { @@ -86,8 +67,6 @@ public class FlowLayoutManager extends BlockStackingLayoutManager { } } -System.out.println("Flow BreakPoss: " + vecBreakPoss); - return new BreakPoss( new BlockBreakPosition(curLM, 0, vecBreakPoss)); } @@ -96,10 +75,8 @@ System.out.println("Flow BreakPoss: " + vecBreakPoss); } public void addAreas(PositionIterator parentIter, LayoutContext lc) { -System.out.println("FL add: " + parentIter); while (parentIter.hasNext()) { BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next(); -System.out.println("FL add: " + bbp); bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0, bbp.blockps.size()), null); } diff --git a/src/org/apache/fop/layoutmgr/InlineStackingBPLayoutManager.java b/src/org/apache/fop/layoutmgr/InlineStackingBPLayoutManager.java index 5a777a21f..1fb48417f 100644 --- a/src/org/apache/fop/layoutmgr/InlineStackingBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/InlineStackingBPLayoutManager.java @@ -130,9 +130,9 @@ public class InlineStackingBPLayoutManager extends AbstractBPLayoutManager { if (prevPos != null) { // ASSERT (prevPos.getLM() == this) if (prevPos.getLM() != this) { - System.err.println( - "InlineStackingBPLayoutManager.resetPosition: " + - "LM mismatch!!!"); + //log.error( + // "InlineStackingBPLayoutManager.resetPosition: " + + // "LM mismatch!!!"); } // Back up the child LM Position Position childPos = prevPos.getPosition(); @@ -496,7 +496,7 @@ public class InlineStackingBPLayoutManager extends AbstractBPLayoutManager { spaceRange.min) * dSpaceAdjust); } if (iAdjust != 0) { - System.err.println("Add leading space: " + iAdjust); + //log.error("Add leading space: " + iAdjust); Space ls = new Space(); ls.setWidth(iAdjust); parentArea.addChild(ls); diff --git a/src/org/apache/fop/layoutmgr/LayoutManager.java b/src/org/apache/fop/layoutmgr/LayoutManager.java index 15763ec0b..089b1493b 100644 --- a/src/org/apache/fop/layoutmgr/LayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LayoutManager.java @@ -14,7 +14,6 @@ import org.apache.fop.area.Area; * The interface for all LayoutManagers. */ public interface LayoutManager { - public boolean generateAreas(); public boolean generatesInlineAreas(); public Area getParentArea (Area childArea); public boolean addChild (Area childArea); diff --git a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java index 9f75da9b5..0f060d3fb 100644 --- a/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LeafNodeLayoutManager.java @@ -48,10 +48,6 @@ public class LeafNodeLayoutManager extends AbstractBPLayoutManager { curArea = ia; } - public boolean generateAreas() { - return flush(); - } - protected boolean flush() { return false; } diff --git a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java index 72e385c12..489af7459 100644 --- a/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/LineBPLayoutManager.java @@ -29,7 +29,6 @@ import org.apache.fop.area.inline.Character; import java.util.ListIterator; import java.util.Iterator; import java.util.List; -import java.util.Vector; import java.util.ArrayList; @@ -59,7 +58,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { /** Break positions returned by inline content. */ - private Vector m_vecInlineBreaks = new Vector(100); + private ArrayList m_vecInlineBreaks = new ArrayList(); private BreakPoss m_prevBP = null; // Last confirmed break position private boolean m_bJustify = false; // True if fo:block text-align=JUSTIFY @@ -113,7 +112,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { BreakPoss prevBP = null; BreakPoss bp = null; // proposed BreakPoss - Vector vecPossEnd = new Vector(); + ArrayList vecPossEnd = new ArrayList(); // IPD remaining in line MinOptMax availIPD = context.getStackLimit(); @@ -130,12 +129,12 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { // INITIALIZE LAYOUT CONTEXT FOR CALL TO CHILD LM // First break for the child LM in each of its areas boolean bFirstBPforLM = (m_vecInlineBreaks.isEmpty() || - (((BreakPoss) m_vecInlineBreaks.lastElement()). + (((BreakPoss) m_vecInlineBreaks.get(m_vecInlineBreaks.size() - 1)). getLayoutManager() != curLM)); // Need previous breakpoint! ATTENTION when backing up for hyphenation! prevBP = (m_vecInlineBreaks.isEmpty()) ? null : - (BreakPoss) m_vecInlineBreaks.lastElement(); + (BreakPoss) m_vecInlineBreaks.get(m_vecInlineBreaks.size() - 1); initChildLC(inlineLC, prevBP, (m_vecInlineBreaks.size() == iPrevLineEnd), bFirstBPforLM, new SpaceSpecifier(true)); @@ -148,7 +147,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { inlineLC.setFlags(LayoutContext.SUPPRESS_LEADING_SPACE, (m_vecInlineBreaks.size() == iPrevLineEnd && !m_vecInlineBreaks.isEmpty() && - ((BreakPoss) m_vecInlineBreaks.lastElement()). + ((BreakPoss) m_vecInlineBreaks.get(m_vecInlineBreaks.size() - 1)). isForcedBreak() == false)); // GET NEXT POSSIBLE BREAK FROM CHILD LM @@ -280,9 +279,9 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { // ATTENTION: make sure this hasn't gotten start space for next // LM added onto it! actual.add(m_prevBP.resolveTrailingSpace(true)); - System.err.println("Target opt=" + availIPD.opt + " bp.opt=" + - actual.opt + " bp.max=" + actual.max + " bm.min=" + - actual.min); + //log.error("Target opt=" + availIPD.opt + " bp.opt=" + + // actual.opt + " bp.max=" + actual.max + " bm.min=" + + // actual.min); // Don't justify last line in the sequence or if forced line-end boolean bJustify = (m_bJustify && !m_prevBP.isForcedBreak() && @@ -292,7 +291,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { private void reset() { - while (m_vecInlineBreaks.lastElement() != m_prevBP) { + while (m_vecInlineBreaks.get(m_vecInlineBreaks.size() - 1) != m_prevBP) { m_vecInlineBreaks.remove(m_vecInlineBreaks.size() - 1); } reset(m_prevBP.getPosition()); @@ -317,9 +316,9 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { - private BreakPoss getBestBP(Vector vecPossEnd) { + private BreakPoss getBestBP(ArrayList vecPossEnd) { if (vecPossEnd.size() == 1) { - return ((BreakCost) vecPossEnd.elementAt(0)).getBP(); + return ((BreakCost) vecPossEnd.get(0)).getBP(); } // Choose the best break (use a sort on cost!) Iterator iter = vecPossEnd.iterator(); @@ -359,7 +358,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { while (bpIter.hasPrevious() && bpIter.previous() != prevBP) ; if (bpIter.next() != prevBP) { - System.err.println("findHyphenPoss: problem!"); + //log.error("findHyphenPoss: problem!"); return null; } StringBuffer sbChars = new StringBuffer(30); @@ -375,7 +374,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { prevBP = bp; } m_vecInlineBreaks.remove(m_vecInlineBreaks.size() - 1); // remove last - System.err.println("Word to hyphenate: " + sbChars.toString()); + //log.debug("Word to hyphenate: " + sbChars.toString()); // Now find all hyphenation points in this word (get in an array of offsets) // hyphProps are from the block level?. Note that according to the spec, @@ -422,7 +421,7 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { (double)(actual.opt - actual.min); } } - System.err.println("Adjustment factor=" + dAdjust); + //log.debug("Adjustment factor=" + dAdjust); BreakPoss curLineBP = new BreakPoss( new LineBreakPosition(this, m_vecInlineBreaks.size() - 1, dAdjust)); @@ -473,46 +472,5 @@ public class LineBPLayoutManager extends InlineStackingBPLayoutManager { setCurrentArea(null); // ?? necessary } - - // NOTE: PATCHED FOR NOW TO ADD BreakPoss stuff to Kerion's changes - public boolean generateAreas() { - // Make break positions and return lines! - // Set up a LayoutContext - int ipd = 0; - BreakPoss bp; - Vector vecBreakPoss = new Vector(20); - - // Force area creation on first call - // NOTE: normally not necessary when fully integrated! - LayoutContext childLC = - new LayoutContext(LayoutContext.CHECK_REF_AREA); - - while (!isFinished()) { - if ((bp = getNextBreakPoss(childLC, null)) != null) { - if (bp.checkIPD()) { - // Need IPD in order to layout lines! - // This is supposed to bubble up to PageLM to - // make the necessary flow reference area, depending - // on span and break-before flags set as the BreakPoss - // makes its way back up the call stack. - // Fake it for now! - parentLM.getParentArea(null); - ipd = parentLM.getContentIPD(); - childLC.flags &= ~LayoutContext.CHECK_REF_AREA; - childLC.setStackLimit( new MinOptMax(ipd - m_iIndents - - m_iTextIndent)); - } else { - vecBreakPoss.add(bp); - // Reset stackLimit for non-first lines - childLC.setStackLimit(new MinOptMax(ipd - m_iIndents)); - } - } - } - addAreas( new BreakPossPosIter(vecBreakPoss, 0, - vecBreakPoss.size()), 0.0); - return false; - } - - } diff --git a/src/org/apache/fop/layoutmgr/LineLayoutManager.java b/src/org/apache/fop/layoutmgr/LineLayoutManager.java deleted file mode 100644 index 70a13224c..000000000 --- a/src/org/apache/fop/layoutmgr/LineLayoutManager.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.layoutmgr; - - -import org.apache.fop.fo.FObj; -import org.apache.fop.area.Area; -import org.apache.fop.area.LineArea; -import org.apache.fop.area.MinOptMax; -import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.fo.properties.VerticalAlign; - -import org.apache.fop.area.inline.Word; -import org.apache.fop.area.inline.Space; -import org.apache.fop.area.inline.Character; - -import java.util.ListIterator; -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; - -/** - * LayoutManager for lines. It builds one or more lines containing - * inline areas generated by its sub layout managers. - * - * The line layout manager does the following things: - * receives a list of inline creating layout managers - * adds the inline areas retrieved from the child layout managers - * finds the best line break position - * adds complete line to parent - * stores the starting position for each line in case of recreation - * if ipd not changed but line contains resolved values (eg. page number), redoes from that line - * when freeing memory, release all layout managers and inline areas before current position - * As each child layout manager is used it gets the start, end and normal references for id area, footnotes, floats, links, colour-back properties - * first line properties are set and used by the child when retrieving the inline area(s) - * - * Hyphenation is handled by asking the child to split the words then this - * adds the hyph char. If redone then exra char ignored. - * - * How do we handle Unicode BIDI? - */ -public class LineLayoutManager extends AbstractLayoutManager { - private LineInfo currentLine = null; - private boolean bFirstLine = true; - private MinOptMax totalIPD; - // the following values must be set by the block - // these are the dominant basline and lineheight values - private int lineHeight; - private int lead; - private int follow; - - List lmList; - List lines = new ArrayList(); - - private LayoutPos bestPos = null; - private MinOptMax bestIPD = null; - - static class LineInfo { - LayoutPos startPos; - LineArea area; - boolean hasResolved = false; - boolean noJustify = false; - // footnotes, floats? - } - - public LineLayoutManager(FObj fobjBlock, List lms, int lh, int l, - int f) { - super(fobjBlock); - lmList = lms; - lineHeight = lh; - lead = l; - follow = f; - } - - public int getContentIPD() { - return parentLM.getContentIPD(); - } - - /** - * Call child layout managers to generate content as long as they - * generate inline areas. If a block-level generating LM is found, - * finish any line being filled and return to the parent LM. - */ - public boolean generateAreas() { - // if a side float is added and the line contains content - // where the ipd depends on the line width then restart - // the line with the adjusted length - - while (curPos.lmIndex < lmList.size()) { - LeafNodeLayoutManager curLM = - (LeafNodeLayoutManager) lmList.get(curPos.lmIndex); - curLM.setParentLM(this); - - LeafNodeLayoutManager nextLM = null; - if (curPos.lmIndex + 1 < lmList.size()) { - nextLM = (LeafNodeLayoutManager) lmList.get( - curPos.lmIndex + 1); - while (nextLM.size() == 0) { - lmList.remove(curPos.lmIndex + 1); - if (curPos.lmIndex + 1 == lmList.size()) { - nextLM = null; - break; - } - nextLM = (LeafNodeLayoutManager) lmList.get( - curPos.lmIndex + 1); - - } - } - if (nextLM != null) { - nextLM.setParentLM(this); - } - if (curLM.resolved()) { - currentLine.hasResolved = true; - } - while (curPos.subIndex < curLM.size()) { - InlineArea ia = curLM.get(curPos.subIndex); - InlineArea next = null; - if (curPos.subIndex + 1 < curLM.size()) { - next = curLM.get(curPos.subIndex + 1); - } else if (curPos.lmIndex + 1 < lmList.size()) { - if (nextLM != null) { - next = nextLM.get(0); - } - } - if (currentLine != null && !currentLine.noJustify && - (curPos.subIndex + 1 == curLM.size() && - curPos.lmIndex + 1 == lmList.size())) { - currentLine.noJustify = true; - } - if (addChild(ia, next)) { - if (flush()) { - return true; - } - } - // flush final line in same context as other lines - // handle last line concepts - if (curPos.subIndex + 1 == curLM.size() && - curPos.lmIndex + 1 == lmList.size()) { - if (flush()) { - return true; - } - if (curPos.subIndex + 1 == curLM.size() && - curPos.lmIndex + 1 == lmList.size()) { - return false; - } - - } - curPos.subIndex++; - } - curPos.lmIndex++; - curPos.subIndex = 0; - } - return false; - } - - /** - * Align and position curLine and add it to parentContainer. - * Set curLine to null. - */ - public boolean flush() { - if (currentLine != null) { - // Adjust spacing as necessary - adjustSpacing(); - currentLine.area.verticalAlign(lineHeight, lead, follow); - - boolean res = parentLM.addChild(currentLine.area); - - lines.add(currentLine); - currentLine = null; - bestPos = null; - bestIPD = null; - - return res; - } - return false; - } - - /** - * Do the ipd adjustment for stretch areas etc. - * Consecutive spaces need to be collapsed if possible. - * should this be on the line area so it can finish resolved areas? - */ - private void adjustSpacing() { - List inlineAreas = currentLine.area.getInlineAreas(); - - // group text elements to split at hyphen if available - // remove collapsable spaces at start or end on line - - // backtrack to best position - while (true) { - if (curPos.lmIndex == bestPos.lmIndex && - curPos.subIndex == bestPos.subIndex) { - break; - } - - InlineArea inline = - (InlineArea) inlineAreas.get(inlineAreas.size() - 1); - MinOptMax ipd = inline.getAllocationIPD(); - totalIPD.subtract(ipd); - - inlineAreas.remove(inlineAreas.size() - 1); - currentLine.noJustify = false; - - curPos.subIndex--; - if (curPos.subIndex == -1) { - curPos.lmIndex--; - LeafNodeLayoutManager curLM = - (LeafNodeLayoutManager) lmList.get( curPos.lmIndex); - curPos.subIndex = curLM.size() - 1; - } - } - - - // for justify also stretch spaces to fill - // stretch to best match - float percentAdjust = 0; - boolean maxSide = false; - int realWidth = bestIPD.opt; - if (bestIPD.opt > parentLM.getContentIPD()) { - if (bestIPD.opt - parentLM.getContentIPD() < - (bestIPD.max - bestIPD.opt)) { - percentAdjust = (bestIPD.opt - parentLM.getContentIPD()) / - (float)(bestIPD.max - bestIPD.opt); - realWidth = parentLM.getContentIPD(); - } else { - percentAdjust = 1; - realWidth = bestIPD.max; - } - maxSide = true; - } else { - if (parentLM.getContentIPD() - bestIPD.opt < - bestIPD.opt - bestIPD.min) { - percentAdjust = (parentLM.getContentIPD() - bestIPD.opt) / - (float)(bestIPD.opt - bestIPD.min); - realWidth = parentLM.getContentIPD(); - } else { - percentAdjust = 1; - realWidth = bestIPD.min; - } - } - if (percentAdjust > 0) { - for (Iterator iter = inlineAreas.iterator(); iter.hasNext();) { - InlineArea inline = (InlineArea) iter.next(); - int width; - MinOptMax iipd = inline.getAllocationIPD(); - if (!maxSide) { - width = iipd.opt + - (int)((iipd.max - iipd.opt) * percentAdjust); - } else { - width = iipd.opt - - (int)((iipd.opt - iipd.min) * percentAdjust); - } - inline.setWidth(width); - } - } - - // don't justify lines ending with U+000A or last line - if (/*justify && */!currentLine.noJustify && - realWidth != parentLM.getContentIPD()) { - ArrayList spaces = new ArrayList(); - for (Iterator iter = inlineAreas.iterator(); iter.hasNext();) { - InlineArea inline = (InlineArea) iter.next(); - if (inline instanceof Space /* && !((Space)inline).fixed*/) { - spaces.add(inline); - } - } - for (Iterator iter = spaces.iterator(); iter.hasNext();) { - Space space = (Space) iter.next(); - space.setWidth(space.getWidth() + - (parentLM.getContentIPD() - realWidth) / - spaces.size()); - } - } - - } - - /** - * Return current lineArea or generate a new one if necessary. - */ - public Area getParentArea(Area childArea) { - if (currentLine.area == null) { - createLine(); - } - return currentLine.area; - } - - protected void createLine() { - currentLine = new LineInfo(); - currentLine.startPos = curPos; - currentLine.area = new LineArea(); - /* Set line IPD from parentArea - * This accounts for indents. What about first line indent? - * Should we set an "isFirst" flag on the lineArea to signal - * that to the parent (Block) LM? That's where indent property - * information will be managed. - */ - Area parent = parentLM.getParentArea(currentLine.area); - // currentLine.area.setContentIPD(parent.getContentIPD()); - // totalIPD = new MinOptMax(); - // OR??? - totalIPD = new MinOptMax(); - this.bFirstLine = false; - } - - /** - * Called by child LayoutManager when it has filled one of its areas. - * See if the area will fit in the current container. - * If so, add it. - * This should also handle floats if childArea is an anchor. - * @param childArea the area to add: should be an InlineArea subclass! - */ - public boolean addChild(InlineArea inlineArea, InlineArea nextArea) { - if (currentLine == null) { - createLine(); - } - - // add side floats first - - int pIPD = parentLM.getContentIPD(); - - currentLine.area.addInlineArea(inlineArea); - totalIPD.add(inlineArea.getAllocationIPD()); - - LayoutInfo info = inlineArea.info; - if (info == null) { - info = new LayoutInfo(); - } - LayoutInfo ninfo; - if (nextArea != null && nextArea.info != null) { - ninfo = nextArea.info; - } else { - ninfo = new LayoutInfo(); - } - - // the best pos cannot be before the first area - if (bestPos == null || bestIPD == null) { - bestPos = new LayoutPos(); - bestPos.lmIndex = curPos.lmIndex; - bestPos.subIndex = curPos.subIndex; - MinOptMax imop = inlineArea.getAllocationIPD(); - bestIPD = new MinOptMax(imop.min, imop.opt, imop.max); - } else { - - // bestPos changed only when it can break - // before/after a space or other atomic inlines - // check keep-with on this and next - // since chars are optimized as words we cannot assume a - // word is complete and therefore hyphenate or break after - // side floats effect the available ipd but do not add to line - - if (!ninfo.keepPrev && !info.keepNext && - !(info.isText && ninfo.isText)) { - if (Math.abs(bestIPD.opt - pIPD) > - Math.abs(totalIPD.opt - pIPD) && - (totalIPD.min <= pIPD)) { - bestPos.lmIndex = curPos.lmIndex; - bestPos.subIndex = curPos.subIndex; - bestIPD = new MinOptMax(totalIPD.min, totalIPD.opt, - totalIPD.max); - } - } - } - - // Forced line break after this area (ex. ends with LF in nowrap) - if (info.breakAfter) { - currentLine.noJustify = true; - return true; - } - - if (totalIPD.min > pIPD) { - return true; - } - - return false; - } - - public boolean addChild(Area childArea) { - return false; - } -} - diff --git a/src/org/apache/fop/layoutmgr/PageLayoutManager.java b/src/org/apache/fop/layoutmgr/PageLayoutManager.java index f05a5ef87..a30e3335b 100644 --- a/src/org/apache/fop/layoutmgr/PageLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/PageLayoutManager.java @@ -76,7 +76,6 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab * rendering process can also run in a parallel thread. */ public void run() { - //generateAreas(); doLayout(); flush(); } @@ -89,11 +88,11 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab LayoutContext childLC = new LayoutContext(0); while (!isFinished()) { ArrayList vecBreakPoss = new ArrayList(); - makeNewPage(false, false); if ((bp = getNextBreakPoss(childLC, null)) != null) { vecBreakPoss.add(bp); addAreas( new BreakPossPosIter(vecBreakPoss, 0, vecBreakPoss.size()), null); + finishPage(); } } @@ -125,9 +124,10 @@ public class PageLayoutManager extends AbstractBPLayoutManager implements Runnab vecBreakPoss.add(bp); } } -System.out.println("BREAKS: " + vecBreakPoss.size()); - return new BreakPoss( - new BlockBreakPosition(curLM, 0, vecBreakPoss)); + if(vecBreakPoss.size() > 0) { + return new BreakPoss( + new BlockBreakPosition(curLM, 0, vecBreakPoss)); + } } setFinished(true); return null; @@ -137,7 +137,6 @@ System.out.println("BREAKS: " + vecBreakPoss.size()); while (parentIter.hasNext()) { BlockBreakPosition bbp = (BlockBreakPosition) parentIter.next(); -System.out.println("ADD BREAKS: " + bbp.blockps.size()); bbp.getLM().addAreas( new BreakPossPosIter(bbp.blockps, 0, bbp.blockps.size()), null); } @@ -178,8 +177,8 @@ System.out.println("ADD BREAKS: " + bbp.blockps.size()); // end the page. getParentArea(area); // Alternatively the child LM indicates to parent that it's full? - System.out.println("size: " + area.getAllocationBPD().max + - ":" + curSpan.getMaxBPD().min); + //System.out.println("size: " + area.getAllocationBPD().max + + // ":" + curSpan.getMaxBPD().min); if (area.getAllocationBPD().max >= curSpan.getMaxBPD().min) { // Consider it filled if (curSpan.getColumnCount() == curSpanColumns) { diff --git a/src/org/apache/fop/layoutmgr/SpaceSpecifier.java b/src/org/apache/fop/layoutmgr/SpaceSpecifier.java index 2a7fa801b..676611f1f 100644 --- a/src/org/apache/fop/layoutmgr/SpaceSpecifier.java +++ b/src/org/apache/fop/layoutmgr/SpaceSpecifier.java @@ -9,7 +9,7 @@ package org.apache.fop.layoutmgr; import org.apache.fop.area.MinOptMax; import org.apache.fop.traits.SpaceVal; -import java.util.Vector; +import java.util.ArrayList; /** * Accumulate a sequence of space-specifiers (XSL space type) on @@ -21,7 +21,7 @@ public class SpaceSpecifier implements Cloneable { private boolean m_bStartsRefArea; private boolean m_bHasForcing = false; - private Vector m_vecSpaceVals = new Vector(3); + private ArrayList m_vecSpaceVals = new ArrayList(); public SpaceSpecifier(boolean bStartsRefArea) { @@ -32,7 +32,7 @@ public class SpaceSpecifier implements Cloneable { try { SpaceSpecifier ss = (SpaceSpecifier) super.clone(); // Clone the vector, but share the objects in it! - ss.m_vecSpaceVals = new Vector(this.m_vecSpaceVals.size()); + ss.m_vecSpaceVals = new ArrayList(); ss.m_vecSpaceVals.addAll(this.m_vecSpaceVals); return ss; } catch (CloneNotSupportedException cnse) { @@ -95,7 +95,7 @@ public class SpaceSpecifier implements Cloneable { // Start from the end and count conditional specifiers // Stop at first non-conditional for (; lastIndex > 0; --lastIndex) { - SpaceVal sval = (SpaceVal) m_vecSpaceVals.elementAt( + SpaceVal sval = (SpaceVal) m_vecSpaceVals.get( lastIndex - 1); if (!sval.bConditional) { break; @@ -105,7 +105,7 @@ public class SpaceSpecifier implements Cloneable { MinOptMax resSpace = new MinOptMax(0); int iMaxPrec = -1; for (int index = 0; index < lastIndex; index++) { - SpaceVal sval = (SpaceVal) m_vecSpaceVals.elementAt(index); + SpaceVal sval = (SpaceVal) m_vecSpaceVals.get(index); if (m_bHasForcing) { resSpace.add(sval.space); } else if (sval.iPrecedence > iMaxPrec) { diff --git a/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java b/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java index 3421142ea..dc573270d 100644 --- a/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java +++ b/src/org/apache/fop/layoutmgr/TextBPLayoutManager.java @@ -22,7 +22,7 @@ import org.apache.fop.fo.properties.VerticalAlign; //import org.apache.fop.fo.properties.*; -import java.util.Vector; // or use ArrayList ??? +import java.util.ArrayList; /** * LayoutManager for text (a sequence of characters) which generates one @@ -52,7 +52,7 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { // Hold all possible breaks for the text in this LM's FO. - private Vector m_vecAreaInfo; + private ArrayList m_vecAreaInfo; /** Non-space characters on which we can end a line. */ static private final String s_breakChars = "-/" ; @@ -90,7 +90,7 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { super(fobj); this.chars = chars; this.textInfo = textInfo; - this.m_vecAreaInfo = new Vector(chars.length / 5); // Guess + this.m_vecAreaInfo = new ArrayList(); // With CID fonts, space isn't neccesary currentFontState.width(32) m_spaceIPD = CharUtilities.getCharWidth(' ', textInfo.fs); @@ -118,24 +118,11 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { return null; } - /** - * Generate inline areas for words in text. - */ - public boolean generateAreas() { - // Handle white-space characteristics. Maybe there is no area to - // generate.... - - // Iterate over characters and make text areas. - // Add each one to parent. Handle word-space. - return false; - } - - public void getWordChars(StringBuffer sbChars, Position bp1, Position bp2) { LeafPosition endPos = (LeafPosition) bp2; AreaInfo ai = - (AreaInfo) m_vecAreaInfo.elementAt(endPos.getLeafPos()); + (AreaInfo) m_vecAreaInfo.get(endPos.getLeafPos()); // Skip all leading spaces for hyphenation int i; for (i = ai.m_iStartIndex; i < ai.m_iBreakIndex && @@ -163,15 +150,15 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { if (prevPos != null) { // ASSERT (prevPos.getLM() == this) if (prevPos.getLM() != this) { - System.err.println( - "TextBPLayoutManager.resetPosition: " + "LM mismatch!!!"); + //log.error( + // "TextBPLayoutManager.resetPosition: " + "LM mismatch!!!"); } LeafPosition tbp = (LeafPosition) prevPos; AreaInfo ai = - (AreaInfo) m_vecAreaInfo.elementAt(tbp.getLeafPos()); + (AreaInfo) m_vecAreaInfo.get(tbp.getLeafPos()); if (ai.m_iBreakIndex != m_iNextStart) { m_iNextStart = ai.m_iBreakIndex; - m_vecAreaInfo.setSize(tbp.getLeafPos() + 1); + m_vecAreaInfo.ensureCapacity(tbp.getLeafPos() + 1); // TODO: reset or recalculate total IPD = sum of all word IPD // up to the break position m_ipdTotal = ai.m_ipdArea; @@ -179,7 +166,7 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { } } else { // Reset to beginning! - m_vecAreaInfo.setSize(0); + m_vecAreaInfo.clear(); m_iNextStart = 0; setFinished(false); } @@ -453,7 +440,7 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { */ while (posIter.hasNext()) { LeafPosition tbpNext = (LeafPosition) posIter.next(); - ai = (AreaInfo) m_vecAreaInfo.elementAt(tbpNext.getLeafPos()); + ai = (AreaInfo) m_vecAreaInfo.get(tbpNext.getLeafPos()); if (iStart == -1) { iStart = ai.m_iStartIndex; } @@ -483,8 +470,8 @@ public class TextBPLayoutManager extends AbstractBPLayoutManager { new String(chars, iStart, ai.m_iBreakIndex - iStart), ai.m_ipdArea.opt + iAdjust); if (iWScount > 0) { - System.err.println("Adjustment per word-space= " + - iAdjust / iWScount); + //log.error("Adjustment per word-space= " + + // iAdjust / iWScount); word.setWSadjust(iAdjust / iWScount); } if ((chars[iStart] == SPACE || chars[iStart] == NBSPACE) && diff --git a/src/org/apache/fop/layoutmgr/TextLayoutManager.java b/src/org/apache/fop/layoutmgr/TextLayoutManager.java deleted file mode 100644 index 07ce7f1b0..000000000 --- a/src/org/apache/fop/layoutmgr/TextLayoutManager.java +++ /dev/null @@ -1,264 +0,0 @@ -/* - * $Id$ - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources. - */ - -package org.apache.fop.layoutmgr; - -import org.apache.fop.fo.FObj; -import org.apache.fop.fo.TextInfo; -import org.apache.fop.area.Area; -import org.apache.fop.area.Trait; -import org.apache.fop.area.inline.InlineArea; -import org.apache.fop.area.inline.Word; -import org.apache.fop.area.inline.Space; -import org.apache.fop.util.CharUtilities; -import org.apache.fop.fo.properties.VerticalAlign; - -import org.apache.fop.fo.properties.*; - -import java.util.ListIterator; -import java.util.ArrayList; - -/** - * LayoutManager for text (a sequence of characters) which generates one - * or more inline areas. - */ -public class TextLayoutManager extends LeafNodeLayoutManager { - - private char[] chars; - private TextInfo textInfo; - - ArrayList words = new ArrayList(); - - private static final char NEWLINE = '\n'; - private static final char RETURN = '\r'; - private static final char TAB = '\t'; - private static final char LINEBREAK = '\u2028'; - private static final char ZERO_WIDTH_SPACE = '\u200B'; - // byte order mark - private static final char ZERO_WIDTH_NOBREAK_SPACE = '\uFEFF'; - - /* values that prev (below) may take */ - protected static final int NOTHING = 0; - protected static final int WHITESPACE = 1; - protected static final int TEXT = 2; - - public TextLayoutManager(FObj fobj, char[] chars, TextInfo textInfo) { - super(fobj); - this.chars = chars; - this.textInfo = textInfo; - } - - public int size() { - parseChars(); - return words.size(); - } - - public InlineArea get(int index) { - parseChars(); - return (InlineArea) words.get(index); - } - - /** - * Generate inline areas for words in text. - */ - public boolean generateAreas() { - // Handle white-space characteristics. Maybe there is no area to - // generate.... - - // Iterate over characters and make text areas. - // Add each one to parent. Handle word-space. - return false; - } - - protected void parseChars() { - if (chars == null) { - return; - } - - int whitespaceWidth; - // With CID fonts, space isn't neccesary currentFontState.width(32) - whitespaceWidth = CharUtilities.getCharWidth(' ', textInfo.fs); - - int wordStart = -1; - int wordLength = 0; - int wordWidth = 0; - int spaceWidth = 0; - - int prev = NOTHING; - int i = 0; - - /* iterate over each character */ - for (; i < chars.length; i++) { - int charWidth; - /* get the character */ - char c = chars[i]; - if (!(CharUtilities.isSpace(c) || (c == NEWLINE) || - (c == RETURN) || (c == TAB) || (c == LINEBREAK))) { - charWidth = CharUtilities.getCharWidth(c, textInfo.fs); - prev = TEXT; - wordLength++; - wordWidth += charWidth; - // Add support for zero-width spaces - if (charWidth <= 0 && c != ZERO_WIDTH_SPACE && - c != ZERO_WIDTH_NOBREAK_SPACE) - charWidth = whitespaceWidth; - } else { - if ((c == NEWLINE) || (c == RETURN) || (c == TAB)) - charWidth = whitespaceWidth; - else - charWidth = CharUtilities.getCharWidth(c, textInfo.fs); - - if (prev == WHITESPACE) { - - // if current & previous are WHITESPACE - - if (textInfo.whiteSpaceCollapse == - WhiteSpaceCollapse.FALSE) { - if (CharUtilities.isSpace(c)) { - spaceWidth += CharUtilities.getCharWidth(c, - textInfo.fs); - } else if (c == NEWLINE || c == LINEBREAK) { - // force line break - if (spaceWidth > 0) { - Space is = new Space(); - is.setWidth(spaceWidth); - spaceWidth = 0; - words.add(is); - } - } else if (c == TAB) { - spaceWidth += 8 * whitespaceWidth; - } - } else if (c == LINEBREAK) { - // Line separator - // Breaks line even if WhiteSpaceCollapse = True - if (spaceWidth > 0) { - Space is = new Space(); - is.setWidth(spaceWidth); - is.info = new LayoutInfo(); - is.info.breakAfter = true; - spaceWidth = 0; - words.add(is); - } - } - - } else if (prev == TEXT) { - - // if current is WHITESPACE and previous TEXT - // the current word made it, so - // add the space before the current word (if there - // was some) - - if (spaceWidth > 0) { - Space is = new Space(); - is.setWidth(spaceWidth); - spaceWidth = 0; - words.add(is); - } - - // add the current word - - if (wordLength > 0) { - // The word might contain nonbreaking - // spaces. Split the word and add Space - // as necessary. All spaces inside the word - // Have a fixed width. - words.add( createWord( - new String(chars, wordStart + 1, - wordLength), wordWidth)); - - // reset word width - wordWidth = 0; - } - - // deal with this new whitespace following the - // word we just added - prev = WHITESPACE; - - spaceWidth = CharUtilities.getCharWidth(c, textInfo.fs); - - if (textInfo.whiteSpaceCollapse == - WhiteSpaceCollapse.FALSE) { - if (c == NEWLINE || c == LINEBREAK) { - // force a line break - } else if (c == TAB) { - spaceWidth = whitespaceWidth; - } - } else if (c == LINEBREAK) { - } - } else { - - // if current is WHITESPACE and no previous - - if (textInfo.whiteSpaceCollapse == - WhiteSpaceCollapse.FALSE) { - if (CharUtilities.isSpace(c)) { - prev = WHITESPACE; - spaceWidth = CharUtilities.getCharWidth(c, - textInfo.fs); - } else if (c == NEWLINE) { - // force line break - // textdecoration not used because spaceWidth is 0 - Space is = new Space(); - is.setWidth(spaceWidth); - words.add(is); - } else if (c == TAB) { - prev = WHITESPACE; - spaceWidth = 8 * whitespaceWidth; - } - - } else { - // skip over it - wordStart++; - } - } - wordStart = i; - wordLength = 0; - } - } // end of iteration over text - - if (wordLength > 0) { - // The word might contain nonbreaking - // spaces. Split the word and add Space - // as necessary. All spaces inside the word - // Have a fixed width. - if (wordStart + wordLength > chars.length - 1) { - wordLength = chars.length - 1 - wordStart; - } - - words.add( createWord( - new String(chars, wordStart + 1, wordLength), - wordWidth)); - } - - chars = null; - } - - protected Word createWord(String str, int width) { - Word curWordArea = new Word(); - curWordArea.setWidth(width); - curWordArea.setHeight(textInfo.fs.getAscender() - - textInfo.fs.getDescender()); - curWordArea.setOffset(textInfo.fs.getAscender()); - curWordArea.info = new LayoutInfo(); - curWordArea.info.lead = textInfo.fs.getAscender(); - curWordArea.info.alignment = VerticalAlign.BASELINE; - curWordArea.info.blOffset = true; - - curWordArea.setWord(str); - // curWordArea.addTrait(new Trait(Trait.FONT_STATE, textInfo.fs)); - //curWordArea.addTrait(Trait.FONT_STATE, textInfo.fs); - return curWordArea; - } - - /** Try to split the word area by hyphenating the word. */ - public boolean splitArea(Area areaToSplit, SplitContext context) { - context.nextArea = areaToSplit; - return false; - } - -} -