List idents = style.getTextDecorations();
if (idents != null) {
result = new ArrayList(idents.size());
if (idents.contains(IdentValue.UNDERLINE)) {
TextDecoration decoration = new TextDecoration(IdentValue.UNDERLINE);
// JDK returns zero so create additional space equal to one
// "underlineThickness"
if (fm.getUnderlineOffset() == 0) {
decoration.setOffset(Math.round((baseline + fm.getUnderlineThickness())));
} else {
decoration.setOffset(Math.round((baseline + fm.getUnderlineOffset())));
}
decoration.setThickness(Math.round(fm.getUnderlineThickness()));
// JDK on Linux returns some goofy values for
// LineMetrics.getUnderlineOffset(). Compensate by always
// making sure underline fits inside the descender
if (fm.getUnderlineOffset() == 0) { // HACK, are we running under the JDK
int maxOffset =
baseline + (int)fm.getDescent() - decoration.getThickness();
if (decoration.getOffset() > maxOffset) {
decoration.setOffset(maxOffset);
}
}
result.add(decoration);
}
if (idents.contains(IdentValue.LINE_THROUGH)) {
TextDecoration decoration = new TextDecoration(IdentValue.LINE_THROUGH);
decoration.setOffset(Math.round(baseline + fm.getStrikethroughOffset()));
decoration.setThickness(Math.round(fm.getStrikethroughThickness()));
result.add(decoration);
}
if (idents.contains(IdentValue.OVERLINE)) {
TextDecoration decoration = new TextDecoration(IdentValue.OVERLINE);
decoration.setOffset(0);
decoration.setThickness(Math.round(fm.getUnderlineThickness()));
result.add(decoration);
}
}
return result;