View | Details | Raw Unified | Return to bug 60898
Collapse All | Expand All

(-)XSSFColor.java (+38 lines)
Lines 23-28 Link Here
23
import org.apache.poi.ss.usermodel.IndexedColors;
23
import org.apache.poi.ss.usermodel.IndexedColors;
24
import org.apache.poi.util.Internal;
24
import org.apache.poi.util.Internal;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
25
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
26
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColors;
27
import org.w3c.dom.DOMException;
26
28
27
/**
29
/**
28
 * Represents a color in SpreadsheetML
30
 * Represents a color in SpreadsheetML
Lines 29-34 Link Here
29
 */
31
 */
30
public class XSSFColor extends ExtendedColor {
32
public class XSSFColor extends ExtendedColor {
31
    private final CTColor ctColor;
33
    private final CTColor ctColor;
34
    private CTColors indexedColors;
32
35
33
    /**
36
    /**
34
     * Create an instance of XSSFColor from the supplied XML bean
37
     * Create an instance of XSSFColor from the supplied XML bean
Lines 36-41 Link Here
36
    public XSSFColor(CTColor color) {
39
    public XSSFColor(CTColor color) {
37
        this.ctColor = color;
40
        this.ctColor = color;
38
    }
41
    }
42
    
43
    public XSSFColor(CTColors indexedColors, CTColor color){
44
    	this.indexedColors = indexedColors;
45
    	this.ctColor = color;
46
    }
39
47
40
    /**
48
    /**
41
     * Create an new instance of XSSFColor
49
     * Create an new instance of XSSFColor
Lines 179-184 Link Here
179
         return rgb;
187
         return rgb;
180
      }
188
      }
181
   }
189
   }
190
   
191
   @Override
192
   protected byte[] getRGBOrARGB() throws DOMException{
193
	   if(isIndexed() && hasCustomIndexedColors()){
194
		   String hexString = indexedColors.getDomNode().getAttributes().getNamedItem("rgb").getNodeValue();
195
		   return hexStringToByteArray(hexString);
196
	   }
197
	   return super.getRGBOrARGB();
198
   }
199
   
200
   private boolean hasCustomIndexedColors(){
201
      
202
       if (indexedColors == null) {
203
           return false;
204
       }
205
       if (indexedColors.getIndexedColors() == null) {
206
           return false;
207
       }
208
       return true;
209
   }
210
   
211
   private byte[] hexStringToByteArray(String s) {
212
	    byte[] b = new byte[s.length() / 2];
213
	    for (int i = 0; i < b.length; i++) {
214
	      int index = i * 2;
215
	      int v = Integer.parseInt(s.substring(index, index + 2), 16);
216
	      b[i] = (byte) v;
217
	    }
218
	    return b;
219
	  }
182
220
183
   @Override
221
   @Override
184
   protected byte[] getStoredRBG() {
222
   protected byte[] getStoredRBG() {

Return to bug 60898