]> source.dussan.org Git - poi.git/commitdiff
remove more deprecated code (fix some issues)
authorPJ Fanning <fanningpj@apache.org>
Wed, 9 Dec 2020 18:12:53 +0000 (18:12 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 9 Dec 2020 18:12:53 +0000 (18:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884265 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java

index db18e0fc9beeb0fce8ffc4098551af860d764378..3f78756a7d40f936a27fcee5b62a273bc3742655 100644 (file)
@@ -182,7 +182,7 @@ public final class HSSFCellStyle implements CellStyle, Duplicatable {
     }
     public void setFont(HSSFFont font) {
         _format.setIndentNotParentFont(true);
-        short fontindex = font.getIndex();
+        short fontindex = (short) font.getIndex();
         _format.setFontIndex(fontindex);
     }
 
index bce40f070759039b59fca8e05347c4f8a8e32a97..05ab55555036d04ec730ba692f1d2b1b7299c0d6 100644 (file)
@@ -19,10 +19,10 @@ package org.apache.poi.xssf.usermodel;
 
 import java.io.IOException;
 
+import org.apache.poi.common.usermodel.fonts.FontCharset;
 import org.apache.poi.ooxml.POIXMLException;
 import org.apache.poi.ss.usermodel.BaseTestFont;
 import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FontCharset;
 import org.apache.poi.ss.usermodel.FontFamily;
 import org.apache.poi.ss.usermodel.FontScheme;
 import org.apache.poi.ss.usermodel.FontUnderline;
@@ -82,30 +82,30 @@ public final class TestXSSFFont extends BaseTestFont{
 
        @SuppressWarnings("deprecation")
        @Test
-       public void testCharSet() throws IOException {
+       public void testCharSetWithDeprecatedFontCharset() throws IOException {
                CTFont ctFont=CTFont.Factory.newInstance();
                CTIntProperty prop=ctFont.addNewCharset();
-               prop.setVal(FontCharset.ANSI.getValue());
+               prop.setVal(org.apache.poi.ss.usermodel.FontCharset.ANSI.getValue());
 
                ctFont.setCharsetArray(0,prop);
                XSSFFont xssfFont=new XSSFFont(ctFont);
                assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());
 
-               xssfFont.setCharSet(FontCharset.DEFAULT);
-               assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
+               xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.DEFAULT);
+               assertEquals(org.apache.poi.ss.usermodel.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());
+        xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN);
+        assertEquals(org.apache.poi.ss.usermodel.FontCharset.RUSSIAN.getValue(), xssfFont.getCharSet());
         // And set with the Charset index
-        xssfFont.setCharSet(FontCharset.ARABIC.getValue());
-        assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
-        xssfFont.setCharSet((byte)(FontCharset.ARABIC.getValue()));
-        assertEquals(FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
+        xssfFont.setCharSet(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue());
+        assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
+        xssfFont.setCharSet((byte)(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue()));
+        assertEquals(org.apache.poi.ss.usermodel.FontCharset.ARABIC.getValue(), xssfFont.getCharSet());
 
         // This one isn't allowed
-        assertNull(FontCharset.valueOf(9999));
+        assertNull(org.apache.poi.ss.usermodel.FontCharset.valueOf(9999));
         try {
            xssfFont.setCharSet(9999);
            fail("Shouldn't be able to set an invalid charset");
@@ -131,6 +131,55 @@ public final class TestXSSFFont extends BaseTestFont{
         wb2.close();
        }
 
+       @Test
+       public void testCharSet() throws IOException {
+               CTFont ctFont=CTFont.Factory.newInstance();
+               CTIntProperty prop=ctFont.addNewCharset();
+               prop.setVal(FontCharset.ANSI.getNativeId());
+
+               ctFont.setCharsetArray(0,prop);
+               XSSFFont xssfFont=new XSSFFont(ctFont);
+               assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());
+
+               xssfFont.setCharSet(FontCharset.DEFAULT);
+               assertEquals(FontCharset.DEFAULT.getNativeId(),ctFont.getCharsetArray(0).getVal());
+
+               // Try with a few less usual ones:
+               // Set with the Charset itself
+               xssfFont.setCharSet(FontCharset.RUSSIAN);
+               assertEquals(FontCharset.RUSSIAN.getNativeId(), xssfFont.getCharSet());
+               // And set with the Charset index
+               xssfFont.setCharSet(FontCharset.ARABIC.getNativeId());
+               assertEquals(FontCharset.ARABIC.getNativeId(), xssfFont.getCharSet());
+               xssfFont.setCharSet((byte)(FontCharset.ARABIC.getNativeId()));
+               assertEquals(FontCharset.ARABIC.getNativeId(), xssfFont.getCharSet());
+
+               // This one isn't allowed
+               assertNull(FontCharset.valueOf(9999));
+               try {
+                       xssfFont.setCharSet(9999);
+                       fail("Shouldn't be able to set an invalid charset");
+               } catch(POIXMLException e) {
+                       // expected here
+               }
+
+               // Now try with a few sample files
+
+               // Normal charset
+               XSSFWorkbook wb1 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
+               assertEquals(0,
+                               wb1.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+               );
+               wb1.close();
+
+               // GB2312 charset
+               XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("49273.xlsx");
+               assertEquals(134,
+                               wb2.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFont().getCharSet()
+               );
+               wb2.close();
+       }
+
        @Test
        public void testFontName() {
                CTFont ctFont=CTFont.Factory.newInstance();