1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski package fvt.uno.sw.paragraph; 23*b1cdbd2cSJim Jagielski 24*b1cdbd2cSJim Jagielski import static org.junit.Assert.*; 25*b1cdbd2cSJim Jagielski 26*b1cdbd2cSJim Jagielski import org.junit.After; 27*b1cdbd2cSJim Jagielski import org.junit.Before; 28*b1cdbd2cSJim Jagielski import org.junit.Ignore; 29*b1cdbd2cSJim Jagielski import org.junit.Test; 30*b1cdbd2cSJim Jagielski import org.openoffice.test.common.FileUtil; 31*b1cdbd2cSJim Jagielski import org.openoffice.test.common.Testspace; 32*b1cdbd2cSJim Jagielski import org.openoffice.test.uno.UnoApp; 33*b1cdbd2cSJim Jagielski import com.sun.star.text.*; 34*b1cdbd2cSJim Jagielski import com.sun.star.beans.*; 35*b1cdbd2cSJim Jagielski import com.sun.star.frame.XStorable; 36*b1cdbd2cSJim Jagielski import com.sun.star.uno.UnoRuntime; 37*b1cdbd2cSJim Jagielski 38*b1cdbd2cSJim Jagielski public class ParagraphIndentAndSpacing { 39*b1cdbd2cSJim Jagielski private static final UnoApp app = new UnoApp(); 40*b1cdbd2cSJim Jagielski XText xText = null; 41*b1cdbd2cSJim Jagielski 42*b1cdbd2cSJim Jagielski @Before setUp()43*b1cdbd2cSJim Jagielski public void setUp() throws Exception { 44*b1cdbd2cSJim Jagielski app.start(); 45*b1cdbd2cSJim Jagielski 46*b1cdbd2cSJim Jagielski } 47*b1cdbd2cSJim Jagielski 48*b1cdbd2cSJim Jagielski @After tearDown()49*b1cdbd2cSJim Jagielski public void tearDown() throws Exception { 50*b1cdbd2cSJim Jagielski app.close(); 51*b1cdbd2cSJim Jagielski } 52*b1cdbd2cSJim Jagielski /* 53*b1cdbd2cSJim Jagielski * test paragraph spacing 54*b1cdbd2cSJim Jagielski * 1.new a text document 55*b1cdbd2cSJim Jagielski * 2.insert some text 56*b1cdbd2cSJim Jagielski * 3.set paragraph spacing:before text,after text,above paragraph,below paragraph 57*b1cdbd2cSJim Jagielski * 4.save to odt and close it 58*b1cdbd2cSJim Jagielski * 5.reopen the saved document and check the paragraph spacing 59*b1cdbd2cSJim Jagielski */ 60*b1cdbd2cSJim Jagielski @Test testParagraphSpacingSetting()61*b1cdbd2cSJim Jagielski public void testParagraphSpacingSetting() throws Exception { 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 64*b1cdbd2cSJim Jagielski xText = xTextDocument.getText(); 65*b1cdbd2cSJim Jagielski 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!" + 66*b1cdbd2cSJim Jagielski "Hello,world!Hello,world!"); 67*b1cdbd2cSJim Jagielski // create text cursor for selecting and formatting text 68*b1cdbd2cSJim Jagielski XTextCursor xTextCursor = xText.createTextCursor(); 69*b1cdbd2cSJim Jagielski XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 70*b1cdbd2cSJim Jagielski //set paragraph margin with page border 71*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaLeftMargin",2000); 72*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaRightMargin",3000); 73*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaTopMargin",1000); 74*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaBottomMargin",4000); 75*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaFirstLineIndent",4000); 76*b1cdbd2cSJim Jagielski 77*b1cdbd2cSJim Jagielski //save to odt 78*b1cdbd2cSJim Jagielski XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 79*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 80*b1cdbd2cSJim Jagielski aStoreProperties_odt[0] = new PropertyValue(); 81*b1cdbd2cSJim Jagielski aStoreProperties_odt[1] = new PropertyValue(); 82*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Name = "Override"; 83*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Value = true; 84*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Name = "FilterName"; 85*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 86*b1cdbd2cSJim Jagielski xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 87*b1cdbd2cSJim Jagielski //save to doc 88*b1cdbd2cSJim Jagielski XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 89*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 90*b1cdbd2cSJim Jagielski aStoreProperties_doc[0] = new PropertyValue(); 91*b1cdbd2cSJim Jagielski aStoreProperties_doc[1] = new PropertyValue(); 92*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Name = "Override"; 93*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Value = true; 94*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Name = "FilterName"; 95*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Value = "MS Word 97"; 96*b1cdbd2cSJim Jagielski xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 97*b1cdbd2cSJim Jagielski app.closeDocument(xTextDocument); 98*b1cdbd2cSJim Jagielski 99*b1cdbd2cSJim Jagielski //reopen the document and assert line spacing 100*b1cdbd2cSJim Jagielski XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 101*b1cdbd2cSJim Jagielski XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 102*b1cdbd2cSJim Jagielski //verify paragraph indent and spacing 103*b1cdbd2cSJim Jagielski assertEquals("assert before text margin",2000,xCursorProps_Assert_odt.getPropertyValue("ParaLeftMargin")); 104*b1cdbd2cSJim Jagielski assertEquals("assert after text margin",3000,xCursorProps_Assert_odt.getPropertyValue("ParaRightMargin")); 105*b1cdbd2cSJim Jagielski assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_odt.getPropertyValue("ParaTopMargin")); 106*b1cdbd2cSJim Jagielski assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_odt.getPropertyValue("ParaBottomMargin")); 107*b1cdbd2cSJim Jagielski assertEquals("assert first line indent",4001,xCursorProps_Assert_odt.getPropertyValue("ParaFirstLineIndent")); 108*b1cdbd2cSJim Jagielski assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent")); 109*b1cdbd2cSJim Jagielski 110*b1cdbd2cSJim Jagielski //reopen the document and assert line spacing 111*b1cdbd2cSJim Jagielski XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 112*b1cdbd2cSJim Jagielski XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 113*b1cdbd2cSJim Jagielski //verify paragraph indent and spacing 114*b1cdbd2cSJim Jagielski assertEquals("assert before text margin",2000,xCursorProps_Assert_doc.getPropertyValue("ParaLeftMargin")); 115*b1cdbd2cSJim Jagielski assertEquals("assert after text margin",3000,xCursorProps_Assert_doc.getPropertyValue("ParaRightMargin")); 116*b1cdbd2cSJim Jagielski assertEquals("assert above paragraph margin",1000,xCursorProps_Assert_doc.getPropertyValue("ParaTopMargin")); 117*b1cdbd2cSJim Jagielski assertEquals("assert below paragraph margin",4001,xCursorProps_Assert_doc.getPropertyValue("ParaBottomMargin")); 118*b1cdbd2cSJim Jagielski assertEquals("assert first line indent",4001,xCursorProps_Assert_doc.getPropertyValue("ParaFirstLineIndent")); 119*b1cdbd2cSJim Jagielski assertEquals("assert paragraph first line is no autoindent",false,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent")); 120*b1cdbd2cSJim Jagielski } 121*b1cdbd2cSJim Jagielski @Test@Ignore("Bug #120646 - [testUNO patch]the auto indent effect of first line lost when save to doc") testParagraphIndent()122*b1cdbd2cSJim Jagielski public void testParagraphIndent() throws Exception { 123*b1cdbd2cSJim Jagielski 124*b1cdbd2cSJim Jagielski XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 125*b1cdbd2cSJim Jagielski xText = xTextDocument.getText(); 126*b1cdbd2cSJim Jagielski 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!" + 127*b1cdbd2cSJim Jagielski "Hello,world!Hello,world!"); 128*b1cdbd2cSJim Jagielski // create text cursor for selecting and formatting text 129*b1cdbd2cSJim Jagielski XTextCursor xTextCursor = xText.createTextCursor(); 130*b1cdbd2cSJim Jagielski XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 131*b1cdbd2cSJim Jagielski //set paragraph margin with page border 132*b1cdbd2cSJim Jagielski xCursorProps.setPropertyValue("ParaIsAutoFirstLineIndent",true); 133*b1cdbd2cSJim Jagielski 134*b1cdbd2cSJim Jagielski //save to odt 135*b1cdbd2cSJim Jagielski XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 136*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 137*b1cdbd2cSJim Jagielski aStoreProperties_odt[0] = new PropertyValue(); 138*b1cdbd2cSJim Jagielski aStoreProperties_odt[1] = new PropertyValue(); 139*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Name = "Override"; 140*b1cdbd2cSJim Jagielski aStoreProperties_odt[0].Value = true; 141*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Name = "FilterName"; 142*b1cdbd2cSJim Jagielski aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 143*b1cdbd2cSJim Jagielski xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 144*b1cdbd2cSJim Jagielski //save to doc 145*b1cdbd2cSJim Jagielski XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 146*b1cdbd2cSJim Jagielski PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 147*b1cdbd2cSJim Jagielski aStoreProperties_doc[0] = new PropertyValue(); 148*b1cdbd2cSJim Jagielski aStoreProperties_doc[1] = new PropertyValue(); 149*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Name = "Override"; 150*b1cdbd2cSJim Jagielski aStoreProperties_doc[0].Value = true; 151*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Name = "FilterName"; 152*b1cdbd2cSJim Jagielski aStoreProperties_doc[1].Value = "MS Word 97"; 153*b1cdbd2cSJim Jagielski xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 154*b1cdbd2cSJim Jagielski app.closeDocument(xTextDocument); 155*b1cdbd2cSJim Jagielski 156*b1cdbd2cSJim Jagielski 157*b1cdbd2cSJim Jagielski //reopen the document and assert paragraph indent 158*b1cdbd2cSJim Jagielski XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc"))); 159*b1cdbd2cSJim Jagielski XPropertySet xCursorProps_Assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor()); 160*b1cdbd2cSJim Jagielski //verify paragraph auto indent 161*b1cdbd2cSJim Jagielski assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_doc.getPropertyValue("ParaIsAutoFirstLineIndent")); 162*b1cdbd2cSJim Jagielski 163*b1cdbd2cSJim Jagielski //reopen the document and assert paragraph indent 164*b1cdbd2cSJim Jagielski XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 165*b1cdbd2cSJim Jagielski XPropertySet xCursorProps_Assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor()); 166*b1cdbd2cSJim Jagielski //verify paragraph auto indent 167*b1cdbd2cSJim Jagielski assertEquals("assert paragraph first line is autoindent",true,xCursorProps_Assert_odt.getPropertyValue("ParaIsAutoFirstLineIndent")); 168*b1cdbd2cSJim Jagielski } 169*b1cdbd2cSJim Jagielski 170*b1cdbd2cSJim Jagielski } 171