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 2021/10/13 20:39:02 UTC

svn commit: r1894206 - in /poi/trunk: poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java

Author: kiwiwings
Date: Wed Oct 13 20:39:01 2021
New Revision: 1894206

URL: http://svn.apache.org/viewvc?rev=1894206&view=rev
Log:
#64716 - wmf display error
update heuristic to respect location of bounding box

Modified:
    poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
    poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java

Modified: poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?rev=1894206&r1=1894205&r2=1894206&view=diff
==============================================================================
--- poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java (original)
+++ poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java Wed Oct 13 20:39:01 2021
@@ -30,6 +30,7 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
+import java.util.regex.Pattern;
 import java.util.stream.Stream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
@@ -56,6 +57,9 @@ class TestPPTX2PNG {
     private static boolean xslfOnly;
     private static final POIDataSamples samples = POIDataSamples.getSlideShowInstance();
 
+    private static final Pattern XSLF_EXT = Pattern.compile("(?i).*\\.pptx$");
+    private static final Pattern ALL_EXT = Pattern.compile("(?i).*\\.(ppt.?|emf|wmf)$");
+
     private static final File basedir = null;
 
     private static final String files =
@@ -91,27 +95,32 @@ class TestPPTX2PNG {
     public static Stream<Arguments> data() throws IOException {
         // Junit closes all closable arguments after the usage
         // therefore we need to wrap the archive in non-closable arrays
-
+        Stream<Arguments> result;
         if (basedir != null && basedir.getName().endsWith(".zip")) {
             ZipFile zipFile = new ZipFile(basedir);
             archive = zipFile;
-            return zipFile.stream().map(f -> Arguments.of(f.getName(), f, new ZipFile[]{zipFile}));
+            result = zipFile.stream().
+                map(f -> Arguments.of(new File(f.getName()).getName(), f, new ZipFile[]{zipFile}));
         } else if (basedir != null && basedir.getName().endsWith(".7z")) {
             SevenZFile sevenZFile = new SevenZFile(basedir);
             archive = sevenZFile;
-            return ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().filter(f -> !f.isDirectory()).map(f -> Arguments.of(f.getName(), f, new SevenZFile[]{sevenZFile}));
+            result = ((ArrayList<SevenZArchiveEntry>)sevenZFile.getEntries()).stream().
+                filter(f -> !f.isDirectory()).
+                map(f -> Arguments.of(f.getName(), f, new SevenZFile[]{sevenZFile}));
         } else {
-            return Stream.of(files.split(", ?")).
+            result = Stream.of(files.split(", ?")).
                 map(basedir == null ? samples::getFile : f -> new File(basedir, f)).
                 map(f -> Arguments.of(f.getName(), f, f.getParentFile()));
         }
+
+        return result.filter(args -> (xslfOnly ? XSLF_EXT : ALL_EXT).matcher((String)args.get()[0]).find());
+
     }
 
     // use filename instead of File object to omit full pathname in test name
     @ParameterizedTest(name = "{0} ({index})")
     @MethodSource("data")
     void render(String fileName, Object fileObj, Object fileContainer) throws Exception {
-        assumeFalse(xslfOnly && fileName.matches(".*\\.(ppt|emf|wmf)$"), "ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run");
         PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "null"));
         if (svgFiles.contains(fileName)) {
             PPTX2PNG.main(getArgs(fileName, fileObj, fileContainer, "svg"));

Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java?rev=1894206&r1=1894205&r2=1894206&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java Wed Oct 13 20:39:01 2021
@@ -27,6 +27,7 @@ import java.awt.Graphics2D;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Dimension2D;
+import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.io.InputStream;
 import java.nio.charset.Charset;
@@ -36,6 +37,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Spliterator;
 import java.util.function.Consumer;
+import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
@@ -230,9 +232,8 @@ public class HemfPicture implements Iter
                         ? winBounds
                         : emfBounds;
             } else {
-                double recHyp = dia(recBounds);
                 b = Stream.of(emfBounds, winBounds, viewBounds).
-                    min(comparingDouble(r -> abs(dia(r) - recHyp))).get();
+                    min(comparingDouble(r -> diff(r, recBounds))).get();
             }
 
             ctx.translate(graphicsBounds.getCenterX(), graphicsBounds.getCenterY());
@@ -258,8 +259,14 @@ public class HemfPicture implements Iter
         }
     }
 
-    private static double dia(Rectangle2D bounds) {
-        return Math.sqrt(bounds.getWidth()*bounds.getWidth() + bounds.getHeight()*bounds.getWidth());
+    private static double diff(Rectangle2D bounds, Rectangle2D target) {
+        double d = 0;
+        for (int i=0; i<4; i++) {
+            Function<Rectangle2D,Double> fx = (i < 2) ? Rectangle2D::getMinX : Rectangle2D::getMaxX;
+            Function<Rectangle2D,Double> fy = (i % 2 == 0) ? Rectangle2D::getMinY : Rectangle2D::getMaxY;
+            d += Point2D.distanceSq(fx.apply(bounds), fy.apply(bounds), fx.apply(target), fy.apply(target));
+        }
+        return d;
     }
 
     public Iterable<HwmfEmbedded> getEmbeddings() {



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