gffloodg commented on code in PR #409:
URL: https://github.com/apache/poi/pull/409#discussion_r1058339320
##########
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java:
##########
@@ -158,6 +162,78 @@ private static void
fetchFontColor(CTTextCharacterProperties props, Consumer<Pai
}
+ /**
+ * Returns the font highlight (background) color for this text run.
+ * This returns a {@link SolidPaint}, or null if no highlight is set.
+ *
+ * @return The font highlight (background) colour associated with the run,
null if no highlight.
+ *
+ * @see org.apache.poi.sl.draw.DrawPaint#getPaint(java.awt.Graphics2D,
PaintStyle)
+ * @see SolidPaint#getSolidColor()
+ * @since POI 5.2.4
+ */
+ @Override
+ public PaintStyle getHighlightColor() {
+ XSLFShape shape = getParagraph().getParentShape();
+ final boolean hasPlaceholder = shape.getPlaceholder() != null;
+ return fetchCharacterProperty((props, val) ->
fetchHighlightColor(props, val, shape, hasPlaceholder));
+ }
+
+
+ private static void fetchHighlightColor(CTTextCharacterProperties props,
Consumer<PaintStyle> val, XSLFShape shape, boolean hasPlaceholder) {
+ if (props == null) {
+ return;
+ }
+
+ final CTColor col = props.getHighlight();
+ if (col == null) {
+ return;
+ }
+
+ final CTSRgbColor rgbCol = col.getSrgbClr();
+ final byte[] cols = rgbCol.getVal();
+ final SolidPaint paint = DrawPaint.createSolidPaint(new Color(0xFF &
cols[0], 0xFF & cols[1], 0xFF & cols[2]));
+ val.accept(paint);
+ }
+
+ /**
+ * Sets the font highlight (background) color for this text run -
convenience function
+ *
+ * @param color The highlight (background) color to set.
+ * @since POI 5.2.4
+ */
+ @Override
+ public void setHighlightColor(final Color color) {
+ setHighlightColor(DrawPaint.createSolidPaint(color));
+ }
+
+ /**
+ * Set the highlight (background) color for this text run.
+ *
+ * @param color The highlight (background) color to set.
+ *
+ * @see org.apache.poi.sl.draw.DrawPaint#createSolidPaint(Color)
+ * @since POI 5.2.4
+ */
+ @Override
+ public void setHighlightColor(final PaintStyle color) {
+ if (!(color instanceof SolidPaint)) {
+ LOG.atWarn().log("Currently only SolidPaint is supported!");
+ return;
Review Comment:
Updated and added tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]