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 2020/05/05 13:36:30 UTC
svn commit: r1877398 [3/3] - in /poi: site/src/documentation/content/xdocs/
trunk/ trunk/compile-lib/ trunk/lib/ trunk/lib/main/ trunk/lib/ooxml/
trunk/ooxml-lib/ trunk/src/java/org/apache/poi/sl/draw/
trunk/src/java/org/apache/poi/sl/draw/binding/ tru...
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java?rev=1877398&r1=1877397&r2=1877398&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFSimpleShape.java Tue May 5 13:36:30 2020
@@ -21,24 +21,19 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
+import java.io.File;
import java.io.IOException;
import java.util.List;
-import org.apache.poi.sl.draw.DrawFactory;
-import org.apache.poi.sl.draw.geom.TestPresetGeometries;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.sl.usermodel.Placeholder;
-import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.apache.poi.xslf.util.PPTX2PNG;
import org.apache.xmlbeans.XmlObject;
import org.junit.Test;
import org.openxmlformats.schemas.drawingml.x2006.main.CTEffectStyleItem;
@@ -53,330 +48,277 @@ import org.openxmlformats.schemas.drawin
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
public class TestXSLFSimpleShape {
-
+
@Test
public void testLineStyles() throws IOException {
- XMLSlideShow ppt = new XMLSlideShow();
- XSLFSlide slide = ppt.createSlide();
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFSlide slide = ppt.createSlide();
- XSLFSimpleShape shape = slide.createAutoShape();
- assertEquals(1, slide.getShapes().size());
- // line properties are not set by default
- assertFalse(getSpPr(shape).isSetLn());
-
- assertEquals(0., shape.getLineWidth(), 0);
- assertNull(shape.getLineColor());
- assertNull(shape.getLineDash());
- assertNull(shape.getLineCap());
-
- shape.setLineWidth(0);
- shape.setLineColor(null);
- shape.setLineDash(null);
- shape.setLineCap(null);
-
- assertTrue(getSpPr(shape).isSetLn());
- assertTrue(getSpPr(shape).getLn().isSetNoFill());
-
- // line width
- shape.setLineWidth(1.0);
- assertEquals(1.0, shape.getLineWidth(), 0);
- assertEquals(Units.EMU_PER_POINT, getSpPr(shape).getLn().getW());
- shape.setLineWidth(5.5);
- assertEquals(5.5, shape.getLineWidth(), 0);
- assertEquals(Units.toEMU(5.5), getSpPr(shape).getLn().getW());
- shape.setLineWidth(0.0);
- // setting line width to zero unsets the W attribute
- assertFalse(getSpPr(shape).getLn().isSetW());
-
- // line cap
- shape.setLineCap(LineCap.FLAT);
- assertEquals(LineCap.FLAT, shape.getLineCap());
- assertEquals(STLineCap.FLAT, getSpPr(shape).getLn().getCap());
- shape.setLineCap(LineCap.SQUARE);
- assertEquals(LineCap.SQUARE, shape.getLineCap());
- assertEquals(STLineCap.SQ, getSpPr(shape).getLn().getCap());
- shape.setLineCap(LineCap.ROUND);
- assertEquals(LineCap.ROUND, shape.getLineCap());
- assertEquals(STLineCap.RND, getSpPr(shape).getLn().getCap());
- shape.setLineCap(null);
- // setting cap to null unsets the Cap attribute
- assertFalse(getSpPr(shape).getLn().isSetCap());
-
- // line dash
- shape.setLineDash(LineDash.SOLID);
- assertEquals(LineDash.SOLID, shape.getLineDash());
- assertEquals(STPresetLineDashVal.SOLID, getSpPr(shape).getLn().getPrstDash().getVal());
- shape.setLineDash(LineDash.DASH_DOT);
- assertEquals(LineDash.DASH_DOT, shape.getLineDash());
- assertEquals(STPresetLineDashVal.DASH_DOT, getSpPr(shape).getLn().getPrstDash().getVal());
- shape.setLineDash(LineDash.LG_DASH_DOT);
- assertEquals(LineDash.LG_DASH_DOT, shape.getLineDash());
- assertEquals(STPresetLineDashVal.LG_DASH_DOT, getSpPr(shape).getLn().getPrstDash().getVal());
- shape.setLineDash(null);
- // setting dash width to null unsets the Dash element
- assertFalse(getSpPr(shape).getLn().isSetPrstDash());
-
- // line color
- assertFalse(getSpPr(shape).getLn().isSetSolidFill());
- shape.setLineColor(Color.RED);
- assertEquals(Color.RED, shape.getLineColor());
- assertTrue(getSpPr(shape).getLn().isSetSolidFill());
- shape.setLineColor(Color.BLUE);
- assertEquals(Color.BLUE, shape.getLineColor());
- assertTrue(getSpPr(shape).getLn().isSetSolidFill());
- shape.setLineColor(null);
- assertNull(shape.getLineColor());
- // setting dash width to null unsets the SolidFill element
- assertFalse(getSpPr(shape).getLn().isSetSolidFill());
-
- XSLFSimpleShape ln2 = slide.createAutoShape();
- ln2.setLineDash(LineDash.DOT);
- assertEquals(LineDash.DOT, ln2.getLineDash());
- ln2.setLineWidth(0.);
- assertEquals(0., ln2.getLineWidth(), 0);
-
- XSLFSimpleShape ln3 = slide.createAutoShape();
- ln3.setLineWidth(1.);
- assertEquals(1., ln3.getLineWidth(), 0);
- ln3.setLineDash(null);
- assertNull(ln3.getLineDash());
- ln3.setLineCap(null);
- assertNull(ln3.getLineDash());
-
- ppt.close();
+ XSLFSimpleShape shape = slide.createAutoShape();
+ assertEquals(1, slide.getShapes().size());
+ // line properties are not set by default
+ assertFalse(getSpPr(shape).isSetLn());
+
+ assertEquals(0., shape.getLineWidth(), 0);
+ assertNull(shape.getLineColor());
+ assertNull(shape.getLineDash());
+ assertNull(shape.getLineCap());
+
+ shape.setLineWidth(0);
+ shape.setLineColor(null);
+ shape.setLineDash(null);
+ shape.setLineCap(null);
+
+ assertTrue(getSpPr(shape).isSetLn());
+ assertTrue(getSpPr(shape).getLn().isSetNoFill());
+
+ // line width
+ shape.setLineWidth(1.0);
+ assertEquals(1.0, shape.getLineWidth(), 0);
+ assertEquals(Units.EMU_PER_POINT, getSpPr(shape).getLn().getW());
+ shape.setLineWidth(5.5);
+ assertEquals(5.5, shape.getLineWidth(), 0);
+ assertEquals(Units.toEMU(5.5), getSpPr(shape).getLn().getW());
+ shape.setLineWidth(0.0);
+ // setting line width to zero unsets the W attribute
+ assertFalse(getSpPr(shape).getLn().isSetW());
+
+ // line cap
+ shape.setLineCap(LineCap.FLAT);
+ assertEquals(LineCap.FLAT, shape.getLineCap());
+ assertEquals(STLineCap.FLAT, getSpPr(shape).getLn().getCap());
+ shape.setLineCap(LineCap.SQUARE);
+ assertEquals(LineCap.SQUARE, shape.getLineCap());
+ assertEquals(STLineCap.SQ, getSpPr(shape).getLn().getCap());
+ shape.setLineCap(LineCap.ROUND);
+ assertEquals(LineCap.ROUND, shape.getLineCap());
+ assertEquals(STLineCap.RND, getSpPr(shape).getLn().getCap());
+ shape.setLineCap(null);
+ // setting cap to null unsets the Cap attribute
+ assertFalse(getSpPr(shape).getLn().isSetCap());
+
+ // line dash
+ shape.setLineDash(LineDash.SOLID);
+ assertEquals(LineDash.SOLID, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.SOLID, getSpPr(shape).getLn().getPrstDash().getVal());
+ shape.setLineDash(LineDash.DASH_DOT);
+ assertEquals(LineDash.DASH_DOT, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.DASH_DOT, getSpPr(shape).getLn().getPrstDash().getVal());
+ shape.setLineDash(LineDash.LG_DASH_DOT);
+ assertEquals(LineDash.LG_DASH_DOT, shape.getLineDash());
+ assertEquals(STPresetLineDashVal.LG_DASH_DOT, getSpPr(shape).getLn().getPrstDash().getVal());
+ shape.setLineDash(null);
+ // setting dash width to null unsets the Dash element
+ assertFalse(getSpPr(shape).getLn().isSetPrstDash());
+
+ // line color
+ assertFalse(getSpPr(shape).getLn().isSetSolidFill());
+ shape.setLineColor(Color.RED);
+ assertEquals(Color.RED, shape.getLineColor());
+ assertTrue(getSpPr(shape).getLn().isSetSolidFill());
+ shape.setLineColor(Color.BLUE);
+ assertEquals(Color.BLUE, shape.getLineColor());
+ assertTrue(getSpPr(shape).getLn().isSetSolidFill());
+ shape.setLineColor(null);
+ assertNull(shape.getLineColor());
+ // setting dash width to null unsets the SolidFill element
+ assertFalse(getSpPr(shape).getLn().isSetSolidFill());
+
+ XSLFSimpleShape ln2 = slide.createAutoShape();
+ ln2.setLineDash(LineDash.DOT);
+ assertEquals(LineDash.DOT, ln2.getLineDash());
+ ln2.setLineWidth(0.);
+ assertEquals(0., ln2.getLineWidth(), 0);
+
+ XSLFSimpleShape ln3 = slide.createAutoShape();
+ ln3.setLineWidth(1.);
+ assertEquals(1., ln3.getLineWidth(), 0);
+ ln3.setLineDash(null);
+ assertNull(ln3.getLineDash());
+ ln3.setLineCap(null);
+ assertNull(ln3.getLineDash());
+ }
}
@Test
public void testFill() throws IOException {
- XMLSlideShow ppt = new XMLSlideShow();
- XSLFSlide slide = ppt.createSlide();
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFSlide slide = ppt.createSlide();
- XSLFAutoShape shape = slide.createAutoShape();
- // line properties are not set by default
- assertFalse(getSpPr(shape).isSetSolidFill());
-
- assertNull(shape.getFillColor());
- shape.setFillColor(null);
- assertNull(shape.getFillColor());
- assertFalse(getSpPr(shape).isSetSolidFill());
-
- shape.setFillColor(Color.RED);
- assertEquals(Color.RED, shape.getFillColor());
- shape.setFillColor(Color.DARK_GRAY);
- assertEquals(Color.DARK_GRAY, shape.getFillColor());
- assertTrue(getSpPr(shape).isSetSolidFill());
-
- shape.setFillColor(null);
- assertNull(shape.getFillColor());
- assertFalse(getSpPr(shape).isSetSolidFill());
- ppt.close();
+ XSLFAutoShape shape = slide.createAutoShape();
+ // line properties are not set by default
+ assertFalse(getSpPr(shape).isSetSolidFill());
+
+ assertNull(shape.getFillColor());
+ shape.setFillColor(null);
+ assertNull(shape.getFillColor());
+ assertFalse(getSpPr(shape).isSetSolidFill());
+
+ shape.setFillColor(Color.RED);
+ assertEquals(Color.RED, shape.getFillColor());
+ shape.setFillColor(Color.DARK_GRAY);
+ assertEquals(Color.DARK_GRAY, shape.getFillColor());
+ assertTrue(getSpPr(shape).isSetSolidFill());
+
+ shape.setFillColor(null);
+ assertNull(shape.getFillColor());
+ assertFalse(getSpPr(shape).isSetSolidFill());
+ }
}
@Test
public void testDefaultProperties() throws IOException {
- XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+ try (XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx")) {
+ XSLFSlide slide6 = ppt.getSlides().get(5);
+ List<XSLFShape> shapes = slide6.getShapes();
+ for (XSLFShape xs : shapes) {
+ XSLFSimpleShape s = (XSLFSimpleShape) xs;
+ // all shapes have a theme color="accent1"
+ assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString());
+ assertEquals(2.0, s.getLineWidth(), 0);
+ assertEquals(LineCap.FLAT, s.getLineCap());
+ assertEquals(new Color(79, 129, 189), s.getLineColor());
+ }
- XSLFSlide slide6 = ppt.getSlides().get(5);
- List<XSLFShape> shapes = slide6.getShapes();
- for(XSLFShape xs : shapes){
- XSLFSimpleShape s = (XSLFSimpleShape)xs;
- // all shapes have a theme color="accent1"
- assertEquals("accent1", s.getSpStyle().getFillRef().getSchemeClr().getVal().toString());
- assertEquals(2.0, s.getLineWidth(), 0);
- assertEquals(LineCap.FLAT, s.getLineCap());
- assertEquals(new Color(79,129,189), s.getLineColor());
+ XSLFSimpleShape s0 = (XSLFSimpleShape) shapes.get(0);
+ // fill is not set
+ assertNull(getSpPr(s0).getSolidFill());
+ //assertEquals(slide6.getTheme().getColor("accent1").getColor(), s0.getFillColor());
+ assertEquals(new Color(79, 129, 189), s0.getFillColor());
+
+ // lighter 80%
+ XSLFSimpleShape s1 = (XSLFSimpleShape) shapes.get(1);
+ CTSchemeColor ref1 = getSpPr(s1).getSolidFill().getSchemeClr();
+ assertEquals(1, ref1.sizeOfLumModArray());
+ assertEquals(1, ref1.sizeOfLumOffArray());
+ assertEquals(20000, ref1.getLumModArray(0).getVal());
+ assertEquals(80000, ref1.getLumOffArray(0).getVal());
+ assertEquals("accent1", ref1.getVal().toString());
+ assertEquals(new Color(220, 230, 242), s1.getFillColor());
+
+ // lighter 60%
+ XSLFSimpleShape s2 = (XSLFSimpleShape) shapes.get(2);
+ CTSchemeColor ref2 = getSpPr(s2).getSolidFill().getSchemeClr();
+ assertEquals(1, ref2.sizeOfLumModArray());
+ assertEquals(1, ref2.sizeOfLumOffArray());
+ assertEquals(40000, ref2.getLumModArray(0).getVal());
+ assertEquals(60000, ref2.getLumOffArray(0).getVal());
+ assertEquals("accent1", ref2.getVal().toString());
+ assertEquals(new Color(185, 205, 229), s2.getFillColor());
+
+ // lighter 40%
+ XSLFSimpleShape s3 = (XSLFSimpleShape) shapes.get(3);
+ CTSchemeColor ref3 = getSpPr(s3).getSolidFill().getSchemeClr();
+ assertEquals(1, ref3.sizeOfLumModArray());
+ assertEquals(1, ref3.sizeOfLumOffArray());
+ assertEquals(60000, ref3.getLumModArray(0).getVal());
+ assertEquals(40000, ref3.getLumOffArray(0).getVal());
+ assertEquals("accent1", ref3.getVal().toString());
+ assertEquals(new Color(149, 179, 215), s3.getFillColor());
+
+ // darker 25%
+ XSLFSimpleShape s4 = (XSLFSimpleShape) shapes.get(4);
+ CTSchemeColor ref4 = getSpPr(s4).getSolidFill().getSchemeClr();
+ assertEquals(1, ref4.sizeOfLumModArray());
+ assertEquals(0, ref4.sizeOfLumOffArray());
+ assertEquals(75000, ref4.getLumModArray(0).getVal());
+ assertEquals("accent1", ref3.getVal().toString());
+ assertEquals(new Color(55, 96, 146), s4.getFillColor());
+
+ XSLFSimpleShape s5 = (XSLFSimpleShape) shapes.get(5);
+ CTSchemeColor ref5 = getSpPr(s5).getSolidFill().getSchemeClr();
+ assertEquals(1, ref5.sizeOfLumModArray());
+ assertEquals(0, ref5.sizeOfLumOffArray());
+ assertEquals(50000, ref5.getLumModArray(0).getVal());
+ assertEquals("accent1", ref5.getVal().toString());
+ assertEquals(new Color(37, 64, 97), s5.getFillColor());
}
-
- XSLFSimpleShape s0 = (XSLFSimpleShape) shapes.get(0);
- // fill is not set
- assertNull(getSpPr(s0).getSolidFill());
- //assertEquals(slide6.getTheme().getColor("accent1").getColor(), s0.getFillColor());
- assertEquals(new Color(79, 129, 189), s0.getFillColor());
-
- // lighter 80%
- XSLFSimpleShape s1 = (XSLFSimpleShape)shapes.get(1);
- CTSchemeColor ref1 = getSpPr(s1).getSolidFill().getSchemeClr();
- assertEquals(1, ref1.sizeOfLumModArray());
- assertEquals(1, ref1.sizeOfLumOffArray());
- assertEquals(20000, ref1.getLumModArray(0).getVal());
- assertEquals(80000, ref1.getLumOffArray(0).getVal());
- assertEquals("accent1", ref1.getVal().toString());
- assertEquals(new Color(220, 230, 242), s1.getFillColor());
-
- // lighter 60%
- XSLFSimpleShape s2 = (XSLFSimpleShape)shapes.get(2);
- CTSchemeColor ref2 = getSpPr(s2).getSolidFill().getSchemeClr();
- assertEquals(1, ref2.sizeOfLumModArray());
- assertEquals(1, ref2.sizeOfLumOffArray());
- assertEquals(40000, ref2.getLumModArray(0).getVal());
- assertEquals(60000, ref2.getLumOffArray(0).getVal());
- assertEquals("accent1", ref2.getVal().toString());
- assertEquals(new Color(185, 205, 229), s2.getFillColor());
-
- // lighter 40%
- XSLFSimpleShape s3 = (XSLFSimpleShape)shapes.get(3);
- CTSchemeColor ref3 = getSpPr(s3).getSolidFill().getSchemeClr();
- assertEquals(1, ref3.sizeOfLumModArray());
- assertEquals(1, ref3.sizeOfLumOffArray());
- assertEquals(60000, ref3.getLumModArray(0).getVal());
- assertEquals(40000, ref3.getLumOffArray(0).getVal());
- assertEquals("accent1", ref3.getVal().toString());
- assertEquals(new Color(149, 179, 215), s3.getFillColor());
-
- // darker 25%
- XSLFSimpleShape s4 = (XSLFSimpleShape)shapes.get(4);
- CTSchemeColor ref4 = getSpPr(s4).getSolidFill().getSchemeClr();
- assertEquals(1, ref4.sizeOfLumModArray());
- assertEquals(0, ref4.sizeOfLumOffArray());
- assertEquals(75000, ref4.getLumModArray(0).getVal());
- assertEquals("accent1", ref3.getVal().toString());
- assertEquals(new Color(55, 96, 146), s4.getFillColor());
-
- XSLFSimpleShape s5 = (XSLFSimpleShape)shapes.get(5);
- CTSchemeColor ref5 = getSpPr(s5).getSolidFill().getSchemeClr();
- assertEquals(1, ref5.sizeOfLumModArray());
- assertEquals(0, ref5.sizeOfLumOffArray());
- assertEquals(50000, ref5.getLumModArray(0).getVal());
- assertEquals("accent1", ref5.getVal().toString());
- assertEquals(new Color(37, 64, 97), s5.getFillColor());
-
- ppt.close();
}
@Test
public void testAnchor() throws IOException {
- XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
- List<XSLFSlide> slide = ppt.getSlides();
+ try (XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx")) {
+ List<XSLFSlide> slide = ppt.getSlides();
- XSLFSlide slide2 = slide.get(1);
- XSLFSlideLayout layout2 = slide2.getSlideLayout();
- List<XSLFShape> shapes2 = slide2.getShapes();
- XSLFTextShape sh1 = (XSLFTextShape)shapes2.get(0);
- assertEquals(Placeholder.CENTERED_TITLE, sh1.getTextType());
- assertEquals("PPTX Title", sh1.getText());
- assertFalse(getSpPr(sh1).isSetXfrm()); // xfrm is not set, the query is delegated to the slide layout
- assertEquals(sh1.getAnchor(), layout2.getTextShapeByType(Placeholder.CENTERED_TITLE).getAnchor());
-
- XSLFTextShape sh2 = (XSLFTextShape)shapes2.get(1);
- assertEquals("Subtitle\nAnd second line", sh2.getText());
- assertEquals(Placeholder.SUBTITLE, sh2.getTextType());
- assertFalse(getSpPr(sh2).isSetXfrm()); // xfrm is not set, the query is delegated to the slide layout
- assertEquals(sh2.getAnchor(), layout2.getTextShapeByType(Placeholder.SUBTITLE).getAnchor());
-
- XSLFSlide slide5 = slide.get(4);
- XSLFSlideLayout layout5 = slide5.getSlideLayout();
- XSLFTextShape shTitle = slide5.getTextShapeByType(Placeholder.TITLE);
- assertEquals("Hyperlinks", shTitle.getText());
- // xfrm is not set, the query is delegated to the slide layout
- assertFalse(getSpPr(shTitle).isSetXfrm());
- // xfrm is not set, the query is delegated to the slide master
- assertFalse(getSpPr(layout5.getTextShapeByType(Placeholder.TITLE)).isSetXfrm());
- assertTrue(getSpPr(layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE)).isSetXfrm());
- assertEquals(shTitle.getAnchor(), layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE).getAnchor());
-
- ppt.close();
+ XSLFSlide slide2 = slide.get(1);
+ XSLFSlideLayout layout2 = slide2.getSlideLayout();
+ List<XSLFShape> shapes2 = slide2.getShapes();
+ XSLFTextShape sh1 = (XSLFTextShape) shapes2.get(0);
+ assertEquals(Placeholder.CENTERED_TITLE, sh1.getTextType());
+ assertEquals("PPTX Title", sh1.getText());
+ assertFalse(getSpPr(sh1).isSetXfrm()); // xfrm is not set, the query is delegated to the slide layout
+ assertEquals(sh1.getAnchor(), layout2.getTextShapeByType(Placeholder.CENTERED_TITLE).getAnchor());
+
+ XSLFTextShape sh2 = (XSLFTextShape) shapes2.get(1);
+ assertEquals("Subtitle\nAnd second line", sh2.getText());
+ assertEquals(Placeholder.SUBTITLE, sh2.getTextType());
+ assertFalse(getSpPr(sh2).isSetXfrm()); // xfrm is not set, the query is delegated to the slide layout
+ assertEquals(sh2.getAnchor(), layout2.getTextShapeByType(Placeholder.SUBTITLE).getAnchor());
+
+ XSLFSlide slide5 = slide.get(4);
+ XSLFSlideLayout layout5 = slide5.getSlideLayout();
+ XSLFTextShape shTitle = slide5.getTextShapeByType(Placeholder.TITLE);
+ assertEquals("Hyperlinks", shTitle.getText());
+ // xfrm is not set, the query is delegated to the slide layout
+ assertFalse(getSpPr(shTitle).isSetXfrm());
+ // xfrm is not set, the query is delegated to the slide master
+ assertFalse(getSpPr(layout5.getTextShapeByType(Placeholder.TITLE)).isSetXfrm());
+ assertTrue(getSpPr(layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE)).isSetXfrm());
+ assertEquals(shTitle.getAnchor(), layout5.getSlideMaster().getTextShapeByType(Placeholder.TITLE).getAnchor());
+ }
}
- @SuppressWarnings("unused")
+ @SuppressWarnings({"unused", "deprecation"})
@Test
public void testShadowEffects() throws IOException{
- XMLSlideShow ppt = new XMLSlideShow();
- XSLFSlide slide = ppt.createSlide();
- CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
- CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
- assertNotNull(lst);
- for(CTEffectStyleItem ef : lst.getEffectStyleArray()){
- CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFSlide slide = ppt.createSlide();
+ CTStyleMatrix styleMatrix = slide.getTheme().getXmlObject().getThemeElements().getFmtScheme();
+ CTEffectStyleList lst = styleMatrix.getEffectStyleLst();
+ assertNotNull(lst);
+ for (CTEffectStyleItem ef : lst.getEffectStyleArray()) {
+ CTOuterShadowEffect obj = ef.getEffectLst().getOuterShdw();
+ }
}
- ppt.close();
}
-
+
@Test
public void testValidGeometry() throws Exception {
- XMLSlideShow ppt = new XMLSlideShow();
- XSLFSlide slide = ppt.createSlide();
+ try (XMLSlideShow ppt = new XMLSlideShow()) {
+ XSLFSlide slide = ppt.createSlide();
- XSLFSimpleShape shape = slide.createAutoShape();
- CTShapeProperties spPr = getSpPr(shape);
-
- CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();
- prstGeom.setPrst(STShapeType.Enum.forInt(1));
-
- assertNotNull(prstGeom.getPrst());
- assertNotNull(prstGeom.getPrst().toString());
- assertNotNull(spPr.getPrstGeom());
- spPr.setPrstGeom(prstGeom);
- assertNotNull(spPr.getPrstGeom().getPrst());
- assertNotNull(spPr.getPrstGeom().getPrst().toString());
-
- assertNotNull(shape.getGeometry());
-
- ppt.close();
- }
+ XSLFSimpleShape shape = slide.createAutoShape();
+ CTShapeProperties spPr = getSpPr(shape);
-
- @Test
- public void testInvalidGeometry() throws Exception {
- XMLSlideShow ppt = new XMLSlideShow();
- XSLFSlide slide = ppt.createSlide();
-
- XSLFSimpleShape shape = slide.createAutoShape();
- CTShapeProperties spPr = getSpPr(shape);
-
- CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();
- prstGeom.setPrst(STShapeType.Enum.forInt(1));
-
- assertNotNull(prstGeom.getPrst());
- assertNotNull(prstGeom.getPrst().toString());
- assertNotNull(spPr.getPrstGeom());
- spPr.setPrstGeom(prstGeom);
- assertNotNull(spPr.getPrstGeom().getPrst());
- assertNotNull(spPr.getPrstGeom().getPrst().toString());
-
- try {
- // cause the geometries to be not found
- TestPresetGeometries.clearPreset();
- try {
- shape.getGeometry();
- fail("Should fail without the geometry");
- } catch (IllegalStateException e) {
- assertTrue(e.getMessage(), e.getMessage().contains("line"));
- }
- } finally {
- // reset to not affect other tests
- TestPresetGeometries.resetPreset();
+ CTPresetGeometry2D prstGeom = CTPresetGeometry2D.Factory.newInstance();
+ prstGeom.setPrst(STShapeType.Enum.forInt(1));
+
+ assertNotNull(prstGeom.getPrst());
+ assertNotNull(prstGeom.getPrst().toString());
+ assertNotNull(spPr.getPrstGeom());
+ spPr.setPrstGeom(prstGeom);
+ assertNotNull(spPr.getPrstGeom().getPrst());
+ assertNotNull(spPr.getPrstGeom().getPrst().toString());
+
+ assertNotNull(shape.getGeometry());
}
-
- ppt.close();
}
- @SuppressWarnings("Duplicates")
@Test
- public void testArrayStoreException() throws IOException {
- XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("aascu.org_workarea_downloadasset.aspx_id=5864.pptx");
- Dimension pgsize = ppt.getPageSize();
-
- for (Slide<?,?> s : ppt.getSlides()) {
- //System.out.println("Slide: " + s);
-
- BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB);
- Graphics2D graphics = img.createGraphics();
-
- // default rendering options
- graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
- graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
- graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
-
- // draw stuff
- s.draw(graphics);
-
- graphics.dispose();
- img.flush();
- }
- ppt.close();
+ public void testArrayStoreException() throws Exception {
+ File file = POIDataSamples.getSlideShowInstance().getFile("aascu.org_workarea_downloadasset.aspx_id=5864.pptx");
+ String[] args = {
+ "-format", "null", // png,gif,jpg,svg or null for test
+ "-slide", "-1", // -1 for all
+ "-outdir", new File("build/tmp/").getCanonicalPath(),
+ "-quiet",
+ "-fixside", "long",
+ "-scale", "800",
+ file.getAbsolutePath()
+ };
+ PPTX2PNG.main(args);
}
-
+
static CTShapeProperties getSpPr(XSLFShape shape) {
XmlObject xo = shape.getShapeProperties();
assertTrue(xo instanceof CTShapeProperties);
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java?rev=1877398&r1=1877397&r2=1877398&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java Tue May 5 13:36:30 2020
@@ -25,23 +25,20 @@ import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
-import java.util.List;
import org.apache.poi.ddf.AbstractEscherOptRecord;
import org.apache.poi.ddf.EscherArrayProperty;
import org.apache.poi.ddf.EscherContainerRecord;
import org.apache.poi.ddf.EscherPropertyTypes;
import org.apache.poi.ddf.EscherSimpleProperty;
-import org.apache.poi.sl.draw.binding.CTAdjPoint2D;
-import org.apache.poi.sl.draw.binding.CTCustomGeometry2D;
-import org.apache.poi.sl.draw.binding.CTPath2D;
-import org.apache.poi.sl.draw.binding.CTPath2DArcTo;
-import org.apache.poi.sl.draw.binding.CTPath2DCubicBezierTo;
-import org.apache.poi.sl.draw.binding.CTPath2DLineTo;
-import org.apache.poi.sl.draw.binding.CTPath2DList;
-import org.apache.poi.sl.draw.binding.CTPath2DMoveTo;
-import org.apache.poi.sl.draw.binding.ObjectFactory;
+import org.apache.poi.sl.draw.geom.AdjustPoint;
+import org.apache.poi.sl.draw.geom.ArcToCommand;
+import org.apache.poi.sl.draw.geom.ClosePathCommand;
+import org.apache.poi.sl.draw.geom.CurveToCommand;
import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.draw.geom.LineToCommand;
+import org.apache.poi.sl.draw.geom.MoveToCommand;
+import org.apache.poi.sl.draw.geom.Path;
import org.apache.poi.sl.usermodel.AutoShape;
import org.apache.poi.sl.usermodel.ShapeContainer;
import org.apache.poi.sl.usermodel.ShapeType;
@@ -72,7 +69,6 @@ public class HSLFAutoShape extends HSLFT
static final byte[] SEGMENTINFO_CLOSE = new byte[]{0x01, (byte)0x60};
static final byte[] SEGMENTINFO_END = new byte[]{0x00, (byte)0x80};
- private static final ObjectFactory OF = new ObjectFactory();
private static final BitField PATH_INFO = BitFieldFactory.getInstance(0xE000);
private static final BitField ESCAPE_INFO = BitFieldFactory.getInstance(0x1F00);
@@ -211,11 +207,7 @@ public class HSLFAutoShape extends HSLFT
}
CustomGeometry getGeometry(Path2D path2D) {
- final CTCustomGeometry2D cusGeo = OF.createCTCustomGeometry2D();
- cusGeo.setAvLst(OF.createCTGeomGuideList());
- cusGeo.setGdLst(OF.createCTGeomGuideList());
- cusGeo.setAhLst(OF.createCTAdjustHandleList());
- cusGeo.setCxnLst(OF.createCTConnectionSiteList());
+ final CustomGeometry cusGeo = new CustomGeometry();
final AbstractEscherOptRecord opt = getEscherOptRecord();
@@ -239,11 +231,8 @@ public class HSLFAutoShape extends HSLFT
final int[] xyPoints = new int[2];
boolean isClosed = false;
- final CTPath2DList pathLst = OF.createCTPath2DList();
- final CTPath2D pathCT = OF.createCTPath2D();
- final List<Object> moveLst = pathCT.getCloseOrMoveToOrLnTo();
- pathLst.getPath().add(pathCT);
- cusGeo.setPathLst(pathLst);
+ final Path path = new Path();
+ cusGeo.addPath(path);
while (segIter.hasNext()) {
byte[] segElem = segIter.next();
@@ -253,20 +242,20 @@ public class HSLFAutoShape extends HSLFT
}
switch (pi) {
case escape:
- handleEscapeInfo(pathCT, path2D, segElem, vertIter);
+ handleEscapeInfo(path, path2D, segElem, vertIter);
break;
case moveTo:
- handleMoveTo(vertIter, xyPoints, moveLst, path2D);
+ handleMoveTo(vertIter, xyPoints, path, path2D);
break;
case lineTo:
- handleLineTo(vertIter, xyPoints, moveLst, path2D);
+ handleLineTo(vertIter, xyPoints, path, path2D);
break;
case curveTo:
- handleCurveTo(vertIter, xyPoints, moveLst, path2D);
+ handleCurveTo(vertIter, xyPoints, path, path2D);
break;
case close:
if (path2D.getCurrentPoint() != null) {
- moveLst.add(OF.createCTPath2DClose());
+ path.addCommand(new ClosePathCommand());
path2D.closePath();
}
isClosed = true;
@@ -277,15 +266,15 @@ public class HSLFAutoShape extends HSLFT
}
if (!isClosed) {
- handleClosedShape(opt, moveLst, path2D);
+ handleClosedShape(opt, path, path2D);
}
final Rectangle2D bounds = getBounds(opt, path2D);
- pathCT.setW((int)Math.rint(bounds.getWidth()));
- pathCT.setH((int)Math.rint(bounds.getHeight()));
+ path.setW((int)Math.rint(bounds.getWidth()));
+ path.setH((int)Math.rint(bounds.getHeight()));
- return new CustomGeometry(cusGeo);
+ return cusGeo;
}
private static Rectangle2D getBounds(AbstractEscherOptRecord opt, Path2D path2D) {
@@ -306,76 +295,79 @@ public class HSLFAutoShape extends HSLFT
}
}
- private static void handleClosedShape(AbstractEscherOptRecord opt, List<Object> moveLst, Path2D path2D) {
+ private static void handleClosedShape(AbstractEscherOptRecord opt, Path path, Path2D path2D) {
EscherSimpleProperty shapePath = getEscherProperty(opt, EscherPropertyTypes.GEOMETRY__SHAPEPATH);
HSLFFreeformShape.ShapePath sp = HSLFFreeformShape.ShapePath.valueOf(shapePath == null ? 1 : shapePath.getPropertyValue());
if (sp == LINES_CLOSED || sp == CURVES_CLOSED) {
- moveLst.add(OF.createCTPath2DClose());
+ path.addCommand(new ClosePathCommand());
path2D.closePath();
}
}
- private static void handleMoveTo(Iterator<byte[]> vertIter, int[] xyPoints, List<Object> moveLst, Path2D path2D) {
+ private static void handleMoveTo(Iterator<byte[]> vertIter, int[] xyPoints, Path path, Path2D path2D) {
if (!vertIter.hasNext()) {
return;
}
- final CTPath2DMoveTo m = OF.createCTPath2DMoveTo();
+ final MoveToCommand m = new MoveToCommand();
m.setPt(fillPoint(vertIter.next(), xyPoints));
- moveLst.add(m);
+ path.addCommand(m);
path2D.moveTo(xyPoints[0], xyPoints[1]);
}
- private static void handleLineTo(Iterator<byte[]> vertIter, int[] xyPoints, List<Object> moveLst, Path2D path2D) {
+ private static void handleLineTo(Iterator<byte[]> vertIter, int[] xyPoints, Path path, Path2D path2D) {
if (!vertIter.hasNext()) {
return;
}
- handleMoveTo0(moveLst, path2D);
+ handleMoveTo0(path, path2D);
- final CTPath2DLineTo m = OF.createCTPath2DLineTo();
+ final LineToCommand m = new LineToCommand();
m.setPt(fillPoint(vertIter.next(), xyPoints));
- moveLst.add(m);
+ path.addCommand(m);
path2D.lineTo(xyPoints[0], xyPoints[1]);
}
- private static void handleCurveTo(Iterator<byte[]> vertIter, int[] xyPoints, List<Object> moveLst, Path2D path2D) {
+ private static void handleCurveTo(Iterator<byte[]> vertIter, int[] xyPoints, Path path, Path2D path2D) {
if (!vertIter.hasNext()) {
return;
}
- handleMoveTo0(moveLst, path2D);
+ handleMoveTo0(path, path2D);
- final CTPath2DCubicBezierTo m = OF.createCTPath2DCubicBezierTo();
- List<CTAdjPoint2D> mLst = m.getPt();
+ final CurveToCommand m = new CurveToCommand();
int[] pts = new int[6];
+ AdjustPoint[] ap = new AdjustPoint[3];
for (int i=0; vertIter.hasNext() && i<3; i++) {
- mLst.add(fillPoint(vertIter.next(), xyPoints));
+ ap[i] = fillPoint(vertIter.next(), xyPoints);
pts[i*2] = xyPoints[0];
pts[i*2+1] = xyPoints[1];
- if (i == 2) {
- moveLst.add(m);
- path2D.curveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
- }
}
+
+ m.setPt1(ap[0]);
+ m.setPt2(ap[1]);
+ m.setPt3(ap[2]);
+
+ path.addCommand(m);
+ path2D.curveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]);
}
/**
* Sometimes the path2D is not initialized - this initializes it with the 0,0 position
*/
- private static void handleMoveTo0(List<Object> moveLst, Path2D path2D) {
+ private static void handleMoveTo0(Path moveLst, Path2D path2D) {
if (path2D.getCurrentPoint() == null) {
- final CTPath2DMoveTo m = OF.createCTPath2DMoveTo();
+ final MoveToCommand m = new MoveToCommand();
- CTAdjPoint2D pt = OF.createCTAdjPoint2D();
+ AdjustPoint pt = new AdjustPoint();
pt.setX("0");
pt.setY("0");
m.setPt(pt);
- moveLst.add(m);
+ moveLst.addCommand(m);
path2D.moveTo(0, 0);
}
}
- private static void handleEscapeInfo(CTPath2D pathCT, Path2D path2D, byte[] segElem, Iterator<byte[]> vertIter) {
+ private static void handleEscapeInfo(Path pathCT, Path2D path2D, byte[] segElem, Iterator<byte[]> vertIter) {
HSLFAutoShape.EscapeInfo ei = getEscapeInfo(segElem);
if (ei == null) {
return;
@@ -412,14 +404,14 @@ public class HSLFAutoShape extends HSLFT
path2D.append(arc2D, true);
- CTPath2DArcTo arcTo = OF.createCTPath2DArcTo();
+ ArcToCommand arcTo = new ArcToCommand();
arcTo.setHR(d2s(bounds.getHeight()/2.0));
arcTo.setWR(d2s(bounds.getWidth()/2.0));
arcTo.setStAng(d2s(-arc2D.getAngleStart()*60000.));
arcTo.setSwAng(d2s(-arc2D.getAngleExtent()*60000.));
- pathCT.getCloseOrMoveToOrLnTo().add(arcTo);
+ pathCT.addCommand(arcTo);
break;
}
@@ -487,7 +479,7 @@ public class HSLFAutoShape extends HSLFT
}
- private static CTAdjPoint2D fillPoint(byte[] xyMaster, int[] xyPoints) {
+ private static AdjustPoint fillPoint(byte[] xyMaster, int[] xyPoints) {
if (xyMaster == null || xyPoints == null) {
LOG.log(POILogger.WARN, "Master bytes or points not set - ignore point");
return null;
@@ -512,8 +504,8 @@ public class HSLFAutoShape extends HSLFT
return toPoint(xyPoints);
}
- private static CTAdjPoint2D toPoint(int[] xyPoints) {
- CTAdjPoint2D pt = OF.createCTAdjPoint2D();
+ private static AdjustPoint toPoint(int[] xyPoints) {
+ AdjustPoint pt = new AdjustPoint();
pt.setX(Integer.toString(xyPoints[0]));
pt.setY(Integer.toString(xyPoints[1]));
return pt;
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=1877398&r1=1877397&r2=1877398&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 Tue May 5 13:36:30 2020
@@ -368,7 +368,10 @@ public abstract class HSLFSimpleShape ex
break;
}
- return new Guide(name, "val "+Math.rint(adjval * (isDegreeUnit ? 65536. : 100000./21000.)));
+ Guide gd = new Guide();
+ gd.setName(name);
+ gd.setFmla("val "+Math.rint(adjval * (isDegreeUnit ? 65536. : 100000./21000.)));
+ return gd;
}
@Override
Modified: poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java?rev=1877398&r1=1877397&r2=1877398&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/sl/draw/geom/TestPresetGeometries.java Tue May 5 13:36:30 2020
@@ -21,13 +21,11 @@ package org.apache.poi.sl.draw.geom;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import java.net.URL;
import java.util.Enumeration;
-import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
@@ -35,8 +33,9 @@ import org.junit.Test;
public class TestPresetGeometries {
@Test
public void testRead(){
- Map<String, CustomGeometry> shapes = PresetGeometries.getInstance();
+ PresetGeometries shapes = PresetGeometries.getInstance();
assertEquals(187, shapes.size());
+ assertEquals(0x4533584F, shapes.hashCode());
for(String name : shapes.keySet()) {
CustomGeometry geom = shapes.get(name);
@@ -46,30 +45,17 @@ public class TestPresetGeometries {
assertNotNull(path);
}
}
-
+
// we get the same instance on further calls
assertSame(shapes, PresetGeometries.getInstance());
}
- // 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;
- }
-
@Ignore("problem solved? Turn back on if this debugging is still in process.")
@Test
public void testCheckXMLParser() throws Exception{
- // Gump reports a strange error because of an unavailable XML Parser, let's try to find out where
+ // Gump reports a strange error because of an unavailable XML Parser, let's try to find out where
// this comes from
- //
+ //
Enumeration<URL> resources = this.getClass().getClassLoader().getResources("META-INF/services/javax.xml.stream.XMLEventFactory");
printURLs(resources);
resources = ClassLoader.getSystemResources("META-INF/services/javax.xml.stream.XMLEventFactory");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org