autoshapes.java
来自「EXCEL read and write」· Java 代码 · 共 381 行 · 第 1/2 页
JAVA
381 行
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hslf.model;
import org.apache.poi.ddf.EscherProperties;
import java.awt.geom.*;
/**
* Stores definition of auto-shapes.
* See the Office Drawing 97-2007 Binary Format Specification for details.
*
* TODO: follow the spec and define all the auto-shapes
*
* @author Yegor Kozlov
*/
public class AutoShapes {
protected static ShapeOutline[] shapes;
/**
* Return shape outline by shape type
* @param type shape type see {@link ShapeTypes}
*
* @return the shape outline
*/
public static ShapeOutline getShapeOutline(int type){
ShapeOutline outline = shapes[type];
return outline;
}
/**
* Auto-shapes are defined in the [0,21600] coordinate system.
* We need to transform it into normal slide coordinates
*
*/
public static java.awt.Shape transform(java.awt.Shape outline, Rectangle2D anchor){
AffineTransform at = new AffineTransform();
at.translate(anchor.getX(), anchor.getY());
at.scale(
1.0f/21600*anchor.getWidth(),
1.0f/21600*anchor.getHeight()
);
return at.createTransformedShape(outline);
}
static {
shapes = new ShapeOutline[255];
shapes[ShapeTypes.Rectangle] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
Rectangle2D path = new Rectangle2D.Float(0, 0, 21600, 21600);
return path;
}
};
shapes[ShapeTypes.RoundRectangle] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
RoundRectangle2D path = new RoundRectangle2D.Float(0, 0, 21600, 21600, adjval, adjval);
return path;
}
};
shapes[ShapeTypes.Ellipse] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
Ellipse2D path = new Ellipse2D.Float(0, 0, 21600, 21600);
return path;
}
};
shapes[ShapeTypes.Diamond] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
GeneralPath path = new GeneralPath();
path.moveTo(10800, 0);
path.lineTo(21600, 10800);
path.lineTo(10800, 21600);
path.lineTo(0, 10800);
path.closePath();
return path;
}
};
//m@0,l,21600r21600
shapes[ShapeTypes.IsocelesTriangle] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 10800);
GeneralPath path = new GeneralPath();
path.moveTo(adjval, 0);
path.lineTo(0, 21600);
path.lineTo(21600, 21600);
path.closePath();
return path;
}
};
shapes[ShapeTypes.RightTriangle] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
GeneralPath path = new GeneralPath();
path.moveTo(0, 0);
path.lineTo(21600, 21600);
path.lineTo(0, 21600);
path.closePath();
return path;
}
};
shapes[ShapeTypes.Parallelogram] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
GeneralPath path = new GeneralPath();
path.moveTo(adjval, 0);
path.lineTo(21600, 0);
path.lineTo(21600 - adjval, 21600);
path.lineTo(0, 21600);
path.closePath();
return path;
}
};
shapes[ShapeTypes.Trapezoid] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
GeneralPath path = new GeneralPath();
path.moveTo(0, 0);
path.lineTo(adjval, 21600);
path.lineTo(21600 - adjval, 21600);
path.lineTo(21600, 0);
path.closePath();
return path;
}
};
shapes[ShapeTypes.Hexagon] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
GeneralPath path = new GeneralPath();
path.moveTo(adjval, 0);
path.lineTo(21600 - adjval, 0);
path.lineTo(21600, 10800);
path.lineTo(21600 - adjval, 21600);
path.lineTo(adjval, 21600);
path.lineTo(0, 10800);
path.closePath();
return path;
}
};
shapes[ShapeTypes.Octagon] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 6326);
GeneralPath path = new GeneralPath();
path.moveTo(adjval, 0);
path.lineTo(21600 - adjval, 0);
path.lineTo(21600, adjval);
path.lineTo(21600, 21600-adjval);
path.lineTo(21600-adjval, 21600);
path.lineTo(adjval, 21600);
path.lineTo(0, 21600-adjval);
path.lineTo(0, adjval);
path.closePath();
return path;
}
};
shapes[ShapeTypes.Plus] = new ShapeOutline(){
public java.awt.Shape getOutline(Shape shape){
int adjval = shape.getEscherProperty(EscherProperties.GEOMETRY__ADJUSTVALUE, 5400);
GeneralPath path = new GeneralPath();
path.moveTo(adjval, 0);
path.lineTo(21600 - adjval, 0);
path.lineTo(21600 - adjval, adjval);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?