mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
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
This commit is contained in:
parent
acdf2ec981
commit
edc7f8fd6f
@ -81,7 +81,11 @@ public class XSSFTextRun {
|
|||||||
if(fill.isSetSrgbClr()){
|
if(fill.isSetSrgbClr()){
|
||||||
CTSRgbColor clr = fill.getSrgbClr();
|
CTSRgbColor clr = fill.getSrgbClr();
|
||||||
byte[] rgb = clr.getVal();
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -255,7 +255,7 @@ class TestXSSFDrawing {
|
|||||||
assertTrue(rPr.getI());
|
assertTrue(rPr.getI());
|
||||||
assertEquals(STTextUnderlineType.SNG, rPr.getU());
|
assertEquals(STTextUnderlineType.SNG, rPr.getU());
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
new byte[]{0, (byte)128, (byte)128} ,
|
new byte[]{-1, 0, (byte)128, (byte)128} ,
|
||||||
rPr.getSolidFill().getSrgbClr().getVal());
|
rPr.getSolidFill().getSrgbClr().getVal());
|
||||||
|
|
||||||
checkRewrite(wb);
|
checkRewrite(wb);
|
||||||
@ -325,7 +325,7 @@ class TestXSSFDrawing {
|
|||||||
CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
|
CTTextCharacterProperties rPr = pr.getRArray(0).getRPr();
|
||||||
assertEquals("Arial", rPr.getLatin().getTypeface());
|
assertEquals("Arial", rPr.getLatin().getTypeface());
|
||||||
assertArrayEquals(
|
assertArrayEquals(
|
||||||
new byte[]{0, (byte)128, (byte)128} ,
|
new byte[]{-1, 0, (byte)128, (byte)128} ,
|
||||||
rPr.getSolidFill().getSrgbClr().getVal());
|
rPr.getSolidFill().getSrgbClr().getVal());
|
||||||
checkRewrite(wb);
|
checkRewrite(wb);
|
||||||
wb.close();
|
wb.close();
|
||||||
|
|||||||
@ -20,8 +20,8 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
import static org.apache.poi.ss.usermodel.FontCharset.*;
|
import static org.apache.poi.ss.usermodel.FontCharset.*;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.poi.common.usermodel.fonts.FontCharset;
|
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) {
|
private static void checkFontColor(Workbook wb) {
|
||||||
int fontIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFontIndex();
|
int fontIdx = wb.getSheetAt(0).getRow(0).getCell(0).getCellStyle().getFontIndex();
|
||||||
Font font = wb.getFontAt(fontIdx);
|
Font font = wb.getFontAt(fontIdx);
|
||||||
|
|||||||
@ -30,7 +30,7 @@ public abstract class ExtendedColor implements Color {
|
|||||||
* @param clr awt Color to set
|
* @param clr awt Color to set
|
||||||
*/
|
*/
|
||||||
protected void setColor(java.awt.Color clr) {
|
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()});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user