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.

XSLFAutoShape.java 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 org.apache.poi.util.Beta;
  21. import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
  22. import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
  23. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  24. import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
  25. import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
  26. import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
  27. import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual;
  28. /**
  29. * Represents a shape with a preset geometry.
  30. *
  31. * @author Yegor Kozlov
  32. */
  33. @Beta
  34. public class XSLFAutoShape extends XSLFTextShape {
  35. /*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
  36. super(shape, sheet);
  37. }
  38. /*package*/
  39. static XSLFAutoShape create(CTShape shape, XSLFSheet sheet) {
  40. if (shape.getSpPr().isSetCustGeom()) {
  41. return new XSLFFreeformShape(shape, sheet);
  42. } else if (shape.getNvSpPr().getCNvSpPr().isSetTxBox()) {
  43. return new XSLFTextBox(shape, sheet);
  44. } else {
  45. return new XSLFAutoShape(shape, sheet);
  46. }
  47. }
  48. /**
  49. * @param shapeId 1-based shapeId
  50. */
  51. static CTShape prototype(int shapeId) {
  52. CTShape ct = CTShape.Factory.newInstance();
  53. CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
  54. CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
  55. cnv.setName("AutoShape " + shapeId);
  56. cnv.setId(shapeId + 1);
  57. nvSpPr.addNewCNvSpPr();
  58. nvSpPr.addNewNvPr();
  59. CTShapeProperties spPr = ct.addNewSpPr();
  60. CTPresetGeometry2D prst = spPr.addNewPrstGeom();
  61. prst.setPrst(STShapeType.RECT);
  62. prst.addNewAvLst();
  63. return ct;
  64. }
  65. protected CTTextBody getTextBody(boolean create){
  66. CTShape shape = (CTShape) getXmlObject();
  67. CTTextBody txBody = shape.getTxBody();
  68. if (txBody == null && create) {
  69. txBody = shape.addNewTxBody();
  70. txBody.addNewBodyPr();
  71. txBody.addNewLstStyle();
  72. }
  73. return txBody;
  74. }
  75. }