blob: 1f626a5baf4f748eef781e731776390219858bba (
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/*
* $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;
// FOP
import org.apache.fop.layout.Area;
import org.apache.fop.apps.FOPException;
import org.apache.fop.datatypes.IDReferences;
import org.apache.fop.fo.properties.FOPropertyMapping;
import org.xml.sax.Attributes;
/**
* base class for representation of formatting objects and their processing
*/
public class FObj extends FONode {
public PropertyList properties;
protected PropertyManager propMgr;
protected String name;
public FObj(FObj parent) {
super(parent);
}
public void setName(String str) {
name = "fo:" + str;
}
protected PropertyListBuilder getListBuilder() {
PropertyListBuilder plb = new PropertyListBuilder();
plb.addList(FOPropertyMapping.getGenericMappings());
return plb;
}
/**
* Handle the attributes for this element.
* The attributes must be used immediately as the sax attributes
* will be altered for the next element.
*/
public void handleAttrs(Attributes attlist) throws FOPException {
String uri = "http://www.w3.org/1999/XSL/Format";
properties =
getListBuilder().makeList(uri, name, attlist,
(parent == null) ? null
: parent.properties, parent);
properties.setFObj(this);
this.propMgr = makePropertyManager(properties);
setWritingMode();
}
protected PropertyManager makePropertyManager(PropertyList propertyList) {
return new PropertyManager(propertyList);
}
/**
* adds characters (does nothing here)
* @param data text
* @param start start position
* @param length length of the text
*/
protected void addCharacters(char data[], int start, int length) {
// ignore
}
/**
* generates the area or areas for this formatting object
* and adds these to the area. This method should always be
* overridden by all sub classes
*
* @param area
*/
public Status layout(Area area) throws FOPException {
// should always be overridden
return new Status(Status.OK);
}
/**
* returns the name of the formatting object
* @return the name of this formatting objects
*/
public String getName() {
return this.name;
}
/**
*
*/
protected void start() {
// do nothing by default
}
/**
*
*/
protected void end() {
// do nothing by default
}
/**
* lets outside sources access the property list
* first used by PageNumberCitation to find the "id" property
* @param name - the name of the desired property to obtain
* @return the property
*/
public Property getProperty(String name) {
return (properties.get(name));
}
/**
* Return the "content width" of the areas generated by this FO.
* This is used by percent-based properties to get the dimension of
* the containing block.
* If an FO has a property with a percentage value, that value
* is usually calculated on the basis of the corresponding dimension
* of the area which contains areas generated by the FO.
* NOTE: subclasses of FObj should implement this to return a reasonable
* value!
*/
public int getContentWidth() {
return 0;
}
/**
* removes property id
* @param idReferences the id to remove
*/
public void removeID(IDReferences idReferences) {
if (((FObj)this).properties.get("id") == null
|| ((FObj)this).properties.get("id").getString() == null)
return;
idReferences.removeID(((FObj)this).properties.get("id").getString());
int numChildren = this.children.size();
for (int i = 0; i < numChildren; i++) {
FONode child = (FONode)children.elementAt(i);
if ((child instanceof FObj)) {
((FObj)child).removeID(idReferences);
}
}
}
public boolean generatesReferenceAreas() {
return false;
}
/**
* Set writing mode for this FO.
* Find nearest ancestor, including self, which generates
* reference areas and use the value of its writing-mode property.
* If no such ancestor is found, use the value on the root FO.
*/
protected void setWritingMode() {
FObj p;
FObj parent;
for (p = this;
!p.generatesReferenceAreas() && (parent = p.getParent()) != null;
p = parent);
this.properties.setWritingMode(p.getProperty("writing-mode").getEnum());
}
}
|