poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r948089 - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/ss/usermodel/ src/ooxml/java/org/apache/poi/xssf/usermodel/ src/ooxml/testcases/org/apache/poi/xssf/usermodel/ test-da...
Date Tue, 25 May 2010 16:25:35 GMT
Author: nick
Date: Tue May 25 16:25:34 2010
New Revision: 948089

URL: http://svn.apache.org/viewvc?rev=948089&view=rev
Log:
Fix bug #49273 - Correct handling for Font Character Sets with indicies greater than 127

Added:
    poi/trunk/test-data/spreadsheet/49273.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.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=948089&r1=948088&r2=948089&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue May 25 16:25:34 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49273 - Correct handling for Font
Character Sets with indicies greater than 127</action>
            <action dev="POI-DEVELOPERS" type="add">49334 - Track the ValueRangeRecords
of charts in HSSFChart, to allow the basic axis operations</action>
            <action dev="POI-DEVELOPERS" type="add">49242 - Track the LinkDataRecords
of charts in HSSFChart</action>
            <action dev="POI-DEVELOPERS" type="add">Improved performance of XSSFWorkbook.write
</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java?rev=948089&r1=948088&r2=948089&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFFont.java Tue May 25 16:25:34 2010
@@ -280,9 +280,29 @@ public final class HSSFFont implements F
      * @see #DEFAULT_CHARSET
      * @see #SYMBOL_CHARSET
      */
-    public byte getCharSet()
+    public int getCharSet()
     {
-        return font.getCharset();
+        byte charset = font.getCharset();
+        if(charset >= 0) {
+           return (int)charset;
+        } else {
+           return charset + 256;
+        }
+    }
+
+    /**
+     * set character-set to use.
+     * @see #ANSI_CHARSET
+     * @see #DEFAULT_CHARSET
+     * @see #SYMBOL_CHARSET
+     */
+    public void setCharSet(int charset)
+    {
+        byte cs = (byte)charset;
+        if(charset > 127) {
+           cs = (byte)(charset-256);
+        }
+        setCharSet(cs);
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java?rev=948089&r1=948088&r2=948089&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Font.java Tue May 25 16:25:34 2010
@@ -251,7 +251,7 @@ public interface Font {
      * @see #DEFAULT_CHARSET
      * @see #SYMBOL_CHARSET
      */
-    byte getCharSet();
+    int getCharSet();
 
     /**
      * set character-set to use.
@@ -260,6 +260,13 @@ public interface Font {
      * @see #SYMBOL_CHARSET
      */
     void setCharSet(byte charset);
+    /**
+     * set character-set to use.
+     * @see #ANSI_CHARSET
+     * @see #DEFAULT_CHARSET
+     * @see #SYMBOL_CHARSET
+     */
+    void setCharSet(int charset);
 
     /**
      * get the index within the XSSFWorkbook (sequence within the collection of Font objects)

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=948089&r1=948088&r2=948089&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 Tue May 25 16:25:34
2010
@@ -107,13 +107,13 @@ public class XSSFFont implements Font {
     /**
      * get character-set to use.
      *
-     * @return byte - character-set
+     * @return int - character-set (0-255)
      * @see org.apache.poi.ss.usermodel.FontCharset
      */
-    public byte getCharSet() {
+    public int getCharSet() {
         CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
         int val = charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
-        return (byte)val;
+        return val;
     }
 
 
@@ -293,6 +293,19 @@ public class XSSFFont implements Font {
      * @see FontCharset
      */
     public void setCharSet(byte charset) {
+       int cs = (int)charset;
+       if(cs < 0) {
+          cs += 256;
+       }
+       setCharSet(cs);
+    }
+    /**
+     * set character-set to use.
+     *
+     * @param charset - charset
+     * @see FontCharset
+     */
+    public void setCharSet(int charset) {
         CTIntProperty charsetProperty = _ctFont.sizeOfCharsetArray() == 0 ? _ctFont.addNewCharset()
: _ctFont.getCharsetArray(0);
         switch (charset) {
             case Font.ANSI_CHARSET:

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=948089&r1=948088&r2=948089&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 Tue May
25 16:25:34 2010
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
 
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
@@ -72,6 +73,21 @@ public final class TestXSSFFont extends 
 
 		xssfFont.setCharSet(FontCharset.DEFAULT);
 		assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
+		
+		
+		// Now try with a few sample files
+		
+		// Normal charset
+      XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+      assertEquals(0, 
+            workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+      );
+		
+		// GB2312 charact set
+      workbook = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
+      assertEquals(134, 
+            workbook.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+      );
 	}
 
 	public void testFontName() {

Added: poi/trunk/test-data/spreadsheet/49273.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/49273.xlsx?rev=948089&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/49273.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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


Mime
View raw message