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