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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*
* $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;
import org.apache.fop.layout.FontState;
import org.apache.fop.layout.FontInfo;
import org.apache.fop.layout.BorderAndPadding;
import org.apache.fop.layout.MarginProps;
import org.apache.fop.layout.BackgroundProps;
import org.apache.fop.fo.properties.BreakAfter;
import org.apache.fop.fo.properties.BreakBefore;
import org.apache.fop.fo.properties.Constants;
import org.apache.fop.layout.HyphenationProps;
import org.apache.fop.apps.FOPException;
import java.text.MessageFormat;
import java.text.FieldPosition;
import org.apache.fop.layout.Area;
import org.apache.fop.layout.ColumnArea;
public class PropertyManager {
private PropertyList properties;
private FontState fontState = null;
private BorderAndPadding borderAndPadding = null;
private HyphenationProps hyphProps = null;
private String[] saLeft;
private String[] saRight;
private String[] saTop;
private String[] saBottom;
private static MessageFormat msgColorFmt =
new MessageFormat("border-{0}-color");
private static MessageFormat msgStyleFmt =
new MessageFormat("border-{0}-style");
private static MessageFormat msgWidthFmt =
new MessageFormat("border-{0}-width");
private static MessageFormat msgPaddingFmt =
new MessageFormat("padding-{0}");
public PropertyManager(PropertyList pList) {
this.properties = pList;
}
private void initDirections() {
saLeft = new String[1];
saRight = new String[1];
saTop = new String[1];
saBottom = new String[1];
saTop[0] = properties.wmAbsToRel(PropertyList.TOP);
saBottom[0] = properties.wmAbsToRel(PropertyList.BOTTOM);
saLeft[0] = properties.wmAbsToRel(PropertyList.LEFT);
saRight[0] = properties.wmAbsToRel(PropertyList.RIGHT);
}
public FontState getFontState(FontInfo fontInfo) throws FOPException {
if (fontState == null) {
String fontFamily = properties.get("font-family").getString();
String fontStyle = properties.get("font-style").getString();
String fontWeight = properties.get("font-weight").getString();
// NOTE: this is incomplete. font-size may be specified with
// various kinds of keywords too
int fontSize = properties.get("font-size").getLength().mvalue();
int fontVariant = properties.get("font-variant").getEnum();
// fontInfo is same for the whole FOP run but set in all FontState
fontState = new FontState(fontInfo, fontFamily, fontStyle,
fontWeight, fontSize, fontVariant);
}
return fontState;
}
public BorderAndPadding getBorderAndPadding() {
if (borderAndPadding == null) {
this.borderAndPadding = new BorderAndPadding();
initDirections();
initBorderInfo(BorderAndPadding.TOP, saTop);
initBorderInfo(BorderAndPadding.BOTTOM, saBottom);
initBorderInfo(BorderAndPadding.LEFT, saLeft);
initBorderInfo(BorderAndPadding.RIGHT, saRight);
}
return borderAndPadding;
}
private void initBorderInfo(int whichSide, String[] saSide) {
borderAndPadding.setPadding(whichSide,
properties.get(msgPaddingFmt.format(saSide)).getCondLength());
// If style = none, force width to 0, don't get Color
int style = properties.get(msgStyleFmt.format(saSide)).getEnum();
if (style != Constants.NONE) {
borderAndPadding.setBorder(whichSide, style,
properties.get(msgWidthFmt.format(saSide)).getCondLength(),
properties.get(msgColorFmt.format(saSide)).getColorType());
}
}
public HyphenationProps getHyphenationProps() {
if (hyphProps == null) {
this.hyphProps = new HyphenationProps();
hyphProps.hyphenate = this.properties.get("hyphenate").getEnum();
hyphProps.hyphenationChar =
this.properties.get("hyphenation-character").getCharacter();
hyphProps.hyphenationPushCharacterCount =
this.properties.get("hyphenation-push-character-count").getNumber().intValue();
hyphProps.hyphenationRemainCharacterCount =
this.properties.get("hyphenation-remain-character-count").getNumber().intValue();
hyphProps.language = this.properties.get("language").getString();
hyphProps.country = this.properties.get("country").getString();
}
return hyphProps;
}
public int checkBreakBefore(Area area) {
if (!(area instanceof ColumnArea)) {
switch (properties.get("break-before").getEnum()) {
case BreakBefore.PAGE:
return Status.FORCE_PAGE_BREAK;
case BreakBefore.ODD_PAGE:
return Status.FORCE_PAGE_BREAK_ODD;
case BreakBefore.EVEN_PAGE:
return Status.FORCE_PAGE_BREAK_EVEN;
case BreakBefore.COLUMN:
return Status.FORCE_COLUMN_BREAK;
default:
return Status.OK;
}
} else {
ColumnArea colArea = (ColumnArea)area;
switch (properties.get("break-before").getEnum()) {
case BreakBefore.PAGE:
// if first ColumnArea, and empty, return OK
if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1))
return Status.OK;
else
return Status.FORCE_PAGE_BREAK;
case BreakBefore.ODD_PAGE:
// if first ColumnArea, empty, _and_ in odd page,
// return OK
if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1)
&& (colArea.getPage().getNumber() % 2 != 0))
return Status.OK;
else
return Status.FORCE_PAGE_BREAK_ODD;
case BreakBefore.EVEN_PAGE:
// if first ColumnArea, empty, _and_ in even page,
// return OK
if (!colArea.hasChildren() && (colArea.getColumnIndex() == 1)
&& (colArea.getPage().getNumber() % 2 == 0))
return Status.OK;
else
return Status.FORCE_PAGE_BREAK_EVEN;
case BreakBefore.COLUMN:
// if ColumnArea is empty return OK
if (!area.hasChildren())
return Status.OK;
else
return Status.FORCE_COLUMN_BREAK;
default:
return Status.OK;
}
}
}
public int checkBreakAfter(Area area) {
switch (properties.get("break-after").getEnum()) {
case BreakAfter.PAGE:
return Status.FORCE_PAGE_BREAK;
case BreakAfter.ODD_PAGE:
return Status.FORCE_PAGE_BREAK_ODD;
case BreakAfter.EVEN_PAGE:
return Status.FORCE_PAGE_BREAK_EVEN;
case BreakAfter.COLUMN:
return Status.FORCE_COLUMN_BREAK;
default:
return Status.OK;
}
}
public MarginProps getMarginProps() {
MarginProps props = new MarginProps();
// Common Margin Properties-Block
props.marginTop =
this.properties.get("margin-top").getLength().mvalue();
props.marginBottom =
this.properties.get("margin-bottom").getLength().mvalue();
props.marginLeft =
this.properties.get("margin-left").getLength().mvalue();
props.marginRight =
this.properties.get("margin-right").getLength().mvalue();
/*
* // need to get opt, min and max
* props.spaceBefore = this.properties.get("space-before").getLength().mvalue();
* props.spaceAfter = this.properties.get("space-after").getLength().mvalue();
* props.startIndent = this.properties.get("start-indent").getLength().mvalue();
* props.endIndent = this.properties.get("end-indent").getLength().mvalue();
*/
return props;
}
public BackgroundProps getBackgroundProps() {
BackgroundProps bp = new BackgroundProps();
return bp;
}
}
|