If the Escher layer is asked to draw text with an invalid font, throw a much more useful error. Plus test

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@564219 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2007-08-09 14:27:06 +00:00
parent 65c68651ab
commit 03f738225f
2 changed files with 22 additions and 0 deletions

View File

@ -95,6 +95,14 @@ public class FontDetails
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);

View File

@ -50,6 +50,20 @@ public class TestEscherGraphics2d extends TestCase
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