cntElem++;
if(containsKey(name)) {
- LOG.log(POILogger.WARN, "Duplicate definoition of " + name);
+ LOG.log(POILogger.WARN, "Duplicate definition of " + name);
}
put(name, new CustomGeometry(cus));
}
String name = spPr.getPrstGeom().getPrst().toString();\r
geom = dict.get(name);\r
if(geom == null) {\r
- throw new IllegalStateException("Unknown shape geometry: " + name);\r
+ throw new IllegalStateException("Unknown shape geometry: " + name + ", available geometries are: " + dict.keySet());\r
}\r
} else if (spPr.isSetCustGeom()){\r
XMLStreamReader staxReader = spPr.getCustGeom().newXMLStreamReader();\r
+++ /dev/null
-/*
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-package org.apache.poi.xslf.geom;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Rectangle2D;
-import java.util.Map;
-
-import org.apache.poi.sl.draw.geom.*;
-import org.junit.Test;
-
-/**
- * Date: 10/24/11
- *
- * @author Yegor Kozlov
- */
-public class TestPresetGeometries {
- @Test
- public void testRead(){
-
- Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
- assertEquals(187, shapes.size());
-
-
- for(String name : shapes.keySet()) {
- CustomGeometry geom = shapes.get(name);
- Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {
- public Guide getAdjustValue(String name) {
- return null;
- }
- });
- for(Path p : geom){
- GeneralPath path = p.getPath(ctx);
- assertNotNull(path);
- }
- }
- }
-}
import java.awt.Dimension;\r
import java.awt.Graphics2D;\r
import java.awt.image.BufferedImage;\r
-import java.io.File;\r
import java.util.HashMap;\r
import java.util.Map;\r
\r
-import javax.imageio.ImageIO;\r
-\r
import org.apache.poi.sl.draw.Drawable;\r
import org.apache.poi.util.JvmBugs;\r
import org.apache.poi.xslf.XSLFTestDataSamples;\r
public void render() throws Exception {\r
String[] testFiles = {"backgrounds.pptx","layouts.pptx", "sample.pptx", "shapes.pptx", "themes.pptx",};\r
for(String sampleFile : testFiles){\r
- XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile);\r
- Dimension pg = pptx.getPageSize();\r
- int slideNo=1;\r
- for(XSLFSlide slide : pptx.getSlides()){\r
- BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB);\r
- Graphics2D graphics = img.createGraphics();\r
- fixFonts(graphics);\r
- slide.draw(graphics);\r
- // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png"));\r
- slideNo++;\r
+ try {\r
+ XMLSlideShow pptx = XSLFTestDataSamples.openSampleDocument(sampleFile);\r
+ Dimension pg = pptx.getPageSize();\r
+ //int slideNo=1;\r
+ for(XSLFSlide slide : pptx.getSlides()){\r
+ BufferedImage img = new BufferedImage(pg.width, pg.height, BufferedImage.TYPE_INT_ARGB);\r
+ Graphics2D graphics = img.createGraphics();\r
+ fixFonts(graphics);\r
+ slide.draw(graphics);\r
+ // ImageIO.write(img, "PNG", new File("build/tmp/"+sampleFile.replaceFirst(".pptx?", "-")+slideNo+".png"));\r
+ //slideNo++;\r
+ }\r
+ } catch (IllegalStateException e) {\r
+ throw new IllegalStateException("While reading file " + sampleFile, e);\r
}\r
}\r
}\r
import static org.junit.Assert.*;\r
\r
import java.awt.Color;\r
+import java.io.IOException;\r
import java.util.List;\r
\r
+import org.apache.poi.sl.draw.geom.TestPresetGeometries;\r
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;\r
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;\r
import org.apache.poi.util.Units;\r
import org.apache.poi.xslf.XSLFTestDataSamples;\r
import org.junit.Test;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleList;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STLineCap;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;\r
+import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;\r
\r
/**\r
* @author Yegor Kozlov\r
public class TestXSLFSimpleShape {\r
\r
@Test\r
- public void testLineStyles() {\r
+ public void testLineStyles() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
\r
assertEquals(null, ln3.getLineDash());\r
ln3.setLineCap(null);\r
assertEquals(null, ln3.getLineDash());\r
+ \r
+ ppt.close();\r
}\r
\r
@Test\r
- public void testFill() {\r
+ public void testFill() throws IOException {\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
\r
shape.setFillColor(null);\r
assertNull(shape.getFillColor());\r
assertFalse(shape.getSpPr().isSetSolidFill());\r
+ ppt.close();\r
}\r
\r
@Test\r
\r
@SuppressWarnings({ "deprecation", "unused" })\r
@Test\r
- public void testShadowEffects(){\r
+ public void testShadowEffects() throws IOException{\r
XMLSlideShow ppt = new XMLSlideShow();\r
XSLFSlide slide = ppt.createSlide();\r
CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();\r
for(CTEffectStyleItem ef : lst.getEffectStyleArray()){\r
CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();\r
}\r
+ ppt.close();\r
+ }\r
+ \r
+ @Test\r
+ public void testValidGeometry() throws Exception {\r
+ XMLSlideShow ppt = new XMLSlideShow();\r
+ XSLFSlide slide = ppt.createSlide();\r
+\r
+ XSLFSimpleShape shape = slide.createAutoShape();\r
+ CTShapeProperties spPr = shape.getSpPr();\r
+ \r
+ CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();\r
+ prstGeom.setPrst(STShapeType.Enum.forInt(1));\r
+ \r
+ assertNotNull(prstGeom.getPrst());\r
+ assertNotNull(prstGeom.getPrst().toString());\r
+ assertNotNull(spPr.getPrstGeom());\r
+ spPr.setPrstGeom(prstGeom);\r
+ assertNotNull(spPr.getPrstGeom().getPrst());\r
+ assertNotNull(spPr.getPrstGeom().getPrst().toString());\r
+ \r
+ assertNotNull(shape.getGeometry());\r
+ \r
+ ppt.close();\r
+ }\r
+\r
+ \r
+ @Test\r
+ public void testInvalidGeometry() throws Exception {\r
+ XMLSlideShow ppt = new XMLSlideShow();\r
+ XSLFSlide slide = ppt.createSlide();\r
+\r
+ XSLFSimpleShape shape = slide.createAutoShape();\r
+ CTShapeProperties spPr = shape.getSpPr();\r
+ \r
+ CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();\r
+ prstGeom.setPrst(STShapeType.Enum.forInt(1));\r
+ \r
+ assertNotNull(prstGeom.getPrst());\r
+ assertNotNull(prstGeom.getPrst().toString());\r
+ assertNotNull(spPr.getPrstGeom());\r
+ spPr.setPrstGeom(prstGeom);\r
+ assertNotNull(spPr.getPrstGeom().getPrst());\r
+ assertNotNull(spPr.getPrstGeom().getPrst().toString());\r
+ \r
+ try {\r
+ // cause the geometries to be not found\r
+ TestPresetGeometries.clearPreset();\r
+ try {\r
+ shape.getGeometry();\r
+ fail("Should fail without the geometry");\r
+ } catch (IllegalStateException e) {\r
+ assertTrue(e.getMessage(), e.getMessage().contains("line"));\r
+ }\r
+ } finally {\r
+ // reset to not affect other tests\r
+ TestPresetGeometries.resetPreset();\r
+ }\r
+ \r
+ ppt.close();\r
}\r
}
\ No newline at end of file
--- /dev/null
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ */
+package org.apache.poi.sl.draw.geom;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Rectangle2D;
+import java.util.Map;
+
+import org.junit.Test;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class TestPresetGeometries {
+ @Test
+ public void testRead(){
+
+ Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
+ assertEquals(187, shapes.size());
+
+
+ for(String name : shapes.keySet()) {
+ CustomGeometry geom = shapes.get(name);
+ Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), new IAdjustableShape() {
+ public Guide getAdjustValue(String name) {
+ return null;
+ }
+ });
+ for(Path p : geom){
+ GeneralPath path = p.getPath(ctx);
+ assertNotNull(path);
+ }
+ }
+ }
+
+ // helper methods to adjust list of presets for other tests
+ public static void clearPreset() {
+ // ensure that we are initialized
+ assertNotNull(PresetGeometries.getInstance());
+
+ // test handling if some presets are not found
+ PresetGeometries._inst.clear();
+ }
+
+ public static void resetPreset() {
+ PresetGeometries._inst = null;
+ }
+}