diff options
author | Nick Burch <nick@apache.org> | 2010-05-25 16:25:34 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-05-25 16:25:34 +0000 |
commit | d8f85ad2ebe0e7085bf8e89fcee16045b6e26f98 (patch) | |
tree | 5316eaa73d56258316142601323d30b38188ad05 /src/ooxml | |
parent | 87891450ba80a8c737257d3c0e73dd2fc970593e (diff) | |
download | poi-d8f85ad2ebe0e7085bf8e89fcee16045b6e26f98.tar.gz poi-d8f85ad2ebe0e7085bf8e89fcee16045b6e26f98.zip |
Fix bug #49273 - Correct handling for Font Character Sets with indicies greater than 127
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@948089 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java | 19 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java | 16 |
2 files changed, 32 insertions, 3 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java index 7fbbee7951..3b92c6fd35 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java @@ -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: diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java index 1bcc98149e..fe8d3a588b 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFont.java @@ -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 BaseTestFont{ 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() { |