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.

TestXSLFTheme.java 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.xslf.usermodel;
  16. import junit.framework.TestCase;
  17. import org.apache.poi.xslf.XSLFTestDataSamples;
  18. import java.awt.Color;
  19. import java.awt.TexturePaint;
  20. /**
  21. * test reading properties from a multi-theme and multi-master document
  22. *
  23. * @author Yegor Kozlov
  24. */
  25. public class TestXSLFTheme extends TestCase {
  26. public void testRead(){
  27. XMLSlideShow ppt = XSLFTestDataSamples.openSampleDocument("themes.pptx");
  28. XSLFSlide[] slides = ppt.getSlides();
  29. slide1(slides[0]);
  30. slide2(slides[1]);
  31. slide3(slides[2]);
  32. slide4(slides[3]);
  33. slide5(slides[4]);
  34. slide6(slides[5]);
  35. slide7(slides[6]);
  36. slide8(slides[7]);
  37. slide9(slides[8]);
  38. slide10(slides[9]);
  39. }
  40. private XSLFShape getShape(XSLFSheet sheet, String name){
  41. for(XSLFShape sh : sheet.getShapes()){
  42. if(sh.getShapeName().equals(name)) return sh;
  43. }
  44. throw new IllegalArgumentException("Shape not found: " + name);
  45. }
  46. void slide1(XSLFSlide slide){
  47. assertEquals(Color.white, slide.getBackground().getFillColor());
  48. XSLFTheme theme = slide.getTheme();
  49. assertEquals("Office Theme", theme.getName());
  50. XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 3");
  51. RenderableShape rsh1 = new RenderableShape(sh1);
  52. XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
  53. assertEquals(Color.white, run1.getFontColor());
  54. assertEquals(new Color(79, 129, 189), sh1.getFillColor());
  55. assertTrue(rsh1.getFillPaint(null) instanceof Color) ; // solid fill
  56. }
  57. void slide2(XSLFSlide slide){
  58. // Background 2, darker 10%
  59. // YK: PPT shows slightly different color: new Color(221, 217, 195)
  60. assertEquals(new Color(214, 212, 203), slide.getBackground().getFillColor());
  61. }
  62. void slide3(XSLFSlide slide){
  63. assertNull(slide.getBackground().getFillColor());
  64. assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
  65. }
  66. void slide4(XSLFSlide slide){
  67. assertNull(slide.getBackground().getFillColor());
  68. assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
  69. XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Rectangle 4");
  70. RenderableShape rsh1 = new RenderableShape(sh1);
  71. XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
  72. assertEquals(Color.white, run1.getFontColor());
  73. assertEquals(new Color(148, 198, 0), sh1.getFillColor());
  74. assertTrue(rsh1.getFillPaint(null) instanceof Color) ; // solid fill
  75. XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 3");
  76. XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
  77. assertEquals(new Color(148, 198, 0), run2.getFontColor());
  78. assertNull(sh2.getFillColor()); // no fill
  79. assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
  80. }
  81. void slide5(XSLFSlide slide){
  82. assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
  83. XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 1");
  84. XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
  85. assertEquals(new Color(148, 198, 0), run2.getFontColor());
  86. assertNull(sh2.getFillColor()); // no fill
  87. // font size is 40pt and scale factor is 90%
  88. assertEquals(36.0, run2.getFontSize());
  89. assertTrue(slide.getSlideLayout().getFollowMasterGraphics());
  90. }
  91. void slide6(XSLFSlide slide){
  92. XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Subtitle 3");
  93. XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
  94. assertEquals(new Color(66, 66, 66), run1.getFontColor());
  95. assertNull(sh1.getFillColor()); // no fill
  96. XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Title 2");
  97. XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
  98. assertEquals(new Color(148, 198, 0), run2.getFontColor());
  99. assertNull(sh2.getFillColor()); // no fill
  100. assertFalse(slide.getSlideLayout().getFollowMasterGraphics());
  101. }
  102. void slide7(XSLFSlide slide){
  103. //YK: PPT reports a slightly different color: r=189,g=239,b=87
  104. assertEquals(new Color(182, 218, 108), slide.getBackground().getFillColor());
  105. assertFalse(slide.getFollowMasterGraphics());
  106. }
  107. void slide8(XSLFSlide slide){
  108. assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
  109. }
  110. void slide9(XSLFSlide slide){
  111. assertTrue(slide.getBackground().getPaint(null) instanceof TexturePaint);
  112. }
  113. void slide10(XSLFSlide slide){
  114. assertTrue(slide.getBackground().getPaint(null).getClass().getName().indexOf("Gradient") > 0);
  115. XSLFTextShape sh1 = (XSLFTextShape)getShape(slide, "Title 3");
  116. XSLFTextRun run1 = sh1.getTextParagraphs().get(0).getTextRuns().get(0);
  117. assertEquals(Color.white, run1.getFontColor());
  118. assertNull(sh1.getFillColor()); // no fill
  119. XSLFTextShape sh2 = (XSLFTextShape)getShape(slide, "Subtitle 4");
  120. XSLFTextRun run2 = sh2.getTextParagraphs().get(0).getTextRuns().get(0);
  121. assertEquals(Color.white, run2.getFontColor());
  122. assertNull(sh2.getFillColor()); // no fill
  123. }
  124. }