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.8KB

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