1*eba4d44aSLiu Zhe /************************************************************** 2*eba4d44aSLiu Zhe * 3*eba4d44aSLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 4*eba4d44aSLiu Zhe * or more contributor license agreements. See the NOTICE file 5*eba4d44aSLiu Zhe * distributed with this work for additional information 6*eba4d44aSLiu Zhe * regarding copyright ownership. The ASF licenses this file 7*eba4d44aSLiu Zhe * to you under the Apache License, Version 2.0 (the 8*eba4d44aSLiu Zhe * "License"); you may not use this file except in compliance 9*eba4d44aSLiu Zhe * with the License. You may obtain a copy of the License at 10*eba4d44aSLiu Zhe * 11*eba4d44aSLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 12*eba4d44aSLiu Zhe * 13*eba4d44aSLiu Zhe * Unless required by applicable law or agreed to in writing, 14*eba4d44aSLiu Zhe * software distributed under the License is distributed on an 15*eba4d44aSLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*eba4d44aSLiu Zhe * KIND, either express or implied. See the License for the 17*eba4d44aSLiu Zhe * specific language governing permissions and limitations 18*eba4d44aSLiu Zhe * under the License. 19*eba4d44aSLiu Zhe * 20*eba4d44aSLiu Zhe *************************************************************/ 21*eba4d44aSLiu Zhe package fvt.uno.sd.shape; 22*eba4d44aSLiu Zhe 23*eba4d44aSLiu Zhe import java.awt.geom.AffineTransform; 24*eba4d44aSLiu Zhe import java.io.File; 25*eba4d44aSLiu Zhe import java.io.IOException; 26*eba4d44aSLiu Zhe 27*eba4d44aSLiu Zhe import org.junit.After; 28*eba4d44aSLiu Zhe import static org.junit.Assert.*; 29*eba4d44aSLiu Zhe 30*eba4d44aSLiu Zhe import org.junit.AfterClass; 31*eba4d44aSLiu Zhe import org.junit.Before; 32*eba4d44aSLiu Zhe import org.junit.Test; 33*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 34*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 35*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 36*eba4d44aSLiu Zhe 37*eba4d44aSLiu Zhe import testlib.uno.PageUtil; 38*eba4d44aSLiu Zhe import testlib.uno.ShapeUtil; 39*eba4d44aSLiu Zhe import testlib.uno.TestUtil; 40*eba4d44aSLiu Zhe 41*eba4d44aSLiu Zhe import com.sun.star.text.WrapTextMode; 42*eba4d44aSLiu Zhe import com.sun.star.text.XText; 43*eba4d44aSLiu Zhe import com.sun.star.text.XTextContent; 44*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 45*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentation; 46*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentationSupplier; 47*eba4d44aSLiu Zhe import com.sun.star.awt.Gradient; 48*eba4d44aSLiu Zhe import com.sun.star.awt.GradientStyle; 49*eba4d44aSLiu Zhe import com.sun.star.awt.Size; 50*eba4d44aSLiu Zhe import com.sun.star.awt.Point; 51*eba4d44aSLiu Zhe import com.sun.star.beans.PropertyValue; 52*eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet; 53*eba4d44aSLiu Zhe import com.sun.star.drawing.DashStyle; 54*eba4d44aSLiu Zhe import com.sun.star.drawing.FillStyle; 55*eba4d44aSLiu Zhe import com.sun.star.drawing.Hatch; 56*eba4d44aSLiu Zhe import com.sun.star.drawing.HatchStyle; 57*eba4d44aSLiu Zhe import com.sun.star.drawing.HomogenMatrix3; 58*eba4d44aSLiu Zhe import com.sun.star.drawing.LineDash; 59*eba4d44aSLiu Zhe import com.sun.star.drawing.LineStyle; 60*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPage; 61*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPages; 62*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier; 63*eba4d44aSLiu Zhe import com.sun.star.drawing.XShape; 64*eba4d44aSLiu Zhe import com.sun.star.drawing.XShapes; 65*eba4d44aSLiu Zhe import com.sun.star.frame.XComponentLoader; 66*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 67*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent; 68*eba4d44aSLiu Zhe import com.sun.star.lang.XMultiServiceFactory; 69*eba4d44aSLiu Zhe 70*eba4d44aSLiu Zhe public class ShapeProperties { 71*eba4d44aSLiu Zhe UnoApp unoApp = new UnoApp(); 72*eba4d44aSLiu Zhe XPresentationSupplier sdDocument = null; 73*eba4d44aSLiu Zhe XPresentation pre = null; 74*eba4d44aSLiu Zhe XComponent precomp = null; 75*eba4d44aSLiu Zhe XComponent impressDocument = null; 76*eba4d44aSLiu Zhe XComponent reLoadFile = null; 77*eba4d44aSLiu Zhe XDrawPagesSupplier drawsupplier = null; 78*eba4d44aSLiu Zhe XDrawPages drawpages = null; 79*eba4d44aSLiu Zhe XShapes xShapes = null; 80*eba4d44aSLiu Zhe XDrawPage xpage = null; 81*eba4d44aSLiu Zhe String filePath = null; 82*eba4d44aSLiu Zhe 83*eba4d44aSLiu Zhe @Before 84*eba4d44aSLiu Zhe public void setUp() throws Exception { 85*eba4d44aSLiu Zhe unoApp.start(); 86*eba4d44aSLiu Zhe createDocumentAndSlide(); 87*eba4d44aSLiu Zhe } 88*eba4d44aSLiu Zhe 89*eba4d44aSLiu Zhe @After 90*eba4d44aSLiu Zhe public void tearDown() throws Exception { 91*eba4d44aSLiu Zhe unoApp.closeDocument(impressDocument); 92*eba4d44aSLiu Zhe unoApp.closeDocument(reLoadFile); 93*eba4d44aSLiu Zhe unoApp.close(); 94*eba4d44aSLiu Zhe if (filePath != null) 95*eba4d44aSLiu Zhe FileUtil.deleteFile(filePath); 96*eba4d44aSLiu Zhe } 97*eba4d44aSLiu Zhe 98*eba4d44aSLiu Zhe /** 99*eba4d44aSLiu Zhe * test Insert a new slide and Insert a new EllipseShape 100*eba4d44aSLiu Zhe * 101*eba4d44aSLiu Zhe * @throws Exception 102*eba4d44aSLiu Zhe */ 103*eba4d44aSLiu Zhe @Test 104*eba4d44aSLiu Zhe public void testInsertShape() throws Exception { 105*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 106*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 107*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 108*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 109*eba4d44aSLiu Zhe xShapes.add(xShape); 110*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 111*eba4d44aSLiu Zhe XPropertySet.class, xShape); 112*eba4d44aSLiu Zhe xPropSet.setPropertyValue("Name", "test"); 113*eba4d44aSLiu Zhe 114*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 115*eba4d44aSLiu Zhe XPropertySet xPropSet2 = (XPropertySet) UnoRuntime.queryInterface( 116*eba4d44aSLiu Zhe XPropertySet.class, xShape); 117*eba4d44aSLiu Zhe assertEquals("Not the same shape","test",xPropSet2.getPropertyValue("Name")); 118*eba4d44aSLiu Zhe assertEquals("Not EllopseShape","com.sun.star.drawing.EllipseShape",xShape.getShapeType()); 119*eba4d44aSLiu Zhe } 120*eba4d44aSLiu Zhe 121*eba4d44aSLiu Zhe /** 122*eba4d44aSLiu Zhe * test Insert text to an EllopseShape 123*eba4d44aSLiu Zhe * 124*eba4d44aSLiu Zhe * @throws Exception 125*eba4d44aSLiu Zhe */ 126*eba4d44aSLiu Zhe @Test 127*eba4d44aSLiu Zhe public void testInsertTextToShape() throws Exception { 128*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 129*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 130*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 131*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 132*eba4d44aSLiu Zhe xShapes.add(xShape); 133*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 134*eba4d44aSLiu Zhe ShapeUtil.addPortion(xShape, "test", false); 135*eba4d44aSLiu Zhe assertEquals("Not put text correctly","test",ShapeUtil.getPortion(xShape)); 136*eba4d44aSLiu Zhe } 137*eba4d44aSLiu Zhe 138*eba4d44aSLiu Zhe /** 139*eba4d44aSLiu Zhe * test Shape fill with Gradient 140*eba4d44aSLiu Zhe * 141*eba4d44aSLiu Zhe * @throws Exception 142*eba4d44aSLiu Zhe */ 143*eba4d44aSLiu Zhe @Test 144*eba4d44aSLiu Zhe public void testShapeFillGradient() throws Exception { 145*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 146*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 147*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 148*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 149*eba4d44aSLiu Zhe xShapes.add(xShape); 150*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 151*eba4d44aSLiu Zhe XPropertySet.class, xShape); 152*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT); 153*eba4d44aSLiu Zhe Gradient aGradient = new Gradient(); 154*eba4d44aSLiu Zhe aGradient.Style = GradientStyle.LINEAR; 155*eba4d44aSLiu Zhe aGradient.StartColor = 0x00ff00; 156*eba4d44aSLiu Zhe aGradient.EndColor = 0xffff00; 157*eba4d44aSLiu Zhe aGradient.Angle = 450; 158*eba4d44aSLiu Zhe aGradient.Border = 0; 159*eba4d44aSLiu Zhe aGradient.XOffset = 0; 160*eba4d44aSLiu Zhe aGradient.YOffset = 0; 161*eba4d44aSLiu Zhe aGradient.StartIntensity = 100; 162*eba4d44aSLiu Zhe aGradient.EndIntensity = 100; 163*eba4d44aSLiu Zhe aGradient.StepCount = 10; 164*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillGradient", aGradient); 165*eba4d44aSLiu Zhe // -------------------------- 166*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 167*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); 168*eba4d44aSLiu Zhe // ---------------------------- 169*eba4d44aSLiu Zhe assertEquals("Not Gradient Fill Style",FillStyle.GRADIENT,xPropSet.getPropertyValue("FillStyle")); 170*eba4d44aSLiu Zhe aGradient=(Gradient) xPropSet.getPropertyValue("FillGradient"); 171*eba4d44aSLiu Zhe assertEquals("Not Linear Gradient",GradientStyle.LINEAR,aGradient.Style); 172*eba4d44aSLiu Zhe } 173*eba4d44aSLiu Zhe 174*eba4d44aSLiu Zhe /** 175*eba4d44aSLiu Zhe * test Shape fill with yellow color 176*eba4d44aSLiu Zhe * 177*eba4d44aSLiu Zhe * @throws Exception 178*eba4d44aSLiu Zhe */ 179*eba4d44aSLiu Zhe @Test 180*eba4d44aSLiu Zhe public void testShapeFillColor() throws Exception { 181*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 182*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 183*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 184*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 185*eba4d44aSLiu Zhe xShapes.add(xShape); 186*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 187*eba4d44aSLiu Zhe XPropertySet.class, xShape); 188*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID); 189*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillColor", 0xffff00); 190*eba4d44aSLiu Zhe // -------------------------- 191*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 192*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); 193*eba4d44aSLiu Zhe // ---------------------------------------------------- 194*eba4d44aSLiu Zhe assertEquals("Not Color Fill Style",FillStyle.SOLID,xPropSet.getPropertyValue("FillStyle")); 195*eba4d44aSLiu Zhe assertEquals("Not Yellow Color Fill",0xffff00,xPropSet.getPropertyValue("FillColor")); 196*eba4d44aSLiu Zhe } 197*eba4d44aSLiu Zhe 198*eba4d44aSLiu Zhe /** 199*eba4d44aSLiu Zhe * test shape fill with Hatch Style(Pattern in MS) 200*eba4d44aSLiu Zhe * @throws Exception 201*eba4d44aSLiu Zhe */ 202*eba4d44aSLiu Zhe @Test 203*eba4d44aSLiu Zhe public void testShapeFillHatch() throws Exception { 204*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 205*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 206*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 207*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 208*eba4d44aSLiu Zhe xShapes.add(xShape); 209*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 210*eba4d44aSLiu Zhe XPropertySet.class, xShape); 211*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH); 212*eba4d44aSLiu Zhe Hatch aHatch=new Hatch(); 213*eba4d44aSLiu Zhe aHatch.Style=HatchStyle.DOUBLE; 214*eba4d44aSLiu Zhe aHatch.Color=0x00ff00; 215*eba4d44aSLiu Zhe aHatch.Distance=100; 216*eba4d44aSLiu Zhe aHatch.Angle=450; 217*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillHatch", aHatch); 218*eba4d44aSLiu Zhe 219*eba4d44aSLiu Zhe // -------------------------- 220*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 221*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); 222*eba4d44aSLiu Zhe // ---------------------------- 223*eba4d44aSLiu Zhe assertEquals("Not Gradient Fill Style",FillStyle.HATCH,xPropSet.getPropertyValue("FillStyle")); 224*eba4d44aSLiu Zhe aHatch=(Hatch) xPropSet.getPropertyValue("FillHatch"); 225*eba4d44aSLiu Zhe assertEquals("Not Double Hatch",HatchStyle.DOUBLE,aHatch.Style); 226*eba4d44aSLiu Zhe } 227*eba4d44aSLiu Zhe 228*eba4d44aSLiu Zhe // ------------Shape Line----------------------------- 229*eba4d44aSLiu Zhe /** 230*eba4d44aSLiu Zhe * test Shape Line style DASH 231*eba4d44aSLiu Zhe * 232*eba4d44aSLiu Zhe * @throws Exception 233*eba4d44aSLiu Zhe */ 234*eba4d44aSLiu Zhe @Test 235*eba4d44aSLiu Zhe public void testShapeLineStyle() throws Exception { 236*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 237*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 238*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 239*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 240*eba4d44aSLiu Zhe xShapes.add(xShape); 241*eba4d44aSLiu Zhe 242*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 243*eba4d44aSLiu Zhe XPropertySet.class, xShape); 244*eba4d44aSLiu Zhe xPropSet.setPropertyValue("LineStyle", LineStyle.DASH); 245*eba4d44aSLiu Zhe 246*eba4d44aSLiu Zhe LineDash aLineDash=new LineDash(); 247*eba4d44aSLiu Zhe aLineDash.Style=DashStyle.ROUND; 248*eba4d44aSLiu Zhe aLineDash.Dots=2; 249*eba4d44aSLiu Zhe aLineDash.DashLen=100; 250*eba4d44aSLiu Zhe aLineDash.Distance=50; 251*eba4d44aSLiu Zhe xPropSet.setPropertyValue("LineDash", aLineDash); 252*eba4d44aSLiu Zhe 253*eba4d44aSLiu Zhe // -------------------------- 254*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 255*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); 256*eba4d44aSLiu Zhe // ---------------------------- 257*eba4d44aSLiu Zhe assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle")); 258*eba4d44aSLiu Zhe aLineDash=(LineDash) xPropSet.getPropertyValue("LineDash"); 259*eba4d44aSLiu Zhe assertEquals("Not Round Dash Style", DashStyle.ROUND ,aLineDash.Style); 260*eba4d44aSLiu Zhe } 261*eba4d44aSLiu Zhe 262*eba4d44aSLiu Zhe /** 263*eba4d44aSLiu Zhe * test Shape Line Color 264*eba4d44aSLiu Zhe * @throws Exception 265*eba4d44aSLiu Zhe */ 266*eba4d44aSLiu Zhe 267*eba4d44aSLiu Zhe @Test 268*eba4d44aSLiu Zhe public void testShapeLineColor() throws Exception { 269*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 270*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 271*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 272*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 273*eba4d44aSLiu Zhe xShapes.add(xShape); 274*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 275*eba4d44aSLiu Zhe XPropertySet.class, xShape); 276*eba4d44aSLiu Zhe xPropSet.setPropertyValue("LineStyle", LineStyle.DASH); 277*eba4d44aSLiu Zhe xPropSet.setPropertyValue("LineColor", 0x00ff00); 278*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 279*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xShape); 280*eba4d44aSLiu Zhe // ---------------------------- 281*eba4d44aSLiu Zhe assertEquals("Not Dash Line Style",LineStyle.DASH,xPropSet.getPropertyValue("LineStyle")); 282*eba4d44aSLiu Zhe assertEquals("wrong line color", 0x00ff00,xPropSet.getPropertyValue("LineColor")); 283*eba4d44aSLiu Zhe } 284*eba4d44aSLiu Zhe 285*eba4d44aSLiu Zhe /** 286*eba4d44aSLiu Zhe * test Shape position and size 287*eba4d44aSLiu Zhe * 288*eba4d44aSLiu Zhe * @throws Exception 289*eba4d44aSLiu Zhe */ 290*eba4d44aSLiu Zhe @Test 291*eba4d44aSLiu Zhe public void testShapePositionSize() throws Exception { 292*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 293*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 294*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 295*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.EllipseShape"); 296*eba4d44aSLiu Zhe xShapes.add(xShape); 297*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 298*eba4d44aSLiu Zhe assertEquals("wrong shape position",1000,xShape.getPosition().X); 299*eba4d44aSLiu Zhe assertEquals("wrong shape Height", 5000 ,xShape.getSize().Height); 300*eba4d44aSLiu Zhe } 301*eba4d44aSLiu Zhe 302*eba4d44aSLiu Zhe /** 303*eba4d44aSLiu Zhe * test Shape rotate with 25 degree. 304*eba4d44aSLiu Zhe * @throws Exception 305*eba4d44aSLiu Zhe */ 306*eba4d44aSLiu Zhe @Test 307*eba4d44aSLiu Zhe public void testShapeRotation() throws Exception { 308*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 309*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 310*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 311*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.RectangleShape"); 312*eba4d44aSLiu Zhe xShapes.add(xShape); 313*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 314*eba4d44aSLiu Zhe XPropertySet.class, xShape); 315*eba4d44aSLiu Zhe xPropSet.setPropertyValue("RotateAngle", 2500); 316*eba4d44aSLiu Zhe xShape=saveAndLoadShape(1,0); 317*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface( 318*eba4d44aSLiu Zhe XPropertySet.class, xShape); 319*eba4d44aSLiu Zhe assertEquals("RotateAngle is not 2500", 2500 , xPropSet.getPropertyValue("RotateAngle")); 320*eba4d44aSLiu Zhe } 321*eba4d44aSLiu Zhe 322*eba4d44aSLiu Zhe 323*eba4d44aSLiu Zhe // ------------------Shape Remove---------------------------- 324*eba4d44aSLiu Zhe /** 325*eba4d44aSLiu Zhe * test Remove shape from impress Document 326*eba4d44aSLiu Zhe * 327*eba4d44aSLiu Zhe * @throws Exception 328*eba4d44aSLiu Zhe */ 329*eba4d44aSLiu Zhe @Test 330*eba4d44aSLiu Zhe public void testShapeRemove() throws Exception { 331*eba4d44aSLiu Zhe Point aPos=null; 332*eba4d44aSLiu Zhe Size aSize=new Size(4000,4000); 333*eba4d44aSLiu Zhe for(int i=0;i<=4;i++){ 334*eba4d44aSLiu Zhe aPos=new Point(1000, 3000*i); 335*eba4d44aSLiu Zhe xShapes=ShapeUtil.getShapes(impressDocument, 0); 336*eba4d44aSLiu Zhe ShapeUtil.createAndInsertShape(impressDocument, xShapes, aPos, aSize, 337*eba4d44aSLiu Zhe "com.sun.star.drawing.EllipseShape"); 338*eba4d44aSLiu Zhe } 339*eba4d44aSLiu Zhe int countBeforeRemove=ShapeUtil.getShapes(impressDocument, 0).getCount(); 340*eba4d44aSLiu Zhe ShapeUtil.removeOneShape(impressDocument, 0, 2); 341*eba4d44aSLiu Zhe int countAfterRemove=ShapeUtil.getShapes(impressDocument, 0).getCount(); 342*eba4d44aSLiu Zhe assertEquals("Not remove shape successfully",1,countBeforeRemove-countAfterRemove); 343*eba4d44aSLiu Zhe reLoadFile = saveAndReloadDoc(impressDocument, 344*eba4d44aSLiu Zhe "impress8", "odp"); 345*eba4d44aSLiu Zhe xShapes=ShapeUtil.getShapes(reLoadFile, 0); 346*eba4d44aSLiu Zhe assertEquals("Shape count is wrong after reload",6,xShapes.getCount()); 347*eba4d44aSLiu Zhe } 348*eba4d44aSLiu Zhe 349*eba4d44aSLiu Zhe /** 350*eba4d44aSLiu Zhe * create a new presentation document and insert a new slide. 351*eba4d44aSLiu Zhe * 352*eba4d44aSLiu Zhe * @throws Exception 353*eba4d44aSLiu Zhe */ 354*eba4d44aSLiu Zhe public void createDocumentAndSlide() throws Exception { 355*eba4d44aSLiu Zhe impressDocument = (XComponent) UnoRuntime.queryInterface( 356*eba4d44aSLiu Zhe XComponent.class, unoApp.newDocument("simpress")); 357*eba4d44aSLiu Zhe drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 358*eba4d44aSLiu Zhe XDrawPagesSupplier.class, impressDocument); 359*eba4d44aSLiu Zhe drawpages = drawsupplier.getDrawPages(); 360*eba4d44aSLiu Zhe drawpages.insertNewByIndex(1); 361*eba4d44aSLiu Zhe xpage = PageUtil.getDrawPageByIndex(impressDocument, 1); 362*eba4d44aSLiu Zhe } 363*eba4d44aSLiu Zhe 364*eba4d44aSLiu Zhe /** 365*eba4d44aSLiu Zhe * Save presentation and reLoad the presentation and shape in it. 366*eba4d44aSLiu Zhe * 367*eba4d44aSLiu Zhe * @param po 368*eba4d44aSLiu Zhe * @param shapeType 369*eba4d44aSLiu Zhe * @return 370*eba4d44aSLiu Zhe * @throws Exception 371*eba4d44aSLiu Zhe */ 372*eba4d44aSLiu Zhe public XShape saveAndLoadShape(int pageIndex, int shapeIndex) throws Exception { 373*eba4d44aSLiu Zhe reLoadFile = saveAndReloadDoc(impressDocument, 374*eba4d44aSLiu Zhe "impress8", "odp"); 375*eba4d44aSLiu Zhe xShapes=ShapeUtil.getShapes(reLoadFile, pageIndex); 376*eba4d44aSLiu Zhe return (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(shapeIndex)); 377*eba4d44aSLiu Zhe } 378*eba4d44aSLiu Zhe /** 379*eba4d44aSLiu Zhe * save and reload Presentation document. 380*eba4d44aSLiu Zhe * 381*eba4d44aSLiu Zhe * @param presentationDocument 382*eba4d44aSLiu Zhe * @param sFilter 383*eba4d44aSLiu Zhe * @param sExtension 384*eba4d44aSLiu Zhe * @return 385*eba4d44aSLiu Zhe * @throws Exception 386*eba4d44aSLiu Zhe */ 387*eba4d44aSLiu Zhe private XComponent saveAndReloadDoc(XComponent presentationDocument, 388*eba4d44aSLiu Zhe String sFilter, String sExtension) throws Exception { 389*eba4d44aSLiu Zhe filePath = Testspace.getPath("tmp/presentationtest." + sExtension); 390*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties = new PropertyValue[2]; 391*eba4d44aSLiu Zhe aStoreProperties[0] = new PropertyValue(); 392*eba4d44aSLiu Zhe aStoreProperties[1] = new PropertyValue(); 393*eba4d44aSLiu Zhe aStoreProperties[0].Name = "Override"; 394*eba4d44aSLiu Zhe aStoreProperties[0].Value = true; 395*eba4d44aSLiu Zhe aStoreProperties[1].Name = "FilterName"; 396*eba4d44aSLiu Zhe aStoreProperties[1].Value = sFilter; 397*eba4d44aSLiu Zhe XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 398*eba4d44aSLiu Zhe XStorable.class, presentationDocument); 399*eba4d44aSLiu Zhe xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 400*eba4d44aSLiu Zhe 401*eba4d44aSLiu Zhe return (XComponent) UnoRuntime.queryInterface(XComponent.class, 402*eba4d44aSLiu Zhe unoApp.loadDocument(filePath)); 403*eba4d44aSLiu Zhe } 404*eba4d44aSLiu Zhe 405*eba4d44aSLiu Zhe } 406