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

TestNumberedList.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 java.util.List;
  21. import junit.framework.TestCase;
  22. import org.apache.poi.hslf.model.Slide;
  23. import org.apache.poi.hslf.model.TextRun;
  24. import org.apache.poi.hslf.model.textproperties.TextPFException9;
  25. import org.apache.poi.hslf.model.textproperties.TextPropCollection;
  26. import org.apache.poi.hslf.record.EscherTextboxWrapper;
  27. import org.apache.poi.hslf.record.StyleTextProp9Atom;
  28. import org.apache.poi.hslf.record.StyleTextPropAtom;
  29. import org.apache.poi.hslf.record.TextAutoNumberSchemeEnum;
  30. import org.apache.poi.POIDataSamples;
  31. /**
  32. * Test that checks numbered list functionality.
  33. *
  34. * @author Alex Nikiforov [mailto:anikif@gmail.com]
  35. */
  36. public final class TestNumberedList extends TestCase {
  37. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  38. protected void setUp() throws Exception {
  39. }
  40. public void testNumberedList() throws Exception {
  41. SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("numbers.ppt"));
  42. assertTrue("No Exceptions while reading file", true);
  43. final Slide[] slides = ppt.getSlides();
  44. assertEquals(2, slides.length);
  45. checkSlide0(slides[0]);
  46. checkSlide1(slides[1]);
  47. }
  48. private void checkSlide0(final Slide s) {
  49. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  50. assertNotNull(numberedListArray);
  51. assertEquals(1, numberedListArray.length);//Just one text box here
  52. final StyleTextProp9Atom numberedListInfo = numberedListArray[0];
  53. assertNotNull(numberedListInfo);
  54. final TextPFException9[] autoNumbers = numberedListInfo.getAutoNumberTypes();
  55. assertNotNull(autoNumbers);
  56. assertEquals(4, autoNumbers.length);
  57. assertTrue(4 == autoNumbers[0].getAutoNumberStartNumber());
  58. assertNull(autoNumbers[1].getAutoNumberStartNumber());
  59. assertTrue(3 == autoNumbers[2].getAutoNumberStartNumber());
  60. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbers[0].getAutoNumberScheme());
  61. assertNull(autoNumbers[1].getAutoNumberScheme());
  62. assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaLcParenRight == autoNumbers[2].getAutoNumberScheme());
  63. TextRun[] textRuns = s.getTextRuns();
  64. assertEquals(2, textRuns.length);
  65. RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
  66. assertEquals("titTe", textRun.getRawText());
  67. assertEquals(1, textRuns[0].getRichTextRuns().length);
  68. assertFalse(textRun.isBullet());
  69. assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
  70. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  71. assertEquals(textRuns.length, styleAtoms.length);
  72. final EscherTextboxWrapper wrapper = styleAtoms[1];
  73. final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
  74. final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
  75. final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
  76. assertEquals(60, props[0].getCharactersCovered());
  77. assertEquals(34, props[1].getCharactersCovered());
  78. assertEquals(68, props[2].getCharactersCovered());
  79. }
  80. private void checkSlide1(final Slide s) {
  81. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  82. assertNotNull(numberedListArray);
  83. assertEquals(1, numberedListArray.length);//Just one text box here
  84. final StyleTextProp9Atom numberedListInfo = numberedListArray[0];
  85. assertNotNull(numberedListInfo);
  86. final TextPFException9[] autoNumbers = numberedListInfo.getAutoNumberTypes();
  87. assertNotNull(autoNumbers);
  88. assertEquals(4, autoNumbers.length);
  89. assertTrue(9 == autoNumbers[0].getAutoNumberStartNumber());
  90. assertNull(autoNumbers[1].getAutoNumberStartNumber());
  91. assertTrue(3 == autoNumbers[2].getAutoNumberStartNumber());
  92. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicParenRight == autoNumbers[0].getAutoNumberScheme());
  93. assertNull(autoNumbers[1].getAutoNumberScheme());
  94. assertTrue(TextAutoNumberSchemeEnum.ANM_AlphaUcPeriod == autoNumbers[2].getAutoNumberScheme());
  95. final TextRun[] textRuns = s.getTextRuns();
  96. assertEquals(2, textRuns.length);
  97. RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
  98. assertEquals("Second Slide Title", textRun.getRawText());
  99. assertEquals(1, textRuns[0].getRichTextRuns().length);
  100. assertFalse(textRun.isBullet());
  101. assertEquals("This is a text placeholder that \rfollows the design pattern\rJust a test\rWithout any paragraph\rSecond paragraph first line c) ;\rSecond paragraph second line d) . \r", textRuns[1].getRawText());
  102. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  103. assertEquals(textRuns.length, styleAtoms.length);
  104. final EscherTextboxWrapper wrapper = styleAtoms[1];
  105. final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
  106. final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
  107. final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
  108. assertEquals(33, props[0].getCharactersCovered());
  109. assertEquals(61, props[1].getCharactersCovered());
  110. assertEquals(68, props[2].getCharactersCovered());
  111. }
  112. }