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

TestNumberedList3.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * if a paragraph has autonumber ()
  34. * @see <a href="http://social.msdn.microsoft.com/Forums/mr-IN/os_binaryfile/thread/650888db-fabd-4b95-88dc-f0455f6e2d28">
  35. * PPT: Missing TextAutoNumberScheme structure providing the style of the number bullets</a>
  36. *
  37. * @author Alex Nikiforov [mailto:anikif@gmail.com]
  38. */
  39. public final class TestNumberedList3 extends TestCase {
  40. private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
  41. protected void setUp() throws Exception {
  42. }
  43. public void testNumberedList() throws Exception {
  44. SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("numbers3.ppt"));
  45. assertTrue("No Exceptions while reading file", true);
  46. final Slide[] slides = ppt.getSlides();
  47. assertEquals(1, slides.length);
  48. final Slide slide = slides[0];
  49. checkSlide(slide);
  50. }
  51. private void checkSlide(final Slide s) {
  52. final StyleTextProp9Atom[] numberedListArray = s.getNumberedListInfo();
  53. assertNotNull(numberedListArray);
  54. assertEquals(1, numberedListArray.length);
  55. final StyleTextProp9Atom numberedListInfoForTextBox = numberedListArray[0];
  56. assertNotNull(numberedListInfoForTextBox);
  57. final TextPFException9[] autoNumbersOfTextBox0 = numberedListInfoForTextBox.getAutoNumberTypes();
  58. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getfBulletHasAutoNumber());
  59. assertEquals(Short.valueOf((short)1), autoNumbersOfTextBox0[0].getAutoNumberStartNumber());//Default value = 1 will be used
  60. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
  61. final TextRun[] textRuns = s.getTextRuns();
  62. assertEquals(3, textRuns.length);
  63. assertEquals("Bulleted list\rMore bullets\rNo bullets here", textRuns[0].getRawText());
  64. assertEquals("Numbered list between two bulleted lists\rSecond numbered list item", textRuns[1].getRawText());
  65. assertEquals("Second bulleted list \u2013 should appear after numbered list\rMore bullets", textRuns[2].getRawText());
  66. assertEquals(2, textRuns[0].getRichTextRuns().length);
  67. assertEquals(1, textRuns[1].getRichTextRuns().length);
  68. assertEquals(1, textRuns[2].getRichTextRuns().length);
  69. assertNull(textRuns[0].getStyleTextProp9Atom());
  70. assertNotNull(textRuns[1].getStyleTextProp9Atom());
  71. assertNull(textRuns[2].getStyleTextProp9Atom());
  72. final TextPFException9[] autoNumbers = textRuns[1].getStyleTextProp9Atom().getAutoNumberTypes();
  73. assertEquals(1, autoNumbers.length);
  74. assertEquals(Short.valueOf((short)1), autoNumbers[0].getfBulletHasAutoNumber());
  75. assertEquals(Short.valueOf((short)1), autoNumbers[0].getAutoNumberStartNumber());//Default value = 1 will be used
  76. assertTrue(TextAutoNumberSchemeEnum.ANM_ArabicPeriod == autoNumbersOfTextBox0[0].getAutoNumberScheme());
  77. final List<TextPropCollection> textProps = textRuns[1].getStyleTextPropAtom().getCharacterStyles();
  78. assertEquals(1, textProps.size());
  79. final TextPropCollection textProp = textProps.get(0);
  80. assertEquals(67, textProp.getCharactersCovered());
  81. RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
  82. assertTrue(textRun.isBullet());
  83. final EscherTextboxWrapper[] styleAtoms = s.getTextboxWrappers();
  84. assertEquals(textRuns.length, styleAtoms.length);
  85. checkSingleRunWrapper(43, styleAtoms[0]);
  86. checkSingleRunWrapper(67, styleAtoms[1]);
  87. }
  88. private void checkSingleRunWrapper(final int exceptedLength, final EscherTextboxWrapper wrapper) {
  89. final StyleTextPropAtom styleTextPropAtom = wrapper.getStyleTextPropAtom();
  90. final List<TextPropCollection> textProps = styleTextPropAtom.getCharacterStyles();
  91. assertEquals(1, textProps.size());
  92. final TextPropCollection[] props = (TextPropCollection[]) textProps.toArray(new TextPropCollection[textProps.size()]);
  93. assertEquals(exceptedLength, props[0].getCharactersCovered());
  94. }
  95. }