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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
* $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.fo.flow;
// FOP
import org.apache.fop.fo.*;
import org.apache.fop.fo.properties.*;
import org.apache.fop.layout.*;
import org.apache.fop.layout.BlockArea;
import org.apache.fop.layout.FontState;
import org.apache.fop.apps.FOPException;
// Java
import java.util.Enumeration;
public class ListItem extends FObj {
public static class Maker extends FObj.Maker {
public FObj make(FObj parent,
PropertyList propertyList) throws FOPException {
return new ListItem(parent, propertyList);
}
}
public static FObj.Maker maker() {
return new ListItem.Maker();
}
int align;
int alignLast;
int breakBefore;
int breakAfter;
int lineHeight;
int startIndent;
int endIndent;
int spaceBefore;
int spaceAfter;
String id;
BlockArea blockArea;
public ListItem(FObj parent, PropertyList propertyList) {
super(parent, propertyList);
this.name = "fo:list-item";
}
public Status layout(Area area) throws FOPException {
if (this.marker == START) {
// Common Accessibility Properties
AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
// Common Aural Properties
AuralProps mAurProps = propMgr.getAuralProps();
// Common Border, Padding, and Background Properties
BorderAndPadding bap = propMgr.getBorderAndPadding();
BackgroundProps bProps = propMgr.getBackgroundProps();
// Common Margin Properties-Block
MarginProps mProps = propMgr.getMarginProps();
// Common Relative Position Properties
RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
// this.properties.get("break-after");
// this.properties.get("break-before");
// this.properties.get("id");
// this.properties.get("keep-together");
// this.properties.get("keep-with-next");
// this.properties.get("keep-with-previous");
// this.properties.get("relative-align");
this.align = this.properties.get("text-align").getEnum();
this.alignLast = this.properties.get("text-align-last").getEnum();
this.lineHeight =
this.properties.get("line-height").getLength().mvalue();
this.spaceBefore =
this.properties.get("space-before.optimum").getLength().mvalue();
this.spaceAfter =
this.properties.get("space-after.optimum").getLength().mvalue();
this.id = this.properties.get("id").getString();
area.getIDReferences().createID(id);
this.marker = 0;
}
/* not sure this is needed given we know area is from list block */
if (area instanceof BlockArea) {
area.end();
}
if (spaceBefore != 0) {
area.addDisplaySpace(spaceBefore);
}
this.blockArea =
new BlockArea(propMgr.getFontState(area.getFontInfo()),
area.getAllocationWidth(), area.spaceLeft(), 0, 0,
0, align, alignLast, lineHeight);
this.blockArea.setGeneratedBy(this);
this.areasGenerated++;
if (this.areasGenerated == 1)
this.blockArea.isFirst(true);
// for normal areas this should be the only pair
this.blockArea.addLineagePair(this, this.areasGenerated);
// markers
if (this.hasMarkers())
this.blockArea.addMarkers(this.getMarkers());
blockArea.setPage(area.getPage());
blockArea.start();
blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
blockArea.setIDReferences(area.getIDReferences());
int numChildren = this.children.size();
if (numChildren != 2) {
throw new FOPException("list-item must have exactly two children");
}
ListItemLabel label = (ListItemLabel)children.elementAt(0);
ListItemBody body = (ListItemBody)children.elementAt(1);
Status status;
// what follows doesn't yet take into account whether the
// body failed completely or only got some text in
if (this.marker == 0) {
// configure id
area.getIDReferences().configureID(id, area);
status = label.layout(blockArea);
if (status.isIncomplete()) {
return status;
}
}
status = body.layout(blockArea);
if (status.isIncomplete()) {
blockArea.end();
area.addChild(blockArea);
area.increaseHeight(blockArea.getHeight());
area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
this.marker = 1;
return status;
}
blockArea.end();
area.addChild(blockArea);
area.increaseHeight(blockArea.getHeight());
area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
if (spaceAfter != 0) {
area.addDisplaySpace(spaceAfter);
}
/* not sure this is needed given we know area is from list block */
if (area instanceof BlockArea) {
area.start();
}
this.blockArea.isLast(true);
return new Status(Status.OK);
}
/**
* Return the content width of the boxes generated by this FO.
*/
public int getContentWidth() {
if (blockArea != null)
return blockArea.getContentWidth(); // getAllocationWidth()??
else
return 0; // not laid out yet
}
}
|