This is an automated email from the ASF dual-hosted git repository.

jaragunde pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0f4b50b7fd Support theme colors as highlight color in pptx. (#1174)
0f4b50b7fd is described below

commit 0f4b50b7fd358ae8115b1684ec8acbb1bc5ced2e
Author: Jacobo Aragunde PĂ©rez <[email protected]>
AuthorDate: Thu Jul 2 17:43:07 2026 +0200

    Support theme colors as highlight color in pptx. (#1174)
    
    Although the PowerPoint UI doesn't allow it, it's possible to use a
    theme color for text highlight. Some external software seems to do it,
    and PowerPoint displays the highlight correctly.
    
    In POI we expected the highlight color to always be srgbClr, or return
    null. In POI 5.5.x it was even a crash, the null check was added later.
    
    We change fetchHighlightColor to use XSLFColor to determine the color
    instead of reading the RGB directly. That class supports the different
    XML tags that implement colors in OOXML.
---
 .../java/org/apache/poi/xslf/usermodel/XSLFTextRun.java |  11 ++++++-----
 .../org/apache/poi/xslf/usermodel/TestXSLFTextRun.java  |  16 ++++++++++++++++
 test-data/slideshow/text-highlight.pptx                 | Bin 0 -> 31851 bytes
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java 
b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
index 8da9c28050..e8cbda95c0 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java
@@ -190,14 +190,15 @@ public class XSLFTextRun implements TextRun, 
HighlightColorSupport {
             return;
         }
 
-        final CTSRgbColor rgbCol = col.getSrgbClr();
-        if (rgbCol == null) {
+        XSLFSheet sheet = shape.getSheet();
+        XSLFTheme theme = sheet.getTheme();
+        XSLFColor xslfCol = new XSLFColor(col, theme, null, sheet);
+        Color javaCol = xslfCol.getColor();
+        if (javaCol == null) {
             return;
         }
 
-        final byte[] cols = rgbCol.getVal();
-        final SolidPaint paint = DrawPaint.createSolidPaint(new Color(0xFF & 
cols[0], 0xFF & cols[1], 0xFF & cols[2]));
-        highlightColor.accept(paint);
+        highlightColor.accept(DrawPaint.createSolidPaint(javaCol));
     }
 
     /**
diff --git 
a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java 
b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java
index 50c84734db..b81e17b5ee 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestXSLFTextRun.java
@@ -31,6 +31,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 import java.awt.Color;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.List;
 
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.sl.draw.DrawPaint;
@@ -200,4 +201,19 @@ class TestXSLFTextRun {
         }
     }
 
+    @Test
+    void testHighlightColorFromTextBoxes() throws IOException {
+        try (InputStream is = 
POIDataSamples.getSlideShowInstance().openResourceAsStream("text-highlight.pptx");
+             XMLSlideShow ppt = new XMLSlideShow(is)) {
+            List<XSLFShape> shapes = ppt.getSlides().get(0).getShapes();
+
+            XSLFTextShape presetColorBox = (XSLFTextShape) shapes.get(0);
+            XSLFTextRun presetColorRun = 
presetColorBox.getTextParagraphs().get(0).getTextRuns().get(0);
+            assertEquals(new Color(0xFF, 0x00, 0x00), 
getColor(presetColorRun.getHighlightColor()));
+
+            XSLFTextShape themeColorBox = (XSLFTextShape) shapes.get(1);
+            XSLFTextRun themeColorRun = 
themeColorBox.getTextParagraphs().get(0).getTextRuns().get(0);
+            assertEquals(new Color(0x0F, 0x9E, 0xD5), 
getColor(themeColorRun.getHighlightColor()));
+        }
+    }
 }
diff --git a/test-data/slideshow/text-highlight.pptx 
b/test-data/slideshow/text-highlight.pptx
new file mode 100644
index 0000000000..086fa43420
Binary files /dev/null and b/test-data/slideshow/text-highlight.pptx differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to