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.

XSLFShape.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.xmlbeans.XmlObject;
  22. import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
  23. import java.awt.Graphics2D;
  24. import java.awt.geom.Rectangle2D;
  25. /**
  26. * @author Yegor Kozlov
  27. */
  28. @Beta
  29. public abstract class XSLFShape {
  30. public abstract Rectangle2D getAnchor();
  31. public abstract void setAnchor(Rectangle2D anchor);
  32. public abstract XmlObject getXmlObject();
  33. public abstract String getShapeName();
  34. public abstract int getShapeId();
  35. /**
  36. * Rotate this shape.
  37. * <p>
  38. * Positive angles are clockwise (i.e., towards the positive y axis);
  39. * negative angles are counter-clockwise (i.e., towards the negative y axis).
  40. * </p>
  41. *
  42. * @param theta the rotation angle in degrees.
  43. */
  44. public abstract void setRotation(double theta);
  45. /**
  46. * Rotation angle in degrees
  47. * <p>
  48. * Positive angles are clockwise (i.e., towards the positive y axis);
  49. * negative angles are counter-clockwise (i.e., towards the negative y axis).
  50. * </p>
  51. *
  52. * @return rotation angle in degrees
  53. */
  54. public abstract double getRotation();
  55. public abstract void setFlipHorizontal(boolean flip);
  56. public abstract void setFlipVertical(boolean flip);
  57. /**
  58. * Whether the shape is horizontally flipped
  59. *
  60. * @return whether the shape is horizontally flipped
  61. */
  62. public abstract boolean getFlipHorizontal();
  63. public abstract boolean getFlipVertical();
  64. public abstract void draw(Graphics2D graphics);
  65. protected java.awt.Shape getOutline(){
  66. return getAnchor();
  67. }
  68. protected void applyTransform(Graphics2D graphics){
  69. Rectangle2D anchor = getAnchor();
  70. // rotation
  71. double rotation = getRotation();
  72. if(rotation != 0.) {
  73. // PowerPoint rotates shapes relative to the geometric center
  74. double centerX = anchor.getX() + anchor.getWidth()/2;
  75. double centerY = anchor.getY() + anchor.getHeight()/2;
  76. graphics.translate(centerX, centerY);
  77. graphics.rotate(Math.toRadians(rotation));
  78. graphics.translate(-centerX, -centerY);
  79. }
  80. //flip horizontal
  81. if(getFlipHorizontal()){
  82. graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
  83. graphics.scale(-1, 1);
  84. graphics.translate(-anchor.getX() , -anchor.getY());
  85. }
  86. //flip vertical
  87. if(getFlipVertical()){
  88. graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
  89. graphics.scale(1, -1);
  90. graphics.translate(-anchor.getX(), -anchor.getY());
  91. }
  92. }
  93. }