You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2011/03/04 15:01:15 UTC

svn commit: r1077950 - in /poi/trunk/src: documentation/content/xdocs/status.xml java/org/apache/poi/ss/usermodel/FontCharset.java ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java

Author: nick
Date: Fri Mar  4 14:01:14 2011
New Revision: 1077950

URL: http://svn.apache.org/viewvc?rev=1077950&view=rev
Log:
Fix bug #50847 - XSSFFont now accepts the full range of Charsets from FontChartset

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/ss/usermodel/FontCharset.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1077950&r1=1077949&r2=1077950&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Mar  4 14:01:14 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta2" date="2011-??-??">
+           <action dev="poi-developers" type="fix">50847 - XSSFFont now accepts the full range of Charsets from FontChartset</action>
            <action dev="poi-developers" type="fix">50786 - Speed up calls to HSSFColor.getIndexHash() by returning a cached, unmodifiable Map. HSSFColor.getModifiableIndexHash() provides access to the old (slow but modifiable) functionality</action>
            <action dev="poi-developers" type="fix">47100 - Change related formulas and named ranges when XSSFWorkbook.setSheetName is called</action>
         </release>

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/FontCharset.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/FontCharset.java?rev=1077950&r1=1077949&r2=1077950&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/FontCharset.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/FontCharset.java Fri Mar  4 14:01:14 2011
@@ -70,6 +70,8 @@ public enum FontCharset {
     }
 
     public static FontCharset valueOf(int value){
+        if(value >= _table.length)
+           return null;
         return _table[value];
     }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=1077950&r1=1077949&r2=1077950&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Fri Mar  4 14:01:14 2011
@@ -306,19 +306,11 @@ public class XSSFFont implements Font {
      * @see FontCharset
      */
     public void setCharSet(int charset) {
-        CTIntProperty charsetProperty = _ctFont.sizeOfCharsetArray() == 0 ? _ctFont.addNewCharset() : _ctFont.getCharsetArray(0);
-        switch (charset) {
-            case Font.ANSI_CHARSET:
-                charsetProperty.setVal(FontCharset.ANSI.getValue());
-                break;
-            case Font.SYMBOL_CHARSET:
-                charsetProperty.setVal(FontCharset.SYMBOL.getValue());
-                break;
-            case Font.DEFAULT_CHARSET:
-                charsetProperty.setVal(FontCharset.DEFAULT.getValue());
-                break;
-            default:
-                throw new POIXMLException("Attention: an attempt to set a type of unknow charset and charset");
+        FontCharset fontCharset = FontCharset.valueOf(charset);
+        if(fontCharset != null) {
+           setCharSet(fontCharset);
+        } else {
+           throw new POIXMLException("Attention: an attempt to set a type of unknow charset and charset");
         }
     }
 
@@ -328,7 +320,15 @@ public class XSSFFont implements Font {
      * @param charSet
      */
     public void setCharSet(FontCharset charSet) {
-        setCharSet((byte)charSet.getValue());
+       CTIntProperty charsetProperty;
+       if(_ctFont.sizeOfCharsetArray() == 0) {
+          charsetProperty = _ctFont.addNewCharset();
+       } else {
+          charsetProperty = _ctFont.getCharsetArray(0);
+       }
+       // We know that FontCharset only has valid entries in it,
+       //  so we can just set the int value from it
+       charsetProperty.setVal( charSet.getValue() );
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java?rev=1077950&r1=1077949&r2=1077950&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java Fri Mar  4 14:01:14 2011
@@ -17,6 +17,7 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import org.apache.poi.POIXMLException;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
@@ -73,7 +74,22 @@ public final class TestXSSFFont extends 
 
 		xssfFont.setCharSet(FontCharset.DEFAULT);
 		assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
-		
+
+		// Try with a few less usual ones:
+		// Set with the Charset itself
+      xssfFont.setCharSet(FontCharset.RUSSIAN);
+      assertEquals(FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
+      // And set with the Charset index
+      xssfFont.setCharSet(FontCharset.ARABIC.getValue());
+      assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
+      
+      // This one isn't allowed
+      assertEquals(null, FontCharset.valueOf(9999));
+      try {
+         xssfFont.setCharSet(9999);
+         fail("Shouldn't be able to set an invalid charset");
+      } catch(POIXMLException e) {}
+      
 		
 		// Now try with a few sample files
 		



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