1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr  *
3*07d7dbdcSHerbert Dürr  * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr  * or more contributor license agreements.  See the NOTICE file
5*07d7dbdcSHerbert Dürr  * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr  * regarding copyright ownership.  The ASF licenses this file
7*07d7dbdcSHerbert Dürr  * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr  * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr  * with the License.  You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr  *
11*07d7dbdcSHerbert Dürr  *   http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr  *
13*07d7dbdcSHerbert Dürr  * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr  * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr  * KIND, either express or implied.  See the License for the
17*07d7dbdcSHerbert Dürr  * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr  * under the License.
19*07d7dbdcSHerbert Dürr  *
20*07d7dbdcSHerbert Dürr  *************************************************************/
21*07d7dbdcSHerbert Dürr 
22eba4d44aSLiu Zhe package fvt.uno.sw.paragraph;
236194dbcdSLiu Zhe 
246194dbcdSLiu Zhe import static org.junit.Assert.*;
256194dbcdSLiu Zhe 
266194dbcdSLiu Zhe import org.junit.After;
276194dbcdSLiu Zhe import org.junit.Before;
286194dbcdSLiu Zhe import org.junit.Test;
296194dbcdSLiu Zhe import org.openoffice.test.common.FileUtil;
306194dbcdSLiu Zhe import org.openoffice.test.common.Testspace;
316194dbcdSLiu Zhe import org.openoffice.test.uno.UnoApp;
326194dbcdSLiu Zhe 
336194dbcdSLiu Zhe import com.sun.star.style.DropCapFormat;
346194dbcdSLiu Zhe import com.sun.star.text.*;
356194dbcdSLiu Zhe import com.sun.star.beans.*;
366194dbcdSLiu Zhe import com.sun.star.frame.XStorable;
376194dbcdSLiu Zhe import com.sun.star.uno.UnoRuntime;
386194dbcdSLiu Zhe 
396194dbcdSLiu Zhe public class ParagraphDropcap {
406194dbcdSLiu Zhe 	private static final UnoApp app = new UnoApp();
416194dbcdSLiu Zhe 	XText xText = null;
426194dbcdSLiu Zhe 
436194dbcdSLiu Zhe 	@Before
setUp()446194dbcdSLiu Zhe 	public void setUp() throws Exception {
456194dbcdSLiu Zhe 		app.start();
466194dbcdSLiu Zhe 
476194dbcdSLiu Zhe 	}
486194dbcdSLiu Zhe 
496194dbcdSLiu Zhe 	@After
tearDown()506194dbcdSLiu Zhe 	public void tearDown() throws Exception {
516194dbcdSLiu Zhe 		app.close();
526194dbcdSLiu Zhe 	}
536194dbcdSLiu Zhe 	/*
546194dbcdSLiu Zhe 	 * test paragraph background color
556194dbcdSLiu Zhe 	 * 1.new a text document
566194dbcdSLiu Zhe 	 * 2.insert some text
576194dbcdSLiu Zhe 	 * 3.set paragraph drop
586194dbcdSLiu Zhe 	 * 4.save and close the document
596194dbcdSLiu Zhe 	 * 5.reload the saved document and check the paragraph drop cap
606194dbcdSLiu Zhe 	 */
616194dbcdSLiu Zhe 	@Test
testParagraphDropcapSetting()626194dbcdSLiu Zhe 	public void testParagraphDropcapSetting() throws Exception {
636194dbcdSLiu Zhe 
646194dbcdSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
656194dbcdSLiu Zhe 		xText = xTextDocument.getText();
666194dbcdSLiu Zhe 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
676194dbcdSLiu Zhe 				"Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
686194dbcdSLiu Zhe 		// create text cursor for selecting and formatting text
696194dbcdSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
706194dbcdSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
716194dbcdSLiu Zhe 		//set paragraph dropcaps
726194dbcdSLiu Zhe 		DropCapFormat dropcapFormat=new DropCapFormat();
736194dbcdSLiu Zhe 		dropcapFormat.Lines=3;
746194dbcdSLiu Zhe 		dropcapFormat.Distance=101;
756194dbcdSLiu Zhe 		dropcapFormat.Count=9;
766194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
776194dbcdSLiu Zhe 		//xCursorProps.setPropertyValue("DropCapWholeWord",true);
786194dbcdSLiu Zhe 		//save to odt
796194dbcdSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
806194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
816194dbcdSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
826194dbcdSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
836194dbcdSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
846194dbcdSLiu Zhe 		aStoreProperties_odt[0].Value = true;
856194dbcdSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
866194dbcdSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
876194dbcdSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
886194dbcdSLiu Zhe 		//save to doc
896194dbcdSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
906194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
916194dbcdSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
926194dbcdSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
936194dbcdSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
946194dbcdSLiu Zhe 		aStoreProperties_doc[0].Value = true;
956194dbcdSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
966194dbcdSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
976194dbcdSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
986194dbcdSLiu Zhe 		app.closeDocument(xTextDocument);
996194dbcdSLiu Zhe 
1006194dbcdSLiu Zhe 		//reopen the document
1016194dbcdSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1026194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1036194dbcdSLiu Zhe 		//verify paragraph dropcap
1046194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
1056194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_odt.Count);
1066194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
1076194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
1086194dbcdSLiu Zhe 
1096194dbcdSLiu Zhe 		//reopen the document
1106194dbcdSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1116194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1126194dbcdSLiu Zhe 		//verify paragraph dropcap
1136194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
1146194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",9,dropcapFormat_assert_doc.Count);
1156194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
1166194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
1176194dbcdSLiu Zhe 	}
1186194dbcdSLiu Zhe 	@Test
testParagraphDropcapWholewordSetting()1196194dbcdSLiu Zhe 	public void testParagraphDropcapWholewordSetting() throws Exception {
1206194dbcdSLiu Zhe 
1216194dbcdSLiu Zhe 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
1226194dbcdSLiu Zhe 		xText = xTextDocument.getText();
1236194dbcdSLiu Zhe 		xText.setString("we are Chinese,they are American.we are all living in one earth!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!" +
1246194dbcdSLiu Zhe 				"Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!Hello,world!");
1256194dbcdSLiu Zhe 		// create text cursor for selecting and formatting text
1266194dbcdSLiu Zhe 		XTextCursor xTextCursor = xText.createTextCursor();
1276194dbcdSLiu Zhe 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
1286194dbcdSLiu Zhe 		//set paragraph dropcaps
1296194dbcdSLiu Zhe 		DropCapFormat dropcapFormat=new DropCapFormat();
1306194dbcdSLiu Zhe 		dropcapFormat.Lines=3;
1316194dbcdSLiu Zhe 		dropcapFormat.Distance=101;
1326194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapFormat",dropcapFormat);
1336194dbcdSLiu Zhe 		xCursorProps.setPropertyValue("DropCapWholeWord",true);
1346194dbcdSLiu Zhe 		//save to odt
1356194dbcdSLiu Zhe 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1366194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
1376194dbcdSLiu Zhe 		aStoreProperties_odt[0] = new PropertyValue();
1386194dbcdSLiu Zhe 		aStoreProperties_odt[1] = new PropertyValue();
1396194dbcdSLiu Zhe 		aStoreProperties_odt[0].Name = "Override";
1406194dbcdSLiu Zhe 		aStoreProperties_odt[0].Value = true;
1416194dbcdSLiu Zhe 		aStoreProperties_odt[1].Name = "FilterName";
1426194dbcdSLiu Zhe 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
1436194dbcdSLiu Zhe 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
1446194dbcdSLiu Zhe 		//save to doc
1456194dbcdSLiu Zhe 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
1466194dbcdSLiu Zhe 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
1476194dbcdSLiu Zhe 		aStoreProperties_doc[0] = new PropertyValue();
1486194dbcdSLiu Zhe 		aStoreProperties_doc[1] = new PropertyValue();
1496194dbcdSLiu Zhe 		aStoreProperties_doc[0].Name = "Override";
1506194dbcdSLiu Zhe 		aStoreProperties_doc[0].Value = true;
1516194dbcdSLiu Zhe 		aStoreProperties_doc[1].Name = "FilterName";
1526194dbcdSLiu Zhe 		aStoreProperties_doc[1].Value = "MS Word 97";
1536194dbcdSLiu Zhe 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
1546194dbcdSLiu Zhe 		app.closeDocument(xTextDocument);
1556194dbcdSLiu Zhe 
1566194dbcdSLiu Zhe 		//reopen the document
1576194dbcdSLiu Zhe 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
1586194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
1596194dbcdSLiu Zhe 		//verify paragraph dropcap
1606194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_odt = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_odt.getPropertyValue("DropCapFormat"));
1616194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",true,xCursorProps_Assert_odt.getPropertyValue("DropCapWholeWord"));
1626194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_odt.Lines);
1636194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_odt.Distance);
1646194dbcdSLiu Zhe 
1656194dbcdSLiu Zhe 		//reopen the document
1666194dbcdSLiu Zhe 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
1676194dbcdSLiu Zhe 		XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
1686194dbcdSLiu Zhe 		//verify paragraph dropcap
1696194dbcdSLiu Zhe 		DropCapFormat dropcapFormat_assert_doc = (DropCapFormat) UnoRuntime.queryInterface(DropCapFormat.class,xCursorProps_Assert_doc.getPropertyValue("DropCapFormat"));
1706194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",3,dropcapFormat_assert_doc.Lines);
1716194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",101,dropcapFormat_assert_doc.Distance);
1726194dbcdSLiu Zhe 		//when save to doc,the DropCapWholeWord option will disable,and enable dropcapFormat.count
1736194dbcdSLiu Zhe 		assertEquals("assert paragraph dropcaps",false,xCursorProps_Assert_doc.getPropertyValue("DropCapWholeWord"));
1746194dbcdSLiu Zhe 	}
1756194dbcdSLiu Zhe }
176