poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r564219 - in /poi/trunk/src: java/org/apache/poi/hssf/usermodel/FontDetails.java testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
Date Thu, 09 Aug 2007 14:27:06 GMT
Author: nick
Date: Thu Aug  9 07:27:06 2007
New Revision: 564219

URL: http://svn.apache.org/viewvc?view=rev&rev=564219
Log:
If the Escher layer is asked to draw text with an invalid font, throw a much more useful error.
Plus test

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/FontDetails.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/FontDetails.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/FontDetails.java?view=diff&rev=564219&r1=564218&r2=564219
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/FontDetails.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/FontDetails.java Thu Aug  9 07:27:06
2007
@@ -95,6 +95,14 @@
         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);

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java?view=diff&rev=564219&r1=564218&r2=564219
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestEscherGraphics2d.java Thu Aug
 9 07:27:06 2007
@@ -50,6 +50,20 @@
         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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message