You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestXSLFTextShape.java 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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.presentationml.x2006.main.STPlaceholderType;
  19. import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
  20. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
  21. import java.awt.*;
  22. /**
  23. * @author Yegor Kozlov
  24. */
  25. public class TestXSLFTextShape extends TestCase {
  26. public void testLayouts(){
  27. XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("layouts.pptx");
  28. XSLFSlide[] slide = ppt.getSlides();
  29. verifySlide1(slide[0]);
  30. verifySlide2(slide[1]);
  31. verifySlide3(slide[2]);
  32. verifySlide4(slide[3]);
  33. verifySlide7(slide[6]);
  34. verifySlide8(slide[7]);
  35. verifySlide10(slide[9]);
  36. }
  37. void verifySlide1(XSLFSlide slide){
  38. XSLFSlideLayout layout = slide.getSlideLayout();
  39. XSLFShape[] shapes = slide.getShapes();
  40. assertEquals("Title Slide",layout.getName());
  41. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  42. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  43. assertEquals(STPlaceholderType.CTR_TITLE, ph1.getType());
  44. // anchor is not defined in the shape
  45. assertNull(shape1.getSpPr().getXfrm());
  46. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  47. assertNotNull(masterShape1.getSpPr().getXfrm());
  48. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  49. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  50. // none of the following properties are set in the shapes and fetched from the master shape
  51. assertTrue(
  52. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  53. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  54. !bodyPr1.isSetAnchor()
  55. );
  56. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  57. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  58. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  59. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  60. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  61. // now check text properties
  62. assertEquals("Centered Title", shape1.getText());
  63. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  64. assertEquals("Calibri", r1.getFontFamily());
  65. assertEquals(44.0, r1.getFontSize());
  66. assertEquals(Color.black, r1.getFontColor());
  67. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  68. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  69. assertEquals(STPlaceholderType.SUB_TITLE, ph2.getType());
  70. // anchor is not defined in the shape
  71. assertNull(shape2.getSpPr().getXfrm());
  72. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  73. assertNotNull(masterShape2.getSpPr().getXfrm());
  74. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  75. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  76. // none of the following properties are set in the shapes and fetched from the master shape
  77. assertTrue(
  78. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  79. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  80. !bodyPr2.isSetAnchor()
  81. );
  82. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  83. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  84. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  85. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  86. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  87. assertEquals("subtitle", shape2.getText());
  88. XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  89. assertEquals("Calibri", r2.getFontFamily());
  90. assertEquals(32.0, r2.getFontSize());
  91. // TODO fix calculation of tint
  92. //assertEquals(new Color(137, 137, 137), r2.getFontColor());
  93. }
  94. void verifySlide2(XSLFSlide slide){
  95. XSLFSlideLayout layout = slide.getSlideLayout();
  96. XSLFShape[] shapes = slide.getShapes();
  97. assertEquals("Title and Content",layout.getName());
  98. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  99. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  100. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  101. // anchor is not defined in the shape
  102. assertNull(shape1.getSpPr().getXfrm());
  103. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  104. // layout does not have anchor info either, it is in the slide master
  105. assertNull(masterShape1.getSpPr().getXfrm());
  106. masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
  107. assertNotNull(masterShape1.getSpPr().getXfrm());
  108. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  109. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  110. // none of the following properties are set in the shapes and fetched from the master shape
  111. assertTrue(
  112. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  113. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  114. !bodyPr1.isSetAnchor()
  115. );
  116. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  117. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  118. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  119. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  120. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  121. // now check text properties
  122. assertEquals("Title", shape1.getText());
  123. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  124. assertEquals("Calibri", r1.getFontFamily());
  125. assertEquals(44.0, r1.getFontSize());
  126. assertEquals(Color.black, r1.getFontColor());
  127. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  128. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  129. assertFalse(ph2.isSetType()); // <p:ph idx="1"/>
  130. assertTrue(ph2.isSetIdx());
  131. assertEquals(1, ph2.getIdx());
  132. // anchor is not defined in the shape
  133. assertNull(shape2.getSpPr().getXfrm());
  134. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  135. // anchor of the body text is missing in the slide layout, llokup in the slide master
  136. assertNull(masterShape2.getSpPr().getXfrm());
  137. masterShape2 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph2);
  138. assertNotNull(masterShape2.getSpPr().getXfrm());
  139. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  140. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  141. // none of the following properties are set in the shapes and fetched from the master shape
  142. assertTrue(
  143. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  144. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  145. !bodyPr2.isSetAnchor()
  146. );
  147. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  148. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  149. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  150. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  151. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  152. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  153. assertEquals(0, pr1.getParentParagraph().getLevel());
  154. assertEquals("Content", pr1.getText());
  155. assertEquals("Calibri", pr1.getFontFamily());
  156. assertEquals(32.0, pr1.getFontSize());
  157. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  158. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  159. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  160. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  161. assertEquals(1, pr2.getParentParagraph().getLevel());
  162. assertEquals("Level 2", pr2.getText());
  163. assertEquals("Calibri", pr2.getFontFamily());
  164. assertEquals(28.0, pr2.getFontSize());
  165. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  166. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  167. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  168. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  169. assertEquals(2, pr3.getParentParagraph().getLevel());
  170. assertEquals("Level 3", pr3.getText());
  171. assertEquals("Calibri", pr3.getFontFamily());
  172. assertEquals(24.0, pr3.getFontSize());
  173. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  174. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  175. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  176. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  177. assertEquals(3, pr4.getParentParagraph().getLevel());
  178. assertEquals("Level 4", pr4.getText());
  179. assertEquals("Calibri", pr4.getFontFamily());
  180. assertEquals(20.0, pr4.getFontSize());
  181. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  182. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  183. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  184. XSLFTextRun pr5 = shape2.getTextParagraphs().get(4).getTextRuns().get(0);
  185. assertEquals(4, pr5.getParentParagraph().getLevel());
  186. assertEquals("Level 5", pr5.getText());
  187. assertEquals("Calibri", pr5.getFontFamily());
  188. assertEquals(20.0, pr5.getFontSize());
  189. assertEquals(162.0, pr5.getParentParagraph().getLeftMargin());
  190. assertEquals("\u00bb", pr5.getParentParagraph().getBulletCharacter());
  191. assertEquals("Arial", pr5.getParentParagraph().getBulletFont());
  192. }
  193. void verifySlide3(XSLFSlide slide){
  194. XSLFSlideLayout layout = slide.getSlideLayout();
  195. XSLFShape[] shapes = slide.getShapes();
  196. assertEquals("Section Header",layout.getName());
  197. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  198. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  199. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  200. // anchor is not defined in the shape
  201. assertNull(shape1.getSpPr().getXfrm());
  202. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  203. assertNotNull(masterShape1.getSpPr().getXfrm());
  204. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  205. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  206. // none of the following properties are set in the shapes and fetched from the master shape
  207. assertTrue(
  208. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  209. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  210. !bodyPr1.isSetAnchor()
  211. );
  212. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  213. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  214. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  215. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  216. assertEquals(VerticalAlignment.TOP, shape1.getVerticalAlignment());
  217. // now check text properties
  218. assertEquals("Section Title", shape1.getText());
  219. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  220. assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
  221. assertEquals("Calibri", r1.getFontFamily());
  222. assertEquals(40.0, r1.getFontSize());
  223. assertEquals(Color.black, r1.getFontColor());
  224. assertTrue(r1.isBold());
  225. assertFalse(r1.isItalic());
  226. assertFalse(r1.isUnderline());
  227. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  228. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  229. assertEquals(STPlaceholderType.BODY, ph2.getType());
  230. // anchor is not defined in the shape
  231. assertNull(shape2.getSpPr().getXfrm());
  232. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  233. assertNotNull(masterShape2.getSpPr().getXfrm());
  234. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  235. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  236. // none of the following properties are set in the shapes and fetched from the master shape
  237. assertTrue(
  238. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  239. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  240. !bodyPr2.isSetAnchor()
  241. );
  242. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  243. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  244. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  245. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  246. assertEquals(VerticalAlignment.BOTTOM, shape2.getVerticalAlignment());
  247. assertEquals("Section Header", shape2.getText());
  248. XSLFTextRun r2 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  249. assertEquals(TextAlign.LEFT, r2.getParentParagraph().getTextAlign());
  250. assertEquals("Calibri", r2.getFontFamily());
  251. assertEquals(20.0, r2.getFontSize());
  252. // TODO fix calculation of tint
  253. //assertEquals(new Color(137, 137, 137), r2.getFontColor());
  254. }
  255. void verifySlide4(XSLFSlide slide){
  256. XSLFSlideLayout layout = slide.getSlideLayout();
  257. XSLFShape[] shapes = slide.getShapes();
  258. assertEquals("Two Content",layout.getName());
  259. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  260. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  261. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  262. // anchor is not defined in the shape
  263. assertNull(shape1.getSpPr().getXfrm());
  264. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  265. // layout does not have anchor info either, it is in the slide master
  266. assertNull(masterShape1.getSpPr().getXfrm());
  267. masterShape1 = (XSLFTextShape)layout.getSlideMaster().getPlaceholder(ph1);
  268. assertNotNull(masterShape1.getSpPr().getXfrm());
  269. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  270. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  271. // none of the following properties are set in the shapes and fetched from the master shape
  272. assertTrue(
  273. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  274. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  275. !bodyPr1.isSetAnchor()
  276. );
  277. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  278. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  279. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  280. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  281. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  282. // now check text properties
  283. assertEquals("Title", shape1.getText());
  284. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  285. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  286. assertEquals("Calibri", r1.getFontFamily());
  287. assertEquals(44.0, r1.getFontSize());
  288. assertEquals(Color.black, r1.getFontColor());
  289. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  290. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  291. assertFalse(ph2.isSetType());
  292. assertTrue(ph2.isSetIdx());
  293. assertEquals(1, ph2.getIdx()); //<p:ph sz="half" idx="1"/>
  294. // anchor is not defined in the shape
  295. assertNull(shape2.getSpPr().getXfrm());
  296. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  297. assertNotNull(masterShape2.getSpPr().getXfrm());
  298. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  299. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  300. // none of the following properties are set in the shapes and fetched from the master shape
  301. assertTrue(
  302. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  303. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  304. !bodyPr2.isSetAnchor()
  305. );
  306. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  307. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  308. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  309. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  310. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  311. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  312. assertEquals(0, pr1.getParentParagraph().getLevel());
  313. assertEquals("Left", pr1.getText());
  314. assertEquals("Calibri", pr1.getFontFamily());
  315. assertEquals(28.0, pr1.getFontSize());
  316. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  317. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  318. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  319. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  320. assertEquals(1, pr2.getParentParagraph().getLevel());
  321. assertEquals("Level 2", pr2.getParentParagraph().getText());
  322. assertEquals("Calibri", pr2.getFontFamily());
  323. assertEquals(24.0, pr2.getFontSize());
  324. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  325. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  326. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  327. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  328. assertEquals(2, pr3.getParentParagraph().getLevel());
  329. assertEquals("Level 3", pr3.getParentParagraph().getText());
  330. assertEquals("Calibri", pr3.getFontFamily());
  331. assertEquals(20.0, pr3.getFontSize());
  332. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  333. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  334. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  335. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  336. assertEquals(3, pr4.getParentParagraph().getLevel());
  337. assertEquals("Level 4", pr4.getParentParagraph().getText());
  338. assertEquals("Calibri", pr4.getFontFamily());
  339. assertEquals(18.0, pr4.getFontSize());
  340. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  341. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  342. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  343. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  344. XSLFTextRun pr5 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
  345. assertEquals(0, pr5.getParentParagraph().getLevel());
  346. assertEquals("Right", pr5.getText());
  347. assertEquals("Calibri", pr5.getFontFamily());
  348. assertEquals(Color.black, pr5.getFontColor());
  349. }
  350. void verifySlide5(XSLFSlide slide){
  351. XSLFSlideLayout layout = slide.getSlideLayout();
  352. XSLFShape[] shapes = slide.getShapes();
  353. // TODO
  354. }
  355. void verifySlide7(XSLFSlide slide){
  356. XSLFSlideLayout layout = slide.getSlideLayout();
  357. XSLFShape[] shapes = slide.getShapes();
  358. assertEquals("Blank",layout.getName());
  359. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  360. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  361. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  362. // anchor is not defined in the shape
  363. assertNull(shape1.getSpPr().getXfrm());
  364. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  365. // none of the following properties are set in the shapes and fetched from the master shape
  366. assertTrue(
  367. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  368. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  369. !bodyPr1.isSetAnchor()
  370. );
  371. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  372. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  373. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  374. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  375. assertEquals(VerticalAlignment.MIDDLE, shape1.getVerticalAlignment());
  376. // now check text properties
  377. assertEquals("Blank with Default Title", shape1.getText());
  378. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  379. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  380. assertEquals("Calibri", r1.getFontFamily());
  381. assertEquals(44.0, r1.getFontSize());
  382. assertEquals(Color.black, r1.getFontColor());
  383. assertFalse(r1.isBold());
  384. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  385. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  386. // none of the following properties are set in the shapes and fetched from the master shape
  387. assertTrue(
  388. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  389. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  390. !bodyPr2.isSetAnchor()
  391. );
  392. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  393. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  394. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  395. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  396. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  397. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  398. assertEquals(0, pr1.getParentParagraph().getLevel());
  399. assertEquals("Default Text", pr1.getText());
  400. assertEquals("Calibri", pr1.getFontFamily());
  401. assertEquals(18.0, pr1.getFontSize());
  402. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  403. assertEquals("Default", shape3.getTextParagraphs().get(0).getText());
  404. assertEquals("Text with levels", shape3.getTextParagraphs().get(1).getText());
  405. assertEquals("Level 1", shape3.getTextParagraphs().get(2).getText());
  406. assertEquals("Level 2", shape3.getTextParagraphs().get(3).getText());
  407. assertEquals("Level 3", shape3.getTextParagraphs().get(4).getText());
  408. for(int p = 0; p < 5; p++) {
  409. XSLFTextParagraph pr = shape3.getTextParagraphs().get(p);
  410. assertEquals("Calibri", pr.getTextRuns().get(0).getFontFamily());
  411. assertEquals(18.0, pr.getTextRuns().get(0).getFontSize());
  412. }
  413. }
  414. void verifySlide8(XSLFSlide slide){
  415. XSLFSlideLayout layout = slide.getSlideLayout();
  416. XSLFShape[] shapes = slide.getShapes();
  417. assertEquals("Content with Caption",layout.getName());
  418. XSLFTextShape shape1 = (XSLFTextShape)shapes[0];
  419. CTPlaceholder ph1 = shape1.getCTPlaceholder();
  420. assertEquals(STPlaceholderType.TITLE, ph1.getType());
  421. // anchor is not defined in the shape
  422. assertNull(shape1.getSpPr().getXfrm());
  423. XSLFTextShape masterShape1 = (XSLFTextShape)layout.getPlaceholder(ph1);
  424. // layout does not have anchor info either, it is in the slide master
  425. assertNotNull(masterShape1.getSpPr().getXfrm());
  426. assertEquals(masterShape1.getAnchor(), shape1.getAnchor());
  427. CTTextBodyProperties bodyPr1 = shape1.getTextBodyPr();
  428. // none of the following properties are set in the shapes and fetched from the master shape
  429. assertTrue(
  430. !bodyPr1.isSetLIns() && !bodyPr1.isSetRIns() &&
  431. !bodyPr1.isSetBIns() && !bodyPr1.isSetTIns() &&
  432. !bodyPr1.isSetAnchor()
  433. );
  434. assertEquals(7.2, shape1.getLeftInset()); // 0.1"
  435. assertEquals(7.2, shape1.getRightInset()); // 0.1"
  436. assertEquals(3.6, shape1.getTopInset()); // 0.05"
  437. assertEquals(3.6, shape1.getBottomInset()); // 0.05"
  438. assertEquals(VerticalAlignment.BOTTOM, shape1.getVerticalAlignment());
  439. // now check text properties
  440. assertEquals("Caption", shape1.getText());
  441. XSLFTextRun r1 = shape1.getTextParagraphs().get(0).getTextRuns().get(0);
  442. assertEquals(TextAlign.LEFT, r1.getParentParagraph().getTextAlign());
  443. assertEquals("Calibri", r1.getFontFamily());
  444. assertEquals(20.0, r1.getFontSize());
  445. assertEquals(Color.black, r1.getFontColor());
  446. assertTrue(r1.isBold());
  447. XSLFTextShape shape2 = (XSLFTextShape)shapes[1];
  448. CTPlaceholder ph2 = shape2.getCTPlaceholder();
  449. assertFalse(ph2.isSetType());
  450. assertTrue(ph2.isSetIdx());
  451. assertEquals(1, ph2.getIdx());
  452. // anchor is not defined in the shape
  453. assertNull(shape2.getSpPr().getXfrm());
  454. XSLFTextShape masterShape2 = (XSLFTextShape)layout.getPlaceholder(ph2);
  455. assertNotNull(masterShape2.getSpPr().getXfrm());
  456. assertEquals(masterShape2.getAnchor(), shape2.getAnchor());
  457. CTTextBodyProperties bodyPr2 = shape2.getTextBodyPr();
  458. // none of the following properties are set in the shapes and fetched from the master shape
  459. assertTrue(
  460. !bodyPr2.isSetLIns() && !bodyPr2.isSetRIns() &&
  461. !bodyPr2.isSetBIns() && !bodyPr2.isSetTIns() &&
  462. !bodyPr2.isSetAnchor()
  463. );
  464. assertEquals(7.2, shape2.getLeftInset()); // 0.1"
  465. assertEquals(7.2, shape2.getRightInset()); // 0.1"
  466. assertEquals(3.6, shape2.getTopInset()); // 0.05"
  467. assertEquals(3.6, shape2.getBottomInset()); // 0.05"
  468. assertEquals(VerticalAlignment.TOP, shape2.getVerticalAlignment());
  469. XSLFTextRun pr1 = shape2.getTextParagraphs().get(0).getTextRuns().get(0);
  470. assertEquals(0, pr1.getParentParagraph().getLevel());
  471. assertEquals("Level 1", pr1.getText());
  472. assertEquals("Calibri", pr1.getFontFamily());
  473. assertEquals(32.0, pr1.getFontSize());
  474. assertEquals(27.0, pr1.getParentParagraph().getLeftMargin());
  475. assertEquals("\u2022", pr1.getParentParagraph().getBulletCharacter());
  476. assertEquals("Arial", pr1.getParentParagraph().getBulletFont());
  477. XSLFTextRun pr2 = shape2.getTextParagraphs().get(1).getTextRuns().get(0);
  478. assertEquals(1, pr2.getParentParagraph().getLevel());
  479. assertEquals("Level 2", pr2.getParentParagraph().getText());
  480. assertEquals("Calibri", pr2.getFontFamily());
  481. assertEquals(28.0, pr2.getFontSize());
  482. assertEquals(58.5, pr2.getParentParagraph().getLeftMargin());
  483. assertEquals("\u2013", pr2.getParentParagraph().getBulletCharacter());
  484. assertEquals("Arial", pr2.getParentParagraph().getBulletFont());
  485. XSLFTextRun pr3 = shape2.getTextParagraphs().get(2).getTextRuns().get(0);
  486. assertEquals(2, pr3.getParentParagraph().getLevel());
  487. assertEquals("Level 3", pr3.getParentParagraph().getText());
  488. assertEquals("Calibri", pr3.getFontFamily());
  489. assertEquals(24.0, pr3.getFontSize());
  490. assertEquals(90.0, pr3.getParentParagraph().getLeftMargin());
  491. assertEquals("\u2022", pr3.getParentParagraph().getBulletCharacter());
  492. assertEquals("Arial", pr3.getParentParagraph().getBulletFont());
  493. XSLFTextRun pr4 = shape2.getTextParagraphs().get(3).getTextRuns().get(0);
  494. assertEquals(3, pr4.getParentParagraph().getLevel());
  495. assertEquals("Level 4", pr4.getParentParagraph().getText());
  496. assertEquals("Calibri", pr4.getFontFamily());
  497. assertEquals(20.0, pr4.getFontSize());
  498. assertEquals(126.0, pr4.getParentParagraph().getLeftMargin());
  499. assertEquals("\u2013", pr4.getParentParagraph().getBulletCharacter());
  500. assertEquals("Arial", pr4.getParentParagraph().getBulletFont());
  501. XSLFTextShape shape3 = (XSLFTextShape)shapes[2];
  502. assertEquals(VerticalAlignment.TOP, shape3.getVerticalAlignment());
  503. assertEquals("Content with caption", shape3.getText());
  504. pr1 = shape3.getTextParagraphs().get(0).getTextRuns().get(0);
  505. assertEquals(0, pr1.getParentParagraph().getLevel());
  506. assertEquals("Content with caption", pr1.getText());
  507. assertEquals("Calibri", pr1.getFontFamily());
  508. assertEquals(14.0, pr1.getFontSize());
  509. }
  510. void verifySlide10(XSLFSlide slide){
  511. XSLFTextShape footer = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_FTR);
  512. // now check text properties
  513. assertEquals("Apache Software Foundation", footer.getText());
  514. assertEquals(VerticalAlignment.MIDDLE, footer.getVerticalAlignment());
  515. XSLFTextRun r1 = footer.getTextParagraphs().get(0).getTextRuns().get(0);
  516. assertEquals(TextAlign.CENTER, r1.getParentParagraph().getTextAlign());
  517. assertEquals("Calibri", r1.getFontFamily());
  518. assertEquals(12.0, r1.getFontSize());
  519. // TODO calculation of tint is incorrect
  520. assertEquals(new Color(64,64,64), r1.getFontColor());
  521. XSLFTextShape dt = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_DT);
  522. assertEquals("Friday, October 21, 2011", dt.getText());
  523. XSLFTextShape sldNum = (XSLFTextShape)slide.getPlaceholderByType(STPlaceholderType.INT_SLD_NUM);
  524. assertEquals("10", sldNum.getText());
  525. }
  526. }