public boolean isStatic() {
return false;
}
public String calculate(RenderingContext c, FSFunction function, InlineText text) {
InlineLayoutBox iB = text.getParent();
LineBox lineBox = iB.getLineBox();
// There might be a target-counter function after this function.
// Because the leader should fill up the line, we need the correct
// width and must first compute the target-counter function.
boolean dynamic = false;
Iterator childIterator = lineBox.getChildIterator();
while (childIterator.hasNext()) {
Box child = (Box)childIterator.next();
if (child == iB) {
dynamic = true;
} else if (dynamic && child instanceof InlineLayoutBox) {
((InlineLayoutBox)child).lookForDynamicFunctions(c);
}
}
if (dynamic) {
int totalLineWidth = InlineBoxing.positionHorizontally(c, lineBox, 0);
lineBox.setContentWidth(totalLineWidth);
}
// Get leader value and value width
PropertyValue param = (PropertyValue)function.getParameters().get(0);
String value = param.getStringValue();
if (param.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) {
if (value.equals("dotted")) {
value = ". ";
} else if (value.equals("solid")) {
value = "_";
} else if (value.equals("space")) {
value = " ";
}
}
// Compute value width using 100x string to get more precise width.
// Otherwise there might be a small gap at the right side. This is
// necessary because a TextRenderer usually use double/float for width.
StringBuffer tmp = new StringBuffer(100 * value.length());
for (int i = 0; i < 100; i++) {
tmp.append(value);
}
float valueWidth = c.getTextRenderer().getWidth(c.getFontContext(),
iB.getStyle().getFSFont(c), tmp.toString()) / 100f;
int spaceWidth = c.getTextRenderer().getWidth(c.getFontContext(),
iB.getStyle().getFSFont(c), " ");
// compute leader width and necessary count of values
int leaderWidth = iB.getContainingBlockWidth() - iB.getLineBox().getWidth() + text.getWidth();
int count = (int) ((leaderWidth - (2 * spaceWidth)) / valueWidth);
// build leader string
StringBuffer buf = new StringBuffer(count * value.length() + 2);
buf.append(' ');
for (int i = 0; i < count; i++) {
buf.append(value);
}
buf.append(' ');
String leaderString = buf.toString();
// set left margin to ensure that the leader is right aligned (for TOC)
int leaderStringWidth = c.getTextRenderer().getWidth(c.getFontContext(),
iB.getStyle().getFSFont(c), leaderString);
iB.setMarginLeft(c, leaderWidth - leaderStringWidth);
return leaderString;
}