ASF Bugzilla – Attachment 34865 Details for
Bug 60898
XSSFColor's getARGB() method returns a wrong color value when a workbook has a custom indexed color
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
solution 2 (partial)
XSSFColor1.java.patch (text/plain), 1.95 KB, created by
samson
on 2017-03-21 18:23:51 UTC
(
hide
)
Description:
solution 2 (partial)
Filename:
MIME Type:
Creator:
samson
Created:
2017-03-21 18:23:51 UTC
Size:
1.95 KB
patch
obsolete
>Index: XSSFColor.java >=================================================================== >--- XSSFColor.java (revision 293556) >+++ XSSFColor.java (working copy) >@@ -23,6 +23,8 @@ > import org.apache.poi.ss.usermodel.IndexedColors; > import org.apache.poi.util.Internal; > import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; >+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColors; >+import org.w3c.dom.DOMException; > > /** > * Represents a color in SpreadsheetML >@@ -29,6 +31,7 @@ > */ > public class XSSFColor extends ExtendedColor { > private final CTColor ctColor; >+ private CTColors indexedColors; > > /** > * Create an instance of XSSFColor from the supplied XML bean >@@ -36,6 +39,11 @@ > public XSSFColor(CTColor color) { > this.ctColor = color; > } >+ >+ public XSSFColor(CTColors indexedColors, CTColor color){ >+ this.indexedColors = indexedColors; >+ this.ctColor = color; >+ } > > /** > * Create an new instance of XSSFColor >@@ -179,6 +187,36 @@ > return rgb; > } > } >+ >+ @Override >+ protected byte[] getRGBOrARGB() throws DOMException{ >+ if(isIndexed() && hasCustomIndexedColors()){ >+ String hexString = indexedColors.getDomNode().getAttributes().getNamedItem("rgb").getNodeValue(); >+ return hexStringToByteArray(hexString); >+ } >+ return super.getRGBOrARGB(); >+ } >+ >+ private boolean hasCustomIndexedColors(){ >+ >+ if (indexedColors == null) { >+ return false; >+ } >+ if (indexedColors.getIndexedColors() == null) { >+ return false; >+ } >+ return true; >+ } >+ >+ private byte[] hexStringToByteArray(String s) { >+ byte[] b = new byte[s.length() / 2]; >+ for (int i = 0; i < b.length; i++) { >+ int index = i * 2; >+ int v = Integer.parseInt(s.substring(index, index + 2), 16); >+ b[i] = (byte) v; >+ } >+ return b; >+ } > > @Override > protected byte[] getStoredRBG() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 60898
:
34861
|
34862
|
34863
|
34864
| 34865