選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Line.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.hslf.model;
  16. import org.apache.poi.ddf.*;
  17. import org.apache.poi.hslf.usermodel.*;
  18. import org.apache.poi.sl.usermodel.ShapeContainer;
  19. import org.apache.poi.sl.usermodel.ShapeType;
  20. import java.awt.geom.*;
  21. import java.util.ArrayList;
  22. /**
  23. * Represents a line in a PowerPoint drawing
  24. *
  25. * @author Yegor Kozlov
  26. */
  27. public final class Line extends HSLFSimpleShape {
  28. public Line(EscherContainerRecord escherRecord, ShapeContainer<HSLFShape> parent){
  29. super(escherRecord, parent);
  30. }
  31. public Line(ShapeContainer<HSLFShape> parent){
  32. super(null, parent);
  33. _escherContainer = createSpContainer(parent instanceof HSLFGroupShape);
  34. }
  35. public Line(){
  36. this(null);
  37. }
  38. protected EscherContainerRecord createSpContainer(boolean isChild){
  39. _escherContainer = super.createSpContainer(isChild);
  40. EscherSpRecord spRecord = _escherContainer.getChildById(EscherSpRecord.RECORD_ID);
  41. short type = (short)((ShapeType.LINE.nativeId << 4) | 0x2);
  42. spRecord.setOptions(type);
  43. //set default properties for a line
  44. EscherOptRecord opt = getEscherOptRecord();
  45. //default line properties
  46. setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, 4);
  47. setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, 0x10000);
  48. setEscherProperty(opt, EscherProperties.FILL__NOFILLHITTEST, 0x100000);
  49. setEscherProperty(opt, EscherProperties.LINESTYLE__COLOR, 0x8000001);
  50. setEscherProperty(opt, EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0xA0008);
  51. setEscherProperty(opt, EscherProperties.SHADOWSTYLE__COLOR, 0x8000002);
  52. return _escherContainer;
  53. }
  54. public java.awt.Shape getOutline(){
  55. Rectangle2D anchor = getLogicalAnchor2D();
  56. return new Line2D.Double(anchor.getX(), anchor.getY(), anchor.getX() + anchor.getWidth(), anchor.getY() + anchor.getHeight());
  57. }
  58. /**
  59. *
  60. * @return 'absolute' anchor of this shape relative to the parent sheet
  61. *
  62. * @deprecated TODO: remove the whole class, should work with preset geometries instead
  63. */
  64. public Rectangle2D getLogicalAnchor2D(){
  65. Rectangle2D anchor = getAnchor2D();
  66. //if it is a groupped shape see if we need to transform the coordinates
  67. if (getParent() != null){
  68. ArrayList<HSLFGroupShape> lst = new ArrayList<HSLFGroupShape>();
  69. for (ShapeContainer<HSLFShape> parent=this.getParent();
  70. parent instanceof HSLFGroupShape;
  71. parent = ((HSLFGroupShape)parent).getParent()) {
  72. lst.add(0, (HSLFGroupShape)parent);
  73. }
  74. AffineTransform tx = new AffineTransform();
  75. for(HSLFGroupShape prnt : lst) {
  76. Rectangle2D exterior = prnt.getAnchor2D();
  77. Rectangle2D interior = prnt.getInteriorAnchor();
  78. double scaleX = exterior.getWidth() / interior.getWidth();
  79. double scaleY = exterior.getHeight() / interior.getHeight();
  80. tx.translate(exterior.getX(), exterior.getY());
  81. tx.scale(scaleX, scaleY);
  82. tx.translate(-interior.getX(), -interior.getY());
  83. }
  84. anchor = tx.createTransformedShape(anchor).getBounds2D();
  85. }
  86. double angle = getRotation();
  87. if(angle != 0.){
  88. double centerX = anchor.getX() + anchor.getWidth()/2;
  89. double centerY = anchor.getY() + anchor.getHeight()/2;
  90. AffineTransform trans = new AffineTransform();
  91. trans.translate(centerX, centerY);
  92. trans.rotate(Math.toRadians(angle));
  93. trans.translate(-centerX, -centerY);
  94. Rectangle2D rect = trans.createTransformedShape(anchor).getBounds2D();
  95. if((anchor.getWidth() < anchor.getHeight() && rect.getWidth() > rect.getHeight()) ||
  96. (anchor.getWidth() > anchor.getHeight() && rect.getWidth() < rect.getHeight()) ){
  97. trans = new AffineTransform();
  98. trans.translate(centerX, centerY);
  99. trans.rotate(Math.PI/2);
  100. trans.translate(-centerX, -centerY);
  101. anchor = trans.createTransformedShape(anchor).getBounds2D();
  102. }
  103. }
  104. return anchor;
  105. }
  106. }