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.

XSLFSlideLayout.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 org.apache.poi.POIXMLDocumentPart;
  17. import org.apache.poi.openxml4j.opc.PackagePart;
  18. import org.apache.poi.openxml4j.opc.PackageRelationship;
  19. import org.apache.poi.util.Beta;
  20. import org.apache.poi.util.Internal;
  21. import org.apache.xmlbeans.XmlException;
  22. import org.apache.xmlbeans.XmlObject;
  23. import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideLayout;
  24. import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument;
  25. import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
  26. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextListStyle;
  28. import java.io.IOException;
  29. import java.util.Map;
  30. import java.util.HashMap;
  31. import java.awt.*;
  32. import java.awt.geom.AffineTransform;
  33. @Beta
  34. public class XSLFSlideLayout extends XSLFSheet {
  35. private CTSlideLayout _layout;
  36. private XSLFSlideMaster _master;
  37. XSLFSlideLayout() {
  38. super();
  39. _layout = CTSlideLayout.Factory.newInstance();
  40. }
  41. public XSLFSlideLayout(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
  42. super(part, rel);
  43. SldLayoutDocument doc =
  44. SldLayoutDocument.Factory.parse(getPackagePart().getInputStream());
  45. _layout = doc.getSldLayout();
  46. setCommonSlideData(_layout.getCSld());
  47. }
  48. public String getName(){
  49. return _layout.getCSld().getName();
  50. }
  51. /**
  52. * While developing only!
  53. */
  54. @Internal
  55. public CTSlideLayout getXmlObject() {
  56. return _layout;
  57. }
  58. @Override
  59. protected String getRootElementName(){
  60. return "sldLayout";
  61. }
  62. /**
  63. * Slide master object associated with this layout.
  64. * <p>
  65. * Within a slide master slide are contained all elements
  66. * that describe the objects and their corresponding formatting
  67. * for within a presentation slide.
  68. * </p>
  69. * <p>
  70. * Within a slide master slide are two main elements.
  71. * The cSld element specifies the common slide elements such as shapes and
  72. * their attached text bodies. Then the txStyles element specifies the
  73. * formatting for the text within each of these shapes. The other properties
  74. * within a slide master slide specify other properties for within a presentation slide
  75. * such as color information, headers and footers, as well as timing and
  76. * transition information for all corresponding presentation slides.
  77. * </p>
  78. *
  79. * @return slide master. Never null.
  80. * @throws IllegalStateException if slide master was not found
  81. */
  82. @Override
  83. public XSLFSlideMaster getSlideMaster(){
  84. if(_master == null){
  85. for (POIXMLDocumentPart p : getRelations()) {
  86. if (p instanceof XSLFSlideMaster){
  87. _master = (XSLFSlideMaster)p;
  88. }
  89. }
  90. }
  91. if(_master == null) {
  92. throw new IllegalStateException("SlideMaster was not found for " + this.toString());
  93. }
  94. return _master;
  95. }
  96. public XMLSlideShow getSlideShow() {
  97. return (XMLSlideShow)getParent().getParent();
  98. }
  99. public XSLFTheme getTheme(){
  100. return getSlideMaster().getTheme();
  101. }
  102. @Override
  103. protected CTTextListStyle getTextProperties(Placeholder textType) {
  104. XSLFTextShape lp = getTextShapeByType(textType);
  105. CTTextListStyle props = lp.getTextBody(false).getLstStyle();
  106. return props;
  107. }
  108. /**
  109. * Render this sheet into the supplied graphics object
  110. *
  111. */
  112. @Override
  113. protected boolean canDraw(XSLFShape shape){
  114. if(shape instanceof XSLFSimpleShape){
  115. XSLFSimpleShape txt = (XSLFSimpleShape)shape;
  116. CTPlaceholder ph = txt.getCTPlaceholder();
  117. if(ph != null) {
  118. return false;
  119. }
  120. }
  121. return true;
  122. }
  123. @Override
  124. public XSLFBackground getBackground(){
  125. if(_layout.getCSld().isSetBg()) {
  126. return new XSLFBackground(_layout.getCSld().getBg(), this);
  127. }
  128. return null;
  129. }
  130. }