// Case 1. A 'normal' keyword, which means default of 6em/s
// Case 2. A length value, which indicates speed per second
// Case 3. A fraction value, as length per time.
if (styleValue instanceof StyleLength) {
// Case 2.
StyleLength styleLength = (StyleLength) styleValue;
if (styleLength.getUnit() == LengthUnit.EM) {
speed = styleLength.getNumber();
}
} else if (styleValue instanceof StyleFraction) {
// Case 3.
StyleFraction styleFraction = (StyleFraction) styleValue;
StyleValue styleNumerator = styleFraction.getNumerator();
StyleValue styleDenominator = styleFraction.getDenominator();
if ((styleNumerator instanceof StyleLength) &&
(styleDenominator instanceof StyleTime)) {
StyleLength styleLength = (StyleLength) styleNumerator;
StyleTime styleTime = (StyleTime) styleDenominator;
// Convert time to seconds.
double timeInSeconds = timeConverter.convert(styleTime.getNumber(), styleTime.getUnit(), TimeUnit.S);
// If conversion succeded...
if (!Double.isNaN(timeInSeconds)) {
// Return speed in em/sec.
if (styleLength.getUnit() == LengthUnit.EM) {
speed = styleLength.getNumber() / timeInSeconds;
}
}
}
}