You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/02/21 11:56:06 UTC
svn commit: r1661322 [12/14] - in /poi/branches/common_sl: ./
src/examples/src/org/apache/poi/hslf/examples/
src/examples/src/org/apache/poi/xslf/usermodel/
src/java/org/apache/poi/common/usermodel/
src/java/org/apache/poi/hssf/usermodel/ src/java/org/...
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/binding/STTextShapeType.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/binding/STTextShapeType.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/binding/STTextShapeType.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/binding/STTextShapeType.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,389 @@
+/* ====================================================================
+ 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.sl.draw.binding;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlEnumValue;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for ST_TextShapeType.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * <p>
+ * <pre>
+ * <simpleType name="ST_TextShapeType">
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}token">
+ * <enumeration value="textNoShape"/>
+ * <enumeration value="textPlain"/>
+ * <enumeration value="textStop"/>
+ * <enumeration value="textTriangle"/>
+ * <enumeration value="textTriangleInverted"/>
+ * <enumeration value="textChevron"/>
+ * <enumeration value="textChevronInverted"/>
+ * <enumeration value="textRingInside"/>
+ * <enumeration value="textRingOutside"/>
+ * <enumeration value="textArchUp"/>
+ * <enumeration value="textArchDown"/>
+ * <enumeration value="textCircle"/>
+ * <enumeration value="textButton"/>
+ * <enumeration value="textArchUpPour"/>
+ * <enumeration value="textArchDownPour"/>
+ * <enumeration value="textCirclePour"/>
+ * <enumeration value="textButtonPour"/>
+ * <enumeration value="textCurveUp"/>
+ * <enumeration value="textCurveDown"/>
+ * <enumeration value="textCanUp"/>
+ * <enumeration value="textCanDown"/>
+ * <enumeration value="textWave1"/>
+ * <enumeration value="textWave2"/>
+ * <enumeration value="textDoubleWave1"/>
+ * <enumeration value="textWave4"/>
+ * <enumeration value="textInflate"/>
+ * <enumeration value="textDeflate"/>
+ * <enumeration value="textInflateBottom"/>
+ * <enumeration value="textDeflateBottom"/>
+ * <enumeration value="textInflateTop"/>
+ * <enumeration value="textDeflateTop"/>
+ * <enumeration value="textDeflateInflate"/>
+ * <enumeration value="textDeflateInflateDeflate"/>
+ * <enumeration value="textFadeRight"/>
+ * <enumeration value="textFadeLeft"/>
+ * <enumeration value="textFadeUp"/>
+ * <enumeration value="textFadeDown"/>
+ * <enumeration value="textSlantUp"/>
+ * <enumeration value="textSlantDown"/>
+ * <enumeration value="textCascadeUp"/>
+ * <enumeration value="textCascadeDown"/>
+ * </restriction>
+ * </simpleType>
+ * </pre>
+ *
+ */
+@XmlType(name = "ST_TextShapeType", namespace = "http://schemas.openxmlformats.org/drawingml/2006/main")
+@XmlEnum
+public enum STTextShapeType {
+
+
+ /**
+ * No Text Shape
+ *
+ */
+ @XmlEnumValue("textNoShape")
+ TEXT_NO_SHAPE("textNoShape"),
+
+ /**
+ * Plain Text Shape
+ *
+ */
+ @XmlEnumValue("textPlain")
+ TEXT_PLAIN("textPlain"),
+
+ /**
+ * Stop Sign Text Shape
+ *
+ */
+ @XmlEnumValue("textStop")
+ TEXT_STOP("textStop"),
+
+ /**
+ * Triangle Text Shape
+ *
+ */
+ @XmlEnumValue("textTriangle")
+ TEXT_TRIANGLE("textTriangle"),
+
+ /**
+ * Inverted Triangle Text Shape
+ *
+ */
+ @XmlEnumValue("textTriangleInverted")
+ TEXT_TRIANGLE_INVERTED("textTriangleInverted"),
+
+ /**
+ * Chevron Text Shape
+ *
+ */
+ @XmlEnumValue("textChevron")
+ TEXT_CHEVRON("textChevron"),
+
+ /**
+ * Inverted Chevron Text Shape
+ *
+ */
+ @XmlEnumValue("textChevronInverted")
+ TEXT_CHEVRON_INVERTED("textChevronInverted"),
+
+ /**
+ * Inside Ring Text Shape
+ *
+ */
+ @XmlEnumValue("textRingInside")
+ TEXT_RING_INSIDE("textRingInside"),
+
+ /**
+ * Outside Ring Text Shape
+ *
+ */
+ @XmlEnumValue("textRingOutside")
+ TEXT_RING_OUTSIDE("textRingOutside"),
+
+ /**
+ * Upward Arch Text Shape
+ *
+ */
+ @XmlEnumValue("textArchUp")
+ TEXT_ARCH_UP("textArchUp"),
+
+ /**
+ * Downward Arch Text Shape
+ *
+ */
+ @XmlEnumValue("textArchDown")
+ TEXT_ARCH_DOWN("textArchDown"),
+
+ /**
+ * Circle Text Shape
+ *
+ */
+ @XmlEnumValue("textCircle")
+ TEXT_CIRCLE("textCircle"),
+
+ /**
+ * Button Text Shape
+ *
+ */
+ @XmlEnumValue("textButton")
+ TEXT_BUTTON("textButton"),
+
+ /**
+ * Upward Pour Arch Text Shape
+ *
+ */
+ @XmlEnumValue("textArchUpPour")
+ TEXT_ARCH_UP_POUR("textArchUpPour"),
+
+ /**
+ * Downward Pour Arch Text Shape
+ *
+ */
+ @XmlEnumValue("textArchDownPour")
+ TEXT_ARCH_DOWN_POUR("textArchDownPour"),
+
+ /**
+ * Circle Pour Text Shape
+ *
+ */
+ @XmlEnumValue("textCirclePour")
+ TEXT_CIRCLE_POUR("textCirclePour"),
+
+ /**
+ * Button Pour Text Shape
+ *
+ */
+ @XmlEnumValue("textButtonPour")
+ TEXT_BUTTON_POUR("textButtonPour"),
+
+ /**
+ * Upward Curve Text Shape
+ *
+ */
+ @XmlEnumValue("textCurveUp")
+ TEXT_CURVE_UP("textCurveUp"),
+
+ /**
+ * Downward Curve Text Shape
+ *
+ */
+ @XmlEnumValue("textCurveDown")
+ TEXT_CURVE_DOWN("textCurveDown"),
+
+ /**
+ * Upward Can Text Shape
+ *
+ */
+ @XmlEnumValue("textCanUp")
+ TEXT_CAN_UP("textCanUp"),
+
+ /**
+ * Downward Can Text Shape
+ *
+ */
+ @XmlEnumValue("textCanDown")
+ TEXT_CAN_DOWN("textCanDown"),
+
+ /**
+ * Wave 1 Text Shape
+ *
+ */
+ @XmlEnumValue("textWave1")
+ TEXT_WAVE_1("textWave1"),
+
+ /**
+ * Wave 2 Text Shape
+ *
+ */
+ @XmlEnumValue("textWave2")
+ TEXT_WAVE_2("textWave2"),
+
+ /**
+ * Double Wave 1 Text Shape
+ *
+ */
+ @XmlEnumValue("textDoubleWave1")
+ TEXT_DOUBLE_WAVE_1("textDoubleWave1"),
+
+ /**
+ * Wave 4 Text Shape
+ *
+ */
+ @XmlEnumValue("textWave4")
+ TEXT_WAVE_4("textWave4"),
+
+ /**
+ * Inflate Text Shape
+ *
+ */
+ @XmlEnumValue("textInflate")
+ TEXT_INFLATE("textInflate"),
+
+ /**
+ * Deflate Text Shape
+ *
+ */
+ @XmlEnumValue("textDeflate")
+ TEXT_DEFLATE("textDeflate"),
+
+ /**
+ * Bottom Inflate Text Shape
+ *
+ */
+ @XmlEnumValue("textInflateBottom")
+ TEXT_INFLATE_BOTTOM("textInflateBottom"),
+
+ /**
+ * Bottom Deflate Text Shape
+ *
+ */
+ @XmlEnumValue("textDeflateBottom")
+ TEXT_DEFLATE_BOTTOM("textDeflateBottom"),
+
+ /**
+ * Top Inflate Text Shape
+ *
+ */
+ @XmlEnumValue("textInflateTop")
+ TEXT_INFLATE_TOP("textInflateTop"),
+
+ /**
+ * Top Deflate Text Shape
+ *
+ */
+ @XmlEnumValue("textDeflateTop")
+ TEXT_DEFLATE_TOP("textDeflateTop"),
+
+ /**
+ * Deflate-Inflate Text Shape
+ *
+ */
+ @XmlEnumValue("textDeflateInflate")
+ TEXT_DEFLATE_INFLATE("textDeflateInflate"),
+
+ /**
+ * Deflate-Inflate-Deflate Text Shape
+ *
+ */
+ @XmlEnumValue("textDeflateInflateDeflate")
+ TEXT_DEFLATE_INFLATE_DEFLATE("textDeflateInflateDeflate"),
+
+ /**
+ * Right Fade Text Shape
+ *
+ */
+ @XmlEnumValue("textFadeRight")
+ TEXT_FADE_RIGHT("textFadeRight"),
+
+ /**
+ * Left Fade Text Shape
+ *
+ */
+ @XmlEnumValue("textFadeLeft")
+ TEXT_FADE_LEFT("textFadeLeft"),
+
+ /**
+ * Upward Fade Text Shape
+ *
+ */
+ @XmlEnumValue("textFadeUp")
+ TEXT_FADE_UP("textFadeUp"),
+
+ /**
+ * Downward Fade Text Shape
+ *
+ */
+ @XmlEnumValue("textFadeDown")
+ TEXT_FADE_DOWN("textFadeDown"),
+
+ /**
+ * Upward Slant Text Shape
+ *
+ */
+ @XmlEnumValue("textSlantUp")
+ TEXT_SLANT_UP("textSlantUp"),
+
+ /**
+ * Downward Slant Text Shape
+ *
+ */
+ @XmlEnumValue("textSlantDown")
+ TEXT_SLANT_DOWN("textSlantDown"),
+
+ /**
+ * Upward Cascade Text Shape
+ *
+ */
+ @XmlEnumValue("textCascadeUp")
+ TEXT_CASCADE_UP("textCascadeUp"),
+
+ /**
+ * Downward Cascade Text Shape
+ *
+ */
+ @XmlEnumValue("textCascadeDown")
+ TEXT_CASCADE_DOWN("textCascadeDown");
+ private final String value;
+
+ STTextShapeType(String v) {
+ value = v;
+ }
+
+ public String value() {
+ return value;
+ }
+
+ public static STTextShapeType fromValue(String v) {
+ for (STTextShapeType c: STTextShapeType.values()) {
+ if (c.value.equals(v)) {
+ return c;
+ }
+ }
+ throw new IllegalArgumentException(v);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AbsExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AbsExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AbsExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AbsExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Absolute Value Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class AbsExpression implements Expression {
+ private String arg;
+
+ AbsExpression(Matcher m){
+ arg = m.group(1);
+ }
+
+ public double evaluate(Context ctx){
+ double val = ctx.getValue(arg);
+ return Math.abs(val);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddDivideExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddDivideExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddDivideExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddDivideExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Add Divide Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class AddDivideExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ AddDivideExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return (x + y ) / z;
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddSubtractExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddSubtractExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddSubtractExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AddSubtractExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Add Subtract Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class AddSubtractExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ AddSubtractExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return (x + y ) - z;
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AdjustValue.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AdjustValue.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AdjustValue.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/AdjustValue.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTGeomGuide;
+
+/**
+ * Represents a shape adjust values (see section 20.1.9.5 in the spec)
+ *
+ * @author Yegor Kozlov
+ */
+public class AdjustValue extends Guide {
+
+ public AdjustValue(CTGeomGuide gd) {
+ super(gd.getName(), gd.getFmla());
+ }
+
+ @Override
+ public double evaluate(Context ctx){
+ String name = getName();
+ Guide adj = ctx.getAdjustValue(name);
+ if(adj != null) {
+ return adj.evaluate(ctx);
+ }
+ return super.evaluate(ctx);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcTanExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcTanExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcTanExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcTanExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,43 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class ArcTanExpression implements Expression {
+ private String arg1, arg2;
+
+ ArcTanExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ return Math.atan(y / x);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcToCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcToCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcToCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ArcToCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTPath2DArcTo;
+
+import java.awt.geom.Arc2D;
+import java.awt.geom.GeneralPath;
+import java.awt.geom.Point2D;
+
+/**
+ * ArcTo command within a shape path in DrawingML:
+ *
+ * <arcTo wR="wr" hR="hr" stAng="stAng" swAng="swAng"/>
+ *
+ * Where <code>wr</code> and <code>wh</code> are the height and width radiuses
+ * of the supposed circle being used to draw the arc. This gives the circle
+ * a total height of (2 * hR) and a total width of (2 * wR)
+ *
+ * stAng is the <code>start</code> angle and <code></>swAng</code> is the swing angle
+ *
+ * @author Yegor Kozlov
+ */
+public class ArcToCommand implements PathCommand {
+ private String hr, wr, stAng, swAng;
+
+ ArcToCommand(CTPath2DArcTo arc){
+ hr = arc.getHR().toString();
+ wr = arc.getWR().toString();
+ stAng = arc.getStAng().toString();
+ swAng = arc.getSwAng().toString();
+ }
+
+ public void execute(GeneralPath path, Context ctx){
+ double rx = ctx.getValue(wr);
+ double ry = ctx.getValue(hr);
+ double start = ctx.getValue(stAng) / 60000;
+ double extent = ctx.getValue(swAng) / 60000;
+ Point2D pt = path.getCurrentPoint();
+ double x0 = pt.getX() - rx - rx * Math.cos(Math.toRadians(start));
+ double y0 = pt.getY() - ry - ry * Math.sin(Math.toRadians(start));
+
+ Arc2D arc = new Arc2D.Double(
+ x0,
+ y0,
+ 2 * rx, 2 * ry,
+ -start, -extent,
+ Arc2D.OPEN);
+ path.append(arc, true);
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ClosePathCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ClosePathCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ClosePathCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ClosePathCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.geom.GeneralPath;
+
+/**
+ * Date: 10/25/11
+ *
+ * @author Yegor Kozlov
+ */
+public class ClosePathCommand implements PathCommand {
+
+ ClosePathCommand(){
+ }
+
+ public void execute(GeneralPath path, Context ctx){
+ path.closePath();
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Context.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Context.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Context.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Context.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.geom.Rectangle2D;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class Context {
+ final Map<String, Double> _ctx = new HashMap<String, Double>();
+ final IAdjustableShape _props;
+ final Rectangle2D _anchor;
+
+ public Context(CustomGeometry geom, Rectangle2D anchor, IAdjustableShape props){
+ _props = props;
+ _anchor = anchor;
+ for(Guide gd : geom.adjusts) evaluate(gd);
+ for(Guide gd : geom.guides) evaluate(gd);
+ }
+
+ public Rectangle2D getShapeAnchor(){
+ return _anchor;
+ }
+
+ public Guide getAdjustValue(String name){
+ return _props.getAdjustValue(name);
+ }
+
+ public double getValue(String key){
+ if(key.matches("(\\+|-)?\\d+")){
+ return Double.parseDouble(key);
+ }
+
+ Formula builtIn = Formula.builtInFormulas.get(key);
+ if(builtIn != null){
+ return builtIn.evaluate(this);
+ }
+
+ if(!_ctx.containsKey(key)) {
+ throw new RuntimeException("undefined variable: " + key);
+ }
+
+ return _ctx.get(key);
+ }
+
+ public double evaluate(Formula fmla){
+ double result = fmla.evaluate(this);
+ String key = fmla.getName();
+ if(key != null) _ctx.put(key, result);
+ return result;
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,43 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class CosExpression implements Expression {
+ private String arg1, arg2;
+
+ CosExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2)/ 60000;
+ return x * Math.cos(Math.toRadians(y));
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosineArcTanExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosineArcTanExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosineArcTanExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CosineArcTanExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class CosineArcTanExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ CosineArcTanExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return x*Math.cos(Math.atan(z / y));
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CurveToCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CurveToCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CurveToCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CurveToCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,52 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTAdjPoint2D;
+
+import java.awt.geom.GeneralPath;
+
+/**
+ * Date: 10/25/11
+ *
+ * @author Yegor Kozlov
+ */
+public class CurveToCommand implements PathCommand {
+ private String arg1, arg2, arg3, arg4, arg5, arg6;
+
+ CurveToCommand(CTAdjPoint2D pt1, CTAdjPoint2D pt2, CTAdjPoint2D pt3){
+ arg1 = pt1.getX().toString();
+ arg2 = pt1.getY().toString();
+ arg3 = pt2.getX().toString();
+ arg4 = pt2.getY().toString();
+ arg5 = pt3.getX().toString();
+ arg6 = pt3.getY().toString();
+ }
+
+ public void execute(GeneralPath path, Context ctx){
+ double x1 = ctx.getValue(arg1);
+ double y1 = ctx.getValue(arg2);
+ double x2 = ctx.getValue(arg3);
+ double y2 = ctx.getValue(arg4);
+ double x3 = ctx.getValue(arg5);
+ double y3 = ctx.getValue(arg6);
+ path.curveTo((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3);
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CustomGeometry.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CustomGeometry.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CustomGeometry.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/CustomGeometry.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.*;
+
+import org.apache.poi.sl.draw.binding.*;
+
+/**
+ * Definition of a custom geometric shape
+ *
+ * @author Yegor Kozlov
+ */
+public class CustomGeometry implements Iterable<Path>{
+ List<Guide> adjusts = new ArrayList<Guide>();
+ List<Guide> guides = new ArrayList<Guide>();
+ List<Path> paths = new ArrayList<Path>();
+ Path textBounds;
+
+ public CustomGeometry(CTCustomGeometry2D geom) {
+ CTGeomGuideList avLst = geom.getAvLst();
+ if(avLst != null) {
+ for(CTGeomGuide gd : avLst.getGd()){
+ adjusts.add(new AdjustValue(gd));
+ }
+ }
+
+ CTGeomGuideList gdLst = geom.getGdLst();
+ if(gdLst != null) {
+ for(CTGeomGuide gd : gdLst.getGd()){
+ guides.add(new Guide(gd));
+ }
+ }
+
+ CTPath2DList pathLst = geom.getPathLst();
+ if(pathLst != null) {
+ for(CTPath2D spPath : pathLst.getPath()){
+ paths.add(new Path(spPath));
+ }
+ }
+
+ CTGeomRect rect = geom.getRect();
+ if(rect != null) {
+ textBounds = new Path();
+ textBounds.addCommand(
+ new MoveToCommand(rect.getL().toString(), rect.getT().toString()));
+ textBounds.addCommand(
+ new LineToCommand(rect.getR().toString(), rect.getT().toString()));
+ textBounds.addCommand(
+ new LineToCommand(rect.getR().toString(), rect.getB().toString()));
+ textBounds.addCommand(
+ new LineToCommand(rect.getL().toString(), rect.getB().toString()));
+ textBounds.addCommand(
+ new ClosePathCommand());
+ }
+ }
+
+ public Iterator<Path> iterator() {
+ return paths.iterator();
+ }
+
+ public Path getTextBounds(){
+ return textBounds;
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Expression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Expression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Expression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Expression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,31 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public interface Expression {
+
+ double evaluate(Context ctx);
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ExpressionParser.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ExpressionParser.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ExpressionParser.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ExpressionParser.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,69 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.HashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * A simple regexp-based parser of shape guide formulas in DrawingML
+ *
+ * @author Yegor Kozlov
+ */
+public class ExpressionParser {
+ static final HashMap<String, Class> impls = new HashMap<String, Class>();
+ static {
+ impls.put("\\*/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", MultiplyDivideExpression.class);
+ impls.put("\\+- +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)( 0)?", AddSubtractExpression.class);
+ impls.put("\\+/ +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", AddDivideExpression.class);
+ impls.put("\\?: +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", IfElseExpression.class);
+ impls.put("val +([\\-\\w]+)", LiteralValueExpression.class);
+ impls.put("abs +([\\-\\w]+)", AbsExpression.class);
+ impls.put("sqrt +([\\-\\w]+)", SqrtExpression.class);
+ impls.put("max +([\\-\\w]+) +([\\-\\w]+)", MaxExpression.class);
+ impls.put("min +([\\-\\w]+) +([\\-\\w]+)", MinExpression.class);
+ impls.put("at2 +([\\-\\w]+) +([\\-\\w]+)", ArcTanExpression.class);
+ impls.put("sin +([\\-\\w]+) +([\\-\\w]+)", SinExpression.class);
+ impls.put("cos +([\\-\\w]+) +([\\-\\w]+)", CosExpression.class);
+ impls.put("tan +([\\-\\w]+) +([\\-\\w]+)", TanExpression.class);
+ impls.put("cat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", CosineArcTanExpression.class);
+ impls.put("sat2 +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", SinArcTanExpression.class);
+ impls.put("pin +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", PinExpression.class);
+ impls.put("mod +([\\-\\w]+) +([\\-\\w]+) +([\\-\\w]+)", ModExpression.class);
+
+ }
+
+ public static Expression parse(String str){
+ for(String regexp : impls.keySet()) {
+ Pattern ptrn = Pattern.compile(regexp);
+ Matcher m = ptrn.matcher(str);
+ if(m.matches()) {
+ Class c = impls.get(regexp);
+ try {
+ return (Expression)c.getDeclaredConstructor(Matcher.class).newInstance(m);
+ } catch (Exception e){
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ throw new RuntimeException("Unsupported formula: " + str);
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Formula.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Formula.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Formula.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Formula.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,385 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.geom.Rectangle2D;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A guide formula in DrawingML.
+ * This is a base class for adjust values, geometric guides and bilt-in guides
+ *
+ * @author Yegor Kozlov
+ */
+public abstract class Formula {
+
+ String getName(){
+ return null;
+ }
+
+ abstract double evaluate(Context ctx);
+
+ static Map<String, Formula> builtInFormulas = new HashMap<String, Formula>();
+ static {
+ // 3 x 360 / 4 = 270
+ builtInFormulas.put("3cd4", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 270 * 60000;
+ }
+
+ });
+
+ // 3 x 360 / 8 = 135
+ builtInFormulas.put("3cd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 135 * 60000;
+ }
+
+ });
+
+ // 5 x 360 / 8 = 225
+ builtInFormulas.put("5cd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 270 * 60000;
+ }
+
+ });
+
+ // 7 x 360 / 8 = 315
+ builtInFormulas.put("7cd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 270 * 60000;
+ }
+
+ });
+
+ // bottom
+ builtInFormulas.put("b", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getY() + anchor.getHeight();
+ }
+
+ });
+
+ // 360 / 2 = 180
+ builtInFormulas.put("cd2", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 180 * 60000;
+ }
+
+ });
+
+ // 360 / 4 = 90
+ builtInFormulas.put("cd4", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 90 * 60000;
+ }
+
+ });
+
+ // 360 / 8 = 45
+ builtInFormulas.put("cd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return 45 * 60000;
+ }
+
+ });
+
+ // horizontal center
+ builtInFormulas.put("hc", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getX() + anchor.getWidth()/2;
+ }
+
+ });
+
+ // height
+ builtInFormulas.put("h", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight();
+ }
+
+ });
+
+ // height / 2
+ builtInFormulas.put("hd2", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/2;
+ }
+
+ });
+
+ // height / 3
+ builtInFormulas.put("hd3", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/3;
+ }
+
+ });
+
+ // height / 4
+ builtInFormulas.put("hd4", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/4;
+ }
+
+ });
+
+ // height / 5
+ builtInFormulas.put("hd5", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/5;
+ }
+
+ });
+
+ // height / 6
+ builtInFormulas.put("hd6", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/6;
+ }
+
+ });
+
+ // height / 8
+ builtInFormulas.put("hd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getHeight()/8;
+ }
+
+ });
+
+ // left
+ builtInFormulas.put("l", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getX();
+ }
+
+ });
+
+ // long side
+ builtInFormulas.put("ls", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return Math.max(anchor.getWidth(), anchor.getHeight());
+ }
+
+ });
+
+ // right
+ builtInFormulas.put("r", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getX() + anchor.getWidth();
+ }
+
+ });
+
+ // short side
+ builtInFormulas.put("ss", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return Math.min(anchor.getWidth(), anchor.getHeight());
+ }
+
+ });
+
+ // short side / 2
+ builtInFormulas.put("ssd2", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 2;
+ }
+ });
+
+ // short side / 4
+ builtInFormulas.put("ssd4", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 4;
+ }
+ });
+
+ // short side / 6
+ builtInFormulas.put("ssd6", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 6;
+ }
+ });
+
+ // short side / 8
+ builtInFormulas.put("ssd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 8;
+ }
+ });
+
+ // short side / 16
+ builtInFormulas.put("ssd16", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 16;
+ }
+ });
+
+ // short side / 32
+ builtInFormulas.put("ssd32", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ double ss = Math.min(anchor.getWidth(), anchor.getHeight());
+ return ss / 32;
+ }
+ });
+
+ // top
+ builtInFormulas.put("t", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getY();
+ }
+ });
+
+ // vertical center
+ builtInFormulas.put("vc", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ Rectangle2D anchor = ctx.getShapeAnchor();
+ return anchor.getY() + anchor.getHeight()/2;
+ }
+ });
+
+ // width
+ builtInFormulas.put("w", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth();
+ }
+ });
+
+ // width / 2
+ builtInFormulas.put("wd2", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/2;
+ }
+ });
+
+ // width / 3
+ builtInFormulas.put("wd3", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/3;
+ }
+ });
+
+ // width / 4
+ builtInFormulas.put("wd4", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/4;
+ }
+ });
+
+ // width / 5
+ builtInFormulas.put("wd5", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/5;
+ }
+ });
+
+ // width / 6
+ builtInFormulas.put("wd6", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/6;
+ }
+ });
+
+ // width / 8
+ builtInFormulas.put("wd8", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/8;
+ }
+ });
+
+ // width / 10
+ builtInFormulas.put("wd10", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/10;
+ }
+ });
+
+ // width / 32
+ builtInFormulas.put("wd32", new Formula(){
+ @Override
+ double evaluate(Context ctx){
+ return ctx.getShapeAnchor().getWidth()/32;
+ }
+ });
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Guide.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Guide.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Guide.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Guide.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,58 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTGeomGuide;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class Guide extends Formula {
+ private String name, fmla;
+ private Expression expr;
+
+ public Guide(CTGeomGuide gd) {
+ this(gd.getName(), gd.getFmla());
+ }
+
+ public Guide(String nm, String fm){
+ name = nm;
+ fmla = fm;
+ expr = ExpressionParser.parse(fm);
+ }
+
+
+ String getName(){
+ return name;
+ }
+
+ String getFormula(){
+ return fmla;
+ }
+
+ @Override
+ public double evaluate(Context ctx){
+ return expr.evaluate(ctx);
+ }
+
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IAdjustableShape.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IAdjustableShape.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IAdjustableShape.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IAdjustableShape.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+
+/**
+ * A bridge to the consumer application.
+ *
+ * To get a shape geometry one needs to pass shape bounds and adjust values.
+ *
+ * @author Yegor Kozlov
+ */
+public interface IAdjustableShape {
+ /**
+ *
+ * @param name name of a adjust value, e.g. adj1
+ * @return adjust guide defined in the shape or null
+ */
+ Guide getAdjustValue(String name);
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IfElseExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IfElseExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IfElseExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/IfElseExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * If Else Formula:
+ * <p>
+ * Arguments: 3 (fmla="?: x y z")
+ * Usage: "?: x y z" = if (x > 0), then y = value of this guide,
+ * else z = value of this guide
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public class IfElseExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ IfElseExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return x > 0 ? y : z;
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LineToCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LineToCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LineToCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LineToCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,49 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTAdjPoint2D;
+
+import java.awt.geom.GeneralPath;
+
+/**
+ * Date: 10/25/11
+ *
+ * @author Yegor Kozlov
+ */
+public class LineToCommand implements PathCommand {
+ private String arg1, arg2;
+
+ LineToCommand(CTAdjPoint2D pt){
+ arg1 = pt.getX().toString();
+ arg2 = pt.getY().toString();
+ }
+
+ LineToCommand(String s1, String s2){
+ arg1 = s1;
+ arg2 = s2;
+ }
+
+ public void execute(GeneralPath path, Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ path.lineTo((float)x, (float)y);
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LiteralValueExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LiteralValueExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LiteralValueExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/LiteralValueExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,40 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Date: 10/24/11
+ *
+ * @author Yegor Kozlov
+ */
+public class LiteralValueExpression implements Expression {
+ private String arg;
+
+ LiteralValueExpression(Matcher m){
+ arg = m.group(1);
+ }
+
+ public double evaluate(Context ctx){
+ return ctx.getValue(arg);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MaxExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MaxExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MaxExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MaxExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,43 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Maximum Value Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class MaxExpression implements Expression {
+ private String arg1, arg2;
+
+ MaxExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ return Math.max(x, y);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MinExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MinExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MinExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MinExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,43 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Minimum Value Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class MinExpression implements Expression {
+ private String arg1, arg2;
+
+ MinExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ return Math.min(x, y);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ModExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ModExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ModExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/ModExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,49 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Modulo Formula:
+ * <p>
+ * Arguments: 3 (fmla="mod x y z")
+ * Usage: "mod x y z" = sqrt(x^2 + b^2 + c^2) = value of this guide
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public class ModExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ ModExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return Math.sqrt(x*x + y*y + z*z);
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MoveToCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MoveToCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MoveToCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MoveToCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,49 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import org.apache.poi.sl.draw.binding.CTAdjPoint2D;
+
+import java.awt.geom.GeneralPath;
+
+/**
+ * Date: 10/25/11
+ *
+ * @author Yegor Kozlov
+ */
+public class MoveToCommand implements PathCommand {
+ private String arg1, arg2;
+
+ MoveToCommand(CTAdjPoint2D pt){
+ arg1 = pt.getX().toString();
+ arg2 = pt.getY().toString();
+ }
+
+ MoveToCommand(String s1, String s2){
+ arg1 = s1;
+ arg2 = s2;
+ }
+
+ public void execute(GeneralPath path, Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ path.moveTo((float)x, (float)y);
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MultiplyDivideExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MultiplyDivideExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MultiplyDivideExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/MultiplyDivideExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Multiply Divide Formula
+ *
+ * @author Yegor Kozlov
+ */
+public class MultiplyDivideExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ MultiplyDivideExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ return (x * y ) / z;
+ }
+
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Outline.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Outline.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Outline.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Outline.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.Shape;
+
+/**
+* Date: 11/6/11
+*
+* @author Yegor Kozlov
+*/
+public class Outline {
+ private Shape shape;
+ private Path path;
+
+ public Outline(Shape shape, Path path){
+ this.shape = shape;
+ this.path = path;
+ }
+
+ public Path getPath(){
+ return path;
+ }
+
+ public Shape getOutline(){
+ return shape;
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Path.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Path.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Path.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/Path.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,117 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.geom.GeneralPath;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.poi.sl.draw.binding.*;
+
+/**
+ * Specifies a creation path consisting of a series of moves, lines and curves
+ * that when combined forms a geometric shape
+ *
+ * @author Yegor Kozlov
+ */
+public class Path {
+ private final List<PathCommand> commands;
+ boolean _fill, _stroke;
+ long _w, _h;
+
+ public Path(){
+ this(true, true);
+ }
+
+ public Path(boolean fill, boolean stroke){
+ commands = new ArrayList<PathCommand>();
+ _w = -1;
+ _h = -1;
+ _fill = fill;
+ _stroke = stroke;
+ }
+
+ public Path(CTPath2D spPath){
+ _fill = spPath.getFill() != STPathFillMode.NONE;
+ _stroke = spPath.isStroke();
+ _w = spPath.isSetW() ? spPath.getW() : -1;
+ _h = spPath.isSetH() ? spPath.getH() : -1;
+
+ commands = new ArrayList<PathCommand>();
+
+ for(Object ch : spPath.getCloseOrMoveToOrLnTo()){
+ if(ch instanceof CTPath2DMoveTo){
+ CTAdjPoint2D pt = ((CTPath2DMoveTo)ch).getPt();
+ commands.add(new MoveToCommand(pt));
+ } else if (ch instanceof CTPath2DLineTo){
+ CTAdjPoint2D pt = ((CTPath2DLineTo)ch).getPt();
+ commands.add(new LineToCommand(pt));
+ } else if (ch instanceof CTPath2DArcTo){
+ CTPath2DArcTo arc = (CTPath2DArcTo)ch;
+ commands.add(new ArcToCommand(arc));
+ } else if (ch instanceof CTPath2DQuadBezierTo){
+ CTPath2DQuadBezierTo bez = ((CTPath2DQuadBezierTo)ch);
+ CTAdjPoint2D pt1 = bez.getPt().get(0);
+ CTAdjPoint2D pt2 = bez.getPt().get(1);
+ commands.add(new QuadToCommand(pt1, pt2));
+ } else if (ch instanceof CTPath2DCubicBezierTo){
+ CTPath2DCubicBezierTo bez = ((CTPath2DCubicBezierTo)ch);
+ CTAdjPoint2D pt1 = bez.getPt().get(0);
+ CTAdjPoint2D pt2 = bez.getPt().get(1);
+ CTAdjPoint2D pt3 = bez.getPt().get(2);
+ commands.add(new CurveToCommand(pt1, pt2, pt3));
+ } else if (ch instanceof CTPath2DClose){
+ commands.add(new ClosePathCommand());
+ } else {
+ throw new IllegalStateException("Unsupported path segment: " + ch);
+ }
+ }
+ }
+
+ public void addCommand(PathCommand cmd){
+ commands.add(cmd);
+ }
+
+ /**
+ * Convert the internal represenation to java.awt.GeneralPath
+ */
+ public GeneralPath getPath(Context ctx) {
+ GeneralPath path = new GeneralPath();
+ for(PathCommand cmd : commands)
+ cmd.execute(path, ctx);
+ return path;
+ }
+
+ public boolean isStroked(){
+ return _stroke;
+ }
+
+ public boolean isFilled(){
+ return _fill;
+ }
+
+ public long getW(){
+ return _w;
+ }
+
+ public long getH(){
+ return _h;
+ }
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PathCommand.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PathCommand.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PathCommand.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PathCommand.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.awt.geom.GeneralPath;
+
+/**
+ * A path command in DrawingML. One of:
+ *
+ * - arcTo
+ * - moveTo
+ * - lineTo
+ * - cubicBezTo
+ * - quadBezTo
+ * - close
+ *
+ *
+ * @author Yegor Kozlov
+ */
+public interface PathCommand {
+ /**
+ * Execute the command an append a segment to the specified path
+ *
+ * @param path the path to append the result to
+ * @param ctx the context to lookup variables
+ */
+ void execute(GeneralPath path, Context ctx);
+}
Added: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PinExpression.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PinExpression.java?rev=1661322&view=auto
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PinExpression.java (added)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/sl/draw/geom/PinExpression.java Sat Feb 21 10:56:03 2015
@@ -0,0 +1,54 @@
+/*
+ * ====================================================================
+ * 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.sl.draw.geom;
+
+import java.util.regex.Matcher;
+
+/**
+ * Pin To Formula:
+ * <gd name="enAng" fmla="pin 0 adj2 21599999"/>
+ *
+ * <p>
+ * Usage: "pin x y z" = if (y < x), then x = value of this guide
+ * else if (y > z), then z = value of this guide
+ * else y = value of this guide
+ * </p>
+ *
+ * @author Yegor Kozlov
+ */
+public class PinExpression implements Expression {
+ private String arg1, arg2, arg3;
+
+ PinExpression(Matcher m){
+ arg1 = m.group(1);
+ arg2 = m.group(2);
+ arg3 = m.group(3);
+ }
+
+ public double evaluate(Context ctx){
+ double x = ctx.getValue(arg1);
+ double y = ctx.getValue(arg2);
+ double z = ctx.getValue(arg3);
+ if(y < x) return x;
+ else if (y > z) return z;
+ else return y;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org