diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2015-02-21 10:56:03 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2015-02-21 10:56:03 +0000 |
commit | cb09b997c45c042d742971e357ed06166639834a (patch) | |
tree | bb3af7eba812f864e0f5dca3ee4eb95e28c9d72a /src/ooxml/java | |
parent | 17fa00b29ee2e91e6048b43a175276942ada8729 (diff) | |
download | poi-cb09b997c45c042d742971e357ed06166639834a.tar.gz poi-cb09b997c45c042d742971e357ed06166639834a.zip |
initial commit - still lots of errors, but I need to switch to a clean trunk for releasing and testing
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1661322 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/java')
66 files changed, 800 insertions, 3736 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java b/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java index d446ccedde..ddb3f0745b 100644 --- a/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java +++ b/src/ooxml/java/org/apache/poi/xslf/model/PropertyFetcher.java @@ -19,8 +19,8 @@ package org.apache.poi.xslf.model;
-import org.apache.poi.xslf.usermodel.XSLFSimpleShape;
import org.apache.poi.util.Internal;
+import org.apache.poi.xslf.usermodel.XSLFShape;
/**
* Used internally to navigate the PresentationML text style hierarchy and fetch properties
@@ -36,7 +36,7 @@ public abstract class PropertyFetcher<T> { * @param shape the shape being examined
* @return true if the desired property was fetched
*/
- public abstract boolean fetch(XSLFSimpleShape shape) ;
+ public abstract boolean fetch(XSLFShape shape) ;
public T getValue(){
return _value;
diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/AbsExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/AbsExpression.java deleted file mode 100644 index 5790e5383a..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/AbsExpression.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/AddDivideExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/AddDivideExpression.java deleted file mode 100644 index 7fe14e8b1d..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/AddDivideExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/AddSubtractExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/AddSubtractExpression.java deleted file mode 100644 index bd7e47e16d..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/AddSubtractExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/AdjustValue.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/AdjustValue.java deleted file mode 100644 index 8df1d6f875..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/AdjustValue.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcTanExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcTanExpression.java deleted file mode 100644 index 252c0fc62c..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcTanExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java deleted file mode 100644 index b1ea0defc8..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/ArcToCommand.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/ClosePathCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/ClosePathCommand.java deleted file mode 100644 index b9a95404e1..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/ClosePathCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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(); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java deleted file mode 100644 index ea86c51002..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Context.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/CosExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/CosExpression.java deleted file mode 100644 index 47e38f162b..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/CosExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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)); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/CosineArcTanExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/CosineArcTanExpression.java deleted file mode 100644 index cb9928b223..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/CosineArcTanExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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)); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/CurveToCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/CurveToCommand.java deleted file mode 100644 index 6f342d2ee7..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/CurveToCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java deleted file mode 100644 index 4e30ac90d9..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/CustomGeometry.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D; -import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide; -import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuideList; -import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect; -import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D; -import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DList; - -/** - * 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; - - @SuppressWarnings("deprecation") - public CustomGeometry(CTCustomGeometry2D geom) { - CTGeomGuideList avLst = geom.getAvLst(); - if(avLst != null) for(CTGeomGuide gd : avLst.getGdArray()){ - adjusts.add(new AdjustValue(gd)); - } - - CTGeomGuideList gdLst = geom.getGdLst(); - if(gdLst != null) for(CTGeomGuide gd : gdLst.getGdArray()){ - guides.add(new Guide(gd)); - } - - CTPath2DList pathLst = geom.getPathLst(); - if(pathLst != null) for(CTPath2D spPath : pathLst.getPathArray()){ - paths.add(new Path(spPath)); - } - - if(geom.isSetRect()) { - CTGeomRect rect = geom.getRect(); - 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; - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Expression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Expression.java deleted file mode 100644 index 2b0f751f36..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Expression.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -/** - * Date: 10/24/11 - * - * @author Yegor Kozlov - */ -public interface Expression { - - double evaluate(Context ctx); - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/ExpressionParser.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/ExpressionParser.java deleted file mode 100644 index 699f995eab..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/ExpressionParser.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Formula.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Formula.java deleted file mode 100644 index 0d3b2bbba1..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Formula.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - }); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Guide.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Guide.java deleted file mode 100644 index 584e22483d..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Guide.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } - - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java deleted file mode 100644 index 44f5a562f7..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/IAdjustableShape.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/IfElseExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/IfElseExpression.java deleted file mode 100644 index 3e16645f5a..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/IfElseExpression.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java deleted file mode 100644 index 5142dd234a..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/LineToCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/LiteralValueExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/LiteralValueExpression.java deleted file mode 100644 index f84483cd55..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/LiteralValueExpression.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/MaxExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/MaxExpression.java deleted file mode 100644 index 0c7ac3ecbe..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/MaxExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/MinExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/MinExpression.java deleted file mode 100644 index 3e28cdd822..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/MinExpression.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/ModExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/ModExpression.java deleted file mode 100644 index cf17f0564e..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/ModExpression.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java deleted file mode 100644 index 9d9575ace1..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/MoveToCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.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); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/MultiplyDivideExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/MultiplyDivideExpression.java deleted file mode 100644 index 17aca48d15..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/MultiplyDivideExpression.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java deleted file mode 100644 index dbf9f1f9c9..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Outline.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java deleted file mode 100644 index 3f552a4cf9..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/Path.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.drawingml.x2006.main.*; - -import java.awt.geom.GeneralPath; -import java.util.ArrayList; -import java.util.List; - -/** - * 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.getStroke(); - _w = spPath.isSetW() ? spPath.getW() : -1; - _h = spPath.isSetH() ? spPath.getH() : -1; - - commands = new ArrayList<PathCommand>(); - for(XmlObject ch : spPath.selectPath("*")){ - 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.getPtArray(0); - CTAdjPoint2D pt2 = bez.getPtArray(1); - commands.add(new QuadToCommand(pt1, pt2)); - } else if (ch instanceof CTPath2DCubicBezierTo){ - CTPath2DCubicBezierTo bez = ((CTPath2DCubicBezierTo)ch); - CTAdjPoint2D pt1 = bez.getPtArray(0); - CTAdjPoint2D pt2 = bez.getPtArray(1); - CTAdjPoint2D pt3 = bez.getPtArray(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; - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/PathCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/PathCommand.java deleted file mode 100644 index 7b3ec49379..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/PathCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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); -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/PinExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/PinExpression.java deleted file mode 100644 index c1b7fe4466..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/PinExpression.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.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; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java deleted file mode 100644 index 62accc42f3..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/PresetGeometries.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.apache.poi.xslf.usermodel.XMLSlideShow; -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D; - -import java.io.InputStream; -import java.util.LinkedHashMap; - -/** - * Date: 10/25/11 - * - * @author Yegor Kozlov - */ -public class PresetGeometries extends LinkedHashMap<String, CustomGeometry> { - private static PresetGeometries _inst; - - private PresetGeometries(){ - try { - InputStream is = - XMLSlideShow.class.getResourceAsStream("presetShapeDefinitions.xml"); - read(is); - } catch (Exception e){ - throw new RuntimeException(e); - } - } - - private void read(InputStream is) throws Exception { - XmlObject obj = XmlObject.Factory.parse(is); - for (XmlObject def : obj.selectPath("*/*")) { - - String name = def.getDomNode().getLocalName(); - CTCustomGeometry2D geom = CTCustomGeometry2D.Factory.parse(def.toString()); - - if(containsKey(name)) { - System.out.println("Duplicate definoition of " + name) ; - } - put(name, new CustomGeometry(geom)); - } - } - - public static PresetGeometries getInstance(){ - if(_inst == null) _inst = new PresetGeometries(); - - return _inst; - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/QuadToCommand.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/QuadToCommand.java deleted file mode 100644 index 65fd7d45e4..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/QuadToCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; - -import java.awt.geom.GeneralPath; - -/** - * Date: 10/25/11 - * - * @author Yegor Kozlov - */ -public class QuadToCommand implements PathCommand { - private String arg1, arg2, arg3, arg4; - - QuadToCommand(CTAdjPoint2D pt1, CTAdjPoint2D pt2){ - arg1 = pt1.getX().toString(); - arg2 = pt1.getY().toString(); - arg3 = pt2.getX().toString(); - arg4 = pt2.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); - path.quadTo((float)x1, (float)y1, (float)x2, (float)y2); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/SinArcTanExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/SinArcTanExpression.java deleted file mode 100644 index 8ac68e0c63..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/SinArcTanExpression.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import java.util.regex.Matcher; - -/** - * Sine ArcTan Formula: - * <gd name="dy1" fmla="sat2 x y z"/> - * - * <p> - * Arguments: 3 (fmla="sat2 x y z") - * Usage: "sat2 x y z" = (x*sin(arctan(z / y))) = value of this guide - * </p> - * - * @author Yegor Kozlov - */ -public class SinArcTanExpression implements Expression { - private String arg1, arg2, arg3; - - SinArcTanExpression(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.sin(Math.atan(z / y)); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/SinExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/SinExpression.java deleted file mode 100644 index 9e82f5abda..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/SinExpression.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import java.util.regex.Matcher; - -/** - * Sine Formula: - * <gd name="z" fmla="sin x y"/> - * - * <p> - * Arguments: 2 (fmla="sin x y") - * Usage: "sin x y" = (x * sin( y )) = value of this guide - * </p> - * - * @author Yegor Kozlov - */ -public class SinExpression implements Expression { - private String arg1, arg2; - - SinExpression(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.sin(Math.toRadians(y)); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/SqrtExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/SqrtExpression.java deleted file mode 100644 index d798e93a13..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/SqrtExpression.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import java.util.regex.Matcher; - -/** - * Square Root Formula: - * <gd name="x" fmla="sqrt y"/> - * - * <p> - * Arguments: 1 (fmla="sqrt x") - * Usage: "sqrt x" = sqrt(x) = value of this guide - * </p> - * @author Yegor Kozlov - */ -public class SqrtExpression implements Expression { - private String arg; - - SqrtExpression(Matcher m){ - arg =m.group(1); - } - - public double evaluate(Context ctx){ - double val = ctx.getValue(arg); - return Math.sqrt(val); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/model/geom/TanExpression.java b/src/ooxml/java/org/apache/poi/xslf/model/geom/TanExpression.java deleted file mode 100644 index 3435f35603..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/model/geom/TanExpression.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.model.geom; - -import java.util.regex.Matcher; - -/** - * Tangent Formula: - * - * <gd name="z" fmla="tan x y"/> - * - * <p> - * Arguments: 2 (fmla="tan x y") - * Usage: "tan x y" = (x * tan( y )) = value of this guide - * </p> - * - * @author Yegor Kozlov - */ -public class TanExpression implements Expression { - private String arg1, arg2; - - TanExpression(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 x * Math.tan(Math.toRadians(y / 60000)); - } - -} diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java deleted file mode 100644 index 55b4c8492f..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineCap.java +++ /dev/null @@ -1,38 +0,0 @@ -/* ====================================================================
- 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.xslf.usermodel;
-
-/**
- *
- *
- * @author Yegor Kozlov
- */
-public enum LineCap {
- /**
- * Rounded ends
- */
- ROUND,
- /**
- * Square protrudes by half line width
- */
- SQUARE,
-
- /**
- * Line ends at end point
- */
- FLAT;
-}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java deleted file mode 100644 index 71891f841b..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/LineDash.java +++ /dev/null @@ -1,34 +0,0 @@ -/* ====================================================================
- 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.xslf.usermodel;
-
-/**
- * @author Yegor Kozlov
- */
-public enum LineDash {
- SOLID,
- DOT,
- DASH,
- LG_DASH,
- DASH_DOT,
- LG_DASH_DOT,
- LG_DASH_DOT_DOT,
- SYS_DASH,
- SYS_DOT,
- SYS_DASH_DOT,
- SYS_DASH_DOT_DOT;
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java index 053ccd491d..8a11c1cd17 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/RenderableShape.java @@ -40,6 +40,8 @@ import java.util.Comparator; import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.LineCap;
+import org.apache.poi.sl.usermodel.LineDash;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java deleted file mode 100644 index 2570e6cfc9..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAlign.java +++ /dev/null @@ -1,50 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-/**
- * Specified a list of text alignment types
- *
- * @author Yegor Kozlov
- */
-public enum TextAlign {
- /**
- * Align text to the left margin.
- */
- LEFT,
- /**
- * Align text in the center.
- */
- CENTER,
-
- /**
- * Align text to the right margin.
- */
- RIGHT,
-
- /**
- * Align text so that it is justified across the whole line. It
- * is smart in the sense that it will not justify sentences
- * which are short
- */
- JUSTIFY,
- JUSTIFY_LOW,
- DIST,
- THAI_DIST
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java deleted file mode 100644 index 94d6b24358..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextAutofit.java +++ /dev/null @@ -1,59 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-/**
- * Specifies alist of auto-fit types.
- * <p>
- * Autofit specofies that a shape should be auto-fit to fully contain the text described within it.
- * Auto-fitting is when text within a shape is scaled in order to contain all the text inside
- * </p>
- *
- * @author Yegor Kozlov
- */
-public enum TextAutofit {
- /**
- * Specifies that text within the text body should not be auto-fit to the bounding box.
- * Auto-fitting is when text within a text box is scaled in order to remain inside
- * the text box.
- */
- NONE,
- /**
- * Specifies that text within the text body should be normally auto-fit to the bounding box.
- * Autofitting is when text within a text box is scaled in order to remain inside the text box.
- *
- * <p>
- * <em>Example:</em> Consider the situation where a user is building a diagram and needs
- * to have the text for each shape that they are using stay within the bounds of the shape.
- * An easy way this might be done is by using NORMAL autofit
- * </p>
- */
- NORMAL,
- /**
- * Specifies that a shape should be auto-fit to fully contain the text described within it.
- * Auto-fitting is when text within a shape is scaled in order to contain all the text inside.
- *
- * <p>
- * <em>Example:</em> Consider the situation where a user is building a diagram and needs to have
- * the text for each shape that they are using stay within the bounds of the shape.
- * An easy way this might be done is by using SHAPE autofit
- * </p>
- */
- SHAPE
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java deleted file mode 100644 index c4ad6255d8..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextCap.java +++ /dev/null @@ -1,29 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-/**
- * @author Yegor Kozlov
- */
-public enum TextCap {
- NONE,
- SMALL,
- ALL
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java deleted file mode 100644 index 3f35ec23ac..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextDirection.java +++ /dev/null @@ -1,48 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-/**
- * Vertical Text Types
- */
-public enum TextDirection {
- /**
- * Horizontal text. This should be default.
- */
- HORIZONTAL,
- /**
- * Vertical orientation.
- * (each line is 90 degrees rotated clockwise, so it goes
- * from top to bottom; each next line is to the left from
- * the previous one).
- */
- VERTICAL,
- /**
- * Vertical orientation.
- * (each line is 270 degrees rotated clockwise, so it goes
- * from bottom to top; each next line is to the right from
- * the previous one).
- */
- VERTICAL_270,
- /**
- * Determines if all of the text is vertical
- * ("one letter on top of another").
- */
- STACKED;
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java deleted file mode 100644 index 1114b89445..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/TextFragment.java +++ /dev/null @@ -1,90 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-import java.awt.*;
-import java.awt.font.TextLayout;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.text.CharacterIterator;
-
-/**
- * a renderable text fragment
-*/
-class TextFragment {
- final TextLayout _layout;
- final AttributedString _str;
-
- TextFragment(TextLayout layout, AttributedString str){
- _layout = layout;
- _str = str;
- }
-
- void draw(Graphics2D graphics, double x, double y){
- if(_str == null) {
- return;
- }
-
- double yBaseline = y + _layout.getAscent();
-
- Integer textMode = (Integer)graphics.getRenderingHint(XSLFRenderingHint.TEXT_RENDERING_MODE);
- if(textMode != null && textMode == XSLFRenderingHint.TEXT_AS_SHAPES){
- _layout.draw(graphics, (float)x, (float)yBaseline);
- } else {
- graphics.drawString(_str.getIterator(), (float)x, (float)yBaseline );
- }
- }
-
- /**
- * @return full height of this text run which is sum of ascent, descent and leading
- */
- public float getHeight(){
- double h = Math.ceil(_layout.getAscent()) + Math.ceil(_layout.getDescent()) + _layout.getLeading();
- return (float)h;
- }
-
- /**
- *
- * @return width if this text run
- */
- public float getWidth(){
- return _layout.getAdvance();
- }
-
- /**
- *
- * @return the string to be painted
- */
- public String getString(){
- if(_str == null) return "";
-
- AttributedCharacterIterator it = _str.getIterator();
- StringBuffer buf = new StringBuffer();
- for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
- buf.append(c);
- }
- return buf.toString();
- }
-
- @Override
- public String toString(){
- return "[" + getClass().getSimpleName() + "] " + getString();
- }
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java deleted file mode 100644 index fd00a64e26..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/VerticalAlignment.java +++ /dev/null @@ -1,71 +0,0 @@ -/*
- * ====================================================================
- * 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.xslf.usermodel;
-
-/**
- * Specifies a list of available anchoring types for text
- *
- * @author Yegor Kozlov
- */
-public enum VerticalAlignment {
- /**
- * Anchor the text at the top of the bounding rectangle
- */
- TOP,
-
- /**
- * Anchor the text at the middle of the bounding rectangle
- */
- MIDDLE,
-
- /**
- * Anchor the text at the bottom of the bounding rectangle.
- */
- BOTTOM,
-
- /**
- * Anchor the text so that it is justified vertically.
- * <p>
- * When text is horizontal, this spaces out the actual lines of
- * text and is almost always identical in behavior to
- * {@link #DISTRIBUTED} (special case: if only 1 line, then anchored at top).
- * </p>
- * <p>
- * When text is vertical, then it justifies the letters
- * vertically. This is different than {@link #DISTRIBUTED},
- * because in some cases such as very little text in a line,
- * it will not justify.
- * </p>
- */
- JUSTIFIED,
-
- /**
- * Anchor the text so that it is distributed vertically.
- * <p>
- * When text is horizontal, this spaces out the actual lines
- * of text and is almost always identical in behavior to
- * {@link #JUSTIFIED} (special case: if only 1 line, then anchored in middle).
- * </p>
- * <p>
- * When text is vertical, then it distributes the letters vertically.
- * This is different than {@link #JUSTIFIED}, because it always forces distribution
- * of the words, even if there are only one or two words in a line.
- */
- DISTRIBUTED
-}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java index b1c6be4573..1c5f855db3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java @@ -20,7 +20,11 @@ import java.awt.Dimension; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import org.apache.poi.POIXMLDocument; @@ -32,6 +36,9 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePartName; import org.apache.poi.openxml4j.opc.TargetMode; +import org.apache.poi.sl.usermodel.MasterSheet; +import org.apache.poi.sl.usermodel.Resources; +import org.apache.poi.sl.usermodel.SlideShow; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -53,6 +60,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlideSize; import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument; +import sun.reflect.generics.reflectiveObjects.NotImplementedException; + +import com.sun.org.apache.xml.internal.utils.UnImplNode; + /** * High level representation of a ooxml slideshow. * This is the first object most users will construct whether @@ -60,7 +71,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument * top level object for creating new slides/etc. */ @Beta -public class XMLSlideShow extends POIXMLDocument { +public class XMLSlideShow extends POIXMLDocument implements SlideShow { private static POILogger _logger = POILogFactory.getLogger(XMLSlideShow.class); private CTPresentation _presentation; @@ -437,7 +448,7 @@ public class XMLSlideShow extends POIXMLDocument { */ public int addPicture(byte[] pictureData, int format) { XSLFPictureData img = findPictureData(pictureData); - POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format]; + // POIXMLRelation relDesc = XSLFPictureData.RELATIONS[format]; if(img == null) { int imageNumber = _pictures.size(); @@ -485,4 +496,17 @@ public class XMLSlideShow extends POIXMLDocument { return null; } + public MasterSheet<XSLFShape>[] getMasterSheet() { + return getSlideMasters(); + } + + public MasterSheet<XSLFShape> createMasterSheet() throws IOException { + // TODO: implement! + throw new UnsupportedOperationException(); + } + + public Resources getResources() { + // TODO: implement! + throw new UnsupportedOperationException(); + } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java index 1ee8f6f55f..47bcace2f3 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFAutoShape.java @@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.AutoShape;
import org.apache.poi.util.Beta;
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
@@ -35,7 +36,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual; * @author Yegor Kozlov
*/
@Beta
-public class XSLFAutoShape extends XSLFTextShape {
+public class XSLFAutoShape extends XSLFTextShape implements AutoShape {
/*package*/ XSLFAutoShape(CTShape shape, XSLFSheet sheet) {
super(shape, sheet);
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java index 604c9dff3a..80c6a1acbe 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFBackground.java @@ -17,25 +17,20 @@ package org.apache.poi.xslf.usermodel;
+import java.awt.*;
+import java.awt.geom.Rectangle2D;
+
+import org.apache.poi.sl.usermodel.Background;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBackgroundFillStyleList;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground;
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.geom.Rectangle2D;
-
/**
* Background shape
*
* @author Yegor Kozlov
*/
-public class XSLFBackground extends XSLFSimpleShape {
+public class XSLFBackground extends XSLFSimpleShape implements Background {
/* package */XSLFBackground(CTBackground shape, XSLFSheet sheet) {
super(shape, sheet);
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java index c0f4762c7e..527cef781d 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFColor.java @@ -18,22 +18,18 @@ */
package org.apache.poi.xslf.usermodel;
+import java.awt.Color;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.poi.sl.draw.DrawPaint;
+import org.apache.poi.sl.usermodel.ColorStyle;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTHslColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTScRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.w3c.dom.Node;
-import java.awt.Color;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* Encapsulates logic to read color definitions from DrawingML and convert them to java.awt.Color
*
@@ -63,40 +59,37 @@ public class XSLFColor { * If not color information was found in the supplied xml object then a null is returned.
*/
public Color getColor() {
- return _color == null ? null : applyColorTransform(_color);
+ return DrawPaint.applyColorTransform(getColorStyle());
}
- private Color applyColorTransform(Color color){
- Color result = color;
+ public ColorStyle getColorStyle() {
+ return new ColorStyle() {
+ public Color getColor() {
+ return _color;
+ }
- int alpha = getAlpha();
- if(alpha != -1){
- result = new Color(
- result.getRed(), result.getGreen(), result.getBlue(),
- Math.round(255 * alpha * 0.01f));
- }
+ public int getAlpha() {
+ return getRawValue("alpha");
+ }
- int lumOff = getLumOff();
- int lumMod = getLumMod();
- if(lumMod != -1 || lumOff != -1){
- result = modulateLuminanace(result,
- lumMod == -1 ? 100 : lumMod,
- lumOff == -1 ? 0 : lumOff);
- }
+ public int getLumOff() {
+ return getRawValue("lumOff");
+ }
- int shade = getShade();
- if(shade != -1){
- result = shade(result, shade);
- }
+ public int getLumMod() {
+ return getRawValue("lumMod");
+ }
- int tint = getTint();
- if(tint != -1){
- result = tint(result, tint);
- }
+ public int getShade() {
+ return getRawValue("shade");
+ }
- return result;
+ public int getTint() {
+ return getRawValue("tint");
+ }
+ };
}
-
+
Color toColor(XmlObject obj, XSLFTheme theme) {
Color color = null;
for (XmlObject ch : obj.selectPath("*")) {
@@ -140,6 +133,7 @@ public class XSLFColor { color = new Color(0xFF & val[0], 0xFF & val[1], 0xFF & val[2]);
} else {
// YK: color is a string like "menuText" or "windowText", we return black for such cases
+ @SuppressWarnings("unused")
String colorName = sys.getVal().toString();
color = Color.black;
}
@@ -150,66 +144,50 @@ public class XSLFColor { return color;
}
- /**
- * Read a perecentage value from the supplied xml bean.
- * Example:
- * <a:tint val="45000"/>
- *
- * the returned value is 45
- *
- * @return the percentage value in the range [0 .. 100]
- */
- private int getPercentageValue(String elem){
+ private int getRawValue(String elem) {
String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
XmlObject[] obj;
// first ask the context color and if not found, ask the actual color bean
- if(_phClr != null){
+ if (_phClr != null){
obj = _phClr.selectPath(query);
- if(obj.length == 1){
+ if (obj.length == 1){
Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 1000;
+ return Integer.parseInt(attr.getNodeValue());
}
}
}
obj = _xmlObject.selectPath(query);
- if(obj.length == 1){
+ if (obj.length == 1){
Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 1000;
+ return Integer.parseInt(attr.getNodeValue());
}
}
-
- return -1;
+ return -1;
+ }
+
+ /**
+ * Read a perecentage value from the supplied xml bean.
+ * Example:
+ * <a:tint val="45000"/>
+ *
+ * the returned value is 45
+ *
+ * @return the percentage value in the range [0 .. 100]
+ */
+ private int getPercentageValue(String elem){
+ int val = getRawValue(elem);
+ return (val == -1) ? val : (val / 1000);
}
private int getAngleValue(String elem){
- String color = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
- XmlObject[] obj;
-
- // first ask the context color and if not found, ask the actual color bean
- if(_phClr != null){
- obj = _xmlObject.selectPath( color );
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 60000;
- }
- }
- }
-
- obj = _xmlObject.selectPath( color );
- if(obj.length == 1){
- Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
- if(attr != null) {
- return Integer.parseInt(attr.getNodeValue()) / 60000;
- }
- }
- return -1;
+ int val = getRawValue(elem);
+ return (val == -1) ? val : (val / 60000);
}
/**
@@ -387,7 +365,7 @@ public class XSLFColor { * percentage with 0% indicating minimal shade and 100% indicating maximum
* or -1 if the value is not set
*/
- int getShade(){
+ public int getShade(){
return getPercentageValue("shade");
}
@@ -399,70 +377,12 @@ public class XSLFColor { * percentage with 0% indicating minimal tint and 100% indicating maximum
* or -1 if the value is not set
*/
- int getTint(){
+ public int getTint(){
return getPercentageValue("tint");
}
/**
- * Apply lumMod / lumOff adjustments
- *
- * @param c the color to modify
- * @param lumMod luminance modulation in the range [0..100]
- * @param lumOff luminance offset in the range [0..100]
- * @return modified color
- */
- private static Color modulateLuminanace(Color c, int lumMod, int lumOff) {
- Color color;
- if (lumOff > 0) {
- color = new Color(
- (int) (Math.round((255 - c.getRed()) * (100.0 - lumMod) / 100.0 + c.getRed())),
- (int) (Math.round((255 - c.getGreen()) * lumOff / 100.0 + c.getGreen())),
- (int) (Math.round((255 - c.getBlue()) * lumOff / 100.0 + c.getBlue())),
- c.getAlpha()
- );
- } else {
- color = new Color(
- (int) (Math.round(c.getRed() * lumMod / 100.0)),
- (int) (Math.round(c.getGreen() * lumMod / 100.0)),
- (int) (Math.round(c.getBlue() * lumMod / 100.0)),
- c.getAlpha()
- );
- }
- return color;
- }
-
- /**
- * This algorithm returns result different from PowerPoint.
- * TODO: revisit and improve
- */
- private static Color shade(Color c, int shade) {
- return new Color(
- (int)(c.getRed() * shade * 0.01),
- (int)(c.getGreen() * shade * 0.01),
- (int)(c.getBlue() * shade * 0.01),
- c.getAlpha());
- }
-
- /**
- * This algorithm returns result different from PowerPoint.
- * TODO: revisit and improve
- */
- private static Color tint(Color c, int tint) {
- int r = c.getRed();
- int g = c.getGreen();
- int b = c.getBlue();
-
- float ftint = tint / 100.0f;
-
- int red = Math.round(ftint * r + (1 - ftint) * 255);
- int green = Math.round(ftint * g + (1 - ftint) * 255);
- int blue = Math.round(ftint * b + (1 - ftint) * 255);
-
- return new Color(red, green, blue);
- }
-
- /**
* Preset colors defined in DrawingML
*/
static final Map<String, Color> presetColors;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java index 529bacf734..514c1bc90f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java @@ -23,6 +23,7 @@ import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlCursor;
@@ -34,6 +35,7 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D; import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame;
import javax.xml.namespace.QName;
+
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
@@ -58,8 +60,8 @@ public class XSLFGraphicFrame extends XSLFShape { return _sheet;
}
- public int getShapeType(){
- throw new RuntimeException("NotImplemented");
+ public ShapeType getShapeType(){
+ throw new UnsupportedOperationException();
}
public int getShapeId(){
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java index 2ad699b408..f93fc803fb 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGroupShape.java @@ -19,9 +19,17 @@ package org.apache.poi.xslf.usermodel;
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.sl.usermodel.ShapeType;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlObject;
@@ -35,13 +43,6 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.util.Iterator;
-import java.util.List;
-import java.util.regex.Pattern;
-
/**
* Represents a group shape that consists of many shapes grouped together.
*
@@ -207,30 +208,35 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer { public XSLFAutoShape createAutoShape(){
XSLFAutoShape sh = getDrawing().createAutoShape();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFFreeformShape createFreeform(){
XSLFFreeformShape sh = getDrawing().createFreeform();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFTextBox createTextBox(){
XSLFTextBox sh = getDrawing().createTextBox();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFConnectorShape createConnector(){
XSLFConnectorShape sh = getDrawing().createConnector();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
public XSLFGroupShape createGroup(){
XSLFGroupShape sh = getDrawing().createGroup();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -251,6 +257,7 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer { XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
sh.resize();
_shapes.add(sh);
+ sh.setParent(this);
return sh;
}
@@ -343,4 +350,13 @@ public class XSLFGroupShape extends XSLFShape implements XSLFShapeContainer { }
}
+ public ShapeType getShapeType(){
+ return null;
+ }
+
+ public void addShape(XSLFShape shape) {
+ throw new UnsupportedOperationException(
+ "Adding a shape from a different container is not supported -"
+ + " create it from scratch witht XSLFGroupShape.create* methods");
+ }
}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java index 0a33132e28..62f9cc4ad6 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java @@ -21,6 +21,8 @@ import java.io.IOException; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.sl.usermodel.Notes; +import org.apache.poi.sl.usermodel.TextRun; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData; @@ -28,7 +30,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide; import org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument; @Beta -public final class XSLFNotes extends XSLFSheet { +public final class XSLFNotes extends XSLFSheet implements Notes<XSLFShape> { private CTNotesSlide _notes; /** @@ -80,7 +82,6 @@ public final class XSLFNotes extends XSLFSheet { return getMasterSheet().getTheme(); } - @Override public XSLFNotesMaster getMasterSheet() { for (POIXMLDocumentPart p : getRelations()) { if (p instanceof XSLFNotesMaster){ @@ -89,4 +90,20 @@ public final class XSLFNotes extends XSLFSheet { } return null; } + + public TextRun getTextRun() { + for (XSLFShape sh : super.getShapes()) { + if (sh instanceof XSLFTextShape) { + XSLFTextShape txt = (XSLFTextShape)sh; + for (XSLFTextParagraph p : txt.getTextParagraphs()) { + for (XSLFTextRun r : p.getTextRuns()) { + return r; + } + } + } + } + return null; + } + + } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java index 40937e8785..c5de537677 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotesMaster.java @@ -23,6 +23,7 @@ import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.drawingml.x2006.main.CTColorMapping; @@ -46,7 +47,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument; * @author Yegor Kozlov */ @Beta - public class XSLFNotesMaster extends XSLFSheet { + public class XSLFNotesMaster extends XSLFSheet implements MasterSheet<XSLFShape> { private CTNotesMaster _slide; private XSLFTheme _theme; @@ -93,7 +94,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.NotesMasterDocument; } @Override - public XSLFSheet getMasterSheet() { + public MasterSheet getMasterSheet() { return null; } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java index 42dc360cd6..fa4b192ec4 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShadow.java @@ -17,6 +17,7 @@ package org.apache.poi.xslf.usermodel;
+import org.apache.poi.sl.usermodel.Shadow;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTOuterShadowEffect;
import org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor;
@@ -31,7 +32,7 @@ import java.awt.geom.Rectangle2D; *
* @author Yegor Kozlov
*/
-public class XSLFShadow extends XSLFSimpleShape {
+public class XSLFShadow extends XSLFSimpleShape implements Shadow {
private XSLFSimpleShape _parent;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java index 82addf7ddb..aa6e2c712f 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java @@ -19,13 +19,25 @@ package org.apache.poi.xslf.usermodel;
-import java.awt.Graphics2D;
-import java.awt.geom.AffineTransform;
+import java.awt.Color;
import java.awt.geom.Rectangle2D;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Comparator;
-import org.apache.poi.util.Beta;
-import org.apache.poi.util.Internal;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.sl.draw.DrawPaint;
+import org.apache.poi.sl.draw.geom.CustomGeometry;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.util.*;
+import org.apache.poi.xslf.model.PropertyFetcher;
import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
+import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
+import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
/**
* Base super-class class for all shapes in PresentationML
@@ -33,25 +45,43 @@ import org.apache.xmlbeans.XmlObject; * @author Yegor Kozlov
*/
@Beta
-public abstract class XSLFShape {
+public abstract class XSLFShape implements Shape {
+ protected final XmlObject _shape;
+ protected final XSLFSheet _sheet;
+ protected XSLFShapeContainer _parent;
- /**
- * @return the position of this shape within the drawing canvas.
- * The coordinates are expressed in points
- */
- public abstract Rectangle2D getAnchor();
+ private CTShapeProperties _spPr;
+ private CTShapeStyle _spStyle;
+ private CTNonVisualDrawingProps _nvPr;
+ private CTPlaceholder _ph;
- /**
- * @param anchor the position of this shape within the drawing canvas.
- * The coordinates are expressed in points
- */
- public abstract void setAnchor(Rectangle2D anchor);
+ private static final PaintStyle TRANSPARENT_PAINT = new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return new ColorStyle(){
+ public Color getColor() { return DrawPaint.NO_PAINT; }
+ public int getAlpha() { return -1; }
+ public int getLumOff() { return -1; }
+ public int getLumMod() { return -1; }
+ public int getShade() { return -1; }
+ public int getTint() { return -1; }
+ };
+ }
+ };
+
+
+ protected XSLFShape(XmlObject shape, XSLFSheet sheet) {
+ _shape = shape;
+ _sheet = sheet;
+ }
+
/**
* @return the xml bean holding this shape's data
*/
- public abstract XmlObject getXmlObject();
-
+ public XmlObject getXmlObject() {
+ return _shape;
+ }
+
/**
* @return human-readable name of this shape, e.g. "Rectange 3"
*/
@@ -119,97 +149,417 @@ public abstract class XSLFShape { public abstract boolean getFlipVertical();
/**
- * Draw this shape into the supplied canvas
+ * Set the contents of this shape to be a copy of the source shape.
+ * This method is called recursively for each shape when merging slides
*
- * @param graphics the graphics to draw into
+ * @param sh the source shape
+ * @see org.apache.poi.xslf.usermodel.XSLFSlide#importContent(XSLFSheet)
*/
- public abstract void draw(Graphics2D graphics);
+ @Internal
+ void copy(XSLFShape sh) {
+ if (!getClass().isInstance(sh)) {
+ throw new IllegalArgumentException(
+ "Can't copy " + sh.getClass().getSimpleName() + " into " + getClass().getSimpleName());
+ }
+ setAnchor(sh.getAnchor());
+ }
+
+ public void setParent(XSLFShapeContainer parent) {
+ this._parent = parent;
+ }
+
+ public XSLFShapeContainer getParent() {
+ return this._parent;
+ }
+
+ public boolean isPlaceholder() {
+ return false;
+ }
+
+ public StrokeStyle getStrokeStyle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public CustomGeometry getGeometry() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ShapeType getShapeType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public XSLFSheet getSheet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/**
- * Apply 2-D transforms before drawing this shape. This includes rotation and flipping.
+ * fetch shape fill as a java.awt.Paint
*
- * @param graphics the graphics whos transform matrix will be modified
+ * @return either Color or GradientPaint or TexturePaint or null
*/
- protected void applyTransform(Graphics2D graphics) {
- Rectangle2D anchor = getAnchor();
- AffineTransform tx = (AffineTransform)graphics.getRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM);
- if(tx != null) {
- anchor = tx.createTransformedShape(anchor).getBounds2D();
- }
+ @Override
+ public FillStyle getFillStyle() {
+ return new FillStyle() {
+ public PaintStyle getPaint() {
+ PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
+ public boolean fetch(XSLFShape shape) {
+ CTShapeProperties spPr = shape.getSpPr();
+ if (spPr.isSetNoFill()) {
+ setValue(TRANSPARENT_PAINT);
+ return true;
+ }
+
+ PaintStyle paint = null;
+ for (XmlObject obj : spPr.selectPath("*")) {
+ paint = selectPaint(obj, null, getSheet().getPackagePart());
+ if (paint != null) break;
+ }
+
+ if (paint == null) return false;
+
+ setValue(paint);
+ return true;
+ }
+ };
+ fetchShapeProperty(fetcher);
- // rotation
- double rotation = getRotation();
- if (rotation != 0.) {
- // PowerPoint rotates shapes relative to the geometric center
- double centerX = anchor.getCenterX();
- double centerY = anchor.getCenterY();
-
- // normalize rotation
- rotation = (360.+(rotation%360.))%360.;
- int quadrant = (((int)rotation+45)/90)%4;
- double scaleX = 1.0, scaleY = 1.0;
-
- // scale to bounding box (bug #53176)
- if (quadrant == 1 || quadrant == 3) {
- // In quadrant 1 and 3, which is basically a shape in a more or less portrait orientation
- // (45-135 degrees and 225-315 degrees), we need to first rotate the shape by a multiple
- // of 90 degrees and then resize the bounding box to its original bbox. After that we can
- // rotate the shape to the exact rotation amount.
- // It's strange that you'll need to rotate the shape back and forth again, but you can
- // think of it, as if you paint the shape on a canvas. First you rotate the canvas, which might
- // be already (differently) scaled, so you can paint the shape in its default orientation
- // and later on, turn it around again to compare it with its original size ...
- AffineTransform txg = new AffineTransform(); // graphics coordinate space
- AffineTransform txs = new AffineTransform(tx); // shape coordinate space
- txg.translate(centerX, centerY);
- txg.rotate(Math.toRadians(quadrant*90));
- txg.translate(-centerX, -centerY);
- txs.translate(centerX, centerY);
- txs.rotate(Math.toRadians(-quadrant*90));
- txs.translate(-centerX, -centerY);
- txg.concatenate(txs);
- Rectangle2D anchor2 = txg.createTransformedShape(getAnchor()).getBounds2D();
- scaleX = anchor.getWidth() == 0. ? 1.0 : anchor.getWidth() / anchor2.getWidth();
- scaleY = anchor.getHeight() == 0. ? 1.0 : anchor.getHeight() / anchor2.getHeight();
+ PaintStyle paint = fetcher.getValue();
+
+ if (paint != null) return paint;
+
+ // fill color was not found, check if it is defined in the theme
+ CTShapeStyle style = getSpStyle();
+ if (style != null) {
+ // get a reference to a fill style within the style matrix.
+ CTStyleMatrixReference fillRef = style.getFillRef();
+ // The idx attribute refers to the index of a fill style or
+ // background fill style within the presentation's style matrix, defined by the fmtScheme element.
+ // value of 0 or 1000 indicates no background,
+ // values 1-999 refer to the index of a fill style within the fillStyleLst element
+ // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
+ int idx = (int)fillRef.getIdx();
+ CTSchemeColor phClr = fillRef.getSchemeClr();
+ XSLFSheet sheet = _sheet;
+ XSLFTheme theme = sheet.getTheme();
+ XmlObject fillProps = null;
+ CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
+ if(idx >= 1 && idx <= 999){
+ fillProps = matrix.getFillStyleLst().selectPath("*")[idx - 1];
+ } else if (idx >= 1001 ){
+ fillProps = matrix.getBgFillStyleLst().selectPath("*")[idx - 1001];
+ }
+ if(fillProps != null) {
+ paint = selectPaint(fillProps, phClr, sheet.getPackagePart());
+ }
+ }
+ return paint == RenderableShape.NO_PAINT ? null : paint;
}
+ };
+ }
+
+ /**
+ * Walk up the inheritance tree and fetch shape properties.
+ *
+ * The following order of inheritance is assumed:
+ * <p>
+ * slide <-- slideLayout <-- slideMaster
+ * </p>
+ *
+ * @param visitor the object that collects the desired property
+ * @return true if the property was fetched
+ */
+ protected boolean fetchShapeProperty(PropertyFetcher<?> visitor) {
+ boolean ok = visitor.fetch(this);
+
+ XSLFSimpleShape masterShape;
+ XSLFSheet masterSheet = (XSLFSheet)getSheet().getMasterSheet();
+ CTPlaceholder ph = getCTPlaceholder();
+
+ if (masterSheet != null && ph != null) {
+ if (!ok) {
+ masterShape = masterSheet.getPlaceholder(ph);
+ if (masterShape != null) {
+ ok = visitor.fetch(masterShape);
+ }
+ }
+
+ // try slide master
+ if (!ok ) {
+ int textType;
+ if ( !ph.isSetType()) textType = STPlaceholderType.INT_BODY;
+ else {
+ switch (ph.getType().intValue()) {
+ case STPlaceholderType.INT_TITLE:
+ case STPlaceholderType.INT_CTR_TITLE:
+ textType = STPlaceholderType.INT_TITLE;
+ break;
+ case STPlaceholderType.INT_FTR:
+ case STPlaceholderType.INT_SLD_NUM:
+ case STPlaceholderType.INT_DT:
+ textType = ph.getType().intValue();
+ break;
+ default:
+ textType = STPlaceholderType.INT_BODY;
+ break;
+ }
+ }
+ XSLFSheet master = (XSLFSheet)masterSheet.getMasterSheet();
+ if (master != null) {
+ masterShape = master.getPlaceholderByType(textType);
+ if (masterShape != null) {
+ ok = visitor.fetch(masterShape);
+ }
+ }
+ }
+ }
+ return ok;
+ }
- // transformation is applied reversed ...
- graphics.translate(centerX, centerY);
- graphics.rotate(Math.toRadians(rotation-(double)(quadrant*90)));
- graphics.scale(scaleX, scaleY);
- graphics.rotate(Math.toRadians(quadrant*90));
- graphics.translate(-centerX, -centerY);
+ protected CTPlaceholder getCTPlaceholder() {
+ if (_ph == null) {
+ XmlObject[] obj = _shape.selectPath(
+ "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:nvPr/p:ph");
+ if (obj.length == 1) {
+ _ph = (CTPlaceholder) obj[0];
+ }
}
+ return _ph;
+ }
+
+ protected CTShapeStyle getSpStyle() {
+ if (_spStyle == null) {
+ for (XmlObject obj : _shape.selectPath("*")) {
+ if (obj instanceof CTShapeStyle) {
+ _spStyle = (CTShapeStyle) obj;
+ }
+ }
+ }
+ return _spStyle;
+ }
- //flip horizontal
- if (getFlipHorizontal()) {
- graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY());
- graphics.scale(-1, 1);
- graphics.translate(-anchor.getX(), -anchor.getY());
+ protected CTNonVisualDrawingProps getNvPr() {
+ if (_nvPr == null) {
+ XmlObject[] rs = _shape
+ .selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
+ if (rs.length != 0) {
+ _nvPr = (CTNonVisualDrawingProps) rs[0];
+ }
}
+ return _nvPr;
+ }
- //flip vertical
- if (getFlipVertical()) {
- graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight());
- graphics.scale(1, -1);
- graphics.translate(-anchor.getX(), -anchor.getY());
+ protected CTShapeProperties getSpPr() {
+ if (_spPr == null) {
+ for (XmlObject obj : _shape.selectPath("*")) {
+ if (obj instanceof CTShapeProperties) {
+ _spPr = (CTShapeProperties) obj;
+ }
+ }
+ }
+ if (_spPr == null) {
+ throw new IllegalStateException("CTShapeProperties was not found.");
}
+ return _spPr;
}
+ CTTransform2D getXfrm() {
+ PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {
+ public boolean fetch(XSLFShape shape) {
+ CTShapeProperties pr = shape.getSpPr();
+ if (pr.isSetXfrm()) {
+ setValue(pr.getXfrm());
+ return true;
+ }
+ return false;
+ }
+ };
+ fetchShapeProperty(fetcher);
+ return fetcher.getValue();
+ }
+
/**
- * Set the contents of this shape to be a copy of the source shape.
- * This method is called recursively for each shape when merging slides
+ * @return the position of this shape within the drawing canvas.
+ * The coordinates are expressed in points
+ */
+ public Rectangle2D getAnchor() {
+ CTTransform2D xfrm = getXfrm();
+ if (xfrm == null) return null;
+
+ CTPoint2D off = xfrm.getOff();
+ long x = off.getX();
+ long y = off.getY();
+ CTPositiveSize2D ext = xfrm.getExt();
+ long cx = ext.getCx();
+ long cy = ext.getCy();
+ return new Rectangle2D.Double(
+ Units.toPoints(x), Units.toPoints(y),
+ Units.toPoints(cx), Units.toPoints(cy));
+ }
+
+ /**
+ * @param anchor the position of this shape within the drawing canvas.
+ * The coordinates are expressed in points
+ */
+ public void setAnchor(Rectangle2D anchor) {
+ CTShapeProperties spPr = getSpPr();
+ if (spPr == null) return;
+
+ CTTransform2D xfrm = spPr.isSetXfrm() ? spPr.getXfrm() : spPr.addNewXfrm();
+ CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
+ long x = Units.toEMU(anchor.getX());
+ long y = Units.toEMU(anchor.getY());
+ off.setX(x);
+ off.setY(y);
+ CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm
+ .addNewExt();
+ long cx = Units.toEMU(anchor.getWidth());
+ long cy = Units.toEMU(anchor.getHeight());
+ ext.setCx(cx);
+ ext.setCy(cy);
+ }
+
+ /**
+ * Convert shape fill into java.awt.Paint. The result is either Color or
+ * TexturePaint or GradientPaint or null
*
- * @param sh the source shape
- * @see org.apache.poi.xslf.usermodel.XSLFSlide#importContent(XSLFSheet)
+ * @param graphics the target graphics
+ * @param obj the xml to read. Must contain elements from the EG_ColorChoice group:
+ * <code>
+ * a:scrgbClr RGB Color Model - Percentage Variant
+ * a:srgbClr RGB Color Model - Hex Variant
+ * a:hslClr Hue, Saturation, Luminance Color Model
+ * a:sysClr System Color
+ * a:schemeClr Scheme Color
+ * a:prstClr Preset Color
+ * </code>
+ *
+ * @param phClr context color
+ * @param parentPart the parent package part. Any external references (images, etc.) are resolved relative to it.
+ *
+ * @return the applied Paint or null if none was applied
*/
- @Internal
- void copy(XSLFShape sh) {
- if (!getClass().isInstance(sh)) {
- throw new IllegalArgumentException(
- "Can't copy " + sh.getClass().getSimpleName() + " into " + getClass().getSimpleName());
+ protected PaintStyle selectPaint(XmlObject obj, final CTSchemeColor phClr, final PackagePart parentPart) {
+ final XSLFTheme theme = getSheet().getTheme();
+
+ if (obj instanceof CTNoFillProperties) {
+ return TRANSPARENT_PAINT;
}
+
+ if (obj instanceof CTSolidColorFillProperties) {
+ CTSolidColorFillProperties solidFill = (CTSolidColorFillProperties) obj;
+ final XSLFColor c = new XSLFColor(solidFill, theme, phClr);
+ return new SolidPaint() {
+ public ColorStyle getSolidColor() {
+ return c.getColorStyle();
+ }
+ };
+ }
+
+ if (obj instanceof CTBlipFillProperties) {
+ CTBlipFillProperties blipFill = (CTBlipFillProperties)obj;
+ final CTBlip blip = blipFill.getBlip();
+ return new TexturePaint() {
+ private PackagePart getPart() {
+ try {
+ String blipId = blip.getEmbed();
+ PackageRelationship rel = parentPart.getRelationship(blipId);
+ return parentPart.getRelatedPart(rel);
+ } catch (InvalidFormatException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public InputStream getImageData() {
+ try {
+ return getPart().getInputStream();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
- setAnchor(sh.getAnchor());
+ public String getContentType() {
+ /* TOOD: map content-type */
+ return getPart().getContentType();
+ }
+
+ public int getAlpha() {
+ return (blip.sizeOfAlphaModFixArray() > 0)
+ ? blip.getAlphaModFixArray(0).getAmt()
+ : 0;
+ }
+ };
+ }
+
+ if (obj instanceof CTGradientFillProperties) {
+ final CTGradientFillProperties gradFill = (CTGradientFillProperties) obj;
+
+ @SuppressWarnings("deprecation")
+ final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
+
+ Arrays.sort(gs, new Comparator<CTGradientStop>() {
+ public int compare(CTGradientStop o1, CTGradientStop o2) {
+ Integer pos1 = o1.getPos();
+ Integer pos2 = o2.getPos();
+ return pos1.compareTo(pos2);
+ }
+ });
+
+ final ColorStyle cs[] = new ColorStyle[gs.length];
+ final float fractions[] = new float[gs.length];
+
+ int i=0;
+ for (CTGradientStop cgs : gs) {
+ cs[i] = new XSLFColor(cgs, theme, phClr).getColorStyle();
+ fractions[i] = cgs.getPos() / 100000.f;
+ }
+
+ return new GradientPaint() {
+
+ public double getGradientAngle() {
+ return (gradFill.isSetLin())
+ ? gradFill.getLin().getAng() / 60000.d
+ : 0;
+ }
+
+ public ColorStyle[] getGradientColors() {
+ return cs;
+ }
+
+ public float[] getGradientFractions() {
+ return fractions;
+ }
+
+ public boolean isRotatedWithShape() {
+ // TODO: is this correct???
+ return (gradFill.isSetRotWithShape() || !gradFill.getRotWithShape());
+ }
+
+ public GradientType getGradientType() {
+ if (gradFill.isSetLin()) {
+ return GradientType.linear;
+ }
+
+ if (gradFill.isSetPath()) {
+ /* TODO: handle rect path */
+ STPathShadeType.Enum ps = gradFill.getPath().getPath();
+ if (ps == STPathShadeType.CIRCLE) {
+ return GradientType.circular;
+ } else if (ps == STPathShadeType.SHAPE) {
+ return GradientType.shape;
+ }
+ }
+
+ return GradientType.linear;
+ }
+ };
+ }
+
+ return TRANSPARENT_PAINT;
}
+
}
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java index 3a20891846..d839a49d37 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeContainer.java @@ -19,10 +19,12 @@ package org.apache.poi.xslf.usermodel; +import org.apache.poi.sl.usermodel.ShapeContainer; + /** * Common interface for shape containers, e.g. sheets or groups of shapes */ -public interface XSLFShapeContainer extends Iterable<XSLFShape> { +public interface XSLFShapeContainer extends ShapeContainer { /** * create a new shape with a predefined geometry and add it to this shape container @@ -56,27 +58,6 @@ public interface XSLFShapeContainer extends Iterable<XSLFShape> { XSLFPictureShape createPicture(int pictureIndex); /** - * Returns an array containing all of the elements in this container in proper - * sequence (from first to last element). - * - * @return an array containing all of the elements in this container in proper - * sequence - */ - XSLFShape[] getShapes(); - - /** - * Removes the specified shape from this sheet, if it is present - * (optional operation). If this sheet does not contain the element, - * it is unchanged. - * - * @param xShape shape to be removed from this sheet, if present - * @return <tt>true</tt> if this sheet contained the specified element - * @throws IllegalArgumentException if the type of the specified shape - * is incompatible with this sheet (optional) - */ - boolean removeShape(XSLFShape xShape) ; - - /** * Removes all of the elements from this container (optional operation). * The container will be empty after this call returns. */ diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java deleted file mode 100644 index 57163ff742..0000000000 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShapeType.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * ==================================================================== - * 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.xslf.usermodel; - -/** - * known preset shape geometries in PresentationML - * - * @author Yegor Kozlov - */ -public enum XSLFShapeType { - LINE(1), - LINE_INV(2), - TRIANGLE(3), - RT_TRIANGLE(4), - RECT(5), - DIAMOND(6), - PARALLELOGRAM(7), - TRAPEZOID(8), - NON_ISOSCELES_TRAPEZOID(9), - PENTAGON(10), - HEXAGON(11), - HEPTAGON(12), - OCTAGON(13), - DECAGON(14), - DODECAGON(15), - STAR_4(16), - STAR_5(17), - STAR_6(18), - STAR_7(19), - STAR_8(20), - STAR_10(21), - STAR_12(22), - STAR_16(23), - STAR_24(24), - STAR_32(25), - ROUND_RECT(26), - ROUND_1_RECT(27), - ROUND_2_SAME_RECT(28), - ROUND_2_DIAG_RECT(29), - SNIP_ROUND_RECT(30), - SNIP_1_RECT(31), - SNIP_2_SAME_RECT(32), - SNIP_2_DIAG_RECT(33), - PLAQUE(34), - ELLIPSE(35), - TEARDROP(36), - HOME_PLATE(37), - CHEVRON(38), - PIE_WEDGE(39), - PIE(40), - BLOCK_ARC(41), - DONUT(42), - NO_SMOKING(43), - RIGHT_ARROW(44), - LEFT_ARROW(45), - UP_ARROW(46), - DOWN_ARROW(47), - STRIPED_RIGHT_ARROW(48), - NOTCHED_RIGHT_ARROW(49), - BENT_UP_ARROW(50), - LEFT_RIGHT_ARROW(51), - UP_DOWN_ARROW(52), - LEFT_UP_ARROW(53), - LEFT_RIGHT_UP_ARROW(54), - QUAD_ARROW(55), - LEFT_ARROW_CALLOUT(56), - RIGHT_ARROW_CALLOUT(57), - UP_ARROW_CALLOUT(58), - DOWN_ARROW_CALLOUT(59), - LEFT_RIGHT_ARROW_CALLOUT(60), - UP_DOWN_ARROW_CALLOUT(61), - QUAD_ARROW_CALLOUT(62), - BENT_ARROW(63), - UTURN_ARROW(64), - CIRCULAR_ARROW(65), - LEFT_CIRCULAR_ARROW(66), - LEFT_RIGHT_CIRCULAR_ARROW(67), - CURVED_RIGHT_ARROW(68), - CURVED_LEFT_ARROW(69), - CURVED_UP_ARROW(70), - CURVED_DOWN_ARROW(71), - SWOOSH_ARROW(72), - CUBE(73), - CAN(74), - LIGHTNING_BOLT(75), - HEART(76), - SUN(77), - MOON(78), - SMILEY_FACE(79), - IRREGULAR_SEAL_1(80), - IRREGULAR_SEAL_2(81), - FOLDED_CORNER(82), - BEVEL(83), - FRAME(84), - HALF_FRAME(85), - CORNER(86), - DIAG_STRIPE(87), - CHORD(88), - ARC(89), - LEFT_BRACKET(90), - RIGHT_BRACKET(91), - LEFT_BRACE(92), - RIGHT_BRACE(93), - BRACKET_PAIR(94), - BRACE_PAIR(95), - STRAIGHT_CONNECTOR_1(96), - BENT_CONNECTOR_2(97), - BENT_CONNECTOR_3(98), - BENT_CONNECTOR_4(99), - BENT_CONNECTOR_5(100), - CURVED_CONNECTOR_2(101), - CURVED_CONNECTOR_3(102), - CURVED_CONNECTOR_4(103), - CURVED_CONNECTOR_5(104), - CALLOUT_1(105), - CALLOUT_2(106), - CALLOUT_3(107), - ACCENT_CALLOUT_1(108), - ACCENT_CALLOUT_2(109), - ACCENT_CALLOUT_3(110), - BORDER_CALLOUT_1(111), - BORDER_CALLOUT_2(112), - BORDER_CALLOUT_3(113), - ACCENT_BORDER_CALLOUT_1(114), - ACCENT_BORDER_CALLOUT_2(115), - ACCENT_BORDER_CALLOUT_3(116), - WEDGE_RECT_CALLOUT(117), - WEDGE_ROUND_RECT_CALLOUT(118), - WEDGE_ELLIPSE_CALLOUT(119), - CLOUD_CALLOUT(120), - CLOUD(121), - RIBBON(122), - RIBBON_2(123), - ELLIPSE_RIBBON(124), - ELLIPSE_RIBBON_2(125), - LEFT_RIGHT_RIBBON(126), - VERTICAL_SCROLL(127), - HORIZONTAL_SCROLL(128), - WAVE(129), - DOUBLE_WAVE(130), - PLUS(131), - FLOW_CHART_PROCESS(132), - FLOW_CHART_DECISION(133), - FLOW_CHART_INPUT_OUTPUT(134), - FLOW_CHART_PREDEFINED_PROCESS(135), - FLOW_CHART_INTERNAL_STORAGE(136), - FLOW_CHART_DOCUMENT(137), - FLOW_CHART_MULTIDOCUMENT(138), - FLOW_CHART_TERMINATOR(139), - FLOW_CHART_PREPARATION(140), - FLOW_CHART_MANUAL_INPUT(141), - FLOW_CHART_MANUAL_OPERATION(142), - FLOW_CHART_CONNECTOR(143), - FLOW_CHART_PUNCHED_CARD(144), - FLOW_CHART_PUNCHED_TAPE(145), - FLOW_CHART_SUMMING_JUNCTION(146), - FLOW_CHART_OR(147), - FLOW_CHART_COLLATE(148), - FLOW_CHART_SORT(149), - FLOW_CHART_EXTRACT(150), - FLOW_CHART_MERGE(151), - FLOW_CHART_OFFLINE_STORAGE(152), - FLOW_CHART_ONLINE_STORAGE(153), - FLOW_CHART_MAGNETIC_TAPE(154), - FLOW_CHART_MAGNETIC_DISK(155), - FLOW_CHART_MAGNETIC_DRUM(156), - FLOW_CHART_DISPLAY(157), - FLOW_CHART_DELAY(158), - FLOW_CHART_ALTERNATE_PROCESS(159), - FLOW_CHART_OFFPAGE_CONNECTOR(160), - ACTION_BUTTON_BLANK(161), - ACTION_BUTTON_HOME(162), - ACTION_BUTTON_HELP(163), - ACTION_BUTTON_INFORMATION(164), - ACTION_BUTTON_FORWARD_NEXT(165), - ACTION_BUTTON_BACK_PREVIOUS(166), - ACTION_BUTTON_END(167), - ACTION_BUTTON_BEGINNING(168), - ACTION_BUTTON_RETURN(169), - ACTION_BUTTON_DOCUMENT(170), - ACTION_BUTTON_SOUND(171), - ACTION_BUTTON_MOVIE(172), - GEAR_6(173), - GEAR_9(174), - FUNNEL(175), - MATH_PLUS(176), - MATH_MINUS(177), - MATH_MULTIPLY(178), - MATH_DIVIDE(179), - MATH_EQUAL(180), - MATH_NOT_EQUAL(181), - CORNER_TABS(182), - SQUARE_TABS(183), - PLAQUE_TABS(184), - CHART_X(185), - CHART_STAR(186), - CHART_PLUS(187); - - private int _idx; - - XSLFShapeType(int idx){ - _idx = idx; - } - - /** - * - * @return index in the STShapeType enum - */ - int getIndex(){ - return _idx; - } - - static XSLFShapeType forInt(int idx){ - for(XSLFShapeType t : values()){ - if(t._idx == idx) return t; - } - throw new IllegalArgumentException("Unknown shape type: " + idx); - } -} diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java index 35100d1194..c9694e2185 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSheet.java @@ -23,6 +23,8 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.sl.usermodel.MasterSheet; +import org.apache.poi.sl.usermodel.Sheet; import org.apache.poi.util.Beta; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -37,7 +39,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPicture; import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; +import com.sun.org.apache.xml.internal.utils.UnImplNode; + import javax.xml.namespace.QName; + import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.io.IOException; @@ -51,7 +56,7 @@ import java.util.Map; import java.util.regex.Pattern; @Beta -public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer { +public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeContainer, Sheet { private XSLFCommonSlideData _commonSlideData; private XSLFDrawing _drawing; private List<XSLFShape> _shapes; @@ -142,6 +147,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFAutoShape sh = getDrawing().createAutoShape(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -149,6 +155,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFFreeformShape sh = getDrawing().createFreeform(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -156,6 +163,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFTextBox sh = getDrawing().createTextBox(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -163,6 +171,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFConnectorShape sh = getDrawing().createConnector(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -170,6 +179,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFGroupShape sh = getDrawing().createGroup(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -191,6 +201,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC sh.resize(); getShapeList().add(sh); + sh.setParent(this); return sh; } @@ -198,6 +209,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC List<XSLFShape> shapes = getShapeList(); XSLFTable sh = getDrawing().createTable(); shapes.add(sh); + sh.setParent(this); return sh; } @@ -219,6 +231,12 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return getShapeList().iterator(); } + public void addShape(XSLFShape shape) { + throw new UnsupportedOperationException( + "Adding a shape from a different container is not supported -" + + " create it from scratch witht XSLFSheet.create* methods"); + } + /** * Removes the specified shape from this sheet, if it is present * (optional operation). If this sheet does not contain the element, @@ -370,12 +388,6 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC return null; } - /** - * - * @return master of this sheet. - */ - public abstract XSLFSheet getMasterSheet(); - protected XSLFTextShape getTextShapeByType(Placeholder type){ for(XSLFShape shape : this.getShapes()){ if(shape instanceof XSLFTextShape) { @@ -486,7 +498,7 @@ public abstract class XSLFSheet extends POIXMLDocumentPart implements XSLFShapeC * @param graphics */ public void draw(Graphics2D graphics){ - XSLFSheet master = getMasterSheet(); + XSLFSheet master = (XSLFSheet)getMasterSheet(); if(getFollowMasterGraphics() && master != null) master.draw(graphics); graphics.setRenderingHint(XSLFRenderingHint.GROUP_TRANSFORM, new AffineTransform()); diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index d6cfa7fba3..ca548dd636 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -19,26 +19,25 @@ package org.apache.poi.xslf.usermodel;
+import java.awt.*;
+import java.awt.Shape;
+import java.awt.geom.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.poi.sl.draw.geom.*;
+import org.apache.poi.sl.usermodel.*;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineCap;
+import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Units;
import org.apache.poi.xslf.model.PropertyFetcher;
-import org.apache.poi.xslf.model.geom.CustomGeometry;
-import org.apache.poi.xslf.model.geom.Outline;
-import org.apache.poi.xslf.model.geom.Path;
-import org.apache.poi.xslf.model.geom.PresetGeometries;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.drawingml.x2006.main.*;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
-import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
-import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
-
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Rectangle2D;
-import java.util.ArrayList;
-import java.util.List;
+import org.openxmlformats.schemas.presentationml.x2006.main.*;
/**
* Represents a single (non-group) shape in a .pptx slide show
@@ -46,24 +45,11 @@ import java.util.List; * @author Yegor Kozlov
*/
@Beta
-public abstract class XSLFSimpleShape extends XSLFShape {
+public abstract class XSLFSimpleShape extends XSLFShape implements SimpleShape {
private static CTOuterShadowEffect NO_SHADOW = CTOuterShadowEffect.Factory.newInstance();
- private final XmlObject _shape;
- private final XSLFSheet _sheet;
- private CTShapeProperties _spPr;
- private CTShapeStyle _spStyle;
- private CTNonVisualDrawingProps _nvPr;
- private CTPlaceholder _ph;
-
/* package */XSLFSimpleShape(XmlObject shape, XSLFSheet sheet) {
- _shape = shape;
- _sheet = sheet;
- }
-
- @Override
- public XmlObject getXmlObject() {
- return _shape;
+ super(shape,sheet);
}
/**
@@ -78,16 +64,16 @@ public abstract class XSLFSimpleShape extends XSLFShape { *
* @param type
*/
- public void setShapeType(XSLFShapeType type){
+ public void setShapeType(ShapeType type){
CTShape shape = (CTShape) getXmlObject();
- STShapeType.Enum geom = STShapeType.Enum.forInt(type.getIndex());
+ STShapeType.Enum geom = STShapeType.Enum.forInt(type.ooxmlId);
shape.getSpPr().getPrstGeom().setPrst(geom);
}
- public XSLFShapeType getShapeType(){
+ public ShapeType getShapeType(){
CTShape shape = (CTShape) getXmlObject();
STShapeType.Enum geom = shape.getSpPr().getPrstGeom().getPrst();
- return XSLFShapeType.forInt(geom.intValue());
+ return ShapeType.forId(geom.intValue(), true);
}
@Override
@@ -100,101 +86,6 @@ public abstract class XSLFSimpleShape extends XSLFShape { return (int) getNvPr().getId();
}
- protected CTNonVisualDrawingProps getNvPr() {
- if (_nvPr == null) {
- XmlObject[] rs = _shape
- .selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:cNvPr");
- if (rs.length != 0) {
- _nvPr = (CTNonVisualDrawingProps) rs[0];
- }
- }
- return _nvPr;
- }
-
- protected CTShapeProperties getSpPr() {
- if (_spPr == null) {
- for (XmlObject obj : _shape.selectPath("*")) {
- if (obj instanceof CTShapeProperties) {
- _spPr = (CTShapeProperties) obj;
- }
- }
- }
- if (_spPr == null) {
- throw new IllegalStateException("CTShapeProperties was not found.");
- }
- return _spPr;
- }
-
- protected CTShapeStyle getSpStyle() {
- if (_spStyle == null) {
- for (XmlObject obj : _shape.selectPath("*")) {
- if (obj instanceof CTShapeStyle) {
- _spStyle = (CTShapeStyle) obj;
- }
- }
- }
- return _spStyle;
- }
-
- protected CTPlaceholder getCTPlaceholder() {
- if (_ph == null) {
- XmlObject[] obj = _shape.selectPath(
- "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:nvPr/p:ph");
- if (obj.length == 1) {
- _ph = (CTPlaceholder) obj[0];
- }
- }
- return _ph;
- }
-
- CTTransform2D getXfrm() {
- PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {
- public boolean fetch(XSLFSimpleShape shape) {
- CTShapeProperties pr = shape.getSpPr();
- if (pr.isSetXfrm()) {
- setValue(pr.getXfrm());
- return true;
- }
- return false;
- }
- };
- fetchShapeProperty(fetcher);
- return fetcher.getValue();
- }
-
- @Override
- public Rectangle2D getAnchor() {
-
- CTTransform2D xfrm = getXfrm();
-
- CTPoint2D off = xfrm.getOff();
- long x = off.getX();
- long y = off.getY();
- CTPositiveSize2D ext = xfrm.getExt();
- long cx = ext.getCx();
- long cy = ext.getCy();
- return new Rectangle2D.Double(
- Units.toPoints(x), Units.toPoints(y),
- Units.toPoints(cx), Units.toPoints(cy));
- }
-
- @Override
- public void setAnchor(Rectangle2D anchor) {
- CTShapeProperties spPr = getSpPr();
- CTTransform2D xfrm = spPr.isSetXfrm() ? spPr.getXfrm() : spPr.addNewXfrm();
- CTPoint2D off = xfrm.isSetOff() ? xfrm.getOff() : xfrm.addNewOff();
- long x = Units.toEMU(anchor.getX());
- long y = Units.toEMU(anchor.getY());
- off.setX(x);
- off.setY(y);
- CTPositiveSize2D ext = xfrm.isSetExt() ? xfrm.getExt() : xfrm
- .addNewExt();
- long cx = Units.toEMU(anchor.getWidth());
- long cy = Units.toEMU(anchor.getHeight());
- ext.setCx(cx);
- ext.setCy(cy);
- }
-
@Override
public void setRotation(double theta) {
CTShapeProperties spPr = getSpPr();
@@ -314,7 +205,7 @@ public abstract class XSLFSimpleShape extends XSLFShape { */
public double getLineWidth() {
PropertyFetcher<Double> fetcher = new PropertyFetcher<Double>() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -371,7 +262,7 @@ public abstract class XSLFSimpleShape extends XSLFShape { public LineDash getLineDash() {
PropertyFetcher<LineDash> fetcher = new PropertyFetcher<LineDash>() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -421,7 +312,7 @@ public abstract class XSLFSimpleShape extends XSLFShape { */
public LineCap getLineCap() {
PropertyFetcher<LineCap> fetcher = new PropertyFetcher<LineCap>() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
CTLineProperties ln = spPr.getLn();
if (ln != null) {
@@ -499,7 +390,7 @@ public abstract class XSLFSimpleShape extends XSLFShape { */
public XSLFShadow getShadow() {
PropertyFetcher<CTOuterShadowEffect> fetcher = new PropertyFetcher<CTOuterShadowEffect>() {
- public boolean fetch(XSLFSimpleShape shape) {
+ public boolean fetch(XSLFShape shape) {
CTShapeProperties spPr = shape.getSpPr();
if (spPr.isSetEffectLst()) {
CTOuterShadowEffect obj = spPr.getEffectLst().getOuterShdw();
@@ -528,90 +419,11 @@ public abstract class XSLFSimpleShape extends XSLFShape { return (obj == null || obj == NO_SHADOW) ? null : new XSLFShadow(obj, this);
}
- @Override
- public void draw(Graphics2D graphics) {
- RenderableShape rShape = new RenderableShape(this);
- rShape.render(graphics);
-
- // draw line decorations
- Color lineColor = getLineColor();
- if(lineColor != null) {
- graphics.setPaint(lineColor);
- for(Outline o : getDecorationOutlines(graphics)){
- if(o.getPath().isFilled()){
- graphics.fill(o.getOutline());
- }
- if(o.getPath().isStroked()){
- graphics.draw(o.getOutline());
- }
- }
- }
- }
-
-
- /**
- * Walk up the inheritance tree and fetch shape properties.
- *
- * The following order of inheritance is assumed:
- * <p>
- * slide <-- slideLayout <-- slideMaster
- * </p>
- *
- * @param visitor the object that collects the desired property
- * @return true if the property was fetched
- */
- boolean fetchShapeProperty(PropertyFetcher visitor) {
- boolean ok = visitor.fetch(this);
-
- XSLFSimpleShape masterShape;
- XSLFSheet masterSheet = getSheet().getMasterSheet();
- CTPlaceholder ph = getCTPlaceholder();
-
- if (masterSheet != null && ph != null) {
- if (!ok) {
- masterShape = masterSheet.getPlaceholder(ph);
- if (masterShape != null) {
- ok = visitor.fetch(masterShape);
- }
- }
-
- // try slide master
- if (!ok ) {
- int textType;
- if ( !ph.isSetType()) textType = STPlaceholderType.INT_BODY;
- else {
- switch (ph.getType().intValue()) {
- case STPlaceholderType.INT_TITLE:
- case STPlaceholderType.INT_CTR_TITLE:
- textType = STPlaceholderType.INT_TITLE;
- break;
- case STPlaceholderType.INT_FTR:
- case STPlaceholderType.INT_SLD_NUM:
- case STPlaceholderType.INT_DT:
- textType = ph.getType().intValue();
- break;
- default:
- textType = STPlaceholderType.INT_BODY;
- break;
- }
- }
- XSLFSheet master = masterSheet.getMasterSheet();
- if (master != null) {
- masterShape = master.getPlaceholderByType(textType);
- if (masterShape != null) {
- ok = visitor.fetch(masterShape);
- }
- }
- }
- }
- return ok;
- }
-
/**
*
* @return definition of the shape geometry
*/
- CustomGeometry getGeometry(){
+ public CustomGeometry getGeometry(){
CTShapeProperties spPr = getSpPr();
CustomGeometry geom;
PresetGeometries dict = PresetGeometries.getInstance();
@@ -622,23 +434,16 @@ public abstract class XSLFSimpleShape extends XSLFShape { throw new IllegalStateException("Unknown shape geometry: " + name);
}
} else if (spPr.isSetCustGeom()){
- geom = new CustomGeometry(spPr.getCustGeom());
+ XMLStreamReader staxReader = spPr.getCustGeom().newXMLStreamReader();
+ geom = PresetGeometries.convertCustomGeometry(staxReader);
+ try { staxReader.close(); }
+ catch (XMLStreamException e) {}
} else {
geom = dict.get("rect");
}
return geom;
}
-
-
- /**
- * draw any content within this shape (image, text, etc.).
- *
- * @param graphics the graphics to draw into
- */
- public void drawContent(Graphics2D graphics){
-
- }
-
+
@Override
void copy(XSLFShape sh){
super.copy(sh);
@@ -943,4 +748,30 @@ public abstract class XSLFSimpleShape extends XSLFShape { return lst;
}
+ public boolean isPlaceholder() {
+ CTPlaceholder ph = getCTPlaceholder();
+ return ph != null;
+ }
+
+ public Hyperlink getHyperlink() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setHyperlink(Hyperlink hyperlink) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Guide getAdjustValue(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public org.apache.poi.sl.usermodel.LineDecoration getLineDecoration() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java index f2d4b6eff1..af80a57ffc 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlide.java @@ -16,29 +16,31 @@ ==================================================================== */ package org.apache.poi.xslf.usermodel; +import java.awt.Graphics2D; +import java.io.IOException; + import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.sl.usermodel.Notes; +import org.apache.poi.sl.usermodel.Slide; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; +import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupShapeProperties; import org.openxmlformats.schemas.drawingml.x2006.main.CTGroupTransform2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; -import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip; +import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground; import org.openxmlformats.schemas.presentationml.x2006.main.CTCommonSlideData; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape; import org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShapeNonVisual; import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide; import org.openxmlformats.schemas.presentationml.x2006.main.SldDocument; -import org.openxmlformats.schemas.presentationml.x2006.main.CTBackground; - -import java.awt.Graphics2D; -import java.io.IOException; @Beta -public final class XSLFSlide extends XSLFSheet { +public final class XSLFSlide extends XSLFSheet implements Slide { private final CTSlide _slide; private XSLFSlideLayout _layout; private XSLFComments _comments; @@ -111,7 +113,6 @@ public final class XSLFSlide extends XSLFSheet { return "sld"; } - @Override public XSLFSlideLayout getMasterSheet(){ return getSlideLayout(); } @@ -211,6 +212,15 @@ public final class XSLFSlide extends XSLFSheet { } + public boolean getFollowMasterObjects() { + return getFollowMasterGraphics(); + } + + public void setFollowMasterObjects(boolean follow) { + setFollowMasterGraphics(follow); + } + + @Override public void draw(Graphics2D graphics){ @@ -239,4 +249,26 @@ public final class XSLFSlide extends XSLFSheet { return this; } + public boolean getFollowMasterBackground() { + return false; + } + + public void setFollowMasterBackground(boolean follow) { + // not implemented ... also not in the specs + throw new UnsupportedOperationException(); + } + + public boolean getFollowMasterColourScheme() { + return false; + } + + public void setFollowMasterColourScheme(boolean follow) { + // not implemented ... only for OLE objects in the specs + throw new UnsupportedOperationException(); + } + + public void setNotes(Notes<XSLFShape> notes) { + // TODO Auto-generated method stub + + } } diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java index f8cd23ccde..2373641354 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideLayout.java @@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.util.Beta; import org.apache.poi.util.Internal; import org.apache.xmlbeans.XmlException; @@ -30,7 +31,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.SldLayoutDocument; import java.io.IOException; @Beta -public class XSLFSlideLayout extends XSLFSheet { +public class XSLFSlideLayout extends XSLFSheet implements MasterSheet { private CTSlideLayout _layout; private XSLFSlideMaster _master; diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java index d4383c4d9f..ebeec01efb 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFSlideMaster.java @@ -19,6 +19,7 @@ package org.apache.poi.xslf.usermodel; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; +import org.apache.poi.sl.usermodel.MasterSheet; import org.apache.poi.util.Beta; import org.apache.xmlbeans.XmlException; import org.openxmlformats.schemas.drawingml.x2006.main.CTColorMapping; @@ -53,7 +54,7 @@ import java.util.Map; * @author Yegor Kozlov */ @Beta - public class XSLFSlideMaster extends XSLFSheet { + public class XSLFSlideMaster extends XSLFSheet implements MasterSheet { private CTSlideMaster _slide; private Map<String, XSLFSlideLayout> _layouts; private XSLFTheme _theme; @@ -82,7 +83,7 @@ import java.util.Map; } @Override - public XSLFSheet getMasterSheet() { + public MasterSheet getMasterSheet() { return null; } @@ -177,5 +178,4 @@ import java.util.Map; return null; } } - }
\ No newline at end of file diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java index a3671ab63d..a21b9d5e37 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java @@ -21,6 +21,7 @@ package org.apache.poi.xslf.usermodel; import java.awt.Color;
+import org.apache.poi.sl.usermodel.VerticalAlignment;
import org.apache.poi.util.Units;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineEndProperties;
import org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java index e0b383a76b..869421e5c0 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextParagraph.java @@ -18,42 +18,14 @@ package org.apache.poi.xslf.usermodel; import java.awt.Color;
import java.awt.Graphics2D;
-import java.awt.font.LineBreakMeasurer;
-import java.awt.font.TextAttribute;
-import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.poi.hslf.model.TextPainter;
-import org.apache.poi.util.Beta;
-import org.apache.poi.util.Internal;
-import org.apache.poi.util.Units;
+import java.util.*;
+
+import org.apache.poi.sl.usermodel.TextParagraph;
+import org.apache.poi.util.*;
import org.apache.poi.xslf.model.ParagraphPropertyFetcher;
import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextAutonumberBullet;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePercent;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBulletSizePoint;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharBullet;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextLineBreak;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextNormalAutofit;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraphProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextSpacing;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStop;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextTabStopList;
-import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
-import org.openxmlformats.schemas.drawingml.x2006.main.STTextAutonumberScheme;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
@@ -65,16 +37,10 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; * @since POI-3.8
*/
@Beta
-public class XSLFTextParagraph implements Iterable<XSLFTextRun>{
+public class XSLFTextParagraph implements TextParagraph {
private final CTTextParagraph _p;
private final List<XSLFTextRun> _runs;
private final XSLFTextShape _shape;
- private List<TextFragment> _lines;
- private TextFragment _bullet;
- /**
- * the highest line in this paragraph. Used for line spacing.
- */
- private double _maxLineHeight;
XSLFTextParagraph(CTTextParagraph p, XSLFTextShape shape){
_p = p;
@@ -122,7 +88,7 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ return _p;
}
- XSLFTextShape getParentShape() {
+ public XSLFTextShape getParentShape() {
return _shape;
}
@@ -194,7 +160,7 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ /**
* Specifies the alignment that is to be applied to the paragraph.
* Possible values for this include left, right, centered, justified and distributed,
- * see {@link org.apache.poi.xslf.usermodel.TextAlign}.
+ * see {@link org.apache.poi.sl.usermodel.TextAlign}.
*
* @param align text align
*/
@@ -410,6 +376,26 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ /**
*
+ * @return the right margin of the paragraph
+ */
+ public double getRightMargin(){
+ ParagraphPropertyFetcher<Double> fetcher = new ParagraphPropertyFetcher<Double>(getLevel()){
+ public boolean fetch(CTTextParagraphProperties props){
+ if(props.isSetMarR()){
+ double val = Units.toPoints(props.getMarR());
+ setValue(val);
+ return true;
+ }
+ return false;
+ }
+ };
+ fetchParagraphProperty(fetcher);
+ // if the marL attribute is omitted, then a value of 347663 is implied
+ return fetcher.getValue() == null ? 0 : fetcher.getValue();
+ }
+
+ /**
+ *
* @return the default size for a tab character within this paragraph in points
*/
public double getDefaultTabSize(){
@@ -711,10 +697,6 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ return "[" + getClass() + "]" + getText();
}
- List<TextFragment> getTextLines(){
- return _lines;
- }
-
/**
* Returns wrapping width to break lines in this paragraph
*
@@ -754,244 +736,6 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ return width;
}
- public double draw(Graphics2D graphics, double x, double y){
- double leftInset = _shape.getLeftInset();
- double rightInset = _shape.getRightInset();
- RenderableShape rShape = new RenderableShape(_shape);
- Rectangle2D anchor = rShape.getAnchor(graphics);
- double penY = y;
-
- double leftMargin = getLeftMargin();
- boolean firstLine = true;
- double indent = getIndent();
-
- //The vertical line spacing
- double spacing = getLineSpacing();
- for(TextFragment line : _lines){
- double penX = x + leftMargin;
-
- if(firstLine) {
- if(_bullet != null){
- if(indent < 0) {
- // a negative value means "Hanging" indentation and
- // indicates the position of the actual bullet character.
- // (the bullet is shifted to right relative to the text)
- _bullet.draw(graphics, penX + indent, penY);
- } else if(indent > 0){
- // a positive value means the "First Line" indentation:
- // the first line is indented and other lines start at the bullet ofset
- _bullet.draw(graphics, penX, penY);
- penX += indent;
- } else {
- // a zero indent means that the bullet and text have the same offset
- _bullet.draw(graphics, penX, penY);
-
- // don't let text overlay the bullet and advance by the bullet width
- penX += _bullet._layout.getAdvance() + 1;
- }
- } else {
- penX += indent;
- }
- }
-
-
- switch (getTextAlign()) {
- case CENTER:
- penX += (anchor.getWidth() - leftMargin - line.getWidth() - leftInset - rightInset) / 2;
- break;
- case RIGHT:
- penX += (anchor.getWidth() - line.getWidth() - leftInset - rightInset);
- break;
- default:
- break;
- }
-
- line.draw(graphics, penX, penY);
-
- if(spacing > 0) {
- // If linespacing >= 0, then linespacing is a percentage of normal line height.
- penY += spacing*0.01* line.getHeight();
- } else {
- // positive value means absolute spacing in points
- penY += -spacing;
- }
-
- firstLine = false;
- }
-
- return penY - y;
- }
-
- AttributedString getAttributedString(Graphics2D graphics){
-
- String text = getRenderableText();
-
- AttributedString string = new AttributedString(text);
-
- XSLFFontManager fontHandler = (XSLFFontManager)graphics.getRenderingHint(XSLFRenderingHint.FONT_HANDLER);
-
- int startIndex = 0;
- for (XSLFTextRun run : _runs){
- int length = run.getRenderableText().length();
- if(length == 0) {
- // skip empty runs
- continue;
- }
- int endIndex = startIndex + length;
-
- string.addAttribute(TextAttribute.FOREGROUND, run.getFontColor(), startIndex, endIndex);
-
- // user can pass an custom object to convert fonts
- String fontFamily = run.getFontFamily();
- @SuppressWarnings("unchecked")
- Map<String,String> fontMap = (Map<String,String>)graphics.getRenderingHint(TextPainter.KEY_FONTMAP);
- if (fontMap != null && fontMap.containsKey(fontFamily)) {
- fontFamily = fontMap.get(fontFamily);
- }
- if(fontHandler != null) {
- fontFamily = fontHandler.getRendererableFont(fontFamily, run.getPitchAndFamily());
- }
- string.addAttribute(TextAttribute.FAMILY, fontFamily, startIndex, endIndex);
-
- float fontSz = (float)run.getFontSize();
- string.addAttribute(TextAttribute.SIZE, fontSz , startIndex, endIndex);
-
- if(run.isBold()) {
- string.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIndex, endIndex);
- }
- if(run.isItalic()) {
- string.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIndex, endIndex);
- }
- if(run.isUnderline()) {
- string.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIndex, endIndex);
- string.addAttribute(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_TWO_PIXEL, startIndex, endIndex);
- }
- if(run.isStrikethrough()) {
- string.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, startIndex, endIndex);
- }
- if(run.isSubscript()) {
- string.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB, startIndex, endIndex);
- }
- if(run.isSuperscript()) {
- string.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, startIndex, endIndex);
- }
-
-
- startIndex = endIndex;
- }
-
- return string;
- }
-
- /**
- * ensure that the paragraph contains at least one character.
- * We need this trick to correctly measure text
- */
- private void ensureNotEmpty(){
- XSLFTextRun r = addNewTextRun();
- r.setText(" ");
- CTTextCharacterProperties endPr = _p.getEndParaRPr();
- if(endPr != null) {
- if(endPr.isSetSz()) r.setFontSize(endPr.getSz() / 100);
- }
- }
-
- /**
- * break text into lines
- *
- * @param graphics
- * @return array of text fragments,
- * each representing a line of text that fits in the wrapping width
- */
- List<TextFragment> breakText(Graphics2D graphics){
- _lines = new ArrayList<TextFragment>();
-
- // does this paragraph contain text?
- boolean emptyParagraph = _runs.size() == 0;
-
- // ensure that the paragraph contains at least one character
- if(_runs.size() == 0) ensureNotEmpty();
-
- String text = getRenderableText();
- if(text.length() == 0) return _lines;
-
- AttributedString at = getAttributedString(graphics);
- AttributedCharacterIterator it = at.getIterator();
- LineBreakMeasurer measurer = new LineBreakMeasurer(it, graphics.getFontRenderContext()) ;
- for (;;) {
- int startIndex = measurer.getPosition();
-
- double wrappingWidth = getWrappingWidth(_lines.size() == 0, graphics) + 1; // add a pixel to compensate rounding errors
- // shape width can be smaller that the sum of insets (this was proved by a test file)
- if(wrappingWidth < 0) wrappingWidth = 1;
-
- int nextBreak = text.indexOf('\n', startIndex + 1);
- if(nextBreak == -1) nextBreak = it.getEndIndex();
-
- TextLayout layout = measurer.nextLayout((float)wrappingWidth, nextBreak, true);
- if (layout == null) {
- // layout can be null if the entire word at the current position
- // does not fit within the wrapping width. Try with requireNextWord=false.
- layout = measurer.nextLayout((float)wrappingWidth, nextBreak, false);
- }
-
- if(layout == null) {
- // exit if can't break any more
- break;
- }
-
- int endIndex = measurer.getPosition();
- // skip over new line breaks (we paint 'clear' text runs not starting or ending with \n)
- if(endIndex < it.getEndIndex() && text.charAt(endIndex) == '\n'){
- measurer.setPosition(endIndex + 1);
- }
-
- TextAlign hAlign = getTextAlign();
- if(hAlign == TextAlign.JUSTIFY || hAlign == TextAlign.JUSTIFY_LOW) {
- layout = layout.getJustifiedLayout((float)wrappingWidth);
- }
-
- AttributedString str = new AttributedString(it, startIndex, endIndex);
- TextFragment line = new TextFragment(
- layout, // we will not paint empty paragraphs
- emptyParagraph ? null : str);
- _lines.add(line);
-
- _maxLineHeight = Math.max(_maxLineHeight, line.getHeight());
-
- if(endIndex == it.getEndIndex()) break;
-
- }
-
- if(isBullet() && !emptyParagraph) {
- String buCharacter = getBulletCharacter();
- String buFont = getBulletFont();
- if(buFont == null) buFont = getTextRuns().get(0).getFontFamily();
- if(buCharacter != null && buFont != null && _lines.size() > 0) {
- AttributedString str = new AttributedString(buCharacter);
-
- TextFragment firstLine = _lines.get(0);
- AttributedCharacterIterator bit = firstLine._str.getIterator();
-
- Color buColor = getBulletFontColor();
- str.addAttribute(TextAttribute.FOREGROUND, buColor == null ?
- bit.getAttribute(TextAttribute.FOREGROUND) : buColor);
- str.addAttribute(TextAttribute.FAMILY, buFont);
-
- float fontSize = (Float)bit.getAttribute(TextAttribute.SIZE);
- float buSz = (float)getBulletFontSize();
- if(buSz > 0) fontSize *= buSz* 0.01;
- else fontSize = -buSz;
-
- str.addAttribute(TextAttribute.SIZE, fontSize);
-
- TextLayout layout = new TextLayout(str.getIterator(), graphics.getFontRenderContext());
- _bullet = new TextFragment(layout, str);
- }
- }
- return _lines;
- }
-
CTTextParagraphProperties getDefaultMasterStyle(){
CTPlaceholder ph = _shape.getCTPlaceholder();
String defaultStyleSelector;
@@ -1017,7 +761,7 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ // wind up and find the root master sheet which must be slide master
XSLFSheet masterSheet = _shape.getSheet();
while (masterSheet.getMasterSheet() != null){
- masterSheet = masterSheet.getMasterSheet();
+ masterSheet = (XSLFSheet)masterSheet.getMasterSheet();
}
XmlObject[] o = masterSheet.getXmlObject().selectPath(
@@ -1130,4 +874,32 @@ public class XSLFTextParagraph implements Iterable<XSLFTextRun>{ }
}
+ public double getDefaultFontSize() {
+ CTTextCharacterProperties endPr = _p.getEndParaRPr();
+ return (endPr == null || !endPr.isSetSz()) ? 12 : (endPr.getSz() / 100);
+ }
+
+ public String getDefaultFontFamily() {
+ return (_runs.isEmpty() ? "Arial" : _runs.get(0).getFontFamily());
+ }
+
+ public BulletStyle getBulletStyle() {
+ return new BulletStyle(){
+ public String getBulletCharacter() {
+ return XSLFTextParagraph.this.getBulletCharacter();
+ }
+
+ public String getBulletFont() {
+ return XSLFTextParagraph.this.getBulletFont();
+ }
+
+ public double getBulletFontSize() {
+ return XSLFTextParagraph.this.getBulletFontSize();
+ }
+
+ public Color getBulletFontColor() {
+ return XSLFTextParagraph.this.getBulletFontColor();
+ }
+ };
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java index 16d0e803b1..0a6daf6cea 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java @@ -22,6 +22,7 @@ import java.awt.font.TextAttribute; import java.awt.font.TextLayout;
import java.text.AttributedString;
+import org.apache.poi.sl.usermodel.TextRun;
import org.apache.poi.util.Beta;
import org.apache.poi.xslf.model.CharacterPropertyFetcher;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
@@ -45,7 +46,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; * @author Yegor Kozlov
*/
@Beta
-public class XSLFTextRun {
+public class XSLFTextRun implements TextRun {
private final CTRegularTextRun _r;
private final XSLFTextParagraph _p;
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java index d5ae1a2527..b4308c46c9 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextShape.java @@ -23,26 +23,20 @@ import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; import org.apache.poi.POIXMLException; +import org.apache.poi.sl.draw.DrawFactory; +import org.apache.poi.sl.draw.geom.Guide; +import org.apache.poi.sl.usermodel.*; +import org.apache.poi.sl.usermodel.LineDecoration; import org.apache.poi.util.Beta; import org.apache.poi.util.Units; import org.apache.poi.xslf.model.PropertyFetcher; import org.apache.poi.xslf.model.TextBodyPropertyFetcher; import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties; -import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph; -import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType; -import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType; -import org.openxmlformats.schemas.drawingml.x2006.main.STTextWrappingType; -import org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps; -import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder; -import org.openxmlformats.schemas.presentationml.x2006.main.CTShape; -import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; +import org.openxmlformats.schemas.drawingml.x2006.main.*; +import org.openxmlformats.schemas.presentationml.x2006.main.*; /** * Represents a shape that can hold text. @@ -50,7 +44,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType; * @author Yegor Kozlov */ @Beta -public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable<XSLFTextParagraph>{ +public abstract class XSLFTextShape extends XSLFSimpleShape implements TextShape { private final List<XSLFTextParagraph> _paragraphs; /** @@ -338,7 +332,13 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable< } } - + @Override + public Insets2D getInsets() { + Insets2D insets = new Insets2D(getTopInset(), getLeftInset(), getBottomInset(), getRightInset()); + return insets; + } + + /** * @return whether to wrap words within the bounding rectangle */ @@ -453,6 +453,9 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable< // dry-run in a 1x1 image and return the vertical advance BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); + DrawFactory fact = DrawFactory.getInstance(graphics); + fact.getDrawable(this); + breakText(graphics); return drawParagraphs(graphics, 0, 0); } @@ -475,121 +478,6 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable< return anchor; } - /** - * break the contained text into lines - */ - private void breakText(Graphics2D graphics){ - if(!_isTextBroken) { - for(XSLFTextParagraph p : _paragraphs) p.breakText(graphics); - - _isTextBroken = true; - } - } - - @Override - public void drawContent(Graphics2D graphics) { - breakText(graphics); - - RenderableShape rShape = new RenderableShape(this); - Rectangle2D anchor = rShape.getAnchor(graphics); - double x = anchor.getX() + getLeftInset(); - double y = anchor.getY(); - - // remember the initial transform - AffineTransform tx = graphics.getTransform(); - - // Transform of text in flipped shapes is special. - // At this point the flip and rotation transform is already applied - // (see XSLFShape#applyTransform ), but we need to restore it to avoid painting "upside down". - // See Bugzilla 54210. - - if(getFlipVertical()){ - graphics.translate(anchor.getX(), anchor.getY() + anchor.getHeight()); - graphics.scale(1, -1); - graphics.translate(-anchor.getX(), -anchor.getY()); - - // text in vertically flipped shapes is rotated by 180 degrees - double centerX = anchor.getX() + anchor.getWidth()/2; - double centerY = anchor.getY() + anchor.getHeight()/2; - graphics.translate(centerX, centerY); - graphics.rotate(Math.toRadians(180)); - graphics.translate(-centerX, -centerY); - } - - // Horizontal flipping applies only to shape outline and not to the text in the shape. - // Applying flip second time restores the original not-flipped transform - if(getFlipHorizontal()){ - graphics.translate(anchor.getX() + anchor.getWidth(), anchor.getY()); - graphics.scale(-1, 1); - graphics.translate(-anchor.getX() , -anchor.getY()); - } - - - // first dry-run to calculate the total height of the text - double textHeight = getTextHeight(); - - switch (getVerticalAlignment()){ - case TOP: - y += getTopInset(); - break; - case BOTTOM: - y += anchor.getHeight() - textHeight - getBottomInset(); - break; - default: - case MIDDLE: - double delta = anchor.getHeight() - textHeight - - getTopInset() - getBottomInset(); - y += getTopInset() + delta/2; - break; - } - - drawParagraphs(graphics, x, y); - - // restore the transform - graphics.setTransform(tx); - } - - - /** - * paint the paragraphs starting from top left (x,y) - * - * @return the vertical advance, i.e. the cumulative space occupied by the text - */ - private double drawParagraphs(Graphics2D graphics, double x, double y) { - double y0 = y; - for(int i = 0; i < _paragraphs.size(); i++){ - XSLFTextParagraph p = _paragraphs.get(i); - List<TextFragment> lines = p.getTextLines(); - - if(i > 0 && lines.size() > 0) { - // the amount of vertical white space before the paragraph - double spaceBefore = p.getSpaceBefore(); - if(spaceBefore > 0) { - // positive value means percentage spacing of the height of the first line, e.g. - // the higher the first line, the bigger the space before the paragraph - y += spaceBefore*0.01*lines.get(0).getHeight(); - } else { - // negative value means the absolute spacing in points - y += -spaceBefore; - } - } - - y += p.draw(graphics, x, y); - - if(i < _paragraphs.size() - 1) { - double spaceAfter = p.getSpaceAfter(); - if(spaceAfter > 0) { - // positive value means percentage spacing of the height of the last line, e.g. - // the higher the last line, the bigger the space after the paragraph - y += spaceAfter*0.01*lines.get(lines.size() - 1).getHeight(); - } else { - // negative value means the absolute spacing in points - y += -spaceAfter; - } - } - } - return y - y0; - } @Override void copy(XSLFShape sh){ @@ -633,4 +521,19 @@ public abstract class XSLFTextShape extends XSLFSimpleShape implements Iterable< } } + + public LineDecoration getLineDecoration() { + // TODO Auto-generated method stub + return null; + } + + public FillStyle getFillStyle() { + // TODO Auto-generated method stub + return null; + } + + public Guide getAdjustValue(String name) { + // TODO Auto-generated method stub + return null; + } }
\ No newline at end of file |