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.

XSLFGraphicFrame.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.sl.usermodel.Shape;
  21. import org.apache.poi.sl.usermodel.ShapeContainer;
  22. import org.apache.poi.sl.usermodel.ShapeGroup;
  23. import org.apache.poi.util.Beta;
  24. import org.apache.poi.util.Units;
  25. import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
  26. import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D;
  27. import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
  28. import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
  29. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  30. import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
  31. import java.awt.Graphics2D;
  32. import java.awt.geom.AffineTransform;
  33. import java.awt.geom.Rectangle2D;
  34. /**
  35. * @author Yegor Kozlov
  36. */
  37. @Beta
  38. public class XSLFGraphicFrame extends XSLFShape {
  39. private final CTGraphicalObjectFrame _shape;
  40. private final XSLFSheet _sheet;
  41. /*package*/ XSLFGraphicFrame(CTGraphicalObjectFrame shape, XSLFSheet sheet){
  42. _shape = shape;
  43. _sheet = sheet;
  44. }
  45. public CTGraphicalObjectFrame getXmlObject(){
  46. return _shape;
  47. }
  48. public XSLFSheet getSheet(){
  49. return _sheet;
  50. }
  51. public int getShapeType(){
  52. throw new RuntimeException("NotImplemented");
  53. }
  54. public int getShapeId(){
  55. return (int)_shape.getNvGraphicFramePr().getCNvPr().getId();
  56. }
  57. public String getShapeName(){
  58. return _shape.getNvGraphicFramePr().getCNvPr().getName();
  59. }
  60. public Rectangle2D getAnchor(){
  61. CTTransform2D xfrm = _shape.getXfrm();
  62. CTPoint2D off = xfrm.getOff();
  63. long x = off.getX();
  64. long y = off.getY();
  65. CTPositiveSize2D ext = xfrm.getExt();
  66. long cx = ext.getCx();
  67. long cy = ext.getCy();
  68. return new Rectangle2D.Double(
  69. Units.toPoints(x), Units.toPoints(y),
  70. Units.toPoints(cx), Units.toPoints(cy));
  71. }
  72. public void setAnchor(Rectangle2D anchor){
  73. CTTransform2D xfrm = _shape.getXfrm();
  74. CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
  75. long x = Units.toEMU(anchor.getX());
  76. long y = Units.toEMU(anchor.getY());
  77. off.setX(x);
  78. off.setY(y);
  79. CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm
  80. .addNewExt();
  81. long cx = Units.toEMU(anchor.getWidth());
  82. long cy = Units.toEMU(anchor.getHeight());
  83. ext.setCx(cx);
  84. ext.setCy(cy);
  85. }
  86. static XSLFGraphicFrame create(CTGraphicalObjectFrame shape, XSLFSheet sheet){
  87. String uri = shape.getGraphic().getGraphicData().getUri();
  88. if(XSLFTable.TABLE_URI.equals(uri)){
  89. return new XSLFTable(shape, sheet);
  90. } else {
  91. return new XSLFGraphicFrame(shape, sheet);
  92. }
  93. }
  94. /**
  95. * Rotate this shape.
  96. * <p>
  97. * Positive angles are clockwise (i.e., towards the positive y axis);
  98. * negative angles are counter-clockwise (i.e., towards the negative y axis).
  99. * </p>
  100. *
  101. * @param theta the rotation angle in degrees.
  102. */
  103. public void setRotation(double theta){
  104. throw new IllegalArgumentException("Operation not supported");
  105. }
  106. /**
  107. * Rotation angle in degrees
  108. * <p>
  109. * Positive angles are clockwise (i.e., towards the positive y axis);
  110. * negative angles are counter-clockwise (i.e., towards the negative y axis).
  111. * </p>
  112. *
  113. * @return rotation angle in degrees
  114. */
  115. public double getRotation(){
  116. return 0;
  117. }
  118. public void setFlipHorizontal(boolean flip){
  119. throw new IllegalArgumentException("Operation not supported");
  120. }
  121. public void setFlipVertical(boolean flip){
  122. throw new IllegalArgumentException("Operation not supported");
  123. }
  124. /**
  125. * Whether the shape is horizontally flipped
  126. *
  127. * @return whether the shape is horizontally flipped
  128. */
  129. public boolean getFlipHorizontal(){
  130. return false;
  131. }
  132. public boolean getFlipVertical(){
  133. return false;
  134. }
  135. public void draw(Graphics2D graphics){
  136. }
  137. }