blob: 416506a8970adaa8fe72821aada00421feb6c8ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/*
* $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.BlockParent;
import org.apache.fop.area.Block;
import org.apache.fop.area.LineArea;
import java.util.ListIterator;
/**
* LayoutManager for a block FO.
*/
public class BlockLayoutManager extends BlockStackingLayoutManager {
private Block curBlockArea;
public BlockLayoutManager(FObj fobj) {
super(fobj);
}
public void setBlockTextInfo(TextInfo ti) {
}
/**
* Called by child layout manager to get the available space for
* content in the inline progression direction.
* Note that a manager may need to ask its parent for this.
* For a block area, available IPD is determined by indents.
*/
public int getContentIPD() {
// adjust for side floats and indents
//getParentArea(null); // make if not existing
return curBlockArea.getIPD();
}
/**
* Generate areas by tellings all layout managers for its FO's
* children to generate areas.
*/
public void generateAreas() {
ListIterator children = fobj.getChildren();
LayoutManager lm = null;
while (children.hasNext()) {
FObj childFO = (FObj) children.next();
if (childFO.generatesInlineAreas()) {
children.previous();
lm = new LineLayoutManager(children);
} else {
lm = childFO.getLayoutManager();
}
if (lm != null) {
lm.setParentLM(this);
lm.generateAreas();
}
}
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.
* In general, if the LayoutManager already has an Area it simply returns
* it. Otherwise, it makes a new Area of the appropriate class.
* It gets a parent area for its area by calling its parent LM.
* Finally, based on the dimensions of the parent area, it initializes
* its own area. This includes setting the content IPD and the maximum
* BPD.
*/
public Area getParentArea(Area childArea) {
if (curBlockArea == null) {
curBlockArea = new Block();
// Set up dimensions
// Must get dimensions from parent area
Area parentArea = parentLM.getParentArea(curBlockArea);
int referenceIPD = parentArea.getIPD();
curBlockArea.setIPD(referenceIPD);
// Get reference IPD from parentArea
setCurrentArea(curBlockArea); // ??? for generic operations
}
return curBlockArea;
}
public void addChild(Area childArea) {
if (curBlockArea != null) {
if (childArea instanceof LineArea) {
// Something about widows and orphans
// Position the line area and calculate size...
curBlockArea.addLineArea((LineArea) childArea);
} else {
super.addChild(childArea);
}
}
}
// /**
// * Called by child LayoutManager when it has filled one of its areas.
// * If no current container, make one.
// * See if the area will fit in the current container.
// * If so, add it.
// * @param childArea the area to add: will either be a LineArea or
// * a BlockArea.
// */
// public void addChild(Area childArea) {
// /* If the childArea fits entirely in the maximum available BPD
// * add it and return an OK status.
// * If it doesn't all fit, overrun or ask for split?
// * Might as well just add it since the page layout process
// * may need to make other adjustments, resulting in changing
// * split point.
// */
// // Things like breaks on child area can cause premature
// // termination of the current area.
// /* We go past the theoretical maximum to be able to handle things
// * like widows.
// */
// // WARNING: this doesn't take into account space-specifier
// // adujstment between childArea and last content of blockArea!
// if (blockArea.getContentBPD().min + childArea.getAllocationBPD().min
// > blockArea.getAvailBPD().max) {
// if (++extraLines <= iWidows) {
// blockArea.add(childArea);
// }
// else {
// blockArea.setIsLast(false);
// parentLM.addChildArea(blockArea);
// // Make a new one for this area
// blockArea = makeAreaForChild(childArea);
// extraLines = 0; // Count potential widows
// blockArea.add(childArea);
// }
// }
// else {
// blockArea.add(childArea);
// }
// }
}
|