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;
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();
// 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);
* 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");
}
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.
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;
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.
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;
}
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) {
}
}
-System.out.println("Flow BreakPoss: " + vecBreakPoss);
-
return new BreakPoss(
new BlockBreakPosition(curLM, 0, 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);
}
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();
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);
* The interface for all LayoutManagers.
*/
public interface LayoutManager {
- public boolean generateAreas();
public boolean generatesInlineAreas();
public Area getParentArea (Area childArea);
public boolean addChild (Area childArea);
curArea = ia;
}
- public boolean generateAreas() {
- return flush();
- }
-
protected boolean flush() {
return false;
}
import java.util.ListIterator;
import java.util.Iterator;
import java.util.List;
-import java.util.Vector;
import java.util.ArrayList;
/** 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
BreakPoss prevBP = null;
BreakPoss bp = null; // proposed BreakPoss
- Vector vecPossEnd = new Vector();
+ ArrayList vecPossEnd = new ArrayList();
// IPD remaining in line
MinOptMax availIPD = context.getStackLimit();
// 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));
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
// 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() &&
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());
- 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();
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);
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,
(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));
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;
- }
-
-
}
+++ /dev/null
-/*
- * $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;
- }
-}
-
* rendering process can also run in a parallel thread.
*/
public void run() {
- //generateAreas();
doLayout();
flush();
}
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();
}
}
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;
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);
}
// 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) {
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
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) {
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) {
// 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;
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) {
//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
// 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 = "-/" ;
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);
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 &&
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;
}
} else {
// Reset to beginning!
- m_vecAreaInfo.setSize(0);
+ m_vecAreaInfo.clear();
m_iNextStart = 0;
setFinished(false);
}
*/
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;
}
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) &&
+++ /dev/null
-/*
- * $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;
- }
-
-}
-