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/09/16 19:55:23 UTC

svn commit: r1867025 - in /poi/trunk/src: java/org/apache/poi/sl/usermodel/SlideShowFactory.java ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java

Author: kiwiwings
Date: Mon Sep 16 19:55:23 2019
New Revision: 1867025

URL: http://svn.apache.org/viewvc?rev=1867025&view=rev
Log:
Catch missing scratchpad state for EMF / WMF rendering

Modified:
    poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java?rev=1867025&r1=1867024&r2=1867025&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/SlideShowFactory.java Mon Sep 16 19:55:23 2019
@@ -295,8 +295,13 @@ public class SlideShowFactory {
         S extends Shape<S,P>,
         P extends TextParagraph<S,P,? extends TextRun>
     > SlideShow<S,P> createSlideShow(String factoryClass, Object[] args) throws IOException, EncryptedDocumentException {
+        final Class<?> clazz;
+        try {
+            clazz = SlideShowFactory.class.getClassLoader().loadClass(factoryClass);
+        } catch (ClassNotFoundException e) {
+            throw new IOException(factoryClass+" not found - check if poi-scratchpad.jar is on the classpath.");
+        }
         try {
-            Class<?> clazz = SlideShowFactory.class.getClassLoader().loadClass(factoryClass);
             Class<?>[] argsClz = new Class<?>[args.length];
             int i=0;
             for (Object o : args) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java?rev=1867025&r1=1867024&r2=1867025&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java Mon Sep 16 19:55:23 2019
@@ -50,6 +50,7 @@ import java.util.stream.StreamSupport;
 import javax.imageio.ImageIO;
 
 import org.apache.poi.common.usermodel.GenericRecord;
+import org.apache.poi.sl.draw.BitmapImageRenderer;
 import org.apache.poi.sl.draw.DrawPictureShape;
 import org.apache.poi.sl.draw.Drawable;
 import org.apache.poi.sl.draw.ImageRenderer;
@@ -196,6 +197,7 @@ public class PPTX2PNG {
             }
 
             final Dimension2D pgsize = proxy.getSize();
+
             final double lenSide;
             switch (fixSide) {
                 default:
@@ -268,6 +270,9 @@ public class PPTX2PNG {
                 graphics.dispose();
                 img.flush();
             }
+        } catch (NoScratchpadException e) {
+            usage("'"+file.getName()+"': Format not supported - try to include poi-scratchpad.jar into the CLASSPATH.");
+            return;
         }
 
         if (!quiet) {
@@ -322,7 +327,15 @@ public class PPTX2PNG {
 
         @Override
         public void parse(File file) throws IOException {
-            ppt = SlideShowFactory.create(file, null, true);
+            try {
+                ppt = SlideShowFactory.create(file, null, true);
+            } catch (IOException e) {
+                if (e.getMessage().contains("scratchpad")) {
+                    throw new NoScratchpadException(e);
+                } else {
+                    throw e;
+                }
+            }
             slide = ppt.getSlides().get(0);
         }
 
@@ -403,6 +416,10 @@ public class PPTX2PNG {
         @Override
         public void parse(File file) throws IOException {
             imgr = DrawPictureShape.getImageRenderer(null, getContentType());
+            if (imgr instanceof BitmapImageRenderer) {
+                throw new NoScratchpadException();
+            }
+
             // stream needs to be kept open
             is = file.toURI().toURL().openStream();
             imgr.loadImage(is, getContentType());
@@ -452,4 +469,12 @@ public class PPTX2PNG {
         }
     }
 
+    private static class NoScratchpadException extends IOException {
+        public NoScratchpadException() {
+        }
+
+        public NoScratchpadException(Throwable cause) {
+            super(cause);
+        }
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java?rev=1867025&r1=1867024&r2=1867025&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestPPTX2PNG.java Mon Sep 16 19:55:23 2019
@@ -76,8 +76,8 @@ public class TestPPTX2PNG {
 
     @Test
     public void render() throws Exception {
-        assumeFalse("ignore HSLF / .ppt files in no-scratchpad run", xslfOnly && pptFile.toLowerCase(Locale.ROOT).endsWith("ppt"));
-        
+        assumeFalse("ignore HSLF (.ppt) / HEMF (.emf) / HWMF (.wmf) files in no-scratchpad run", xslfOnly && pptFile.matches(".*\\.(ppt|emf|wmf)$"));
+
         String[] args = {
             "-format", "null", // png,gif,jpg or null for test
             "-slide", "-1", // -1 for all



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