1 package fvt.uno.sw.puretext; 2 3 import static org.junit.Assert.*; 4 5 import org.junit.After; 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.openoffice.test.common.FileUtil; 9 import org.openoffice.test.common.Testspace; 10 import org.openoffice.test.uno.UnoApp; 11 import com.sun.star.text.*; 12 import com.sun.star.beans.*; 13 import com.sun.star.frame.XStorable; 14 import com.sun.star.uno.UnoRuntime; 15 16 public class CharacterFontname { 17 private static final UnoApp app = new UnoApp(); 18 XText xText = null; 19 20 @Before 21 public void setUp() throws Exception { 22 app.start(); 23 24 } 25 26 @After 27 public void tearDown() throws Exception { 28 app.close(); 29 } 30 @Test 31 public void testCharacterFontSetting() throws Exception { 32 XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document 33 xText = xTextDocument.getText(); 34 xText.setString("We are Chinese,they are American. We are all living in one earth!" 35 + "and we all love our home very much!!!We are Chinese,they are American. " + 36 "We are all living in one earth!We are Chinese,they are American. " + 37 "We are all living in one earth!We are Chinese,they are American. " + 38 "We are all living in one earth!We are Chinese,they are American. " + 39 "We are all living in one earth!We are Chinese,they are American. " + 40 "We are all living in one earth!We are Chinese,they are American." + 41 " We are all living in one earth!We are Chinese,they are American. " + 42 "We are all living in one earth!We are Chinese,they are American. " + 43 "We are all living in one earth!We are Chinese,they are American. " + 44 "We are all living in one earth!We are Chinese,they are American. " + 45 "We are all living in one earth!We are Chinese,they are American. " + 46 "We are all living in one earth!We are Chinese,they are American. " + 47 "We are all living in one earth!We are Chinese,they are American. " + 48 "We are all living in one earth!We are Chinese,they are American. " + 49 "We are all living in one earth!We are Chinese,they are American. " + 50 "We are all living in one earth!We are Chinese,they are American. " + 51 "We are all living in one earth!We are Chinese,they are American. " + 52 "We are all living in one earth!We are Chinese,they are American. " + 53 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 54 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 55 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 56 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 57 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 58 "We are all living in one earth!We are all living in one earth!We are Chinese,they are American. " + 59 "We are all living in one earth!"); 60 // create text cursor for selecting and formatting text 61 XTextCursor xTextCursor = xText.createTextCursor(); 62 XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor); 63 xTextCursor.gotoStart(false); 64 xTextCursor.goRight((short) 100, true); 65 xCursorProps.setPropertyValue("CharFontName", "Times New Roman"); 66 xTextCursor.gotoRange(xTextCursor, false); 67 xTextCursor.goRight((short) 100, true); 68 xCursorProps.setPropertyValue("CharFontName", "Arial Black"); 69 xTextCursor.gotoRange(xTextCursor, false); 70 xTextCursor.goRight((short) 100, true); 71 xCursorProps.setPropertyValue("CharFontName", "Aharoni"); 72 xTextCursor.gotoRange(xTextCursor, false); 73 xTextCursor.goRight((short) 100, true); 74 xCursorProps.setPropertyValue("CharFontName", "Agency FB"); 75 xTextCursor.gotoRange(xTextCursor, false); 76 xTextCursor.goRight((short) 100, true); 77 xCursorProps.setPropertyValue("CharFontName", "Algerian"); 78 xTextCursor.gotoRange(xTextCursor, false); 79 xTextCursor.goRight((short) 100, true); 80 xCursorProps.setPropertyValue("CharFontName", "Andalus"); 81 xTextCursor.gotoRange(xTextCursor, false); 82 xTextCursor.goRight((short) 100, true); 83 xCursorProps.setPropertyValue("CharFontName", "Bodoni MT Black"); 84 xTextCursor.gotoRange(xTextCursor, false); 85 xTextCursor.goRight((short) 100, true); 86 xCursorProps.setPropertyValue("CharFontName", "BatangChe"); 87 xTextCursor.gotoRange(xTextCursor, false); 88 xTextCursor.goRight((short) 100, true); 89 xCursorProps.setPropertyValue("CharFontName", "Britannic Bold"); 90 xTextCursor.gotoRange(xTextCursor, false); 91 xTextCursor.goRight((short) 100, true); 92 xCursorProps.setPropertyValue("CharFontName", "Cooper Black"); 93 xTextCursor.gotoRange(xTextCursor, false); 94 xTextCursor.goRight((short) 100, true); 95 xCursorProps.setPropertyValue("CharFontName", "DaunPenh"); 96 xTextCursor.gotoRange(xTextCursor, false); 97 xTextCursor.goRight((short) 100, true); 98 xCursorProps.setPropertyValue("CharFontName", "Estrangelo Edessa"); 99 xTextCursor.gotoRange(xTextCursor, false); 100 xTextCursor.goRight((short) 100, true); 101 xCursorProps.setPropertyValue("CharFontName", "Wingdings"); 102 xTextCursor.gotoRange(xTextCursor, false); 103 xTextCursor.goRight((short) 100, true); 104 xCursorProps.setPropertyValue("CharFontName", "Rage Italic"); 105 xTextCursor.gotoRange(xTextCursor, false); 106 xTextCursor.goRight((short) 100, true); 107 xCursorProps.setPropertyValue("CharFontName", "Symbol"); 108 xTextCursor.gotoRange(xTextCursor, false); 109 xTextCursor.goRight((short) 100, true); 110 xCursorProps.setPropertyValue("CharFontName", "Tw Cen MT Condensed Extra Bold"); 111 xTextCursor.gotoRange(xTextCursor, false); 112 xTextCursor.goRight((short) 100, true); 113 xCursorProps.setPropertyValue("CharFontName", "Vivaldi"); 114 xTextCursor.gotoRange(xTextCursor, false); 115 xTextCursor.goRight((short) 100, true); 116 xCursorProps.setPropertyValue("CharFontName", "SimSun"); 117 xTextCursor.gotoRange(xTextCursor, false); 118 xTextCursor.goRight((short) 100, true); 119 xCursorProps.setPropertyValue("CharFontName", "Lucida Bright"); 120 //save to odt 121 XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 122 PropertyValue[] aStoreProperties_odt = new PropertyValue[2]; 123 aStoreProperties_odt[0] = new PropertyValue(); 124 aStoreProperties_odt[1] = new PropertyValue(); 125 aStoreProperties_odt[0].Name = "Override"; 126 aStoreProperties_odt[0].Value = true; 127 aStoreProperties_odt[1].Name = "FilterName"; 128 aStoreProperties_odt[1].Value = "StarOffice XML (Writer)"; 129 xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt); 130 //save to doc 131 XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument); 132 PropertyValue[] aStoreProperties_doc = new PropertyValue[2]; 133 aStoreProperties_doc[0] = new PropertyValue(); 134 aStoreProperties_doc[1] = new PropertyValue(); 135 aStoreProperties_doc[0].Name = "Override"; 136 aStoreProperties_doc[0].Value = true; 137 aStoreProperties_doc[1].Name = "FilterName"; 138 aStoreProperties_doc[1].Value = "MS Word 97"; 139 xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc); 140 app.closeDocument(xTextDocument); 141 142 //reopen the document and assert font style 143 XTextDocument assertDocument=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 144 XTextCursor xTextCursor_assert = assertDocument.getText().createTextCursor(); 145 XPropertySet xCursorProps_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert); 146 147 xTextCursor_assert.gotoStart(false); 148 xTextCursor_assert.goRight((short) 100, true); 149 assertEquals("Times New Roman",xCursorProps_assert.getPropertyValue("CharFontName")); 150 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 151 xTextCursor_assert.goRight((short) 100, true); 152 assertEquals("Arial Black",xCursorProps_assert.getPropertyValue("CharFontName")); 153 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 154 xTextCursor_assert.goRight((short) 100, true); 155 assertEquals("Aharoni",xCursorProps_assert.getPropertyValue("CharFontName")); 156 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 157 xTextCursor_assert.goRight((short) 100, true); 158 assertEquals("Agency FB",xCursorProps_assert.getPropertyValue("CharFontName")); 159 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 160 xTextCursor_assert.goRight((short) 100, true); 161 assertEquals("Algerian",xCursorProps_assert.getPropertyValue("CharFontName")); 162 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 163 xTextCursor_assert.goRight((short) 100, true); 164 assertEquals("Andalus",xCursorProps_assert.getPropertyValue("CharFontName")); 165 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 166 xTextCursor_assert.goRight((short) 100, true); 167 assertEquals("Bodoni MT Black",xCursorProps_assert.getPropertyValue("CharFontName")); 168 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 169 xTextCursor_assert.goRight((short) 100, true); 170 assertEquals("BatangChe",xCursorProps_assert.getPropertyValue("CharFontName")); 171 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 172 xTextCursor_assert.goRight((short) 100, true); 173 assertEquals("Britannic Bold",xCursorProps_assert.getPropertyValue("CharFontName")); 174 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 175 xTextCursor_assert.goRight((short) 100, true); 176 assertEquals("Cooper Black",xCursorProps_assert.getPropertyValue("CharFontName")); 177 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 178 xTextCursor_assert.goRight((short) 100, true); 179 assertEquals("DaunPenh",xCursorProps_assert.getPropertyValue("CharFontName")); 180 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 181 xTextCursor_assert.goRight((short) 100, true); 182 assertEquals("Estrangelo Edessa",xCursorProps_assert.getPropertyValue("CharFontName")); 183 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 184 xTextCursor_assert.goRight((short) 100, true); 185 assertEquals("Wingdings",xCursorProps_assert.getPropertyValue("CharFontName")); 186 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 187 xTextCursor_assert.goRight((short) 100, true); 188 assertEquals("Rage Italic",xCursorProps_assert.getPropertyValue("CharFontName")); 189 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 190 xTextCursor_assert.goRight((short) 100, true); 191 assertEquals("Symbol",xCursorProps_assert.getPropertyValue("CharFontName")); 192 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 193 xTextCursor_assert.goRight((short) 100, true); 194 assertEquals("Tw Cen MT Condensed Extra Bold",xCursorProps_assert.getPropertyValue("CharFontName")); 195 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 196 xTextCursor_assert.goRight((short) 100, true); 197 assertEquals("Vivaldi",xCursorProps_assert.getPropertyValue("CharFontName")); 198 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 199 xTextCursor_assert.goRight((short) 100, true); 200 assertEquals("SimSun",xCursorProps_assert.getPropertyValue("CharFontName")); 201 xTextCursor_assert.gotoRange(xTextCursor_assert, false); 202 xTextCursor_assert.goRight((short) 100, true); 203 assertEquals("Lucida Bright",xCursorProps_assert.getPropertyValue("CharFontName")); 204 205 //reopen the document and assert font style 206 XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt"))); 207 XTextCursor xTextCursor_assert_doc = assertDocument_doc.getText().createTextCursor(); 208 XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor_assert_doc); 209 210 xTextCursor_assert_doc.gotoStart(false); 211 xTextCursor_assert_doc.goRight((short) 100, true); 212 assertEquals("Times New Roman",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 213 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 214 xTextCursor_assert_doc.goRight((short) 100, true); 215 assertEquals("Arial Black",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 216 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 217 xTextCursor_assert_doc.goRight((short) 100, true); 218 assertEquals("Aharoni",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 219 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 220 xTextCursor_assert_doc.goRight((short) 100, true); 221 assertEquals("Agency FB",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 222 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 223 xTextCursor_assert_doc.goRight((short) 100, true); 224 assertEquals("Algerian",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 225 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 226 xTextCursor_assert_doc.goRight((short) 100, true); 227 assertEquals("Andalus",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 228 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 229 xTextCursor_assert_doc.goRight((short) 100, true); 230 assertEquals("Bodoni MT Black",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 231 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 232 xTextCursor_assert_doc.goRight((short) 100, true); 233 assertEquals("BatangChe",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 234 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 235 xTextCursor_assert_doc.goRight((short) 100, true); 236 assertEquals("Britannic Bold",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 237 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 238 xTextCursor_assert_doc.goRight((short) 100, true); 239 assertEquals("Cooper Black",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 240 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 241 xTextCursor_assert_doc.goRight((short) 100, true); 242 assertEquals("DaunPenh",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 243 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 244 xTextCursor_assert_doc.goRight((short) 100, true); 245 assertEquals("Estrangelo Edessa",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 246 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 247 xTextCursor_assert_doc.goRight((short) 100, true); 248 assertEquals("Wingdings",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 249 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 250 xTextCursor_assert_doc.goRight((short) 100, true); 251 assertEquals("Rage Italic",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 252 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 253 xTextCursor_assert_doc.goRight((short) 100, true); 254 assertEquals("Symbol",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 255 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 256 xTextCursor_assert_doc.goRight((short) 100, true); 257 assertEquals("Tw Cen MT Condensed Extra Bold",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 258 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 259 xTextCursor_assert_doc.goRight((short) 100, true); 260 assertEquals("Vivaldi",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 261 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 262 xTextCursor_assert_doc.goRight((short) 100, true); 263 assertEquals("SimSun",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 264 xTextCursor_assert_doc.gotoRange(xTextCursor_assert_doc, false); 265 xTextCursor_assert_doc.goRight((short) 100, true); 266 assertEquals("Lucida Bright",xCursorProps_assert_doc.getPropertyValue("CharFontName")); 267 } 268 } 269