mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
87891450ba
commit
d8f85ad2eb
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.7-SNAPSHOT" date="2010-??-??">
|
<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">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">49242 - Track the LinkDataRecords of charts in HSSFChart</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">Improved performance of XSSFWorkbook.write </action>
|
<action dev="POI-DEVELOPERS" type="add">Improved performance of XSSFWorkbook.write </action>
|
||||||
|
|
|
@ -280,9 +280,29 @@ public final class HSSFFont implements Font {
|
||||||
* @see #DEFAULT_CHARSET
|
* @see #DEFAULT_CHARSET
|
||||||
* @see #SYMBOL_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -251,7 +251,7 @@ public interface Font {
|
||||||
* @see #DEFAULT_CHARSET
|
* @see #DEFAULT_CHARSET
|
||||||
* @see #SYMBOL_CHARSET
|
* @see #SYMBOL_CHARSET
|
||||||
*/
|
*/
|
||||||
byte getCharSet();
|
int getCharSet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set character-set to use.
|
* set character-set to use.
|
||||||
|
@ -260,6 +260,13 @@ public interface Font {
|
||||||
* @see #SYMBOL_CHARSET
|
* @see #SYMBOL_CHARSET
|
||||||
*/
|
*/
|
||||||
void setCharSet(byte 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)
|
* get the index within the XSSFWorkbook (sequence within the collection of Font objects)
|
||||||
|
|
|
@ -107,13 +107,13 @@ public class XSSFFont implements Font {
|
||||||
/**
|
/**
|
||||||
* get character-set to use.
|
* get character-set to use.
|
||||||
*
|
*
|
||||||
* @return byte - character-set
|
* @return int - character-set (0-255)
|
||||||
* @see org.apache.poi.ss.usermodel.FontCharset
|
* @see org.apache.poi.ss.usermodel.FontCharset
|
||||||
*/
|
*/
|
||||||
public byte getCharSet() {
|
public int getCharSet() {
|
||||||
CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
|
CTIntProperty charset = _ctFont.sizeOfCharsetArray() == 0 ? null : _ctFont.getCharsetArray(0);
|
||||||
int val = charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
|
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
|
* @see FontCharset
|
||||||
*/
|
*/
|
||||||
public void setCharSet(byte charset) {
|
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);
|
CTIntProperty charsetProperty = _ctFont.sizeOfCharsetArray() == 0 ? _ctFont.addNewCharset() : _ctFont.getCharsetArray(0);
|
||||||
switch (charset) {
|
switch (charset) {
|
||||||
case Font.ANSI_CHARSET:
|
case Font.ANSI_CHARSET:
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
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.CTBooleanProperty;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
||||||
|
@ -72,6 +73,21 @@ public final class TestXSSFFont extends BaseTestFont{
|
||||||
|
|
||||||
xssfFont.setCharSet(FontCharset.DEFAULT);
|
xssfFont.setCharSet(FontCharset.DEFAULT);
|
||||||
assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
|
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() {
|
public void testFontName() {
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue