You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestXSLFTextRun.java 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.xslf.usermodel;
  20. import static org.apache.poi.sl.TestCommonSL.sameColor;
  21. import static org.junit.Assert.assertEquals;
  22. import static org.junit.Assert.assertFalse;
  23. import static org.junit.Assert.assertTrue;
  24. import static org.mockito.Mockito.mock;
  25. import static org.mockito.Mockito.when;
  26. import java.awt.Color;
  27. import java.io.IOException;
  28. import org.apache.poi.sl.draw.DrawTextParagraph;
  29. import org.junit.Test;
  30. /**
  31. * @author Yegor Kozlov
  32. */
  33. public class TestXSLFTextRun {
  34. @Test
  35. public void testRunProperties() throws IOException {
  36. XMLSlideShow ppt = new XMLSlideShow();
  37. XSLFSlide slide = ppt.createSlide();
  38. XSLFTextShape sh = slide.createAutoShape();
  39. XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun();
  40. assertEquals("en-US", r.getRPr(true).getLang());
  41. assertEquals(0., r.getCharacterSpacing(), 0);
  42. r.setCharacterSpacing(3);
  43. assertEquals(3., r.getCharacterSpacing(), 0);
  44. r.setCharacterSpacing(-3);
  45. assertEquals(-3., r.getCharacterSpacing(), 0);
  46. r.setCharacterSpacing(0);
  47. assertEquals(0., r.getCharacterSpacing(), 0);
  48. assertFalse(r.getRPr(true).isSetSpc());
  49. assertTrue(sameColor(Color.black, r.getFontColor()));
  50. r.setFontColor(Color.red);
  51. assertTrue(sameColor(Color.red, r.getFontColor()));
  52. assertEquals("Calibri", r.getFontFamily());
  53. r.setFontFamily("Arial");
  54. assertEquals("Arial", r.getFontFamily());
  55. assertEquals(18.0, r.getFontSize(), 0);
  56. r.setFontSize(13.0);
  57. assertEquals(13.0, r.getFontSize(), 0);
  58. assertFalse(r.isSuperscript());
  59. r.setSuperscript(true);
  60. assertTrue(r.isSuperscript());
  61. r.setSuperscript(false);
  62. assertFalse(r.isSuperscript());
  63. assertFalse(r.isSubscript());
  64. r.setSubscript(true);
  65. assertTrue(r.isSubscript());
  66. r.setSubscript(false);
  67. assertFalse(r.isSubscript());
  68. ppt.close();
  69. }
  70. @Test
  71. public void testUnicodeSurrogates() throws Exception {
  72. final String unicodeSurrogates = "\uD835\uDF4A\uD835\uDF4B\uD835\uDF4C\uD835\uDF4D\uD835\uDF4E"
  73. + "\uD835\uDF4F\uD835\uDF50\uD835\uDF51\uD835\uDF52\uD835\uDF53\uD835\uDF54\uD835"
  74. + "\uDF55\uD835\uDF56\uD835\uDF57\uD835\uDF58\uD835\uDF59\uD835\uDF5A\uD835\uDF5B"
  75. + "\uD835\uDF5C\uD835\uDF5D\uD835\uDF5E\uD835\uDF5F\uD835\uDF60\uD835\uDF61\uD835"
  76. + "\uDF62\uD835\uDF63\uD835\uDF64\uD835\uDF65\uD835\uDF66\uD835\uDF67\uD835\uDF68"
  77. + "\uD835\uDF69\uD835\uDF6A\uD835\uDF6B\uD835\uDF6C\uD835\uDF6D\uD835\uDF6E\uD835"
  78. + "\uDF6F\uD835\uDF70\uD835\uDF71\uD835\uDF72\uD835\uDF73\uD835\uDF74\uD835\uDF75"
  79. + "\uD835\uDF76\uD835\uDF77\uD835\uDF78\uD835\uDF79\uD835\uDF7A";
  80. try (XMLSlideShow ppt = new XMLSlideShow()) {
  81. XSLFSlide slide = ppt.createSlide();
  82. XSLFTextShape sh = slide.createAutoShape();
  83. XSLFTextParagraph p = sh.addNewTextParagraph();
  84. XSLFTextRun r = p.addNewTextRun();
  85. r.setText(unicodeSurrogates);
  86. assertEquals(unicodeSurrogates, new DrawTextParagraph(p).getRenderableText(r));
  87. }
  88. }
  89. @Test
  90. public void testCopyNullFontSize() throws IOException {
  91. XMLSlideShow ppt = new XMLSlideShow();
  92. XSLFSlide slide = ppt.createSlide();
  93. XSLFTextShape sh = slide.createAutoShape();
  94. XSLFTextRun r = sh.addNewTextParagraph().addNewTextRun();
  95. XSLFTextRun s = mock(XSLFTextRun.class);
  96. when(s.getFontSize()).thenReturn(null);
  97. r.copy(s);
  98. }
  99. }