aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java6
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java4
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java28
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/ExtendedColor.java2
4 files changed, 35 insertions, 5 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
index 955d4f0901..c525167e90 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextRun.java
@@ -81,7 +81,11 @@ public class XSSFTextRun {
if(fill.isSetSrgbClr()){
CTSRgbColor clr = fill.getSrgbClr();
byte[] rgb = clr.getVal();
- return new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2]);
+ if (rgb.length == 3) {
+ return new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2]);
+ } else {
+ return new Color(0xFF & rgb[1], 0xFF & rgb[2], 0xFF & rgb[3], 0xFF & rgb[0]);
+ }
}
}
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
index d689226fc4..ec00e27441 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
@@ -255,7 +255,7 @@ class TestXSSFDrawing {
assertTrue(rPr.getI());
assertEquals(STTextUnderlineType.SNG, rPr.getU());
assertArrayEquals(
- new byte[]{0, (byte)128, (byte)128} ,
+ new byte[]{-1, 0, (byte)128, (byte)128} ,
rPr.getSolidFill().getSrgbClr().getVal());
checkRewrite(wb);
@@ -325,7 +325,7 @@ class TestXSSFDrawing {
CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
assertEquals("Arial", rPr.getLatin().getTypeface());
assertArrayEquals(
- new byte[]{0, (byte)128, (byte)128} ,
+ new byte[]{-1, 0, (byte)128, (byte)128} ,
rPr.getSolidFill().getSrgbClr().getVal());
checkRewrite(wb);
wb.close();
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java
index 35bcd75f00..6c62954cc7 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFFont.java
@@ -20,8 +20,8 @@ package org.apache.poi.xssf.usermodel;
import static org.apache.poi.ss.usermodel.FontCharset.*;
import static org.junit.jupiter.api.Assertions.*;
+import java.awt.Color;
import java.io.IOException;
-import java.util.Arrays;
import java.util.stream.Stream;
import org.apache.poi.common.usermodel.fonts.FontCharset;
@@ -536,6 +536,32 @@ public final class TestXSSFFont extends BaseTestFont {
}
}
+ @Test
+ public void testBug62272b() throws IOException {
+ try (XSSFWorkbook wb = new XSSFWorkbook()) {
+ Sheet sheet = wb.createSheet("test");
+ Row row = sheet.createRow(0);
+ Cell cell = row.createCell(0);
+
+ // create a font with alpha
+ XSSFFont font = wb.createFont();
+ font.setColor(new XSSFColor(new Color(0x33, 0xCC, 0x66, 0x7f), null));
+
+ XSSFCellStyle style = wb.createCellStyle();
+ style.setFont(font);
+
+ cell.setCellStyle(style);
+ cell.setCellValue("testtext");
+
+ // make sure the alpha-value was stored properly
+ checkFontColor(wb);
+
+ /*try (OutputStream out = new FileOutputStream("/tmp/testout.xlsx")) {
+ wb.write(out);
+ }*/
+ }
+ }
+
private static void checkFontColor(Workbook wb) {
int fontIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFontIndex();
Font font = wb.getFontAt(fontIdx);
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/ExtendedColor.java b/poi/src/main/java/org/apache/poi/ss/usermodel/ExtendedColor.java
index c481fff7fb..ed932b13f3 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/ExtendedColor.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/ExtendedColor.java
@@ -30,7 +30,7 @@ public abstract class ExtendedColor implements Color {
* @param clr awt Color to set
*/
protected void setColor(java.awt.Color clr) {
- setRGB(new byte[]{(byte)clr.getRed(), (byte)clr.getGreen(), (byte)clr.getBlue()});
+ setRGB(new byte[]{(byte)clr.getAlpha(), (byte)clr.getRed(), (byte)clr.getGreen(), (byte)clr.getBlue()});
}
/**