* @throws IllegalArgumentException indicated the font metrics could not be determined (this is thrown since methods
* depending upon this method can not handle a <code>null</code> return).
*/
public FontMetrics getFontMetrics(final LayoutStyle styleSheet) throws IllegalArgumentException
{
final CSSValue fontFamily = getNormalizedFontFamilyName(styleSheet.getValue(FontStyleKeys.FONT_FAMILY));
if (fontFamily == null)
{
// If this case happens, the stylesheet is not implemented correctly. At that point,
// we have to assume that the whole engine is no longer behaving valid and therefore we
// abort early.
throw new IllegalArgumentException("No valid font family specified.");
}
final String fontName;
if (fontFamily instanceof CSSStringValue)
{
final CSSStringValue svalue = (CSSStringValue) fontFamily;
fontName = svalue.getValue();
}
else
{
fontName = fontFamily.getCSSText();
}
final CSSValue value = styleSheet.getValue(FontStyleKeys.FONT_SIZE);
final int resolution = (int) getNumericFeatureValue(OutputProcessorFeature.DEVICE_RESOLUTION);
final double fontSize = StyleSheetUtility.convertLengthToDouble(value, resolution);
final boolean antiAliasing = FontSmooth.ALWAYS.equals(styleSheet.getValue(FontStyleKeys.FONT_SMOOTH));
final CSSValue boldVal = styleSheet.getValue(FontStyleKeys.FONT_WEIGHT);
final CSSValue italicsVal = styleSheet.getValue(FontStyleKeys.FONT_STYLE);
return getFontMetrics(fontName, fontSize, computeBold(boldVal), computeItalics(italicsVal), "UTF-8", false, antiAliasing);
}