Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TestXSLFTextShape.java 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xslf.usermodel;
  16. import junit.framework.TestCase;
  17. import org.apache.poi.xslf.XSLFTestDataSamples;
  18. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
  19. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
  20. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
  21. import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
  22. import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
  23. import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
  24. import java.awt.Color;
  25. /**
  26. * @author Yegor Kozlov
  27. */
  28. public class TestXSLFTextShape extends TestCase {
  29. public void testLayouts(){
  30. XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
  31. XSLFSlide[] slide = ppt.getSlides();
  32. verifySlide1(slide[0]);
  33. verifySlide2(slide[1]);
  34. verifySlide3(slide[2]);
  35. verifySlide4(slide[3]);
  36. verifySlide7(slide[6]);
  37. verifySlide8(slide[7]);
  38. verifySlide10(slide[9]);
  39. }
  40. void verifySlide1(XSLFSlide slide){
  41. XSLFSlideLayout layout = slide.getSlideLayout();
  42. XSLFShape[] shapes = slide.getShapes();
  43. assertEquals("Title Slide",layout.getName());
  44. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  45. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  46. assertEquals(STPlaceholderType.CTR_TITLE, ph1.getType());
  47. // anchor is not defined in the shape
  48. assertNull(shape1.getSpPr().getXfrm());
  49. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  50. assertNotNull(masterShape1.getSpPr().getXfrm());
  51. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  52. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  53. // none of the following properties are set in the shapes and fetched from the master shape
  54. assertTrue(
  55. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  56. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  57. !bodyPr1.isSetAnchor()
  58. );
  59. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  60. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  61. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  62. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  63. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  64. // now check text properties
  65. assertEquals("Centered Title", shape1.getText());
  66. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  67. assertEquals("Calibri", r1.getFontFamily());
  68. assertEquals(44.0, r1.getFontSize());
  69. assertEquals(Color.black, r1.getFontColor());
  70. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  71. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  72. assertEquals(STPlaceholderType.SUB_TITLE, ph2.getType());
  73. // anchor is not defined in the shape
  74. assertNull(shape2.getSpPr().getXfrm());
  75. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  76. assertNotNull(masterShape2.getSpPr().getXfrm());
  77. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  78. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  79. // none of the following properties are set in the shapes and fetched from the master shape
  80. assertTrue(
  81. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  82. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  83. !bodyPr2.isSetAnchor()
  84. );
  85. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  86. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  87. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  88. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  89. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  90. assertEquals("subtitle", shape2.getText());
  91. XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  92. assertEquals("Calibri", r2.getFontFamily());
  93. assertEquals(32.0, r2.getFontSize());
  94. // TODO fix calculation of tint
  95. //assertEquals(new Color(137, 137, 137), r2.getFontColor());
  96. }
  97. void verifySlide2(XSLFSlide slide){
  98. XSLFSlideLayout layout = slide.getSlideLayout();
  99. XSLFShape[] shapes = slide.getShapes();
  100. assertEquals("Title and Content",layout.getName());
  101. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  102. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  103. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  104. // anchor is not defined in the shape
  105. assertNull(shape1.getSpPr().getXfrm());
  106. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  107. // layout does not have anchor info either, it is in the slide master
  108. assertNull(masterShape1.getSpPr().getXfrm());
  109. masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
  110. assertNotNull(masterShape1.getSpPr().getXfrm());
  111. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  112. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  113. // none of the following properties are set in the shapes and fetched from the master shape
  114. assertTrue(
  115. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  116. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  117. !bodyPr1.isSetAnchor()
  118. );
  119. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  120. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  121. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  122. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  123. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  124. // now check text properties
  125. assertEquals("Title", shape1.getText());
  126. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  127. assertEquals("Calibri", r1.getFontFamily());
  128. assertEquals(44.0, r1.getFontSize());
  129. assertEquals(Color.black, r1.getFontColor());
  130. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  131. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  132. assertFalse(ph2.isSetType()); // <p:ph idx="1"/>
  133. assertTrue(ph2.isSetIdx());
  134. assertEquals(1, ph2.getIdx());
  135. // anchor is not defined in the shape
  136. assertNull(shape2.getSpPr().getXfrm());
  137. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  138. // anchor of the body text is missing in the slide layout, llokup in the slide master
  139. assertNull(masterShape2.getSpPr().getXfrm());
  140. masterShape2 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph2);
  141. assertNotNull(masterShape2.getSpPr().getXfrm());
  142. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  143. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  144. // none of the following properties are set in the shapes and fetched from the master shape
  145. assertTrue(
  146. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  147. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  148. !bodyPr2.isSetAnchor()
  149. );
  150. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  151. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  152. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  153. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  154. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  155. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  156. assertEquals(0, pr1.getParentParagraph().getLevel());
  157. assertEquals("Content", pr1.getText());
  158. assertEquals("Calibri", pr1.getFontFamily());
  159. assertEquals(32.0, pr1.getFontSize());
  160. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  161. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  162. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  163. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  164. assertEquals(1, pr2.getParentParagraph().getLevel());
  165. assertEquals("Level 2", pr2.getText());
  166. assertEquals("Calibri", pr2.getFontFamily());
  167. assertEquals(28.0, pr2.getFontSize());
  168. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  169. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  170. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  171. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  172. assertEquals(2, pr3.getParentParagraph().getLevel());
  173. assertEquals("Level 3", pr3.getText());
  174. assertEquals("Calibri", pr3.getFontFamily());
  175. assertEquals(24.0, pr3.getFontSize());
  176. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  177. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  178. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  179. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  180. assertEquals(3, pr4.getParentParagraph().getLevel());
  181. assertEquals("Level 4", pr4.getText());
  182. assertEquals("Calibri", pr4.getFontFamily());
  183. assertEquals(20.0, pr4.getFontSize());
  184. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  185. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  186. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  187. XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
  188. assertEquals(4, pr5.getParentParagraph().getLevel());
  189. assertEquals("Level 5", pr5.getText());
  190. assertEquals("Calibri", pr5.getFontFamily());
  191. assertEquals(20.0, pr5.getFontSize());
  192. assertEquals(162.0, pr5.getParentParagraph().getLeftMargin());
  193. assertEquals("\u00bb", pr5.getParentParagraph().getBulletCharacter());
  194. assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
  195. }
  196. void verifySlide3(XSLFSlide slide){
  197. XSLFSlideLayout layout = slide.getSlideLayout();
  198. XSLFShape[] shapes = slide.getShapes();
  199. assertEquals("Section Header",layout.getName());
  200. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  201. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  202. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  203. // anchor is not defined in the shape
  204. assertNull(shape1.getSpPr().getXfrm());
  205. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  206. assertNotNull(masterShape1.getSpPr().getXfrm());
  207. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  208. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  209. // none of the following properties are set in the shapes and fetched from the master shape
  210. assertTrue(
  211. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  212. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  213. !bodyPr1.isSetAnchor()
  214. );
  215. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  216. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  217. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  218. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  219. assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
  220. // now check text properties
  221. assertEquals("Section Title", shape1.getText());
  222. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  223. assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
  224. assertEquals("Calibri", r1.getFontFamily());
  225. assertEquals(40.0, r1.getFontSize());
  226. assertEquals(Color.black, r1.getFontColor());
  227. assertTrue(r1.isBold());
  228. assertFalse(r1.isItalic());
  229. assertFalse(r1.isUnderline());
  230. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  231. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  232. assertEquals(STPlaceholderType.BODY, ph2.getType());
  233. // anchor is not defined in the shape
  234. assertNull(shape2.getSpPr().getXfrm());
  235. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  236. assertNotNull(masterShape2.getSpPr().getXfrm());
  237. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  238. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  239. // none of the following properties are set in the shapes and fetched from the master shape
  240. assertTrue(
  241. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  242. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  243. !bodyPr2.isSetAnchor()
  244. );
  245. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  246. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  247. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  248. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  249. assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
  250. assertEquals("Section Header", shape2.getText());
  251. XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  252. assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
  253. assertEquals("Calibri", r2.getFontFamily());
  254. assertEquals(20.0, r2.getFontSize());
  255. // TODO fix calculation of tint
  256. //assertEquals(new Color(137, 137, 137), r2.getFontColor());
  257. }
  258. void verifySlide4(XSLFSlide slide){
  259. XSLFSlideLayout layout = slide.getSlideLayout();
  260. XSLFShape[] shapes = slide.getShapes();
  261. assertEquals("Two Content",layout.getName());
  262. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  263. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  264. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  265. // anchor is not defined in the shape
  266. assertNull(shape1.getSpPr().getXfrm());
  267. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  268. // layout does not have anchor info either, it is in the slide master
  269. assertNull(masterShape1.getSpPr().getXfrm());
  270. masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
  271. assertNotNull(masterShape1.getSpPr().getXfrm());
  272. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  273. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  274. // none of the following properties are set in the shapes and fetched from the master shape
  275. assertTrue(
  276. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  277. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  278. !bodyPr1.isSetAnchor()
  279. );
  280. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  281. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  282. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  283. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  284. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  285. // now check text properties
  286. assertEquals("Title", shape1.getText());
  287. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  288. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  289. assertEquals("Calibri", r1.getFontFamily());
  290. assertEquals(44.0, r1.getFontSize());
  291. assertEquals(Color.black, r1.getFontColor());
  292. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  293. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  294. assertFalse(ph2.isSetType());
  295. assertTrue(ph2.isSetIdx());
  296. assertEquals(1, ph2.getIdx()); //<p:ph sz="half" idx="1"/>
  297. // anchor is not defined in the shape
  298. assertNull(shape2.getSpPr().getXfrm());
  299. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  300. assertNotNull(masterShape2.getSpPr().getXfrm());
  301. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  302. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  303. // none of the following properties are set in the shapes and fetched from the master shape
  304. assertTrue(
  305. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  306. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  307. !bodyPr2.isSetAnchor()
  308. );
  309. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  310. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  311. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  312. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  313. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  314. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  315. assertEquals(0, pr1.getParentParagraph().getLevel());
  316. assertEquals("Left", pr1.getText());
  317. assertEquals("Calibri", pr1.getFontFamily());
  318. assertEquals(28.0, pr1.getFontSize());
  319. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  320. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  321. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  322. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  323. assertEquals(1, pr2.getParentParagraph().getLevel());
  324. assertEquals("Level 2", pr2.getParentParagraph().getText());
  325. assertEquals("Calibri", pr2.getFontFamily());
  326. assertEquals(24.0, pr2.getFontSize());
  327. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  328. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  329. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  330. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  331. assertEquals(2, pr3.getParentParagraph().getLevel());
  332. assertEquals("Level 3", pr3.getParentParagraph().getText());
  333. assertEquals("Calibri", pr3.getFontFamily());
  334. assertEquals(20.0, pr3.getFontSize());
  335. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  336. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  337. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  338. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  339. assertEquals(3, pr4.getParentParagraph().getLevel());
  340. assertEquals("Level 4", pr4.getParentParagraph().getText());
  341. assertEquals("Calibri", pr4.getFontFamily());
  342. assertEquals(18.0, pr4.getFontSize());
  343. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  344. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  345. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  346. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  347. XSLFTextRun pr5 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
  348. assertEquals(0, pr5.getParentParagraph().getLevel());
  349. assertEquals("Right", pr5.getText());
  350. assertEquals("Calibri", pr5.getFontFamily());
  351. assertEquals(Color.black, pr5.getFontColor());
  352. }
  353. void verifySlide5(XSLFSlide slide){
  354. XSLFSlideLayout layout = slide.getSlideLayout();
  355. XSLFShape[] shapes = slide.getShapes();
  356. // TODO
  357. }
  358. void verifySlide7(XSLFSlide slide){
  359. XSLFSlideLayout layout = slide.getSlideLayout();
  360. XSLFShape[] shapes = slide.getShapes();
  361. assertEquals("Blank",layout.getName());
  362. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  363. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  364. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  365. // anchor is not defined in the shape
  366. assertNull(shape1.getSpPr().getXfrm());
  367. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  368. // none of the following properties are set in the shapes and fetched from the master shape
  369. assertTrue(
  370. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  371. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  372. !bodyPr1.isSetAnchor()
  373. );
  374. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  375. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  376. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  377. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  378. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  379. // now check text properties
  380. assertEquals("Blank with Default Title", shape1.getText());
  381. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  382. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  383. assertEquals("Calibri", r1.getFontFamily());
  384. assertEquals(44.0, r1.getFontSize());
  385. assertEquals(Color.black, r1.getFontColor());
  386. assertFalse(r1.isBold());
  387. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  388. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  389. // none of the following properties are set in the shapes and fetched from the master shape
  390. assertTrue(
  391. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  392. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  393. !bodyPr2.isSetAnchor()
  394. );
  395. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  396. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  397. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  398. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  399. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  400. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  401. assertEquals(0, pr1.getParentParagraph().getLevel());
  402. assertEquals("Default Text", pr1.getText());
  403. assertEquals("Calibri", pr1.getFontFamily());
  404. assertEquals(18.0, pr1.getFontSize());
  405. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  406. assertEquals("Default", shape3.getTextParagraphs().get(0).getText());
  407. assertEquals("Text with levels", shape3.getTextParagraphs().get(1).getText());
  408. assertEquals("Level 1", shape3.getTextParagraphs().get(2).getText());
  409. assertEquals("Level 2", shape3.getTextParagraphs().get(3).getText());
  410. assertEquals("Level 3", shape3.getTextParagraphs().get(4).getText());
  411. for(int p = 0; p < 5; p++) {
  412. XSLFTextParagraph pr = shape3.getTextParagraphs().get(p);
  413. assertEquals("Calibri", pr.getTextRuns().get(0).getFontFamily());
  414. assertEquals(18.0, pr.getTextRuns().get(0).getFontSize());
  415. }
  416. }
  417. void verifySlide8(XSLFSlide slide){
  418. XSLFSlideLayout layout = slide.getSlideLayout();
  419. XSLFShape[] shapes = slide.getShapes();
  420. assertEquals("Content with Caption",layout.getName());
  421. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  422. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  423. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  424. // anchor is not defined in the shape
  425. assertNull(shape1.getSpPr().getXfrm());
  426. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  427. // layout does not have anchor info either, it is in the slide master
  428. assertNotNull(masterShape1.getSpPr().getXfrm());
  429. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  430. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  431. // none of the following properties are set in the shapes and fetched from the master shape
  432. assertTrue(
  433. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  434. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  435. !bodyPr1.isSetAnchor()
  436. );
  437. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  438. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  439. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  440. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  441. assertEquals(VerticalAlignment.BOTTOM, shape1.getVerticalAlignment());
  442. // now check text properties
  443. assertEquals("Caption", shape1.getText());
  444. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  445. assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
  446. assertEquals("Calibri", r1.getFontFamily());
  447. assertEquals(20.0, r1.getFontSize());
  448. assertEquals(Color.black, r1.getFontColor());
  449. assertTrue(r1.isBold());
  450. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  451. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  452. assertFalse(ph2.isSetType());
  453. assertTrue(ph2.isSetIdx());
  454. assertEquals(1, ph2.getIdx());
  455. // anchor is not defined in the shape
  456. assertNull(shape2.getSpPr().getXfrm());
  457. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  458. assertNotNull(masterShape2.getSpPr().getXfrm());
  459. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  460. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  461. // none of the following properties are set in the shapes and fetched from the master shape
  462. assertTrue(
  463. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  464. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  465. !bodyPr2.isSetAnchor()
  466. );
  467. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  468. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  469. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  470. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  471. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  472. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  473. assertEquals(0, pr1.getParentParagraph().getLevel());
  474. assertEquals("Level 1", pr1.getText());
  475. assertEquals("Calibri", pr1.getFontFamily());
  476. assertEquals(32.0, pr1.getFontSize());
  477. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  478. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  479. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  480. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  481. assertEquals(1, pr2.getParentParagraph().getLevel());
  482. assertEquals("Level 2", pr2.getParentParagraph().getText());
  483. assertEquals("Calibri", pr2.getFontFamily());
  484. assertEquals(28.0, pr2.getFontSize());
  485. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  486. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  487. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  488. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  489. assertEquals(2, pr3.getParentParagraph().getLevel());
  490. assertEquals("Level 3", pr3.getParentParagraph().getText());
  491. assertEquals("Calibri", pr3.getFontFamily());
  492. assertEquals(24.0, pr3.getFontSize());
  493. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  494. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  495. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  496. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  497. assertEquals(3, pr4.getParentParagraph().getLevel());
  498. assertEquals("Level 4", pr4.getParentParagraph().getText());
  499. assertEquals("Calibri", pr4.getFontFamily());
  500. assertEquals(20.0, pr4.getFontSize());
  501. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  502. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  503. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  504. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  505. assertEquals(VerticalAlignment.TOP, shape3.getVerticalAlignment());
  506. assertEquals("Content with caption", shape3.getText());
  507. pr1 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
  508. assertEquals(0, pr1.getParentParagraph().getLevel());
  509. assertEquals("Content with caption", pr1.getText());
  510. assertEquals("Calibri", pr1.getFontFamily());
  511. assertEquals(14.0, pr1.getFontSize());
  512. }
  513. void verifySlide10(XSLFSlide slide){
  514. XSLFTextShape footer = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_FTR);
  515. // now check text properties
  516. assertEquals("Apache Software Foundation", footer.getText());
  517. assertEquals(VerticalAlignment.MIDDLE, footer.getVerticalAlignment());
  518. XSLFTextRun r1 = footer.getTextParagraphs().get(0).getTextRuns().get(0);
  519. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  520. assertEquals("Calibri", r1.getFontFamily());
  521. assertEquals(12.0, r1.getFontSize());
  522. // TODO calculation of tint is incorrect
  523. assertEquals(new Color(64,64,64), r1.getFontColor());
  524. XSLFTextShape dt = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_DT);
  525. assertEquals("Friday, October 21, 2011", dt.getText());
  526. XSLFTextShape sldNum = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_SLD_NUM);
  527. assertEquals("10", sldNum.getText());
  528. }
  529. public void testTitleStyles(){
  530. XMLSlideShow ppt = new XMLSlideShow();
  531. XSLFSlideMaster master = ppt.getSlideMasters()[0];
  532. XSLFTheme theme = master.getTheme();
  533. XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE);
  534. XSLFSlide slide = ppt.createSlide(layout) ;
  535. assertSame(layout, slide.getSlideLayout());
  536. assertSame(master, slide.getSlideMaster());
  537. XSLFTextShape titleShape = (XSLFTextShape)slide.getPlaceholder(0);
  538. titleShape.setText("Apache POI");
  539. XSLFTextParagraph paragraph = titleShape.getTextParagraphs().get(0);
  540. XSLFTextRun textRun = paragraph.getTextRuns().get(0);
  541. // level 1 : default title style on the master slide
  542. // /p:sldMaster/p:txStyles/p:titleStyle/a:lvl1pPr
  543. CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getTitleStyle().getLvl1PPr();
  544. CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
  545. assertEquals(4400, lv1CPr.getSz());
  546. assertEquals(44.0, textRun.getFontSize());
  547. assertEquals("+mj-lt", lv1CPr.getLatin().getTypeface());
  548. assertEquals("Calibri", theme.getMajorFont());
  549. assertEquals("Calibri", textRun.getFontFamily());
  550. lv1CPr.setSz(3200);
  551. assertEquals(32.0, textRun.getFontSize());
  552. lv1CPr.getLatin().setTypeface("Arial");
  553. assertEquals("Arial", textRun.getFontFamily());
  554. assertEquals(STTextAlignType.CTR, lv1PPr.getAlgn());
  555. assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
  556. lv1PPr.setAlgn(STTextAlignType.L);
  557. assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
  558. // level 2: title placeholder on the master slide
  559. // /p:sldMaster/p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="title"]
  560. XSLFTextShape tx2 = master.getPlaceholder(0);
  561. CTTextParagraphProperties lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
  562. CTTextCharacterProperties lv2CPr = lv2PPr.addNewDefRPr();
  563. lv2CPr.setSz(3300);
  564. assertEquals(33.0, textRun.getFontSize());
  565. lv2CPr.addNewLatin().setTypeface("Times");
  566. assertEquals("Times", textRun.getFontFamily());
  567. lv2PPr.setAlgn(STTextAlignType.R);
  568. assertEquals(TextAlign.RIGHT, paragraph.getTextAlign());
  569. // level 3: title placeholder on the slide layout
  570. // /p:sldLayout /p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="ctrTitle"]
  571. XSLFTextShape tx3 = layout.getPlaceholder(0);
  572. CTTextParagraphProperties lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
  573. CTTextCharacterProperties lv3CPr = lv3PPr.addNewDefRPr();
  574. lv3CPr.setSz(3400);
  575. assertEquals(34.0, textRun.getFontSize());
  576. lv3CPr.addNewLatin().setTypeface("Courier New");
  577. assertEquals("Courier New", textRun.getFontFamily());
  578. lv3PPr.setAlgn(STTextAlignType.CTR);
  579. assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
  580. // level 4: default text properties in the shape itself
  581. // ./p:sp/p:txBody/a:lstStyle/a:lvl1pPr
  582. CTTextParagraphProperties lv4PPr = titleShape.getTextBody(true).getLstStyle().addNewLvl1PPr();
  583. CTTextCharacterProperties lv4CPr = lv4PPr.addNewDefRPr();
  584. lv4CPr.setSz(3500);
  585. assertEquals(35.0, textRun.getFontSize());
  586. lv4CPr.addNewLatin().setTypeface("Arial");
  587. assertEquals("Arial", textRun.getFontFamily());
  588. lv4PPr.setAlgn(STTextAlignType.L);
  589. assertEquals(TextAlign.LEFT, paragraph.getTextAlign());
  590. // level 5: text properties are defined in the text run
  591. CTTextParagraphProperties lv5PPr = paragraph.getXmlObject().addNewPPr();
  592. CTTextCharacterProperties lv5CPr = textRun.getXmlObject().getRPr();
  593. lv5CPr.setSz(3600);
  594. assertEquals(36.0, textRun.getFontSize());
  595. lv5CPr.addNewLatin().setTypeface("Calibri");
  596. assertEquals("Calibri", textRun.getFontFamily());
  597. lv5PPr.setAlgn(STTextAlignType.CTR);
  598. assertEquals(TextAlign.CENTER, paragraph.getTextAlign());
  599. }
  600. public void testBodyStyles(){
  601. XMLSlideShow ppt = new XMLSlideShow();
  602. XSLFSlideMaster master = ppt.getSlideMasters()[0];
  603. XSLFTheme theme = master.getTheme();
  604. XSLFSlideLayout layout = master.getLayout(SlideLayout.TITLE_AND_CONTENT);
  605. XSLFSlide slide = ppt.createSlide(layout) ;
  606. assertSame(layout, slide.getSlideLayout());
  607. assertSame(master, slide.getSlideMaster());
  608. XSLFTextShape tx1 = (XSLFTextShape)slide.getPlaceholder(1);
  609. tx1.clearText();
  610. XSLFTextParagraph p1 = tx1.addNewTextParagraph();
  611. assertEquals(0, p1.getLevel());
  612. XSLFTextRun r1 = p1.addNewTextRun();
  613. r1.setText("Apache POI");
  614. XSLFTextParagraph p2 = tx1.addNewTextParagraph();
  615. p2.setLevel(1);
  616. assertEquals(1, p2.getLevel());
  617. XSLFTextRun r2 = p2.addNewTextRun();
  618. r2.setText("HSLF");
  619. XSLFTextParagraph p3 = tx1.addNewTextParagraph();
  620. p3.setLevel(2);
  621. assertEquals(2, p3.getLevel());
  622. XSLFTextRun r3 = p3.addNewTextRun();
  623. r3.setText("XSLF");
  624. // level 1 : default title style on the master slide
  625. // /p:sldMaster/p:txStyles/p:bodyStyle/a:lvl1pPr
  626. CTTextParagraphProperties lv1PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl1PPr();
  627. CTTextCharacterProperties lv1CPr = lv1PPr.getDefRPr();
  628. CTTextParagraphProperties lv2PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl2PPr();
  629. CTTextCharacterProperties lv2CPr = lv2PPr.getDefRPr();
  630. CTTextParagraphProperties lv3PPr = master.getXmlObject().getTxStyles().getBodyStyle().getLvl3PPr();
  631. CTTextCharacterProperties lv3CPr = lv3PPr.getDefRPr();
  632. // lv1
  633. assertEquals(3200, lv1CPr.getSz());
  634. assertEquals(32.0, r1.getFontSize());
  635. assertEquals("+mn-lt", lv1CPr.getLatin().getTypeface());
  636. assertEquals("Calibri", theme.getMinorFont());
  637. assertEquals("Calibri", r1.getFontFamily());
  638. lv1CPr.setSz(3300);
  639. assertEquals(33.0, r1.getFontSize());
  640. lv1CPr.getLatin().setTypeface("Arial");
  641. assertEquals("Arial", r1.getFontFamily());
  642. assertEquals(STTextAlignType.L, lv1PPr.getAlgn());
  643. assertEquals(TextAlign.LEFT, p1.getTextAlign());
  644. lv1PPr.setAlgn(STTextAlignType.R);
  645. assertEquals(TextAlign.RIGHT, p1.getTextAlign());
  646. //lv2
  647. assertEquals(2800, lv2CPr.getSz());
  648. assertEquals(28.0, r2.getFontSize());
  649. lv2CPr.setSz(3300);
  650. assertEquals(33.0, r2.getFontSize());
  651. lv2CPr.getLatin().setTypeface("Times");
  652. assertEquals("Times", r2.getFontFamily());
  653. assertEquals(STTextAlignType.L, lv2PPr.getAlgn());
  654. assertEquals(TextAlign.LEFT, p2.getTextAlign());
  655. lv2PPr.setAlgn(STTextAlignType.R);
  656. assertEquals(TextAlign.RIGHT, p2.getTextAlign());
  657. //lv3
  658. assertEquals(2400, lv3CPr.getSz());
  659. assertEquals(24.0, r3.getFontSize());
  660. lv3CPr.setSz(2500);
  661. assertEquals(25.0, r3.getFontSize());
  662. lv3CPr.getLatin().setTypeface("Courier New");
  663. assertEquals("Courier New", r3.getFontFamily());
  664. assertEquals(STTextAlignType.L, lv3PPr.getAlgn());
  665. assertEquals(TextAlign.LEFT, p3.getTextAlign());
  666. lv3PPr.setAlgn(STTextAlignType.R);
  667. assertEquals(TextAlign.RIGHT, p3.getTextAlign());
  668. // level 2: body placeholder on the master slide
  669. // /p:sldMaster/p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="body"]
  670. XSLFTextShape tx2 = master.getPlaceholder(1);
  671. assertEquals(Placeholder.BODY, tx2.getTextType());
  672. lv1PPr = tx2.getTextBody(true).getLstStyle().addNewLvl1PPr();
  673. lv1CPr = lv1PPr.addNewDefRPr();
  674. lv2PPr = tx2.getTextBody(true).getLstStyle().addNewLvl2PPr();
  675. lv2CPr = lv2PPr.addNewDefRPr();
  676. lv3PPr = tx2.getTextBody(true).getLstStyle().addNewLvl3PPr();
  677. lv3CPr = lv3PPr.addNewDefRPr();
  678. lv1CPr.setSz(3300);
  679. assertEquals(33.0, r1.getFontSize());
  680. lv1CPr.addNewLatin().setTypeface("Times");
  681. assertEquals("Times", r1.getFontFamily());
  682. lv1PPr.setAlgn(STTextAlignType.L);
  683. assertEquals(TextAlign.LEFT, p1.getTextAlign());
  684. lv2CPr.setSz(3300);
  685. assertEquals(33.0, r2.getFontSize());
  686. lv2CPr.addNewLatin().setTypeface("Times");
  687. assertEquals("Times", r2.getFontFamily());
  688. lv2PPr.setAlgn(STTextAlignType.L);
  689. assertEquals(TextAlign.LEFT, p2.getTextAlign());
  690. lv3CPr.setSz(3300);
  691. assertEquals(33.0, r3.getFontSize());
  692. lv3CPr.addNewLatin().setTypeface("Times");
  693. assertEquals("Times", r3.getFontFamily());
  694. lv3PPr.setAlgn(STTextAlignType.L);
  695. assertEquals(TextAlign.LEFT, p3.getTextAlign());
  696. // level 3: body placeholder on the slide layout
  697. // /p:sldLayout /p:cSld/p:spTree/p:sp/p:nvPr/p:ph[@type="ctrTitle"]
  698. XSLFTextShape tx3 = layout.getPlaceholder(1);
  699. assertEquals(Placeholder.BODY, tx2.getTextType());
  700. lv1PPr = tx3.getTextBody(true).getLstStyle().addNewLvl1PPr();
  701. lv1CPr = lv1PPr.addNewDefRPr();
  702. lv2PPr = tx3.getTextBody(true).getLstStyle().addNewLvl2PPr();
  703. lv2CPr = lv2PPr.addNewDefRPr();
  704. lv3PPr = tx3.getTextBody(true).getLstStyle().addNewLvl3PPr();
  705. lv3CPr = lv3PPr.addNewDefRPr();
  706. lv1CPr.setSz(3400);
  707. assertEquals(34.0, r1.getFontSize());
  708. lv1CPr.addNewLatin().setTypeface("Courier New");
  709. assertEquals("Courier New", r1.getFontFamily());
  710. lv1PPr.setAlgn(STTextAlignType.CTR);
  711. assertEquals(TextAlign.CENTER, p1.getTextAlign());
  712. lv2CPr.setSz(3400);
  713. assertEquals(34.0, r2.getFontSize());
  714. lv2CPr.addNewLatin().setTypeface("Courier New");
  715. assertEquals("Courier New", r2.getFontFamily());
  716. lv2PPr.setAlgn(STTextAlignType.CTR);
  717. assertEquals(TextAlign.CENTER, p2.getTextAlign());
  718. lv3CPr.setSz(3400);
  719. assertEquals(34.0, r3.getFontSize());
  720. lv3CPr.addNewLatin().setTypeface("Courier New");
  721. assertEquals("Courier New", r3.getFontFamily());
  722. lv3PPr.setAlgn(STTextAlignType.CTR);
  723. assertEquals(TextAlign.CENTER, p3.getTextAlign());
  724. // level 4: default text properties in the shape itself
  725. // ./p:sp/p:txBody/a:lstStyle/a:lvl1pPr
  726. lv1PPr = tx1.getTextBody(true).getLstStyle().addNewLvl1PPr();
  727. lv1CPr = lv1PPr.addNewDefRPr();
  728. lv2PPr = tx1.getTextBody(true).getLstStyle().addNewLvl2PPr();
  729. lv2CPr = lv2PPr.addNewDefRPr();
  730. lv3PPr = tx1.getTextBody(true).getLstStyle().addNewLvl3PPr();
  731. lv3CPr = lv3PPr.addNewDefRPr();
  732. lv1CPr.setSz(3500);
  733. assertEquals(35.0, r1.getFontSize());
  734. lv1CPr.addNewLatin().setTypeface("Arial");
  735. assertEquals("Arial", r1.getFontFamily());
  736. lv1PPr.setAlgn(STTextAlignType.L);
  737. assertEquals(TextAlign.LEFT, p1.getTextAlign());
  738. lv2CPr.setSz(3500);
  739. assertEquals(35.0, r2.getFontSize());
  740. lv2CPr.addNewLatin().setTypeface("Arial");
  741. assertEquals("Arial", r2.getFontFamily());
  742. lv2PPr.setAlgn(STTextAlignType.L);
  743. assertEquals(TextAlign.LEFT, p2.getTextAlign());
  744. lv3CPr.setSz(3500);
  745. assertEquals(35.0, r3.getFontSize());
  746. lv3CPr.addNewLatin().setTypeface("Arial");
  747. assertEquals("Arial", r3.getFontFamily());
  748. lv3PPr.setAlgn(STTextAlignType.L);
  749. assertEquals(TextAlign.LEFT, p3.getTextAlign());
  750. // level 5: text properties are defined in the text run
  751. lv1PPr = p1.getXmlObject().isSetPPr() ? p1.getXmlObject().getPPr() : p1.getXmlObject().addNewPPr();
  752. lv1CPr = r1.getXmlObject().getRPr();
  753. lv2PPr = p2.getXmlObject().isSetPPr() ? p2.getXmlObject().getPPr() : p2.getXmlObject().addNewPPr();
  754. lv2CPr = r2.getXmlObject().getRPr();
  755. lv3PPr = p3.getXmlObject().isSetPPr() ? p3.getXmlObject().getPPr() : p3.getXmlObject().addNewPPr();
  756. lv3CPr = r3.getXmlObject().getRPr();
  757. lv1CPr.setSz(3600);
  758. assertEquals(36.0, r1.getFontSize());
  759. lv1CPr.addNewLatin().setTypeface("Calibri");
  760. assertEquals("Calibri", r1.getFontFamily());
  761. lv1PPr.setAlgn(STTextAlignType.CTR);
  762. assertEquals(TextAlign.CENTER, p1.getTextAlign());
  763. lv2CPr.setSz(3600);
  764. assertEquals(36.0, r2.getFontSize());
  765. lv2CPr.addNewLatin().setTypeface("Calibri");
  766. assertEquals("Calibri", r2.getFontFamily());
  767. lv2PPr.setAlgn(STTextAlignType.CTR);
  768. assertEquals(TextAlign.CENTER, p2.getTextAlign());
  769. lv3CPr.setSz(3600);
  770. assertEquals(36.0, r3.getFontSize());
  771. lv3CPr.addNewLatin().setTypeface("Calibri");
  772. assertEquals("Calibri", r3.getFontFamily());
  773. lv3PPr.setAlgn(STTextAlignType.CTR);
  774. assertEquals(TextAlign.CENTER, p3.getTextAlign());
  775. }
  776. }