poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1875499 - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/sl/draw/ trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/
Date Sat, 21 Mar 2020 18:25:39 GMT
Author: kiwiwings
Date: Sat Mar 21 18:25:38 2020
New Revision: 1875499

URL: http://svn.apache.org/viewvc?rev=1875499&view=rev
Log:
#64241 - XSLF - Wrong scheme colors used when rendering

Modified:
    poi/site/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
    poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java

Modified: poi/site/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1875499&r1=1875498&r2=1875499&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Sat Mar 21 18:25:38 2020
@@ -81,6 +81,7 @@
             <action type="fix" fixes-bug="64186" context="OPC">Decrease usage of ThreadLocals
in XML Signature API</action>
             <action type="fix" fixes-bug="64213" context="SS_Common">Picture.resize(double
scale) scales width wrong for small pictures and when dx1 is set</action>
             <action type="fix" fixes-bug="63712" context="OPC">upgrading xmlsec causes
junit tests to fail</action>
+            <action type="fix" fixes-bug="64241" context="XSLF">XSLF - Wrong scheme
colors used when rendering</action>
         </actions>
     </release>
 

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java?rev=1875499&r1=1875498&r2=1875499&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawSimpleShape.java Sat Mar 21 18:25:38 2020
@@ -139,13 +139,11 @@ public class DrawSimpleShape extends Dra
     }
 
     protected Paint getFillPaint(Graphics2D graphics) {
-        final PaintStyle ps = getShape().getFillStyle().getPaint();
         DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape());
-        return drawPaint.getPaint(graphics, ps);
+        return drawPaint.getPaint(graphics, getShape().getFillStyle().getPaint());
     }
 
     protected Paint getLinePaint(Graphics2D graphics) {
-        final PaintStyle ps = getShape().getFillStyle().getPaint();
         DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(getShape());
         return drawPaint.getPaint(graphics, getShape().getStrokeStyle().getPaint());
     }

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java?rev=1875499&r1=1875498&r2=1875499&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/DrawTextParagraph.java Sat Mar 21 18:25:38 2020
@@ -568,7 +568,7 @@ public class DrawTextParagraph implement
             text = new StringBuilder();
         }
 
-        PlaceableShape<?,?> ps = getParagraphShape();
+        final DrawPaint dp = new DrawPaint(getParagraphShape());
         DrawFontManager dfm = DrawFactory.getInstance(graphics).getFontManager(graphics);
         assert(dfm != null);
 
@@ -587,7 +587,7 @@ public class DrawTextParagraph implement
             int endIndex = text.length();
 
             PaintStyle fgPaintStyle = run.getFontColor();
-            Paint fgPaint = new DrawPaint(ps).getPaint(graphics, fgPaintStyle);
+            Paint fgPaint = dp.getPaint(graphics, fgPaintStyle);
             attList.add(new AttributedStringData(TextAttribute.FOREGROUND, fgPaint, beginIndex,
endIndex));
 
             Double fontSz = run.getFontSize();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java?rev=1875499&r1=1875498&r2=1875499&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java Sat Mar 21 18:25:38
2020
@@ -19,9 +19,8 @@
 package org.apache.poi.xslf.usermodel;
 
 import java.awt.Color;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+
+import javax.xml.namespace.QName;
 
 import org.apache.poi.sl.draw.DrawPaint;
 import org.apache.poi.sl.usermodel.AbstractColorStyle;
@@ -31,6 +30,7 @@ import org.apache.poi.util.Beta;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTFontReference;
@@ -42,7 +42,6 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
-import org.w3c.dom.Node;
 
 /**
  * Encapsulates logic to read color definitions from DrawingML and convert them to java.awt.Color
@@ -50,7 +49,8 @@ import org.w3c.dom.Node;
 @Beta
 @Internal
 public class XSLFColor {
-    private final static POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);
+    private static final POILogger LOGGER = POILogFactory.getLogger(XSLFColor.class);
+    private static final QName VAL_ATTR = new QName("val");
 
     private XmlObject _xmlObject;
     private Color _color;
@@ -133,37 +133,48 @@ public class XSLFColor {
     }
 
     private Color toColor(XmlObject obj, XSLFTheme theme) {
+        if (obj == null) {
+            return _phClr == null ? null : toColor(_phClr, theme);
+        }
+
+        final XmlCursor cur = obj.newCursor();
         Color color = null;
-        List<XmlObject> xo = new ArrayList<>();
-        xo.add(obj);
-        xo.addAll(Arrays.asList(obj.selectPath("*")));
-        boolean isFirst = true;
-        for (XmlObject ch : xo) {
-            if (ch instanceof CTHslColor) {
-                color = toColor((CTHslColor)ch);
-            } else if (ch instanceof CTPresetColor) {
-                color = toColor((CTPresetColor)ch);
-            } else if (ch instanceof CTSchemeColor) {
-                color = toColor((CTSchemeColor)ch, theme);
-            } else if (ch instanceof CTScRgbColor) {
-                color = toColor((CTScRgbColor)ch);
-            } else if (ch instanceof CTSRgbColor) {
-                color = toColor((CTSRgbColor)ch);
-            } else if (ch instanceof CTSystemColor) {
-                color = toColor((CTSystemColor)ch);
-            } else if (!(ch instanceof CTFontReference)) {
-                if (!isFirst) {
+        try {
+            XmlObject ch;
+            for (int idx=0; color == null && (ch = nextObject(obj, cur, idx)) !=
null; idx++) {
+                if (ch instanceof CTHslColor) {
+                    color = toColor((CTHslColor)ch);
+                } else if (ch instanceof CTPresetColor) {
+                    color = toColor((CTPresetColor)ch);
+                } else if (ch instanceof CTSchemeColor) {
+                    color = toColor((CTSchemeColor)ch, theme);
+                } else if (ch instanceof CTScRgbColor) {
+                    color = toColor((CTScRgbColor)ch);
+                } else if (ch instanceof CTSRgbColor) {
+                    color = toColor((CTSRgbColor)ch);
+                } else if (ch instanceof CTSystemColor) {
+                    color = toColor((CTSystemColor)ch);
+                } else if (!(ch instanceof CTFontReference) && idx > 0) {
                     throw new IllegalArgumentException("Unexpected color choice: " + ch.getClass());
                 }
             }
-            if (color != null) {
-                break;
-            }
-            isFirst = false;
+        } finally {
+            cur.dispose();
         }
         return color;
     }
 
+    private static XmlObject nextObject(XmlObject obj, XmlCursor cur, int idx) {
+        switch (idx) {
+            case 0:
+                return obj;
+            case 1:
+                return cur.toFirstChild() ? cur.getObject() : null;
+            default:
+                return cur.toNextSibling() ? cur.getObject() : null;
+        }
+    }
+
     /**
      * Sets the solid color
      *
@@ -234,29 +245,26 @@ public class XSLFColor {
     }
 
     private static int getRawValue(CTSchemeColor phClr, XmlObject xmlObject, String elem)
{
-        String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main'
$this//a:" + elem;
-
-        XmlObject[] obj;
-
-        // first ask the context color and if not found, ask the actual color bean
-        if (phClr != null){
-            obj = phClr.selectPath(query);
-            if (obj.length == 1){
-                Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
-                if(attr != null) {
-                    return Integer.parseInt(attr.getNodeValue());
-                }
+        for (XmlObject obj : new XmlObject[]{xmlObject,phClr}) {
+            if (obj == null) {
+                continue;
             }
-        }
-
-        obj = xmlObject.selectPath(query);
-        if (obj.length == 1){
-            Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
-            if(attr != null) {
-                return Integer.parseInt(attr.getNodeValue());
+            XmlCursor cur = obj.newCursor();
+            try {
+                if (!(
+                        cur.toChild(XSLFRelation.NS_DRAWINGML, elem) ||
+                        (cur.toFirstChild() && cur.toChild(XSLFRelation.NS_DRAWINGML,
elem))
+                    )) {
+                    continue;
+                }
+                String str = cur.getAttributeText(VAL_ATTR);
+                if (str != null && !"".equals(str)) {
+                    return Integer.parseInt(str);
+                }
+            } finally {
+                cur.dispose();
             }
         }
-
         return -1;
     }
 

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java?rev=1875499&r1=1875498&r2=1875499&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java Sat Mar 21 18:25:38
2020
@@ -56,6 +56,7 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
+import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture;
 import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
@@ -565,25 +566,23 @@ public abstract class XSLFShape implemen
             return selectPaint(fp.getGradFill(), phClr, theme);
         } else if (fp.isSetMatrixStyle()) {
             return selectPaint(fp.getMatrixStyle(), theme, fp.isLineStyle(), hasPlaceholder);
+        } else if (phClr != null) {
+            return selectPaint(phClr, theme);
         } else {
             return null;
         }
     }
 
+    protected PaintStyle selectPaint(CTSchemeColor phClr, final XSLFTheme theme) {
+        final XSLFColor c = new XSLFColor(null, theme, phClr, _sheet);
+        return DrawPaint.createSolidPaint(c.getColorStyle());
+    }
+
     @SuppressWarnings("WeakerAccess")
     protected PaintStyle selectPaint(CTSolidColorFillProperties solidFill, CTSchemeColor
phClr, final XSLFTheme theme) {
-        if (solidFill.isSetSchemeClr()) {
-        	// if there's a reference to the placeholder color,
-        	// stop evaluating further and let the caller select
-        	// the next style inheritance level
-//            if (STSchemeColorVal.PH_CLR.equals(solidFill.getSchemeClr().getVal())) {
-//                return null;
-//            }
-            if (phClr == null) {
-                phClr = solidFill.getSchemeClr();
-            }
-        }
-        final XSLFColor c = new XSLFColor(solidFill, theme, phClr, _sheet);
+        CTSchemeColor nestedPhClr = solidFill.getSchemeClr();
+        boolean useNested = nestedPhClr != null && nestedPhClr.getVal() != null &&
!STSchemeColorVal.PH_CLR.equals(nestedPhClr.getVal());
+        final XSLFColor c = new XSLFColor(solidFill, theme, useNested ? nestedPhClr : phClr,
_sheet);
         return DrawPaint.createSolidPaint(c.getColorStyle());
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message