String heightStr = fontMetricsProps.getProperty( "font." + fontName + ".height");
String widthsStr = fontMetricsProps.getProperty( "font." + fontName + ".widths");
String charactersStr = fontMetricsProps.getProperty( "font." + fontName + ".characters");
+
+ // Ensure that this is a font we know about
+ if(heightStr == null || widthsStr == null || charactersStr == null) {
+ // We don't know all we need to about this font
+ // Since we don't know its sizes, we can't work with it
+ throw new IllegalArgumentException("The supplied FontMetrics doesn't know about the font '" + fontName + "', so we can't use it. Please add it to your font metrics file (see StaticFontMetrics.getFontDetails");
+ }
+
int height = Integer.parseInt(heightStr);
FontDetails d = new FontDetails(fontName, height);
String[] charactersStrArray = split(charactersStr, ",", -1);
graphics.drawString("This is a test", 10, 10);
HSSFTextbox t = (HSSFTextbox) escherGroup.getChildren().get(0);
assertEquals("This is a test", t.getString().getString().toString());
+
+ // Check that with a valid font, it's still ok
+ Font font = new Font("Forte", Font.PLAIN, 12);
+ graphics.setFont(font);
+ graphics.drawString("This is another test", 10, 10);
+
+ // But with an invalid font, we get an exception
+ font = new Font("IamAmadeUPfont", Font.PLAIN, 22);
+ graphics.setFont(font);
+ try {
+ graphics.drawString("This is another test", 10, 10);
+ fail();
+ } catch(IllegalArgumentException e) {
+ }
}
public void testFillRect() throws Exception