From 39935860edacc67647d8ff73cc25c95e63e9c7a4 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 11 May 2025 11:08:13 +0000 Subject: [PATCH] support colors as byte[] git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1925499 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFTextParagraph.java | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java index 55e52db3d8..7878e63028 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFTextParagraph.java @@ -252,14 +252,30 @@ public class XSSFTextParagraph implements Iterable{ * @return the color of bullet characters within a given paragraph. * A null value means to use the text font color. */ - public Color getBulletFontColor(){ - ParagraphPropertyFetcher fetcher = new ParagraphPropertyFetcher(getLevel()){ + public Color getBulletFontColor() { + byte[] bytes = getBulletFontColorAsBytes(); + if (bytes == null) { + return null; + } else if (bytes.length == 3) { + return new Color(bytes[0] & 0xFF, bytes[1] & 0xFF, bytes[2] & 0xFF); + } else { + return new Color(0xFF & bytes[1], 0xFF & bytes[2], 0xFF & bytes[3], 0xFF & bytes[0]); + } + } + + /** + * + * @return the color of bullet characters within a given paragraph. + * A null value means to use the text font color. + * @since POI 5.4.2 + */ + public byte[] getBulletFontColorAsBytes() { + ParagraphPropertyFetcher fetcher = new ParagraphPropertyFetcher(getLevel()) { public boolean fetch(CTTextParagraphProperties props){ if(props.isSetBuClr()){ if(props.getBuClr().isSetSrgbClr()){ CTSRgbColor clr = props.getBuClr().getSrgbClr(); - byte[] rgb = clr.getVal(); - setValue(new Color(0xFF & rgb[0], 0xFF & rgb[1], 0xFF & rgb[2])); + setValue(clr.getVal()); return true; } } @@ -275,11 +291,21 @@ public class XSSFTextParagraph implements Iterable{ * * @param color the bullet color */ - public void setBulletFontColor(Color color){ + public void setBulletFontColor(Color color) { + setBulletFontColor(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()}); + } + + /** + * Set the color to be used on bullet characters within a given paragraph. + * + * @param colorArray the bullet color (as byte array) + * @since POI 5.4.2 + */ + public void setBulletFontColor(byte[] colorArray) { CTTextParagraphProperties pr = _p.isSetPPr() ? _p.getPPr() : _p.addNewPPr(); CTColor c = pr.isSetBuClr() ? pr.getBuClr() : pr.addNewBuClr(); CTSRgbColor clr = c.isSetSrgbClr() ? c.getSrgbClr() : c.addNewSrgbClr(); - clr.setVal(new byte[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()}); + clr.setVal(colorArray); } /**