Bug 50847

Summary: XSSFFont.setCharSet(int charset) allows to set only 3 charsets from FontCharset (ANSI, SYMBOL and DEFAULT)
Product: POI Reporter: andrei <andrei.astrouski>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 3.7-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description andrei 2011-03-01 09:50:53 UTC
Try to set FontCharset.MAC value to font via setCharSet(int) method.

Actual: POIXMLException exception
Comment 1 Nick Burch 2011-03-01 11:05:42 UTC
Is that one of the allowed values in .xlsx?
Comment 2 andrei 2011-03-01 11:48:55 UTC
Probably but i'm not sure. For my locale font.getCharSet() returns FontCharset.RUSSIAN.
Comment 3 Nick Burch 2011-03-01 11:55:01 UTC
Any chance you could dig into the Microsoft specs, and check what they say?
Comment 4 andrei 2011-03-02 10:08:47 UTC
I found in the specification (Excel 2007 Binary File Format specification) font character set.
0= Ansi 
1= Default 
2= Symbol 
77= Mac 
128= Japanese 
129= Korean 
130= Johab 
134= GB2312 
136= Chinese Big 5 
161= Greek 
162= Turkish 
163= Vietnamese 
177= Hebrew 
178= Arabic 
186= Baltic 
204= Russian 
222= Thai 
238= East Europe 
255= Oem

Ie the same as FontCharset has.
Comment 5 andrei 2011-03-02 10:18:20 UTC
Patch:

public void setCharSet(int charset) {
        CTIntProperty charsetProperty = _ctFont.sizeOfCharsetArray() == 0 ? _ctFont.addNewCharset() : _ctFont.getCharsetArray(0);
        FontCharset fontCharset = FontCharset.valueOf(charset);
        if (fontCharset != null) {
            charsetProperty.setVal(fontCharset.getValue());
        } else {
            throw new POIXMLException("Attention: an attempt to set a type of unknow charset and charset");
        }
    }
Comment 6 Nick Burch 2011-03-04 09:02:24 UTC
Thanks for the patch. As we already had a setter which took a FontCharset object, I flipped it around a little bit, so we didn't need to do charset -> int -> charset. Fix and unit test committed in 1077950.