Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TestXSLFTextShape.java 45KB

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