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ů.

TestNumberedList3.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.hslf.usermodel;
  20. import static org.junit.Assert.*;
  21. import java.util.List;
  22. import org.apache.poi.POIDataSamples;
  23. import org.apache.poi.hslf.model.textproperties.TextPFException9;
  24. import org.apache.poi.hslf.model.textproperties.TextPropCollection;
  25. import org.apache.poi.hslf.record.*;
  26. import org.junit.Test;
  27. /**
  28. * Test that checks numbered list functionality.
  29. * if a paragraph has autonumber ()
  30. * @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
  31. * PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
  32. *
  33. * @author Alex Nikiforov [mailto:anikif@gmail.com]
  34. */
  35. public final class TestNumberedList3 {
  36. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  37. @Test
  38. public void testNumberedList() throws Exception {
  39. HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("numbers3.ppt"));
  40. assertTrue("No Exceptions while reading file", true);
  41. final List<HSLFSlide> slides = ppt.getSlides();
  42. assertEquals(1, slides.size());
  43. final HSLFSlide slide = slides.get(0);
  44. checkSlide(slide);
  45. }
  46. private void checkSlide(final HSLFSlide s) {
  47. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  48. assertNotNull(numberedListArray);
  49. assertEquals(1, numberedListArray.length);
  50. final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0];
  51. assertNotNull(numberedListInfoForTextBox);
  52. final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox.getAutoNumberTypes();
  53. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber());
  54. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used
  55. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
  56. final List<List<HSLFTextParagraph>> textParass = s.getTextParagraphs();
  57. assertEquals(3, textParass.size());
  58. assertEquals("Bulleted list\rMore bullets\rNo bullets here", HSLFTextParagraph.getRawText(textParass.get(0)));
  59. assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", HSLFTextParagraph.getRawText(textParass.get(1)));
  60. assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", HSLFTextParagraph.getRawText(textParass.get(2)));
  61. assertEquals(3, textParass.get(0).size());
  62. assertEquals(2, textParass.get(1).size());
  63. assertEquals(2, textParass.get(2).size());
  64. assertNull(textParass.get(0).get(0).getStyleTextProp9Atom());
  65. assertNotNull(textParass.get(1).get(0).getStyleTextProp9Atom());
  66. assertNull(textParass.get(2).get(0).getStyleTextProp9Atom());
  67. final TextPFException9[] autoNumbers = textParass.get(1).get(0).getStyleTextProp9Atom().getAutoNumberTypes();
  68. assertEquals(1, autoNumbers.length);
  69. assertEquals(Short.valueOf((short)1), autoNumbers[0].getfBulletHasAutoNumber());
  70. assertEquals(Short.valueOf((short)1), autoNumbers[0].getAutoNumberStartNumber());//Default value = 1 will be used
  71. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
  72. int chCovered = 0;
  73. for (HSLFTextParagraph htp : textParass.get(1)) {
  74. for (HSLFTextRun htr : htp.getTextRuns()) {
  75. TextPropCollection textProp = htr.getCharacterStyle();
  76. chCovered += textProp.getCharactersCovered();
  77. }
  78. }
  79. assertEquals(67, chCovered);
  80. assertTrue(textParass.get(0).get(0).isBullet());
  81. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  82. assertEquals(textParass.size(), styleAtoms.length);
  83. checkSingleRunWrapper(43, styleAtoms[0]);
  84. checkSingleRunWrapper(67, styleAtoms[1]);
  85. }
  86. private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
  87. final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
  88. final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
  89. assertEquals(1, textProps.size());
  90. assertEquals(exceptedLength, textProps.get(0).getCharactersCovered());
  91. }
  92. }