You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2019/05/10 20:55:24 UTC

svn commit: r1859102 - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/sl/draw/ trunk/src/java/org/apache/poi/sl/draw/geom/ trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/

Author: kiwiwings
Date: Fri May 10 20:55:24 2019
New Revision: 1859102

URL: http://svn.apache.org/viewvc?rev=1859102&view=rev
Log:
#59004 - HSLF rendering - adjust values for presetShapeDefinition differs in HSLF/XSLF

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/geom/Context.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.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=1859102&r1=1859101&r2=1859102&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Fri May 10 20:55:24 2019
@@ -88,6 +88,8 @@
 
     <release version="4.1.1" date="2019-07-??">
       <actions>
+        <action dev="PD" type="fix" fixes-bug="59004" context="HSLF">HSLF rendering - adjust values for presetShapeDefinition differs in HSLF/XSLF</action>
+        <action dev="PD" type="fix" context="HSLF">Don't fallback to master shape properties, if master shape is not assigned</action>
         <action dev="PD" type="add" context="POI_Overall">Add a ThreadLocalUtil.clearAllThreadLocals which can be used to clear thread-locals</action>
         <action dev="PD" type="fix" fixes-bug="63371" context="XSSF">XSSFSheet.addMergedRegion should adjust count of merged cells</action>
         <action dev="PD" type="fix" fixes-bug="63073" context="XSSF">Return value of XSSFSheet.addMergedRegion is off by one</action>

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=1859102&r1=1859101&r2=1859102&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 Fri May 10 20:55:24 2019
@@ -307,98 +307,39 @@ public class DrawSimpleShape extends Dra
       , Paint fill
       , Paint line
     ) {
-          Shadow<?,?> shadow = getShape().getShadow();
-          if (shadow == null || (fill == null && line == null)) {
-              return;
-          }
-
-          SolidPaint shadowPaint = shadow.getFillStyle();
-          Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor());
-
-          double shapeRotation = getShape().getRotation();
-          if(getShape().getFlipVertical()) {
-              shapeRotation += 180;
-          }
-          double angle = shadow.getAngle() - shapeRotation;
-          double dist = shadow.getDistance();
-          double dx = dist * Math.cos(Math.toRadians(angle));
-          double dy = dist * Math.sin(Math.toRadians(angle));
-
-          graphics.translate(dx, dy);
-
-          for(Outline o : outlines){
-              java.awt.Shape s = o.getOutline();
-              Path p = o.getPath();
-              graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
-              graphics.setPaint(shadowColor);
-
-              if(fill != null && p.isFilled()){
-                  fillPaintWorkaround(graphics, s);
-              } else if (line != null && p.isStroked()) {
-                  graphics.draw(s);
-              }
-          }
-
-          graphics.translate(-dx, -dy);
-      }
-
-    protected static CustomGeometry getCustomGeometry(String name) {
-        return getCustomGeometry(name, null);
-    }
-
-    protected static CustomGeometry getCustomGeometry(String name, Graphics2D graphics) {
-        @SuppressWarnings("unchecked")
-        Map<String, CustomGeometry> presets = (graphics == null)
-            ? null
-            : (Map<String, CustomGeometry>)graphics.getRenderingHint(Drawable.PRESET_GEOMETRY_CACHE);
-
-        if (presets == null) {
-            presets = new HashMap<>();
-            if (graphics != null) {
-                graphics.setRenderingHint(Drawable.PRESET_GEOMETRY_CACHE, presets);
-            }
+        Shadow<?,?> shadow = getShape().getShadow();
+        if (shadow == null || (fill == null && line == null)) {
+            return;
+        }
 
-            String packageName = "org.apache.poi.sl.draw.binding";
-            InputStream presetIS = Drawable.class.getResourceAsStream("presetShapeDefinitions.xml");
+        SolidPaint shadowPaint = shadow.getFillStyle();
+        Color shadowColor = DrawPaint.applyColorTransform(shadowPaint.getSolidColor());
 
-            // StAX:
-            EventFilter startElementFilter = new EventFilter() {
-                @Override
-                public boolean accept(XMLEvent event) {
-                    return event.isStartElement();
-                }
-            };
-
-            try {
-                XMLInputFactory staxFactory = StaxHelper.newXMLInputFactory();
-                XMLEventReader staxReader = staxFactory.createXMLEventReader(presetIS);
-                XMLEventReader staxFiltRd = staxFactory.createFilteredReader(staxReader, startElementFilter);
-                // Ignore StartElement:
-                staxFiltRd.nextEvent();
-                // JAXB:
-                JAXBContext jaxbContext = JAXBContext.newInstance(packageName);
-                Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-
-                while (staxFiltRd.peek() != null) {
-                    StartElement evRoot = (StartElement)staxFiltRd.peek();
-                    String cusName = evRoot.getName().getLocalPart();
-                    // XMLEvent ev = staxReader.nextEvent();
-                    JAXBElement<org.apache.poi.sl.draw.binding.CTCustomGeometry2D> el = unmarshaller.unmarshal(staxReader, CTCustomGeometry2D.class);
-                    CTCustomGeometry2D cusGeom = el.getValue();
-
-                    presets.put(cusName, new CustomGeometry(cusGeom));
-                }
-
-                staxFiltRd.close();
-                staxReader.close();
-            } catch (Exception e) {
-                throw new RuntimeException("Unable to load preset geometries.", e);
-            } finally {
-                IOUtils.closeQuietly(presetIS);
+        double shapeRotation = getShape().getRotation();
+        if (getShape().getFlipVertical()) {
+            shapeRotation += 180;
+        }
+        double angle = shadow.getAngle() - shapeRotation;
+        double dist = shadow.getDistance();
+        double dx = dist * Math.cos(Math.toRadians(angle));
+        double dy = dist * Math.sin(Math.toRadians(angle));
+
+        graphics.translate(dx, dy);
+
+        for (Outline o : outlines) {
+            java.awt.Shape s = o.getOutline();
+            Path p = o.getPath();
+            graphics.setRenderingHint(Drawable.GRADIENT_SHAPE, s);
+            graphics.setPaint(shadowColor);
+
+            if (fill != null && p.isFilled()) {
+                fillPaintWorkaround(graphics, s);
+            } else if (line != null && p.isStroked()) {
+                graphics.draw(s);
             }
         }
 
-        return presets.get(name);
+        graphics.translate(-dx, -dy);
     }
 
     protected Collection<Outline> computeOutlines(Graphics2D graphics) {

Modified: poi/trunk/src/java/org/apache/poi/sl/draw/geom/Context.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/draw/geom/Context.java?rev=1859102&r1=1859101&r2=1859102&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/draw/geom/Context.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/draw/geom/Context.java Fri May 10 20:55:24 2019
@@ -51,8 +51,7 @@ public class Context {
     }
 
     Guide getAdjustValue(String name){
-        // ignore HSLF props for now ... the results with default value are usually better - see #59004
-        return (_props.getClass().getName().contains("hslf")) ? null : _props.getAdjustValue(name);
+        return _props.getAdjustValue(name);
     }
 
     public double getValue(String key){

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java?rev=1859102&r1=1859101&r2=1859102&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java Fri May 10 20:55:24 2019
@@ -321,8 +321,10 @@ public abstract class HSLFSimpleShape ex
             name = "1";
         }
 
+        final int adjInt = Integer.parseInt(name);
+
         short escherProp;
-        switch (Integer.parseInt(name)) {
+        switch (adjInt) {
             case 1: escherProp = EscherProperties.GEOMETRY__ADJUSTVALUE; break;
             case 2: escherProp = EscherProperties.GEOMETRY__ADJUST2VALUE; break;
             case 3: escherProp = EscherProperties.GEOMETRY__ADJUST3VALUE; break;
@@ -336,14 +338,36 @@ public abstract class HSLFSimpleShape ex
             default: throw new HSLFException();
         }
 
-        // TODO: the adjust values need to be corrected somehow depending on the shape width/height
-        // see https://social.msdn.microsoft.com/Forums/en-US/3f69ebb3-62a0-4fdd-b367-64790dfb2491/presetshapedefinitionsxml-does-not-specify-width-and-height-form-some-autoshapes?forum=os_binaryfile
-        
-        // the adjust value can be format dependent, e.g. hexagon has different values,
-        // other shape types have the same adjust values in OOXML and native
         int adjval = getEscherProperty(escherProp, -1);
 
-        return (adjval == -1) ? null : new Guide(name, "val "+adjval);
+        if (adjval == -1) {
+            return null;
+        }
+
+        // Bug 59004
+        // the adjust value are format dependent, we scale them up so they match the OOXML ones.
+        // see https://social.msdn.microsoft.com/Forums/en-US/33e458e6-58df-48fe-9a10-e303ab08991d/preset-shapes-for-ppt?forum=os_binaryfile
+
+        // usually we deal with length units and only very few degree units:
+        boolean isDegreeUnit = false;
+        switch (getShapeType()) {
+            case ARC:
+            case BLOCK_ARC:
+            case CHORD:
+            case PIE:
+                isDegreeUnit = (adjInt == 1 || adjInt == 2);
+                break;
+            case CIRCULAR_ARROW:
+            case LEFT_CIRCULAR_ARROW:
+            case LEFT_RIGHT_CIRCULAR_ARROW:
+                isDegreeUnit = (adjInt == 2 || adjInt == 3 || adjInt == 4);
+                break;
+            case MATH_NOT_EQUAL:
+                isDegreeUnit = (adjInt == 2);
+                break;
+        }
+
+        return new Guide(name, "val "+Math.rint(adjval * (isDegreeUnit ? 65536. : 100000./21000.)));
     }
 
     @Override



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