// this is an inline area that can have other inlines as children
public class InlineParent extends InlineArea {
- ArrayList inlines = new ArrayList();
+ protected ArrayList inlines = new ArrayList();
public InlineParent() {
}
import org.apache.fop.render.Renderer;
public class Space extends Stretch {
- public boolean collapse = true;
- public boolean fixed = false;
public void render(Renderer renderer) {
renderer.renderInlineSpace(this);
import org.apache.fop.fo.properties.*;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.layoutmgr.LMiter;
+import org.apache.fop.layoutmgr.InlineStackingBPLayoutManager;
+import org.apache.fop.layoutmgr.ContentLayoutManager;
+
/**
*/
-public class Title extends ToBeImplementedElement {
+public class Title extends FObjMixed {
public Title(FONode parent) {
super(parent);
new org.apache.fop.area.Title();
// use special layout manager to add the inline areas
// to the Title.
+ InlineStackingBPLayoutManager lm;
+ lm = new InlineStackingBPLayoutManager(this,
+ new LMiter(children.listIterator()));
+ lm.init();
+
+ // get breaks then add areas to title
+
+ ContentLayoutManager clm = new ContentLayoutManager(title);
+ lm.setParentLM(clm);
+
+ clm.fillArea(lm);
+
return title;
}
import org.apache.fop.layout.FontState;
import org.apache.fop.apps.FOPException;
import org.apache.fop.layoutmgr.LayoutManager;
+import org.apache.fop.layoutmgr.InlineStackingBPLayoutManager;
import org.apache.fop.layoutmgr.LeafNodeLayoutManager;
+import org.apache.fop.layoutmgr.ContentLayoutManager;
import org.apache.fop.layoutmgr.LayoutContext;
+import org.apache.fop.layoutmgr.LMiter;
import org.apache.fop.area.MinOptMax;
+import org.apache.fop.area.inline.Space;
+import org.apache.fop.area.inline.Word;
+import org.apache.fop.area.inline.Stretch;
+import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.util.CharUtilities;
+import org.apache.fop.apps.StructureHandler;
+import org.apache.fop.area.Trait;
import java.util.List;
+import java.util.ArrayList;
/**
* Implements fo:leader; main property of leader leader-pattern.
int ruleStyle;
int ruleThickness;
int leaderPattern;
+ int patternWidth;
+ protected FontInfo fontInfo = null;
+ protected FontState fontState;
+ protected InlineArea leaderArea = null;
public Leader(FONode parent) {
super(parent);
}
protected InlineArea getInlineArea(int refIPD) {
- setup();
-
- org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
-
+ if(leaderArea == null) {
+ createLeaderArea();
+ }
MinOptMax alloc = getAllocationIPD(refIPD);
- leader.setAllocationIPD(alloc);
- leader.setWidth(alloc.opt);
+ if(leaderArea instanceof Stretch) {
+ ((Stretch)leaderArea).setAllocationIPD(alloc);
+ } else if(leaderArea instanceof FilledArea) {
+ ((FilledArea)leaderArea).setAllocationIPD(alloc);
+ }
+ leaderArea.setWidth(alloc.opt);
+ return leaderArea;
+ }
+
+ protected void createLeaderArea() {
+ setup();
if(leaderPattern == LeaderPattern.RULE) {
+ org.apache.fop.area.inline.Leader leader = new org.apache.fop.area.inline.Leader();
+
leader.setRuleStyle(ruleStyle);
leader.setRuleThickness(ruleThickness);
+
+ leaderArea = leader;
+ } else if (leaderPattern == LeaderPattern.SPACE) {
+ Space space = new Space();
+
+ leaderArea = space;
+ } else if(leaderPattern == LeaderPattern.DOTS) {
+ Word w = new Word();
+ char dot = '.'; // userAgent.getLeaderDotChar();
+
+ w.setWord("" + dot);
+ w.addTrait(Trait.FONT_NAME, fontState.getFontName());
+ w.addTrait(Trait.FONT_SIZE,
+ new Integer(fontState.getFontSize()));
+ // set offset of dot within inline parent
+ w.setOffset(fontState.getAscender());
+ int width = CharUtilities.getCharWidth(dot, fontState);
+ Space spacer = null;
+ if(patternWidth > width) {
+ spacer = new Space();
+ spacer.setWidth(patternWidth - width);
+ width = patternWidth;
+ }
+ FilledArea fa = new FilledArea();
+ fa.setUnitWidth(width);
+ fa.addChild(w);
+ if(spacer != null) {
+ fa.addChild(spacer);
+ }
+
+ leaderArea = fa;
+ } else if(leaderPattern == LeaderPattern.USECONTENT) {
+ InlineStackingBPLayoutManager lm;
+ lm = new InlineStackingBPLayoutManager(this,
+ new LMiter(children.listIterator()));
+ lm.init();
+
+ // get breaks then add areas to FilledArea
+ FilledArea fa = new FilledArea();
+
+ ContentLayoutManager clm = new ContentLayoutManager(fa);
+ lm.setParentLM(clm);
+
+ clm.fillArea(lm);
+ int width = clm.getStackingSize();
+ Space spacer = null;
+ if(patternWidth > width) {
+ spacer = new Space();
+ spacer.setWidth(patternWidth - width);
+ width = patternWidth;
+ }
+ fa.setUnitWidth(width);
+ if(spacer != null) {
+ fa.addChild(spacer);
+ }
+ leaderArea = fa;
}
+ }
+
+ protected static class FilledArea extends InlineParent {
+ MinOptMax alloc;
+ int unitWidth;
+
+ public FilledArea() {
+ }
+
+ public void setUnitWidth(int w) {
+ unitWidth = w;
+ }
+
+ public void setAllocationIPD(MinOptMax all) {
+ alloc = all;
+ }
+
+ public MinOptMax getAllocationIPD() {
+ return alloc;
+ }
+
+ public void addChild(InlineArea childArea) {
+ inlines.add(childArea);
+ }
+
+ public List getChildAreas() {
+ int units = (int)(getWidth() / unitWidth);
+ ArrayList newList = new ArrayList();
+ for(int count = 0; count < units; count++) {
+ newList.addAll(inlines);
+ }
+ return newList;
+ }
+ }
- return leader;
+ public void setStructHandler(StructureHandler st) {
+ super.setStructHandler(st);
+ fontInfo = st.getFontInfo();
}
public void setup() {
BackgroundProps bProps = propMgr.getBackgroundProps();
// Common Font Properties
- //this.fontState = propMgr.getFontState(area.getFontInfo());
+ this.fontState = propMgr.getFontState(fontInfo);
// Common Margin Properties-Inline
MarginInlineProps mProps = propMgr.getMarginInlineProps();
}
// if leaderPatternWidth = 0 = default = use-font-metric
- int leaderPatternWidth =
+ patternWidth =
this.properties.get("leader-pattern-width").getLength().mvalue();
}
getLogger().warn("fo:title should be first in page-sequence");
} else {
this.titleFO = (Title)child;
- structHandler.startPageSequence(this, titleFO, layoutMasterSet);
- sequenceStarted = true;
}
} else if (childName.equals("fo:flow")) {
if (this.mainFlow != null) {
--- /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.area.Area;
+import org.apache.fop.area.MinOptMax;
+
+import java.util.ArrayList;
+
+/**
+ * Content Layout Manager.
+ * For use with objects that contain inline areas such as
+ * leader use-content and title.
+ */
+public class ContentLayoutManager implements LayoutManager {
+ Area holder;
+ int stackSize;
+
+ public ContentLayoutManager(Area area) {
+ holder = area;
+ }
+
+ public void fillArea(BPLayoutManager curLM) {
+
+ ArrayList childBreaks = new ArrayList();
+ MinOptMax stack = new MinOptMax();
+ int ipd = 1000000;
+ BreakPoss bp;
+
+ LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA);
+ childLC.setLeadingSpace(new SpaceSpecifier(false));
+ childLC.setTrailingSpace(new SpaceSpecifier(false));
+ // set stackLimit for lines
+ childLC.setStackLimit(new MinOptMax(ipd));
+ childLC.setRefIPD(ipd);
+
+ while (!curLM.isFinished()) {
+ if ((bp = curLM.getNextBreakPoss(childLC, null)) != null) {
+ stack.add(bp.getStackingSize());
+ childBreaks.add(bp);
+ }
+ }
+
+ LayoutContext lc = new LayoutContext(0);
+ lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true);
+ lc.setLeadingSpace(new SpaceSpecifier(false));
+ lc.setTrailingSpace(new SpaceSpecifier(false));
+ PositionIterator breakPosIter =
+ new BreakPossPosIter(childBreaks, 0, childBreaks.size());
+ curLM.addAreas(breakPosIter, lc);
+ stackSize = stack.opt;
+ }
+
+ public int getStackingSize() {
+ return stackSize;
+ }
+
+ public boolean generatesInlineAreas() {
+ return true;
+ }
+
+ public Area getParentArea (Area childArea) {
+ return holder;
+ }
+
+ public boolean addChild (Area childArea) {
+ holder.addChild(childArea);
+ return true;
+ }
+
+ public void setParentLM(LayoutManager lm) {
+ }
+
+ public int getContentIPD() {
+ return 10000000;
+ }
+
+}
+
BreakPoss.ISLAST);
bp.setStackingSize(curArea.getAllocationIPD());
bp.setNonStackingSize(curArea.getAllocationBPD());
+ bp.setTrailingSpace(new SpaceSpecifier(false));
int bpd = curArea.getHeight();
switch(alignment) {
return pdfInfo;
}
+ public PDFInfo getInfo() {
+ return info;
+ }
+
/**
* Make a Type 0 sampled function
*
public String convertTitleToString(Title title) {
String str = "";
List children = title.getInlineAreas();
+ str = convertToString(children);
+ return str.trim();
+ }
+ private String convertToString(List children) {
+ String str = "";
for (int count = 0; count < children.size(); count++) {
InlineArea inline = (InlineArea) children.get(count);
if (inline instanceof Character) {
str += ((Character) inline).getChar();
} else if (inline instanceof Word) {
str += ((Word) inline).getWord();
+ } else if (inline instanceof InlineParent) {
+ str += convertToString(((InlineParent)inline).getChildAreas());
} else {
str += " ";
}
}
- return str.trim();
+ return str;
}
public void startPageSequence(Title seqTitle) {
}
public void renderInlineParent(InlineParent ip) {
- // currentBlockIPPosition += ip.getWidth();
- Iterator iter = ip.getChildAreas().iterator();
- while (iter.hasNext()) {
+ int saveIP = currentBlockIPPosition;
+ Iterator iter = ip.getChildAreas().iterator();
+ while (iter.hasNext()) {
((InlineArea)iter.next()).render(this);
}
+ currentBlockIPPosition = saveIP + ip.getWidth();
}
protected void renderBlocks(List blocks) {
return true;
}
+ public void startPageSequence(Title seqTitle) {
+ if(seqTitle != null) {
+ String str = convertTitleToString(seqTitle);
+ PDFInfo info = this.pdfDoc.getInfo();
+ info.setTitle(str);
+ }
+ }
+
/**
* The pdf page is prepared by making the page.
* The page is made in the pdf document without any contents