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.textbox; 22*eba4d44aSLiu Zhe 23*eba4d44aSLiu Zhe import static org.junit.Assert.assertEquals; 24*eba4d44aSLiu Zhe 25*eba4d44aSLiu Zhe import org.junit.After; 26*eba4d44aSLiu Zhe import org.junit.Before; 27*eba4d44aSLiu Zhe import org.junit.Test; 28*eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil; 29*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace; 30*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 31*eba4d44aSLiu Zhe 32*eba4d44aSLiu Zhe import testlib.uno.PageUtil; 33*eba4d44aSLiu Zhe import testlib.uno.ShapeUtil; 34*eba4d44aSLiu Zhe import testlib.uno.TestUtil; 35*eba4d44aSLiu Zhe 36*eba4d44aSLiu Zhe import com.sun.star.awt.Gradient; 37*eba4d44aSLiu Zhe import com.sun.star.awt.GradientStyle; 38*eba4d44aSLiu Zhe import com.sun.star.awt.Point; 39*eba4d44aSLiu Zhe import com.sun.star.awt.Size; 40*eba4d44aSLiu Zhe import com.sun.star.beans.PropertyValue; 41*eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet; 42*eba4d44aSLiu Zhe import com.sun.star.drawing.FillStyle; 43*eba4d44aSLiu Zhe import com.sun.star.drawing.Hatch; 44*eba4d44aSLiu Zhe import com.sun.star.drawing.HatchStyle; 45*eba4d44aSLiu Zhe import com.sun.star.drawing.TextVerticalAdjust; 46*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPage; 47*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPages; 48*eba4d44aSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier; 49*eba4d44aSLiu Zhe import com.sun.star.drawing.XShape; 50*eba4d44aSLiu Zhe import com.sun.star.drawing.XShapes; 51*eba4d44aSLiu Zhe import com.sun.star.frame.XStorable; 52*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent; 53*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentation; 54*eba4d44aSLiu Zhe import com.sun.star.presentation.XPresentationSupplier; 55*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 56*eba4d44aSLiu Zhe 57*eba4d44aSLiu Zhe public class FillProperties { 58*eba4d44aSLiu Zhe UnoApp unoApp = new UnoApp(); 59*eba4d44aSLiu Zhe XPresentationSupplier sdDocument = null; 60*eba4d44aSLiu Zhe XPresentation pre = null; 61*eba4d44aSLiu Zhe XComponent precomp = null; 62*eba4d44aSLiu Zhe XComponent impressDocument = null; 63*eba4d44aSLiu Zhe XComponent reLoadFile = null; 64*eba4d44aSLiu Zhe XDrawPagesSupplier drawsupplier = null; 65*eba4d44aSLiu Zhe XDrawPages drawpages = null; 66*eba4d44aSLiu Zhe XShapes xShapes = null; 67*eba4d44aSLiu Zhe XDrawPage xpage = null; 68*eba4d44aSLiu Zhe String filePath = null; 69*eba4d44aSLiu Zhe 70*eba4d44aSLiu Zhe @Before setUp()71*eba4d44aSLiu Zhe public void setUp() throws Exception { 72*eba4d44aSLiu Zhe unoApp.start(); 73*eba4d44aSLiu Zhe createDocumentAndSlide(); 74*eba4d44aSLiu Zhe } 75*eba4d44aSLiu Zhe 76*eba4d44aSLiu Zhe @After tearDown()77*eba4d44aSLiu Zhe public void tearDown() throws Exception { 78*eba4d44aSLiu Zhe unoApp.closeDocument(impressDocument); 79*eba4d44aSLiu Zhe unoApp.closeDocument(reLoadFile); 80*eba4d44aSLiu Zhe unoApp.close(); 81*eba4d44aSLiu Zhe if (filePath != null) 82*eba4d44aSLiu Zhe FileUtil.deleteFile(filePath); 83*eba4d44aSLiu Zhe } 84*eba4d44aSLiu Zhe 85*eba4d44aSLiu Zhe /** 86*eba4d44aSLiu Zhe * test Insert text to an Textbox 87*eba4d44aSLiu Zhe * 88*eba4d44aSLiu Zhe * @throws Exception 89*eba4d44aSLiu Zhe */ 90*eba4d44aSLiu Zhe @Test testInsertTextToTextbox()91*eba4d44aSLiu Zhe public void testInsertTextToTextbox() throws Exception { 92*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 93*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 94*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 95*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.TextShape"); 96*eba4d44aSLiu Zhe xShapes.add(xShape); 97*eba4d44aSLiu Zhe xShape = saveAndLoadShape(1, 0); 98*eba4d44aSLiu Zhe ShapeUtil.addPortion(xShape, "test", false); 99*eba4d44aSLiu Zhe assertEquals("Not put text correctly", "test", 100*eba4d44aSLiu Zhe ShapeUtil.getPortion(xShape)); 101*eba4d44aSLiu Zhe } 102*eba4d44aSLiu Zhe 103*eba4d44aSLiu Zhe /** 104*eba4d44aSLiu Zhe * test textbox fill with Gradient 105*eba4d44aSLiu Zhe * 106*eba4d44aSLiu Zhe * @throws Exception 107*eba4d44aSLiu Zhe */ 108*eba4d44aSLiu Zhe @Test testFillGradient()109*eba4d44aSLiu Zhe public void testFillGradient() throws Exception { 110*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 111*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 112*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 113*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.TextShape"); 114*eba4d44aSLiu Zhe xShapes.add(xShape); 115*eba4d44aSLiu Zhe ShapeUtil.addPortion(xShape, "test", false); 116*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 117*eba4d44aSLiu Zhe XPropertySet.class, xShape); 118*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.GRADIENT); 119*eba4d44aSLiu Zhe Gradient aGradient = new Gradient(); 120*eba4d44aSLiu Zhe aGradient.Style = GradientStyle.LINEAR; 121*eba4d44aSLiu Zhe aGradient.StartColor = 0x00ff00; 122*eba4d44aSLiu Zhe aGradient.EndColor = 0xffff00; 123*eba4d44aSLiu Zhe aGradient.Angle = 450; 124*eba4d44aSLiu Zhe aGradient.Border = 0; 125*eba4d44aSLiu Zhe aGradient.XOffset = 0; 126*eba4d44aSLiu Zhe aGradient.YOffset = 0; 127*eba4d44aSLiu Zhe aGradient.StartIntensity = 100; 128*eba4d44aSLiu Zhe aGradient.EndIntensity = 100; 129*eba4d44aSLiu Zhe aGradient.StepCount = 10; 130*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillGradient", aGradient); 131*eba4d44aSLiu Zhe // -------------------------- 132*eba4d44aSLiu Zhe xShape = saveAndLoadShape(1, 0); 133*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, 134*eba4d44aSLiu Zhe xShape); 135*eba4d44aSLiu Zhe // ---------------------------- 136*eba4d44aSLiu Zhe assertEquals("Not Gradient Fill Style", FillStyle.GRADIENT, 137*eba4d44aSLiu Zhe xPropSet.getPropertyValue("FillStyle")); 138*eba4d44aSLiu Zhe aGradient = (Gradient) xPropSet.getPropertyValue("FillGradient"); 139*eba4d44aSLiu Zhe assertEquals("Not Linear Gradient", GradientStyle.LINEAR, 140*eba4d44aSLiu Zhe aGradient.Style); 141*eba4d44aSLiu Zhe } 142*eba4d44aSLiu Zhe 143*eba4d44aSLiu Zhe /** 144*eba4d44aSLiu Zhe * test textbox fill with yellow color 145*eba4d44aSLiu Zhe * 146*eba4d44aSLiu Zhe * @throws Exception 147*eba4d44aSLiu Zhe */ 148*eba4d44aSLiu Zhe @Test testFillColor()149*eba4d44aSLiu Zhe public void testFillColor() throws Exception { 150*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 151*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 152*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 153*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.TextShape"); 154*eba4d44aSLiu Zhe xShapes.add(xShape); 155*eba4d44aSLiu Zhe ShapeUtil.addPortion(xShape, "test", false); 156*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 157*eba4d44aSLiu Zhe XPropertySet.class, xShape); 158*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.SOLID); 159*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillColor", 0xffff00); 160*eba4d44aSLiu Zhe // -------------------------- 161*eba4d44aSLiu Zhe xShape = saveAndLoadShape(1, 0); 162*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, 163*eba4d44aSLiu Zhe xShape); 164*eba4d44aSLiu Zhe // ---------------------------------------------------- 165*eba4d44aSLiu Zhe assertEquals("Not Color Fill Style", FillStyle.SOLID, 166*eba4d44aSLiu Zhe xPropSet.getPropertyValue("FillStyle")); 167*eba4d44aSLiu Zhe assertEquals("Not Yellow Color Fill", 0xffff00, 168*eba4d44aSLiu Zhe xPropSet.getPropertyValue("FillColor")); 169*eba4d44aSLiu Zhe } 170*eba4d44aSLiu Zhe 171*eba4d44aSLiu Zhe /** 172*eba4d44aSLiu Zhe * test textbox fill with Hatch Style(Pattern in MS) 173*eba4d44aSLiu Zhe * 174*eba4d44aSLiu Zhe * @throws Exception 175*eba4d44aSLiu Zhe */ 176*eba4d44aSLiu Zhe @Test testFillHatch()177*eba4d44aSLiu Zhe public void testFillHatch() throws Exception { 178*eba4d44aSLiu Zhe Point po = new Point(1000, 8000); 179*eba4d44aSLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 180*eba4d44aSLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 181*eba4d44aSLiu Zhe 5000, 5000), "com.sun.star.drawing.TextShape"); 182*eba4d44aSLiu Zhe xShapes.add(xShape); 183*eba4d44aSLiu Zhe ShapeUtil.addPortion(xShape, "test", false); 184*eba4d44aSLiu Zhe XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( 185*eba4d44aSLiu Zhe XPropertySet.class, xShape); 186*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillStyle", FillStyle.HATCH); 187*eba4d44aSLiu Zhe Hatch aHatch = new Hatch(); 188*eba4d44aSLiu Zhe aHatch.Style = HatchStyle.DOUBLE; 189*eba4d44aSLiu Zhe aHatch.Color = 0x00ff00; 190*eba4d44aSLiu Zhe aHatch.Distance = 100; 191*eba4d44aSLiu Zhe aHatch.Angle = 450; 192*eba4d44aSLiu Zhe xPropSet.setPropertyValue("FillHatch", aHatch); 193*eba4d44aSLiu Zhe 194*eba4d44aSLiu Zhe // -------------------------- 195*eba4d44aSLiu Zhe xShape = saveAndLoadShape(1, 0); 196*eba4d44aSLiu Zhe xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, 197*eba4d44aSLiu Zhe xShape); 198*eba4d44aSLiu Zhe // ---------------------------- 199*eba4d44aSLiu Zhe assertEquals("Not Gradient Fill Style", FillStyle.HATCH, 200*eba4d44aSLiu Zhe xPropSet.getPropertyValue("FillStyle")); 201*eba4d44aSLiu Zhe aHatch = (Hatch) xPropSet.getPropertyValue("FillHatch"); 202*eba4d44aSLiu Zhe assertEquals("Not Double Hatch", HatchStyle.DOUBLE, aHatch.Style); 203*eba4d44aSLiu Zhe } 204*eba4d44aSLiu Zhe 205*eba4d44aSLiu Zhe /** 206*eba4d44aSLiu Zhe * create a new presentation document and insert a new slide. 207*eba4d44aSLiu Zhe * 208*eba4d44aSLiu Zhe * @throws Exception 209*eba4d44aSLiu Zhe */ createDocumentAndSlide()210*eba4d44aSLiu Zhe public void createDocumentAndSlide() throws Exception { 211*eba4d44aSLiu Zhe impressDocument = (XComponent) UnoRuntime.queryInterface( 212*eba4d44aSLiu Zhe XComponent.class, unoApp.newDocument("simpress")); 213*eba4d44aSLiu Zhe drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 214*eba4d44aSLiu Zhe XDrawPagesSupplier.class, impressDocument); 215*eba4d44aSLiu Zhe drawpages = drawsupplier.getDrawPages(); 216*eba4d44aSLiu Zhe drawpages.insertNewByIndex(1); 217*eba4d44aSLiu Zhe xpage = PageUtil.getDrawPageByIndex(impressDocument, 1); 218*eba4d44aSLiu Zhe } 219*eba4d44aSLiu Zhe 220*eba4d44aSLiu Zhe /** 221*eba4d44aSLiu Zhe * Save presentation and reLoad the presentation and shape in it. 222*eba4d44aSLiu Zhe * 223*eba4d44aSLiu Zhe * @param po 224*eba4d44aSLiu Zhe * @param shapeType 225*eba4d44aSLiu Zhe * @return 226*eba4d44aSLiu Zhe * @throws Exception 227*eba4d44aSLiu Zhe */ saveAndLoadShape(int pageIndex, int shapeIndex)228*eba4d44aSLiu Zhe public XShape saveAndLoadShape(int pageIndex, int shapeIndex) 229*eba4d44aSLiu Zhe throws Exception { 230*eba4d44aSLiu Zhe reLoadFile = saveAndReloadDoc(impressDocument, "impress8", "odp"); 231*eba4d44aSLiu Zhe xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex); 232*eba4d44aSLiu Zhe return (XShape) UnoRuntime.queryInterface(XShape.class, 233*eba4d44aSLiu Zhe xShapes.getByIndex(shapeIndex)); 234*eba4d44aSLiu Zhe } 235*eba4d44aSLiu Zhe 236*eba4d44aSLiu Zhe /** 237*eba4d44aSLiu Zhe * save and reload Presentation document. 238*eba4d44aSLiu Zhe * 239*eba4d44aSLiu Zhe * @param presentationDocument 240*eba4d44aSLiu Zhe * @param sFilter 241*eba4d44aSLiu Zhe * @param sExtension 242*eba4d44aSLiu Zhe * @return 243*eba4d44aSLiu Zhe * @throws Exception 244*eba4d44aSLiu Zhe */ saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)245*eba4d44aSLiu Zhe private XComponent saveAndReloadDoc(XComponent presentationDocument, 246*eba4d44aSLiu Zhe String sFilter, String sExtension) throws Exception { 247*eba4d44aSLiu Zhe filePath = Testspace.getPath("tmp/textboxfill." + sExtension); 248*eba4d44aSLiu Zhe PropertyValue[] aStoreProperties = new PropertyValue[2]; 249*eba4d44aSLiu Zhe aStoreProperties[0] = new PropertyValue(); 250*eba4d44aSLiu Zhe aStoreProperties[1] = new PropertyValue(); 251*eba4d44aSLiu Zhe aStoreProperties[0].Name = "Override"; 252*eba4d44aSLiu Zhe aStoreProperties[0].Value = true; 253*eba4d44aSLiu Zhe aStoreProperties[1].Name = "FilterName"; 254*eba4d44aSLiu Zhe aStoreProperties[1].Value = sFilter; 255*eba4d44aSLiu Zhe XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 256*eba4d44aSLiu Zhe XStorable.class, presentationDocument); 257*eba4d44aSLiu Zhe xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 258*eba4d44aSLiu Zhe 259*eba4d44aSLiu Zhe return (XComponent) UnoRuntime.queryInterface(XComponent.class, 260*eba4d44aSLiu Zhe unoApp.loadDocument(filePath)); 261*eba4d44aSLiu Zhe } 262*eba4d44aSLiu Zhe } 263