Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TestBugs.java 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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.hslf.usermodel;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertFalse;
  18. import static org.junit.Assert.assertNotNull;
  19. import static org.junit.Assert.assertTrue;
  20. import java.awt.Color;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.util.ArrayList;
  24. import java.util.Date;
  25. import java.util.HashMap;
  26. import java.util.HashSet;
  27. import java.util.List;
  28. import java.util.Map;
  29. import java.util.Set;
  30. import org.apache.poi.ddf.AbstractEscherOptRecord;
  31. import org.apache.poi.ddf.EscherArrayProperty;
  32. import org.apache.poi.ddf.EscherColorRef;
  33. import org.apache.poi.ddf.EscherProperties;
  34. import org.apache.poi.hslf.HSLFTestDataSamples;
  35. import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
  36. import org.apache.poi.hslf.extractor.PowerPointExtractor;
  37. import org.apache.poi.hslf.model.HeadersFooters;
  38. import org.apache.poi.hslf.record.Document;
  39. import org.apache.poi.hslf.record.Record;
  40. import org.apache.poi.hslf.record.SlideListWithText;
  41. import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
  42. import org.apache.poi.hslf.record.TextHeaderAtom;
  43. import org.apache.poi.sl.draw.DrawPaint;
  44. import org.apache.poi.sl.usermodel.PaintStyle;
  45. import org.apache.poi.sl.usermodel.PaintStyle.SolidPaint;
  46. import org.apache.poi.sl.usermodel.PictureData.PictureType;
  47. import org.apache.poi.sl.usermodel.Slide;
  48. import org.apache.poi.sl.usermodel.SlideShow;
  49. import org.apache.poi.sl.usermodel.SlideShowFactory;
  50. import org.apache.poi.sl.usermodel.TextBox;
  51. import org.apache.poi.sl.usermodel.TextParagraph;
  52. import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
  53. import org.apache.poi.sl.usermodel.TextRun;
  54. import org.apache.poi.util.LittleEndian;
  55. import org.apache.poi.util.StringUtil;
  56. import org.apache.poi.util.Units;
  57. import org.junit.Test;
  58. /**
  59. * Testcases for bugs entered in bugzilla
  60. * the Test name contains the bugzilla bug id
  61. *
  62. * @author Yegor Kozlov
  63. */
  64. public final class TestBugs {
  65. /**
  66. * Bug 41384: Array index wrong in record creation
  67. */
  68. @Test
  69. public void bug41384() throws IOException {
  70. HSLFSlideShow ppt = open("41384.ppt");
  71. assertEquals(1, ppt.getSlides().size());
  72. List<HSLFPictureData> pict = ppt.getPictureData();
  73. assertEquals(2, pict.size());
  74. assertEquals(PictureType.JPEG, pict.get(0).getType());
  75. assertEquals(PictureType.JPEG, pict.get(1).getType());
  76. ppt.close();
  77. }
  78. /**
  79. * First fix from Bug 42474: NPE in RichTextRun.isBold()
  80. * when the RichTextRun comes from a Notes model object
  81. */
  82. @Test
  83. public void bug42474_1() throws IOException {
  84. HSLFSlideShow ppt = open("42474-1.ppt");
  85. assertEquals(2, ppt.getSlides().size());
  86. List<HSLFTextParagraph> txrun;
  87. HSLFNotes notes;
  88. notes = ppt.getSlides().get(0).getNotes();
  89. assertNotNull(notes);
  90. txrun = notes.getTextParagraphs().get(0);
  91. assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun));
  92. assertEquals(false, txrun.get(0).getTextRuns().get(0).isBold());
  93. //notes for the second slide are in bold
  94. notes = ppt.getSlides().get(1).getNotes();
  95. assertNotNull(notes);
  96. txrun = notes.getTextParagraphs().get(0);
  97. assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
  98. assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
  99. ppt.close();
  100. }
  101. /**
  102. * Second fix from Bug 42474: Incorrect matching of notes to slides
  103. */
  104. @Test
  105. public void bug42474_2() throws IOException {
  106. HSLFSlideShow ppt = open("42474-2.ppt");
  107. //map slide number and starting phrase of its notes
  108. Map<Integer, String> notesMap = new HashMap<Integer, String>();
  109. notesMap.put(Integer.valueOf(4), "For decades before calculators");
  110. notesMap.put(Integer.valueOf(5), "Several commercial applications");
  111. notesMap.put(Integer.valueOf(6), "There are three variations of LNS that are discussed here");
  112. notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier");
  113. notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L");
  114. for (HSLFSlide slide : ppt.getSlides()) {
  115. Integer slideNumber = Integer.valueOf(slide.getSlideNumber());
  116. HSLFNotes notes = slide.getNotes();
  117. if (notesMap.containsKey(slideNumber)){
  118. assertNotNull(notes);
  119. String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0));
  120. String startingPhrase = notesMap.get(slideNumber);
  121. assertTrue("Notes for slide " + slideNumber + " must start with " +
  122. startingPhrase , text.startsWith(startingPhrase));
  123. }
  124. }
  125. ppt.close();
  126. }
  127. /**
  128. * Bug 42485: All TextBoxes inside ShapeGroups have null TextRuns
  129. */
  130. @Test
  131. public void bug42485 () throws IOException {
  132. HSLFSlideShow ppt = open("42485.ppt");
  133. for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
  134. if(shape instanceof HSLFGroupShape){
  135. HSLFGroupShape group = (HSLFGroupShape)shape;
  136. for (HSLFShape sh : group.getShapes()) {
  137. if(sh instanceof HSLFTextBox){
  138. HSLFTextBox txt = (HSLFTextBox)sh;
  139. assertNotNull(txt.getTextParagraphs());
  140. }
  141. }
  142. }
  143. }
  144. ppt.close();
  145. }
  146. /**
  147. * Bug 42484: NullPointerException from ShapeGroup.getAnchor()
  148. */
  149. @Test
  150. public void bug42484 () throws IOException {
  151. HSLFSlideShow ppt = open("42485.ppt");
  152. for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
  153. if(shape instanceof HSLFGroupShape){
  154. HSLFGroupShape group = (HSLFGroupShape)shape;
  155. assertNotNull(group.getAnchor());
  156. for (HSLFShape sh : group.getShapes()) {
  157. assertNotNull(sh.getAnchor());
  158. }
  159. }
  160. }
  161. ppt.close();
  162. }
  163. /**
  164. * Bug 41381: Exception from Slide.getMasterSheet() on a seemingly valid PPT file
  165. */
  166. @Test
  167. public void bug41381() throws IOException {
  168. HSLFSlideShow ppt = open("alterman_security.ppt");
  169. assertTrue("No Exceptions while reading file", true);
  170. assertEquals(1, ppt.getSlideMasters().size());
  171. assertEquals(1, ppt.getTitleMasters().size());
  172. boolean isFirst = true;
  173. for (HSLFSlide slide : ppt.getSlides()) {
  174. HSLFMasterSheet master = slide.getMasterSheet();
  175. // the first slide follows TitleMaster
  176. assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
  177. isFirst = false;
  178. }
  179. ppt.close();
  180. }
  181. /**
  182. * Bug 42486: Failure parsing a seemingly valid PPT
  183. */
  184. @SuppressWarnings("unused")
  185. @Test
  186. public void bug42486 () throws IOException {
  187. HSLFSlideShow ppt = open("42486.ppt");
  188. for (HSLFSlide slide : ppt.getSlides()) {
  189. List<HSLFShape> shape = slide.getShapes();
  190. }
  191. ppt.close();
  192. }
  193. /**
  194. * Bug 42524: NPE in Shape.getShapeType()
  195. */
  196. @Test
  197. public void bug42524 () throws IOException {
  198. HSLFSlideShow ppt = open("42486.ppt");
  199. //walk down the tree and see if there were no errors while reading
  200. for (HSLFSlide slide : ppt.getSlides()) {
  201. for (HSLFShape shape : slide.getShapes()) {
  202. assertNotNull(shape.getShapeName());
  203. if (shape instanceof HSLFGroupShape){
  204. HSLFGroupShape group = (HSLFGroupShape)shape;
  205. for (HSLFShape comps : group.getShapes()) {
  206. assertNotNull(comps.getShapeName());
  207. }
  208. }
  209. }
  210. }
  211. ppt.close();
  212. }
  213. /**
  214. * Bug 42520: NPE in Picture.getPictureData()
  215. */
  216. @SuppressWarnings("unused")
  217. @Test
  218. public void bug42520 () throws IOException {
  219. HSLFSlideShow ppt = open("42520.ppt");
  220. //test case from the bug report
  221. HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
  222. HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes().get(0);
  223. picture.getPictureData();
  224. //walk down the tree and see if there were no errors while reading
  225. for (HSLFSlide slide : ppt.getSlides()) {
  226. for (HSLFShape shape : slide.getShapes()) {
  227. if (shape instanceof HSLFGroupShape){
  228. HSLFGroupShape group = (HSLFGroupShape)shape;
  229. for (HSLFShape comp : group.getShapes()) {
  230. if (comp instanceof HSLFPictureShape){
  231. HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
  232. }
  233. }
  234. }
  235. }
  236. }
  237. ppt.close();
  238. }
  239. /**
  240. * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
  241. * ( also fixed followup: getTextRuns() returns no text )
  242. */
  243. @Test
  244. public void bug38256 () throws IOException {
  245. HSLFSlideShow ppt = open("38256.ppt");
  246. List<HSLFSlide> slide = ppt.getSlides();
  247. assertEquals(1, slide.size());
  248. List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs();
  249. assertEquals(4, paras.size());
  250. Set<String> txt = new HashSet<String>();
  251. txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");
  252. txt.add("Have a HAPPY DAY");
  253. txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");
  254. txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");
  255. for (List<HSLFTextParagraph> para : paras) {
  256. String text = HSLFTextParagraph.getRawText(para);
  257. assertTrue(text, txt.contains(text));
  258. }
  259. ppt.close();
  260. }
  261. /**
  262. * Bug 38256: RuntimeException: Couldn't instantiate the class for type with id 0.
  263. * ( also fixed followup: getTextRuns() returns no text )
  264. */
  265. @Test
  266. public void bug43781() throws IOException {
  267. HSLFSlideShow ppt = open("43781.ppt");
  268. // Check the first slide
  269. HSLFSlide slide = ppt.getSlides().get(0);
  270. List<List<HSLFTextParagraph>> slTr = slide.getTextParagraphs();
  271. // Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing
  272. assertEquals(3, slTr.size());
  273. assertFalse(slTr.get(0).get(0).isDrawingBased());
  274. assertFalse(slTr.get(1).get(0).isDrawingBased());
  275. assertTrue(slTr.get(2).get(0).isDrawingBased());
  276. assertEquals("", HSLFTextParagraph.getRawText(slTr.get(0)));
  277. assertEquals("First run", HSLFTextParagraph.getRawText(slTr.get(1)));
  278. assertEquals("Second run", HSLFTextParagraph.getRawText(slTr.get(2)));
  279. // Check the shape based text runs
  280. List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>();
  281. for (HSLFShape shape : slide.getShapes()) {
  282. if (shape instanceof HSLFTextShape){
  283. List<HSLFTextParagraph> textRun = ((HSLFTextShape)shape).getTextParagraphs();
  284. lst.addAll(textRun);
  285. }
  286. }
  287. // There are two shapes in the ppt
  288. assertEquals(2, lst.size());
  289. assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
  290. ppt.close();
  291. }
  292. /**
  293. * Bug 44296: HSLF Not Extracting Slide Background Image
  294. */
  295. @Test
  296. public void bug44296 () throws IOException {
  297. HSLFSlideShow ppt = open("44296.ppt");
  298. HSLFSlide slide = ppt.getSlides().get(0);
  299. HSLFBackground b = slide.getBackground();
  300. HSLFFill f = b.getFill();
  301. assertEquals(HSLFFill.FILL_PICTURE, f.getFillType());
  302. HSLFPictureData pict = f.getPictureData();
  303. assertNotNull(pict);
  304. assertEquals(PictureType.JPEG, pict.getType());
  305. ppt.close();
  306. }
  307. /**
  308. * Bug 44770: java.lang.RuntimeException: Couldn't instantiate the class for
  309. * type with id 1036 on class class org.apache.poi.hslf.record.PPDrawing
  310. */
  311. @Test
  312. public void bug44770() throws IOException {
  313. open("44770.ppt").close();
  314. }
  315. /**
  316. * Bug 41071: Will not extract text from Powerpoint TextBoxes
  317. */
  318. @Test
  319. public void bug41071() throws IOException {
  320. HSLFSlideShow ppt = open("41071.ppt");
  321. HSLFSlide slide = ppt.getSlides().get(0);
  322. List<HSLFShape> sh = slide.getShapes();
  323. assertEquals(1, sh.size());
  324. assertTrue(sh.get(0) instanceof HSLFTextShape);
  325. HSLFTextShape tx = (HSLFTextShape)sh.get(0);
  326. assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs()));
  327. List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
  328. assertEquals(3, run.size());
  329. assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
  330. ppt.close();
  331. }
  332. /**
  333. * PowerPoint 95 files should throw a more helpful exception
  334. * @throws IOException
  335. */
  336. @Test(expected=OldPowerPointFormatException.class)
  337. public void bug41711() throws IOException {
  338. // New file is fine
  339. open("SampleShow.ppt").close();
  340. // PowerPoint 95 gives an old format exception
  341. open("PPT95.ppt").close();
  342. }
  343. /**
  344. * Changing text from Ascii to Unicode
  345. */
  346. @Test
  347. public void bug49648() throws IOException {
  348. HSLFSlideShow ppt = open("49648.ppt");
  349. for (HSLFSlide slide : ppt.getSlides()) {
  350. for (List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
  351. String text = HSLFTextParagraph.getRawText(run);
  352. text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
  353. HSLFTextParagraph.setText(run, text);
  354. }
  355. }
  356. ppt.close();
  357. }
  358. /**
  359. * Bug 41246: AIOOB with illegal note references
  360. */
  361. @Test
  362. public void bug41246a() throws IOException {
  363. HSLFSlideShow ppt = open("41246-1.ppt");
  364. HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
  365. ppt.close();
  366. }
  367. @Test
  368. public void bug41246b() throws IOException {
  369. HSLFSlideShow ppt = open("41246-2.ppt");
  370. HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
  371. ppt.close();
  372. }
  373. /**
  374. * Bug 45776: Fix corrupt file problem using TextRun.setText
  375. */
  376. @Test
  377. public void bug45776() throws IOException {
  378. HSLFSlideShow ppt = open("45776.ppt");
  379. // get slides
  380. for (HSLFSlide slide : ppt.getSlides()) {
  381. for (HSLFShape shape : slide.getShapes()) {
  382. if (!(shape instanceof HSLFTextBox)) continue;
  383. HSLFTextBox tb = (HSLFTextBox) shape;
  384. // work with TextBox
  385. String str = tb.getText();
  386. if (!str.contains("$$DATE$$")) continue;
  387. str = str.replace("$$DATE$$", new Date().toString());
  388. tb.setText(str);
  389. List<HSLFTextParagraph> tr = tb.getTextParagraphs();
  390. assertEquals(str.length()+1,tr.get(0).getParagraphStyle().getCharactersCovered());
  391. assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
  392. }
  393. }
  394. ppt.close();
  395. }
  396. @Test
  397. public void bug55732() throws IOException {
  398. HSLFSlideShow ppt = open("bug55732.ppt");
  399. List<HSLFSlide> _slides = ppt.getSlides();
  400. /* Iterate over slides and extract text */
  401. for( HSLFSlide slide : _slides ) {
  402. HeadersFooters hf = slide.getHeadersFooters();
  403. /*boolean visible =*/ hf.isHeaderVisible(); // exception happens here
  404. }
  405. ppt.close();
  406. }
  407. @Test
  408. public void bug56260() throws IOException {
  409. HSLFSlideShow ppt = open("56260.ppt");
  410. List<HSLFSlide> _slides = ppt.getSlides();
  411. assertEquals(13, _slides.size());
  412. // Check the number of TextHeaderAtoms on Slide 1
  413. Document dr = ppt.getDocumentRecord();
  414. SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
  415. SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
  416. int tha = 0;
  417. for (Record r : s1.getSlideRecords()) {
  418. if (r instanceof TextHeaderAtom) tha++;
  419. }
  420. assertEquals(2, tha);
  421. // Check to see that we have a pair next to each other
  422. assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[0].getClass());
  423. assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[1].getClass());
  424. // Check the number of text runs based on the slide (not textbox)
  425. // Will have skipped the empty one
  426. int str = 0;
  427. for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
  428. if (! tr.get(0).isDrawingBased()) str++;
  429. }
  430. assertEquals(2, str);
  431. ppt.close();
  432. }
  433. @Test
  434. public void bug37625() throws IOException {
  435. HSLFSlideShow ppt1 = open("37625.ppt");
  436. assertEquals(29, ppt1.getSlides().size());
  437. HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
  438. assertNotNull(ppt2);
  439. assertEquals(29, ppt2.getSlides().size());
  440. ppt2.close();
  441. ppt1.close();
  442. }
  443. @Test
  444. public void bug57272() throws IOException {
  445. HSLFSlideShow ppt1 = open("57272_corrupted_usereditatom.ppt");
  446. assertEquals(6, ppt1.getSlides().size());
  447. HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
  448. assertNotNull(ppt2);
  449. assertEquals(6, ppt2.getSlides().size());
  450. ppt2.close();
  451. ppt1.close();
  452. }
  453. @Test
  454. public void bug49541() throws IOException {
  455. HSLFSlideShow ppt = open("49541_symbol_map.ppt");
  456. HSLFSlide slide = ppt.getSlides().get(0);
  457. HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
  458. HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
  459. String text = StringUtil.mapMsCodepointString(tb.getText());
  460. assertEquals("\u226575 years", text);
  461. ppt.close();
  462. }
  463. @Test
  464. public void bug47261() throws IOException {
  465. HSLFSlideShow ppt = open("bug47261.ppt");
  466. ppt.removeSlide(0);
  467. ppt.createSlide();
  468. HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
  469. ppt.close();
  470. }
  471. @Test
  472. public void bug56240() throws IOException {
  473. HSLFSlideShow ppt = open("bug56240.ppt");
  474. int slideCnt = ppt.getSlides().size();
  475. assertEquals(105, slideCnt);
  476. HSLFTestDataSamples.writeOutAndReadBack(ppt).close();
  477. ppt.close();
  478. }
  479. @Test
  480. public void bug46441() throws IOException {
  481. HSLFSlideShow ppt = open("bug46441.ppt");
  482. HSLFAutoShape as = (HSLFAutoShape)ppt.getSlides().get(0).getShapes().get(0);
  483. AbstractEscherOptRecord opt = as.getEscherOptRecord();
  484. EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
  485. double exp[][] = {
  486. // r, g, b, position
  487. { 94, 158, 255, 0 },
  488. { 133, 194, 255, 0.399994 },
  489. { 196, 214, 235, 0.699997 },
  490. { 255, 235, 250, 1 }
  491. };
  492. int i = 0;
  493. for (byte data[] : ep) {
  494. EscherColorRef ecr = new EscherColorRef(data, 0, 4);
  495. int rgb[] = ecr.getRGB();
  496. double pos = Units.fixedPointToDouble(LittleEndian.getInt(data, 4));
  497. assertEquals((int)exp[i][0], rgb[0]);
  498. assertEquals((int)exp[i][1], rgb[1]);
  499. assertEquals((int)exp[i][2], rgb[2]);
  500. assertEquals(exp[i][3], pos, 0.01);
  501. i++;
  502. }
  503. ppt.close();
  504. }
  505. @Test
  506. public void bug58516() throws IOException {
  507. open("bug58516.ppt").close();
  508. }
  509. @Test
  510. public void bug45124() throws IOException {
  511. SlideShow<?,?> ppt = open("bug45124.ppt");
  512. Slide<?,?> slide1 = ppt.getSlides().get(1);
  513. TextBox<?,?> res = slide1.createTextBox();
  514. res.setAnchor(new java.awt.Rectangle(60, 150, 700, 100));
  515. res.setText("I am italic-false, bold-true inserted text");
  516. TextParagraph<?,?,?> tp = res.getTextParagraphs().get(0);
  517. TextRun rt = tp.getTextRuns().get(0);
  518. rt.setItalic(false);
  519. assertTrue(rt.isBold());
  520. tp.setBulletStyle(Color.red, 'A');
  521. SlideShow<?,?> ppt2 = HSLFTestDataSamples.writeOutAndReadBack((HSLFSlideShow)ppt);
  522. ppt.close();
  523. res = (TextBox<?,?>)ppt2.getSlides().get(1).getShapes().get(1);
  524. tp = res.getTextParagraphs().get(0);
  525. rt = tp.getTextRuns().get(0);
  526. assertFalse(rt.isItalic());
  527. assertTrue(rt.isBold());
  528. PaintStyle ps = tp.getBulletStyle().getBulletFontColor();
  529. assertTrue(ps instanceof SolidPaint);
  530. Color actColor = DrawPaint.applyColorTransform(((SolidPaint)ps).getSolidColor());
  531. assertEquals(Color.red, actColor);
  532. assertEquals("A", tp.getBulletStyle().getBulletCharacter());
  533. ppt2.close();
  534. }
  535. @Test
  536. public void bug45088() throws IOException {
  537. String template = "[SYSDATE]";
  538. String textExp = "REPLACED_DATE_WITH_A_LONG_ONE";
  539. HSLFSlideShow ppt1 = open("bug45088.ppt");
  540. for (HSLFSlide slide : ppt1.getSlides()) {
  541. for (List<HSLFTextParagraph> paraList : slide.getTextParagraphs()) {
  542. for (HSLFTextParagraph para : paraList) {
  543. for (HSLFTextRun run : para.getTextRuns()) {
  544. String text = run.getRawText();
  545. if (text != null && text.contains(template)) {
  546. String replacedText = text.replace(template, textExp);
  547. run.setText(replacedText);
  548. para.setDirty();
  549. }
  550. }
  551. }
  552. }
  553. }
  554. HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
  555. ppt1.close();
  556. HSLFTextBox tb = (HSLFTextBox)ppt2.getSlides().get(0).getShapes().get(1);
  557. String textAct = tb.getTextParagraphs().get(0).getTextRuns().get(0).getRawText().trim();
  558. assertEquals(textExp, textAct);
  559. ppt2.close();
  560. }
  561. @Test
  562. public void bug45908() throws IOException {
  563. HSLFSlideShow ppt1 = open("bug45908.ppt");
  564. HSLFSlide slide = ppt1.getSlides().get(0);
  565. HSLFAutoShape styleShape = (HSLFAutoShape)slide.getShapes().get(1);
  566. HSLFTextParagraph tp0 = styleShape.getTextParagraphs().get(0);
  567. HSLFTextRun tr0 = tp0.getTextRuns().get(0);
  568. int rows = 5;
  569. int cols = 2;
  570. HSLFTable table = slide.createTable(rows, cols);
  571. for (int i = 0; i < rows; i++) {
  572. for (int j = 0; j < cols; j++) {
  573. HSLFTableCell cell = table.getCell(i, j);
  574. cell.setText("Test");
  575. HSLFTextParagraph tp = cell.getTextParagraphs().get(0);
  576. tp.setBulletStyle('%', tp0.getBulletColor(), tp0.getBulletFont(), tp0.getBulletSize());
  577. tp.setIndent(tp0.getIndent());
  578. tp.setTextAlign(tp0.getTextAlign());
  579. tp.setIndentLevel(tp0.getIndentLevel());
  580. tp.setSpaceAfter(tp0.getSpaceAfter());
  581. tp.setSpaceBefore(tp0.getSpaceBefore());
  582. tp.setBulletStyle();
  583. HSLFTextRun tr = tp.getTextRuns().get(0);
  584. tr.setBold(tr0.isBold());
  585. // rt.setEmbossed();
  586. tr.setFontColor(Color.BLACK);
  587. tr.setFontFamily(tr0.getFontFamily());
  588. tr.setFontSize(tr0.getFontSize());
  589. tr.setItalic(tr0.isItalic());
  590. tr.setShadowed(tr0.isShadowed());
  591. tr.setStrikethrough(tr0.isStrikethrough());
  592. tr.setUnderlined(tr0.isUnderlined());
  593. }
  594. }
  595. table.moveTo(100, 100);
  596. HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
  597. ppt1.close();
  598. HSLFTable tab = (HSLFTable)ppt2.getSlides().get(0).getShapes().get(2);
  599. HSLFTableCell c2 = tab.getCell(0, 0);
  600. HSLFTextParagraph tp1 = c2.getTextParagraphs().get(0);
  601. HSLFTextRun tr1 = tp1.getTextRuns().get(0);
  602. assertFalse(tp1.isBullet());
  603. assertEquals(tp0.getBulletColor(), tp1.getBulletColor());
  604. assertEquals(tp0.getBulletFont(), tp1.getBulletFont());
  605. assertEquals(tp0.getBulletSize(), tp1.getBulletSize());
  606. assertEquals(tp0.getIndent(), tp1.getIndent());
  607. assertEquals(tp0.getTextAlign(), tp1.getTextAlign());
  608. assertEquals(tp0.getIndentLevel(), tp1.getIndentLevel());
  609. assertEquals(tp0.getSpaceAfter(), tp1.getSpaceAfter());
  610. assertEquals(tp0.getSpaceBefore(), tp1.getSpaceBefore());
  611. assertEquals(tr0.isBold(), tr1.isBold());
  612. assertEquals(Color.black, DrawPaint.applyColorTransform(tr1.getFontColor().getSolidColor()));
  613. assertEquals(tr0.getFontFamily(), tr1.getFontFamily());
  614. assertEquals(tr0.getFontSize(), tr1.getFontSize());
  615. assertEquals(tr0.isItalic(), tr1.isItalic());
  616. assertEquals(tr0.isShadowed(), tr1.isShadowed());
  617. assertEquals(tr0.isStrikethrough(), tr1.isStrikethrough());
  618. assertEquals(tr0.isUnderlined(), tr1.isUnderlined());
  619. ppt2.close();
  620. }
  621. @Test
  622. public void bug47904() throws IOException {
  623. HSLFSlideShow ppt1 = new HSLFSlideShow();
  624. HSLFSlideMaster sm = ppt1.getSlideMasters().get(0);
  625. HSLFAutoShape as = (HSLFAutoShape)sm.getShapes().get(0);
  626. HSLFTextParagraph tp = as.getTextParagraphs().get(0);
  627. HSLFTextRun tr = tp.getTextRuns().get(0);
  628. tr.setFontFamily("Tahoma");
  629. tr.setShadowed(true);
  630. tr.setFontSize(44.);
  631. tr.setFontColor(Color.red);
  632. tp.setTextAlign(TextAlign.RIGHT);
  633. ppt1.createSlide().addTitle().setText("foobaa");
  634. HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
  635. ppt1.close();
  636. HSLFTextShape ts = (HSLFTextShape)ppt2.getSlides().get(0).getShapes().get(0);
  637. tp = ts.getTextParagraphs().get(0);
  638. tr = tp.getTextRuns().get(0);
  639. assertEquals(44., tr.getFontSize(), 0);
  640. assertEquals("Tahoma", tr.getFontFamily());
  641. Color colorAct = DrawPaint.applyColorTransform(tr.getFontColor().getSolidColor());
  642. assertEquals(Color.red, colorAct);
  643. assertEquals(TextAlign.RIGHT, tp.getTextAlign());
  644. assertEquals("foobaa", tr.getRawText());
  645. ppt2.close();
  646. }
  647. @Test
  648. public void bug58718() throws IOException {
  649. String files[] = { "bug58718_008524.ppt","bug58718_008558.ppt","bug58718_349008.ppt","bug58718_008495.ppt", };
  650. for (String f : files) {
  651. File sample = HSLFTestDataSamples.getSampleFile(f);
  652. PowerPointExtractor ex = new PowerPointExtractor(sample.getAbsolutePath());
  653. assertNotNull(ex.getText());
  654. ex.close();
  655. }
  656. }
  657. @Test
  658. public void bug58733() throws IOException {
  659. File sample = HSLFTestDataSamples.getSampleFile("bug58733_671884.ppt");
  660. PowerPointExtractor ex = new PowerPointExtractor(sample.getAbsolutePath());
  661. assertNotNull(ex.getText());
  662. ex.close();
  663. }
  664. private static HSLFSlideShow open(String fileName) throws IOException {
  665. File sample = HSLFTestDataSamples.getSampleFile(fileName);
  666. return (HSLFSlideShow)SlideShowFactory.create(sample);
  667. }
  668. }