Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XSLFSlide.java 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 java.io.IOException;
  17. import org.apache.poi.POIXMLDocumentPart;
  18. import org.apache.poi.openxml4j.opc.PackagePart;
  19. import org.apache.poi.openxml4j.opc.PackageRelationship;
  20. import org.apache.poi.sl.usermodel.Slide;
  21. import org.apache.poi.util.Beta;
  22. import org.apache.xmlbeans.XmlException;
  23. import org.openxmlformats.schemas.drawingml.x2006.main.*;
  24. import org.openxmlformats.schemas.presentationml.x2006.main.*;
  25. @Beta
  26. public final class XSLFSlide extends XSLFSheet implements Slide<XSLFShape, XMLSlideShow, XSLFNotes> {
  27. private final CTSlide _slide;
  28. private XSLFSlideLayout _layout;
  29. private XSLFComments _comments;
  30. private XSLFNotes _notes;
  31. /**
  32. * Create a new slide
  33. */
  34. XSLFSlide() {
  35. super();
  36. _slide = prototype();
  37. setCommonSlideData(_slide.getCSld());
  38. }
  39. /**
  40. * Construct a SpreadsheetML slide from a package part
  41. *
  42. * @param part the package part holding the slide data,
  43. * the content type must be <code>application/vnd.openxmlformats-officedocument.slide+xml</code>
  44. * @param rel the package relationship holding this slide,
  45. * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide
  46. */
  47. XSLFSlide(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
  48. super(part, rel);
  49. SldDocument doc =
  50. SldDocument.Factory.parse(getPackagePart().getInputStream());
  51. _slide = doc.getSld();
  52. setCommonSlideData(_slide.getCSld());
  53. }
  54. private static CTSlide prototype(){
  55. CTSlide ctSlide = CTSlide.Factory.newInstance();
  56. CTCommonSlideData cSld = ctSlide.addNewCSld();
  57. CTGroupShape spTree = cSld.addNewSpTree();
  58. CTGroupShapeNonVisual nvGrpSpPr = spTree.addNewNvGrpSpPr();
  59. CTNonVisualDrawingProps cnvPr = nvGrpSpPr.addNewCNvPr();
  60. cnvPr.setId(1);
  61. cnvPr.setName("");
  62. nvGrpSpPr.addNewCNvGrpSpPr();
  63. nvGrpSpPr.addNewNvPr();
  64. CTGroupShapeProperties grpSpr = spTree.addNewGrpSpPr();
  65. CTGroupTransform2D xfrm = grpSpr.addNewXfrm();
  66. CTPoint2D off = xfrm.addNewOff();
  67. off.setX(0);
  68. off.setY(0);
  69. CTPositiveSize2D ext = xfrm.addNewExt();
  70. ext.setCx(0);
  71. ext.setCy(0);
  72. CTPoint2D choff = xfrm.addNewChOff();
  73. choff.setX(0);
  74. choff.setY(0);
  75. CTPositiveSize2D chExt = xfrm.addNewChExt();
  76. chExt.setCx(0);
  77. chExt.setCy(0);
  78. ctSlide.addNewClrMapOvr().addNewMasterClrMapping();
  79. return ctSlide;
  80. }
  81. @Override
  82. public CTSlide getXmlObject() {
  83. return _slide;
  84. }
  85. @Override
  86. protected String getRootElementName(){
  87. return "sld";
  88. }
  89. public XSLFSlideLayout getMasterSheet(){
  90. return getSlideLayout();
  91. }
  92. public XSLFSlideLayout getSlideLayout(){
  93. if(_layout == null){
  94. for (POIXMLDocumentPart p : getRelations()) {
  95. if (p instanceof XSLFSlideLayout){
  96. _layout = (XSLFSlideLayout)p;
  97. }
  98. }
  99. }
  100. if(_layout == null) {
  101. throw new IllegalArgumentException("SlideLayout was not found for " + this.toString());
  102. }
  103. return _layout;
  104. }
  105. public XSLFSlideMaster getSlideMaster(){
  106. return getSlideLayout().getSlideMaster();
  107. }
  108. public XSLFComments getComments() {
  109. if(_comments == null) {
  110. for (POIXMLDocumentPart p : getRelations()) {
  111. if (p instanceof XSLFComments) {
  112. _comments = (XSLFComments)p;
  113. }
  114. }
  115. }
  116. if(_comments == null) {
  117. // This slide lacks comments
  118. // Not all have them, sorry...
  119. return null;
  120. }
  121. return _comments;
  122. }
  123. public XSLFNotes getNotes() {
  124. if(_notes == null) {
  125. for (POIXMLDocumentPart p : getRelations()) {
  126. if (p instanceof XSLFNotes){
  127. _notes = (XSLFNotes)p;
  128. }
  129. }
  130. }
  131. if(_notes == null) {
  132. // This slide lacks notes
  133. // Not all have them, sorry...
  134. return null;
  135. }
  136. return _notes;
  137. }
  138. /**
  139. *
  140. * @return title of this slide or empty string if title is not set
  141. */
  142. public String getTitle(){
  143. XSLFTextShape txt = getTextShapeByType(Placeholder.TITLE);
  144. return txt == null ? "" : txt.getText();
  145. }
  146. @Override
  147. public XSLFTheme getTheme(){
  148. return getSlideLayout().getSlideMaster().getTheme();
  149. }
  150. /**
  151. *
  152. * @return the information about background appearance of this slide
  153. */
  154. @Override
  155. public XSLFBackground getBackground() {
  156. CTBackground bg = _slide.getCSld().getBg();
  157. if(bg != null) {
  158. return new XSLFBackground(bg, this);
  159. } else {
  160. return getMasterSheet().getBackground();
  161. }
  162. }
  163. /**
  164. *
  165. * @return whether shapes on the master slide should be shown or not.
  166. */
  167. public boolean getFollowMasterGraphics(){
  168. return !_slide.isSetShowMasterSp() || _slide.getShowMasterSp();
  169. }
  170. /**
  171. *
  172. * @param value whether shapes on the master slide should be shown or not.
  173. */
  174. public void setFollowMasterGraphics(boolean value){
  175. _slide.setShowMasterSp(value);
  176. }
  177. public boolean getFollowMasterObjects() {
  178. return getFollowMasterGraphics();
  179. }
  180. public void setFollowMasterObjects(boolean follow) {
  181. setFollowMasterGraphics(follow);
  182. }
  183. @Override
  184. public XSLFSlide importContent(XSLFSheet src){
  185. super.importContent(src);
  186. XSLFBackground bgShape = getBackground();
  187. if(bgShape != null) {
  188. CTBackground bg = (CTBackground)bgShape.getXmlObject();
  189. if(bg.isSetBgPr() && bg.getBgPr().isSetBlipFill()){
  190. CTBlip blip = bg.getBgPr().getBlipFill().getBlip();
  191. String blipId = blip.getEmbed();
  192. String relId = importBlip(blipId, src.getPackagePart());
  193. blip.setEmbed(relId);
  194. }
  195. }
  196. return this;
  197. }
  198. public boolean getFollowMasterBackground() {
  199. return false;
  200. }
  201. public void setFollowMasterBackground(boolean follow) {
  202. // not implemented ... also not in the specs
  203. throw new UnsupportedOperationException();
  204. }
  205. public boolean getFollowMasterColourScheme() {
  206. return false;
  207. }
  208. public void setFollowMasterColourScheme(boolean follow) {
  209. // not implemented ... only for OLE objects in the specs
  210. throw new UnsupportedOperationException();
  211. }
  212. public void setNotes(XSLFNotes notes) {
  213. // TODO Auto-generated method stub
  214. }
  215. }