aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2023-01-30 12:19:31 +0000
committerDominik Stadler <centic@apache.org>2023-01-30 12:19:31 +0000
commitedc7f8fd6f63a87aa372334e9942ef5927b6d615 (patch)
tree943f24ee98f05faf72d00355fc1c898e3f21aa4e /poi-ooxml
parentacdf2ec9815fd01d9a9b9db3752fc70dd3914059 (diff)
downloadpoi-edc7f8fd6f63a87aa372334e9942ef5927b6d615.tar.gz
poi-edc7f8fd6f63a87aa372334e9942ef5927b6d615.zip
Bug 54373: Include alpha/transparency value when creating an XSSFColor from an AWT Color object
Use the alpha-value from Color as well git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1907106 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml')
-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
3 files changed, 34 insertions, 4 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);