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 4.9KB

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