From 9f7085a281871ec65e638c2ac497f5981e40823c Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Sun, 3 Oct 2021 21:05:19 +0000 Subject: [PATCH] #65612 - XSLF CustomGeometry - replace XmlStreamReader access with XmlBeans delegate git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893859 13f79535-47bb-0310-9956-ffa450edef68 --- build.gradle | 1 + .../poi/xslf/draw/geom/XSLFAdjustPoint.java | 66 +++++++ .../poi/xslf/draw/geom/XSLFAdjustValue.java | 32 ++++ .../apache/poi/xslf/draw/geom/XSLFArcTo.java | 75 ++++++++ .../xslf/draw/geom/XSLFConnectionSite.java | 71 +++++++ .../poi/xslf/draw/geom/XSLFCurveTo.java | 79 ++++++++ .../xslf/draw/geom/XSLFCustomGeometry.java | 89 +++++++++ .../apache/poi/xslf/draw/geom/XSLFGuide.java | 55 ++++++ .../apache/poi/xslf/draw/geom/XSLFLineTo.java | 52 +++++ .../apache/poi/xslf/draw/geom/XSLFMoveTo.java | 52 +++++ .../apache/poi/xslf/draw/geom/XSLFPath.java | 178 ++++++++++++++++++ .../xslf/draw/geom/XSLFPolarAdjustHandle.java | 36 ++++ .../apache/poi/xslf/draw/geom/XSLFQuadTo.java | 56 ++++++ .../xslf/draw/geom/XSLFXYAdjustHandle.java | 35 ++++ .../poi/xslf/usermodel/XSLFBackground.java | 1 + .../poi/xslf/usermodel/XSLFFreeformShape.java | 20 +- .../poi/xslf/usermodel/XSLFSimpleShape.java | 21 +-- .../apache/poi/xslf/usermodel/XSLFTable.java | 11 +- .../org/apache/poi/xslf/util/PPTX2PNG.java | 8 +- poi-ooxml/src/main/java9/module-info.class | Bin 3689 -> 3732 bytes poi-ooxml/src/main/java9/module-info.java | 1 + .../poi/xslf/usermodel/TestPPTX2PNG.java | 11 +- poi-ooxml/src/test/java9/module-info.class | Bin 5076 -> 5119 bytes poi-ooxml/src/test/java9/module-info.java | 1 + .../apache/poi/sl/draw/DrawSimpleShape.java | 28 +-- .../apache/poi/sl/draw/geom/AdjustPoint.java | 41 +--- .../poi/sl/draw/geom/AdjustPointIf.java | 44 +++++ .../apache/poi/sl/draw/geom/AdjustValue.java | 8 +- .../poi/sl/draw/geom/AdjustValueIf.java | 32 ++++ .../apache/poi/sl/draw/geom/ArcToCommand.java | 57 +++--- .../poi/sl/draw/geom/ArcToCommandIf.java | 72 +++++++ .../poi/sl/draw/geom/ClosePathCommand.java | 2 +- .../poi/sl/draw/geom/ClosePathCommandIf.java | 23 +++ .../poi/sl/draw/geom/ConnectionSite.java | 41 +--- .../poi/sl/draw/geom/ConnectionSiteIf.java | 44 +++++ .../org/apache/poi/sl/draw/geom/Context.java | 12 +- .../poi/sl/draw/geom/CurveToCommand.java | 37 ++-- .../poi/sl/draw/geom/CurveToCommandIf.java | 50 +++++ .../poi/sl/draw/geom/CustomGeometry.java | 20 +- .../org/apache/poi/sl/draw/geom/Guide.java | 88 +-------- .../org/apache/poi/sl/draw/geom/GuideIf.java | 120 ++++++++++++ .../poi/sl/draw/geom/IAdjustableShape.java | 2 +- .../poi/sl/draw/geom/LineToCommand.java | 14 +- .../poi/sl/draw/geom/LineToCommandIf.java | 35 ++++ .../poi/sl/draw/geom/MoveToCommand.java | 15 +- .../poi/sl/draw/geom/MoveToCommandIf.java | 35 ++++ .../org/apache/poi/sl/draw/geom/Outline.java | 8 +- .../org/apache/poi/sl/draw/geom/Path.java | 15 +- .../org/apache/poi/sl/draw/geom/PathIf.java | 55 ++++++ .../poi/sl/draw/geom/PresetGeometries.java | 20 +- .../poi/sl/draw/geom/QuadToCommand.java | 28 +-- .../poi/sl/draw/geom/QuadToCommandIf.java | 42 +++++ .../sl/draw/geom/TestPresetGeometries.java | 25 +-- 53 files changed, 1612 insertions(+), 352 deletions(-) create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustPoint.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustValue.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFArcTo.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFConnectionSite.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCurveTo.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCustomGeometry.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFGuide.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFLineTo.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFMoveTo.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPolarAdjustHandle.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFQuadTo.java create mode 100644 poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFXYAdjustHandle.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/AdjustPointIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/AdjustValueIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/ArcToCommandIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommandIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSiteIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommandIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/GuideIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommandIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommandIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/PathIf.java create mode 100644 poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommandIf.java diff --git a/build.gradle b/build.gradle index 70c22c2f15..81230377d4 100644 --- a/build.gradle +++ b/build.gradle @@ -136,6 +136,7 @@ subprojects { resolutionStrategy { force "commons-io:commons-io:${commonsIoVersion}" force 'org.slf4j:slf4j-api:1.7.32' + force 'com.fasterxml.woodstox:woodstox-core:6.2.6' } } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustPoint.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustPoint.java new file mode 100644 index 0000000000..cd1a161086 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustPoint.java @@ -0,0 +1,66 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFAdjustPoint implements AdjustPointIf { + + private final CTAdjPoint2D pnt; + + public XSLFAdjustPoint(CTAdjPoint2D pnt) { + this.pnt = pnt; + } + + @Override + public String getX() { + return pnt.xgetX().getStringValue(); + } + + @Override + public void setX(String value) { + pnt.setX(value); + } + + @Override + public boolean isSetX() { + return pnt.xgetX() != null; + } + + @Override + public String getY() { + return pnt.xgetY().getStringValue(); + } + + @Override + public void setY(String value) { + pnt.setY(value); + } + + @Override + public boolean isSetY() { + return pnt.xgetY() != null; + + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustValue.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustValue.java new file mode 100644 index 0000000000..a8d9f97c1c --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFAdjustValue.java @@ -0,0 +1,32 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustValueIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFAdjustValue extends XSLFGuide implements AdjustValueIf { + public XSLFAdjustValue(CTGeomGuide guide) { + super(guide); + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFArcTo.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFArcTo.java new file mode 100644 index 0000000000..887ec631f2 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFArcTo.java @@ -0,0 +1,75 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.ArcToCommandIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DArcTo; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFArcTo implements ArcToCommandIf { + private final CTPath2DArcTo arc; + + public XSLFArcTo(CTPath2DArcTo arc) { + this.arc = arc; + } + + @Override + public String getHR() { + return arc.xgetHR().getStringValue(); + } + + @Override + public void setHR(String hr) { + arc.setHR(hr); + } + + @Override + public String getWR() { + return arc.xgetHR().getStringValue(); + } + + @Override + public void setWR(String wr) { + arc.setWR(wr); + } + + @Override + public String getStAng() { + return arc.xgetStAng().getStringValue(); + } + + @Override + public void setStAng(String stAng) { + arc.setStAng(stAng); + } + + @Override + public String getSwAng() { + return arc.xgetSwAng().getStringValue(); + } + + @Override + public void setSwAng(String swAng) { + arc.setSwAng(swAng); + } + +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFConnectionSite.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFConnectionSite.java new file mode 100644 index 0000000000..e7a627414f --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFConnectionSite.java @@ -0,0 +1,71 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.sl.draw.geom.ConnectionSiteIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTConnectionSite; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFConnectionSite implements ConnectionSiteIf { + + final CTConnectionSite cxn; + + public XSLFConnectionSite(CTConnectionSite cxn) { + this.cxn = cxn; + } + + @Override + public AdjustPointIf getPos() { + return new XSLFAdjustPoint(cxn.getPos()); + } + + @Override + public void setPos(AdjustPointIf pos) { + CTAdjPoint2D p = cxn.getPos(); + if (p == null) { + p = cxn.addNewPos(); + } + p.setX(pos.getX()); + p.setY(pos.getY()); + } + + @Override + public String getAng() { + return cxn.xgetAng().getStringValue(); + } + + /** + * Sets the value of the ang property. + */ + @Override + public void setAng(String value) { + cxn.setAng(value); + } + + @Override + public boolean isSetAng() { + return cxn.xgetAng() == null; + } + +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCurveTo.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCurveTo.java new file mode 100644 index 0000000000..0639be87ab --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCurveTo.java @@ -0,0 +1,79 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.sl.draw.geom.CurveToCommandIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFCurveTo implements CurveToCommandIf { + private final CTPath2DCubicBezierTo bezier; + + public XSLFCurveTo(CTPath2DCubicBezierTo bezier) { + this.bezier = bezier; + } + + @Override + public XSLFAdjustPoint getPt1() { + return new XSLFAdjustPoint(bezier.getPtArray(0)); + } + + @Override + public void setPt1(AdjustPointIf pt1) { + CTAdjPoint2D xpt = getOrCreate(0); + xpt.setX(pt1.getX()); + xpt.setY(pt1.getY()); + } + + @Override + public XSLFAdjustPoint getPt2() { + return new XSLFAdjustPoint(bezier.getPtArray(1)); + } + + @Override + public void setPt2(AdjustPointIf pt2) { + CTAdjPoint2D xpt = getOrCreate(1); + xpt.setX(pt2.getX()); + xpt.setY(pt2.getY()); + } + + @Override + public XSLFAdjustPoint getPt3() { + return new XSLFAdjustPoint(bezier.getPtArray(2)); + } + + @Override + public void setPt3(AdjustPointIf pt3) { + CTAdjPoint2D xpt = getOrCreate(2); + xpt.setX(pt3.getX()); + xpt.setY(pt3.getY()); + } + + private CTAdjPoint2D getOrCreate(int idx) { + for (int i=(idx+1)-bezier.sizeOfPtArray(); i > 0; i--) { + bezier.addNewPt(); + } + return bezier.getPtArray(idx); + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCustomGeometry.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCustomGeometry.java new file mode 100644 index 0000000000..0755042f47 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFCustomGeometry.java @@ -0,0 +1,89 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.CustomGeometry; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjustHandleList; +import org.openxmlformats.schemas.drawingml.x2006.main.CTConnectionSite; +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; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPolarAdjustHandle; +import org.openxmlformats.schemas.drawingml.x2006.main.CTXYAdjustHandle; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFCustomGeometry { + public static CustomGeometry convertCustomGeometry(CTCustomGeometry2D custGeom) { + CustomGeometry cg = new CustomGeometry(); + + if (custGeom.isSetAhLst()) { + CTAdjustHandleList ahLst = custGeom.getAhLst(); + for (CTXYAdjustHandle xy : ahLst.getAhXYArray()) { + cg.addAdjustHandle(new XSLFXYAdjustHandle(xy)); + } + for (CTPolarAdjustHandle pol : ahLst.getAhPolarArray()) { + cg.addAdjustHandle(new XSLFPolarAdjustHandle(pol)); + } + } + + if (custGeom.isSetAvLst()) { + CTGeomGuideList avLst = custGeom.getAvLst(); + for (CTGeomGuide gg : avLst.getGdArray()) { + cg.addAdjustGuide(new XSLFAdjustValue(gg)); + } + } + + if (custGeom.isSetGdLst()) { + CTGeomGuideList gdLst = custGeom.getGdLst(); + for (CTGeomGuide gg : gdLst.getGdArray()) { + cg.addGeomGuide(new XSLFGuide(gg)); + } + } + + if (custGeom.isSetRect()) { + CTGeomRect r = custGeom.getRect(); + cg.setTextBounds( + r.xgetL().getStringValue(), + r.xgetT().getStringValue(), + r.xgetR().getStringValue(), + r.xgetB().getStringValue()); + } + + if (custGeom.isSetCxnLst()) { + for (CTConnectionSite cxn : custGeom.getCxnLst().getCxnArray()) { + cg.addConnectionSite(new XSLFConnectionSite((cxn))); + } + } + + CTPath2DList pl = custGeom.getPathLst(); + if (pl != null) { + for (CTPath2D p : pl.getPathArray()) { + cg.addPath(new XSLFPath(p)); + } + } + + return cg; + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFGuide.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFGuide.java new file mode 100644 index 0000000000..5f970c242a --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFGuide.java @@ -0,0 +1,55 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.GuideIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFGuide implements GuideIf { + final CTGeomGuide guide; + + public XSLFGuide(CTGeomGuide guide) { + this.guide = guide; + } + + @Override + public String getName() { + return guide.getName(); + } + + @Override + public void setName(String name) { + guide.setName(name); + } + + @Override + public String getFmla() { + return guide.getFmla(); + } + + @Override + public void setFmla(String fmla) { + guide.setFmla(fmla); + } + +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFLineTo.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFLineTo.java new file mode 100644 index 0000000000..595f9911a6 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFLineTo.java @@ -0,0 +1,52 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.xslf.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.sl.draw.geom.LineToCommandIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DLineTo; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFLineTo implements LineToCommandIf { + + private final CTPath2DLineTo lineTo; + + public XSLFLineTo(CTPath2DLineTo lineTo) { + this.lineTo = lineTo; + } + + @Override + public AdjustPointIf getPt() { + return new XSLFAdjustPoint(lineTo.getPt()); + } + + @Override + public void setPt(AdjustPointIf pt) { + CTAdjPoint2D xpt = lineTo.getPt(); + if (xpt == null) { + xpt = lineTo.addNewPt(); + } + xpt.setX(pt.getX()); + xpt.setY(pt.getY()); + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFMoveTo.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFMoveTo.java new file mode 100644 index 0000000000..65d6c0c287 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFMoveTo.java @@ -0,0 +1,52 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.xslf.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.sl.draw.geom.MoveToCommandIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DMoveTo; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFMoveTo implements MoveToCommandIf { + + private final CTPath2DMoveTo moveTo; + + public XSLFMoveTo(CTPath2DMoveTo moveTo) { + this.moveTo = moveTo; + } + + @Override + public XSLFAdjustPoint getPt() { + return new XSLFAdjustPoint(moveTo.getPt()); + } + + @Override + public void setPt(AdjustPointIf pt) { + CTAdjPoint2D xpt = moveTo.getPt(); + if (xpt == null) { + xpt = moveTo.addNewPt(); + } + xpt.setX(pt.getX()); + xpt.setY(pt.getY()); + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java new file mode 100644 index 0000000000..984d37c29c --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPath.java @@ -0,0 +1,178 @@ +/* ==================================================================== + 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.draw.geom; + +import java.awt.geom.Path2D; + +import org.apache.poi.sl.draw.geom.ClosePathCommand; +import org.apache.poi.sl.draw.geom.Context; +import org.apache.poi.sl.draw.geom.PathCommand; +import org.apache.poi.sl.draw.geom.PathIf; +import org.apache.poi.sl.usermodel.PaintStyle; +import org.apache.poi.util.Beta; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2D; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DArcTo; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DClose; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DCubicBezierTo; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DLineTo; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DMoveTo; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo; +import org.openxmlformats.schemas.drawingml.x2006.main.STPathFillMode; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFPath implements PathIf { + + private final CTPath2D pathXml; + + public XSLFPath(CTPath2D pathXml) { + this.pathXml = pathXml; + } + + @Override + public void addCommand(PathCommand cmd) { + // not supported + } + + @Override + public Path2D.Double getPath(Context ctx) { + Path2D.Double path2D = new Path2D.Double(); + XmlCursor cur = pathXml.newCursor(); + try { + for (boolean hasNext = cur.toFirstChild(); hasNext; hasNext = cur.toNextSibling()) { + XmlObject xo = cur.getObject(); + PathCommand pc; + if (xo instanceof CTPath2DArcTo) { + pc = new XSLFArcTo((CTPath2DArcTo) xo); + } else if (xo instanceof CTPath2DCubicBezierTo) { + pc = new XSLFCurveTo((CTPath2DCubicBezierTo) xo); + } else if (xo instanceof CTPath2DMoveTo) { + pc = new XSLFMoveTo((CTPath2DMoveTo) xo); + } else if (xo instanceof CTPath2DLineTo) { + pc = new XSLFLineTo((CTPath2DLineTo) xo); + } else if (xo instanceof CTPath2DQuadBezierTo) { + pc = new XSLFQuadTo((CTPath2DQuadBezierTo) xo); + } else if (xo instanceof CTPath2DClose) { + pc = new ClosePathCommand(); + } else { + continue; + } + pc.execute(path2D, ctx); + } + } finally { + cur.dispose(); + } + return path2D; + } + + @Override + public boolean isStroked() { + return pathXml.getStroke(); + } + + @Override + public void setStroke(boolean stroke) { + pathXml.setStroke(stroke); + } + + @Override + public boolean isFilled() { + return pathXml.getFill() != STPathFillMode.NONE; + } + + @Override + public PaintStyle.PaintModifier getFill() { + switch (pathXml.getFill().intValue()) { + default: + case STPathFillMode.INT_NONE: + return PaintStyle.PaintModifier.NONE; + case STPathFillMode.INT_NORM: + return PaintStyle.PaintModifier.NORM; + case STPathFillMode.INT_LIGHTEN: + return PaintStyle.PaintModifier.LIGHTEN; + case STPathFillMode.INT_LIGHTEN_LESS: + return PaintStyle.PaintModifier.LIGHTEN_LESS; + case STPathFillMode.INT_DARKEN: + return PaintStyle.PaintModifier.DARKEN; + case STPathFillMode.INT_DARKEN_LESS: + return PaintStyle.PaintModifier.DARKEN_LESS; + } + } + + @Override + public void setFill(PaintStyle.PaintModifier fill) { + STPathFillMode.Enum f; + switch (fill) { + default: + case NONE: + f = STPathFillMode.NONE; + break; + case NORM: + f = STPathFillMode.NORM; + break; + case LIGHTEN: + f = STPathFillMode.LIGHTEN; + break; + case LIGHTEN_LESS: + f = STPathFillMode.LIGHTEN_LESS; + break; + case DARKEN: + f = STPathFillMode.DARKEN; + break; + case DARKEN_LESS: + f = STPathFillMode.DARKEN_LESS; + break; + } + pathXml.setFill(f); + } + + @Override + public long getW() { + return pathXml.getW(); + } + + @Override + public void setW(long w) { + pathXml.setW(w); + } + + @Override + public long getH() { + return pathXml.getH(); + } + + @Override + public void setH(long h) { + pathXml.setH(h); + } + + @Override + public boolean isExtrusionOk() { + return pathXml.getExtrusionOk(); + } + + @Override + public void setExtrusionOk(boolean extrusionOk) { + pathXml.setExtrusionOk(extrusionOk); + } + +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPolarAdjustHandle.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPolarAdjustHandle.java new file mode 100644 index 0000000000..ba086382fe --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFPolarAdjustHandle.java @@ -0,0 +1,36 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustHandle; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPolarAdjustHandle; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFPolarAdjustHandle implements AdjustHandle { + final CTPolarAdjustHandle xobj; + + public XSLFPolarAdjustHandle(CTPolarAdjustHandle xobj) { + this.xobj = xobj; + } + + // define more getter/setter when needed +} \ No newline at end of file diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFQuadTo.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFQuadTo.java new file mode 100644 index 0000000000..5a38aa41c9 --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFQuadTo.java @@ -0,0 +1,56 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustPointIf; +import org.apache.poi.sl.draw.geom.QuadToCommandIf; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFQuadTo implements QuadToCommandIf { + + private final CTPath2DQuadBezierTo bezier; + + public XSLFQuadTo(CTPath2DQuadBezierTo bezier) { + this.bezier = bezier; + } + + @Override + public AdjustPointIf getPt1() { + return new XSLFAdjustPoint(bezier.getPtArray(0)); + } + + @Override + public void setPt1(AdjustPointIf pt1) { + + } + + @Override + public AdjustPointIf getPt2() { + return new XSLFAdjustPoint(bezier.getPtArray(1)); + } + + @Override + public void setPt2(AdjustPointIf pt2) { + + } +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFXYAdjustHandle.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFXYAdjustHandle.java new file mode 100644 index 0000000000..56a2713a5d --- /dev/null +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/draw/geom/XSLFXYAdjustHandle.java @@ -0,0 +1,35 @@ +/* ==================================================================== + 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.draw.geom; + +import org.apache.poi.sl.draw.geom.AdjustHandle; +import org.apache.poi.util.Beta; +import org.openxmlformats.schemas.drawingml.x2006.main.CTXYAdjustHandle; + +/** + * Wrapper / delegate for XmlBeans custom geometry + */ +@Beta +public class XSLFXYAdjustHandle implements AdjustHandle { + final CTXYAdjustHandle xobj; + public XSLFXYAdjustHandle(CTXYAdjustHandle xobj) { + this.xobj = xobj; + } + + // define more getter/setter when needed +} diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFBackground.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFBackground.java index add51e6566..67397d6c50 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFBackground.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFBackground.java @@ -75,6 +75,7 @@ public class XSLFBackground extends XSLFSimpleShape return bg.getBgPr(); } + @Override public void setFillColor(Color color) { CTBackgroundProperties bgPr = getBgPr(true); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java index 593a4ee1ca..838430cc02 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFFreeformShape.java @@ -24,21 +24,16 @@ import java.awt.geom.Path2D; import java.awt.geom.PathIterator; import java.awt.geom.Rectangle2D; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.poi.ooxml.POIXMLTypeLoader; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.sl.draw.geom.CustomGeometry; -import org.apache.poi.sl.draw.geom.PresetGeometries; import org.apache.poi.sl.usermodel.FreeformShape; import org.apache.poi.util.Beta; import org.apache.poi.util.Units; +import org.apache.poi.xslf.draw.geom.XSLFCustomGeometry; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlOptions; import org.openxmlformats.schemas.drawingml.x2006.main.CTAdjPoint2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D; import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect; @@ -135,18 +130,7 @@ public class XSLFFreeformShape extends XSLFAutoShape return null; } - XmlOptions xop = new XmlOptions(POIXMLTypeLoader.DEFAULT_XML_OPTIONS); - xop.setSaveOuter(); - - XMLStreamReader staxReader = ((CTShapeProperties)xo).getCustGeom().newXMLStreamReader(xop); - CustomGeometry custGeo = PresetGeometries.convertCustomGeometry(staxReader); - try { - staxReader.close(); - } catch (XMLStreamException e) { - LOG.atWarn().log("An error occurred while closing a Custom Geometry XML Stream Reader: {}", e.getMessage()); - } - - return custGeo; + return XSLFCustomGeometry.convertCustomGeometry(((CTShapeProperties)xo).getCustGeom()); } @Override diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java index f7424d1807..269a0df884 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSimpleShape.java @@ -22,9 +22,6 @@ package org.apache.poi.xslf.usermodel; import java.awt.Color; import java.awt.geom.Rectangle2D; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.POIXMLUnits; @@ -47,6 +44,7 @@ import org.apache.poi.sl.usermodel.StrokeStyle.LineCompound; 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.draw.geom.XSLFCustomGeometry; import org.apache.poi.xslf.model.PropertyFetcher; import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFEffectProperties; import org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties; @@ -240,7 +238,7 @@ public abstract class XSLFSimpleShape extends XSLFShape /** * @param color the color to paint the shape outline. - * A null value turns off the shape outline. + * A {@code null} value turns off the shape outline. */ public void setLineColor(Color color) { CTLineProperties ln = getLn(this, true); @@ -273,7 +271,7 @@ public abstract class XSLFSimpleShape extends XSLFShape /** * - * @return the color of the shape outline or null + * @return the color of the shape outline or {@code null} * if outline is turned off */ @SuppressWarnings("WeakerAccess") @@ -351,7 +349,7 @@ public abstract class XSLFSimpleShape extends XSLFShape /** * - * @param width line width in points. 0 means no line + * @param width line width in points. {@code 0} means no line */ @SuppressWarnings("WeakerAccess") public void setLineWidth(double width) { @@ -386,7 +384,7 @@ public abstract class XSLFSimpleShape extends XSLFShape } /** - * @return line width in points. 0 means no line. + * @return line width in points. {@code 0} means no line. */ @SuppressWarnings("WeakerAccess") public double getLineWidth() { @@ -709,14 +707,7 @@ public abstract class XSLFSimpleShape extends XSLFShape throw new IllegalStateException("Unknown shape geometry: " + name + ", available geometries are: " + dict.keySet()); } } else if (gp.isSetCustGeom()){ - XMLStreamReader staxReader = gp.getCustGeom().newXMLStreamReader(); - geom = PresetGeometries.convertCustomGeometry(staxReader); - try { - staxReader.close(); - } - catch (XMLStreamException e) { - LOG.atWarn().log("An error occurred while closing a Custom Geometry XML Stream Reader: {}", e.getMessage()); - } + geom = XSLFCustomGeometry.convertCustomGeometry(gp.getCustGeom()); } else { geom = dict.get("rect"); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java index d2adc919e1..2974b46b59 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFTable.java @@ -27,6 +27,8 @@ import java.util.List; import javax.xml.namespace.QName; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ooxml.util.POIXMLUnits; import org.apache.poi.sl.draw.DrawFactory; import org.apache.poi.sl.draw.DrawTableShape; @@ -52,6 +54,7 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFra public class XSLFTable extends XSLFGraphicFrame implements Iterable, TableShape { /* package */ static final String TABLE_URI = "http://schemas.openxmlformats.org/drawingml/2006/table"; + private static final Logger LOG = LogManager.getLogger(XSLFTable.class); private final CTTable _table; private final List _rows; @@ -425,13 +428,17 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable 1 && slideNo > 0 ? outPattern : outPattern.replaceAll("-?\\$\\{slideno}", "")); return INPUT_PATTERN.matcher(inname).replaceAll(outpat); } diff --git a/poi-ooxml/src/main/java9/module-info.class b/poi-ooxml/src/main/java9/module-info.class index 6e355946d831ce4876d2fafb5c8470b24705e9a4..fd29b43f37a2f11a6243e50773ba0f7279e184f8 100644 GIT binary patch delta 228 zcmaDUGewr`)W2Q(7#J8#8BT8G3SeSmHPJKDGu#}PQnaQceA`IIgYNXjqQgaK~8Foxw$)(S@ zYw}GlE5<#OMYs)F_AxRTPFCO$nOx7oIXR76jPbzaT5co8Lz6dfn=>An{DNDP@z`V` z9(P8Q%~3q8jEp*)6L>ipRT&vNfo^1E;0BT`4BLUMoeaBysH(-}TiomhB|QLf1K2dqG4t>L%K zpg$J!+eXY5i5K`nwMe=omheF}*P+v8Mn&Q=kGHF;bd^z|n0V3ywocc1zgi;QWK<$T zUe#|j1jH?FGb&5X`Fxj4x`X7*`j`<7n^lHbaF3B^WW!dMqxb=%aevfOFPibInn#SX zd9$1?TJi)f%wz*C?gD8rbu1I@>&{U4EO$o!kXZW1PK`^gYA3zmi`;(pif?q!WN&!V zT`s+2RQ@}6yq3d0@Tppb^odagACz-=ljdcgd8<|?eNA1aSJiEj~M=9y$q6!?W-_yao7BC&zVY`n3P_oX{kvQherG0rRj^rH}D{lF`dzoF*BK48xd2| zh=@p8B7!v9h=>Sk>Q+^%txMgh`=##Gt@r@gQ-3ew!HbvuJA19O&;IYTe^d-t=tJMT zdx@x;zIEzmo;G3L?5b>e-e#LKl?cRFMC$`#lMb=RVajmO!n~849d27H8B)D0m+Ix> zC@;_}wc~`!L7C;_DZMd;~F_b z^z&j_s0|7#8h3DV^JP$9zA$SE|gE!zUI1KN?`|u%rOq3bl_$dm{U@dJ_ zPkAI&sBYB$PsmIU{X@#XhFpqZ^)Lt<;Bpv-5g3E * - * Furthermore ooxml angle starts at the X-axis and increases clock-wise, - * where as Arc2D api states + * Furthermore, ooxml angle starts at the X-axis and increases clock-wise, + * whereas Arc2D api states * "45 degrees always falls on the line from the center of the ellipse to * the upper right corner of the framing rectangle" * so we need to reverse it diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/ArcToCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/ArcToCommandIf.java new file mode 100644 index 0000000000..6e5942ea89 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/ArcToCommandIf.java @@ -0,0 +1,72 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.sl.draw.geom; + +import static org.apache.poi.sl.draw.geom.Formula.OOXML_DEGREE; + +import java.awt.geom.Arc2D; +import java.awt.geom.Path2D; +import java.awt.geom.Point2D; + +public interface ArcToCommandIf extends PathCommand { + + void setHR(String hr); + + void setWR(String wr); + + void setStAng(String stAng); + + void setSwAng(String swAng); + + String getHR(); + + String getWR(); + + String getStAng(); + + String getSwAng(); + + + @Override + default void execute(Path2D.Double path, Context ctx){ + double rx = ctx.getValue(getWR()); + double ry = ctx.getValue(getHR()); + double ooStart = ctx.getValue(getStAng()) / OOXML_DEGREE; + double ooExtent = ctx.getValue(getSwAng()) / OOXML_DEGREE; + + // skew the angles for AWT output + double awtStart = ArcToCommand.convertOoxml2AwtAngle(ooStart, rx, ry); + double awtSweep = ArcToCommand.convertOoxml2AwtAngle(ooStart+ooExtent, rx, ry)-awtStart; + + // calculate the inverse angle - taken from the (reversed) preset definition + double radStart = Math.toRadians(ooStart); + double invStart = Math.atan2(rx * Math.sin(radStart), ry * Math.cos(radStart)); + + Point2D pt = path.getCurrentPoint(); + // calculate top/left corner + double x0 = pt.getX() - rx * Math.cos(invStart) - rx; + double y0 = pt.getY() - ry * Math.sin(invStart) - ry; + + Arc2D arc = new Arc2D.Double(x0, y0, 2 * rx, 2 * ry, awtStart, awtSweep, Arc2D.OPEN); + path.append(arc, true); + } + + +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommand.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommand.java index ab7a37a444..91d4332331 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommand.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommand.java @@ -39,7 +39,7 @@ import java.awt.geom.Path2D; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2DClose") -public class ClosePathCommand implements PathCommand { +public class ClosePathCommand implements ClosePathCommandIf { @Override public void execute(Path2D.Double path, Context ctx){ diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommandIf.java new file mode 100644 index 0000000000..b212c5db8c --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/ClosePathCommandIf.java @@ -0,0 +1,23 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.sl.draw.geom; + +public interface ClosePathCommandIf extends PathCommand { +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSite.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSite.java index 9f19ebccc6..0ee7571ca4 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSite.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSite.java @@ -41,64 +41,37 @@ import java.util.Objects; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_ConnectionSite", propOrder = {"pos"}) -public final class ConnectionSite { +public final class ConnectionSite implements ConnectionSiteIf { // @XmlElement(required = true) private final AdjustPoint pos = new AdjustPoint(); // @XmlAttribute(name = "ang", required = true) private String ang; - /** - * Gets the value of the pos property. - * - * @return - * possible object is - * {@link AdjustPoint } - * - */ + @Override public AdjustPoint getPos() { return pos; } - /** - * Sets the value of the pos property. - * - * @param pos - * allowed object is - * {@link AdjustPoint } - * - */ - public void setPos(AdjustPoint pos) { + @Override + public void setPos(AdjustPointIf pos) { if (pos != null) { this.pos.setX(pos.getX()); this.pos.setY(pos.getY()); } } - /** - * Gets the value of the ang property. - * - * @return - * possible object is - * {@link String } - * - */ + @Override public String getAng() { return ang; } - /** - * Sets the value of the ang property. - * - * @param value - * allowed object is - * {@link String } - * - */ + @Override public void setAng(String value) { this.ang = value; } + @Override public boolean isSetAng() { return (this.ang!= null); } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSiteIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSiteIf.java new file mode 100644 index 0000000000..68eccfc9a1 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/ConnectionSiteIf.java @@ -0,0 +1,44 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +public interface ConnectionSiteIf { + + /** + * Gets the value of the pos property. + */ + AdjustPointIf getPos(); + + /** + * Sets the value of the pos property. + */ + void setPos(AdjustPointIf pos); + + /** + * Gets the value of the ang property. + */ + String getAng(); + + /** + * Sets the value of the ang property. + */ + void setAng(String value); + + boolean isSetAng(); + +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java index 3ac4495929..2b7c571475 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/Context.java @@ -34,14 +34,14 @@ public class Context { private final Map _ctx = new HashMap<>(); private final IAdjustableShape _props; private final Rectangle2D _anchor; - + public Context(CustomGeometry geom, Rectangle2D anchor, IAdjustableShape props){ _props = props; _anchor = anchor; - for(Guide gd : geom.adjusts) { + for(GuideIf gd : geom.adjusts) { evaluate(gd); } - for(Guide gd : geom.guides) { + for(GuideIf gd : geom.guides) { evaluate(gd); } } @@ -50,7 +50,7 @@ public class Context { return _anchor; } - Guide getAdjustValue(String name){ + GuideIf getAdjustValue(String name){ return _props.getAdjustValue(name); } @@ -65,8 +65,8 @@ public class Context { public double evaluate(Formula fmla){ double result = fmla.evaluate(this); - if (fmla instanceof Guide) { - String key = ((Guide)fmla).getName(); + if (fmla instanceof GuideIf) { + String key = ((GuideIf)fmla).getName(); if (key != null) { _ctx.put(key, result); } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommand.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommand.java index 2e121c7893..01d3f726e5 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommand.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommand.java @@ -43,7 +43,7 @@ import java.util.Objects; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2DCubicBezierTo", propOrder = {"pt"}) -public final class CurveToCommand implements PathCommand { +public final class CurveToCommand implements CurveToCommandIf { // @XmlElement(required = true) private final AdjustPoint pt1 = new AdjustPoint(); @@ -52,38 +52,45 @@ public final class CurveToCommand implements PathCommand { // @XmlElement(required = true) private final AdjustPoint pt3 = new AdjustPoint(); - public void setPt1(AdjustPoint pt1) { + @Override + public AdjustPoint getPt1() { + return pt1; + } + + @Override + public void setPt1(AdjustPointIf pt1) { if (pt1 != null) { this.pt1.setX(pt1.getX()); this.pt1.setY(pt1.getY()); } } - public void setPt2(AdjustPoint pt2) { + @Override + public AdjustPoint getPt2() { + return pt2; + } + + @Override + public void setPt2(AdjustPointIf pt2) { if (pt2 != null) { this.pt2.setX(pt2.getX()); this.pt2.setY(pt2.getY()); } } - public void setPt3(AdjustPoint pt3) { + @Override + public AdjustPoint getPt3() { + return pt3; + } + + @Override + public void setPt3(AdjustPointIf pt3) { if (pt3 != null) { this.pt3.setX(pt3.getX()); this.pt3.setY(pt3.getY()); } } - @Override - public void execute(Path2D.Double path, Context ctx){ - double x1 = ctx.getValue(pt1.getX()); - double y1 = ctx.getValue(pt1.getY()); - double x2 = ctx.getValue(pt2.getX()); - double y2 = ctx.getValue(pt2.getY()); - double x3 = ctx.getValue(pt3.getX()); - double y3 = ctx.getValue(pt3.getY()); - path.curveTo(x1, y1, x2, y2, x3, y3); - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommandIf.java new file mode 100644 index 0000000000..2ea80301c6 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/CurveToCommandIf.java @@ -0,0 +1,50 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +import java.awt.geom.Path2D; + +public interface CurveToCommandIf extends PathCommand { + + AdjustPointIf getPt1(); + + void setPt1(AdjustPointIf pt1); + + AdjustPointIf getPt2(); + + void setPt2(AdjustPointIf pt2); + + AdjustPointIf getPt3(); + + void setPt3(AdjustPointIf pt3); + + + @Override + default void execute(Path2D.Double path, Context ctx){ + AdjustPointIf pt1 = getPt1(); + double x1 = ctx.getValue(pt1.getX()); + double y1 = ctx.getValue(pt1.getY()); + AdjustPointIf pt2 = getPt2(); + double x2 = ctx.getValue(pt2.getX()); + double y2 = ctx.getValue(pt2.getY()); + AdjustPointIf pt3 = getPt3(); + double x3 = ctx.getValue(pt3.getX()); + double y3 = ctx.getValue(pt3.getY()); + path.curveTo(x1, y1, x2, y2, x3, y3); + } +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/CustomGeometry.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/CustomGeometry.java index ff7a1c2f5f..84ef46357f 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/CustomGeometry.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/CustomGeometry.java @@ -49,19 +49,19 @@ import java.util.Objects; * </complexType> * */ -public final class CustomGeometry implements Iterable{ - final List adjusts = new ArrayList<>(); - final List guides = new ArrayList<>(); - final List paths = new ArrayList<>(); +public final class CustomGeometry implements Iterable{ + final List adjusts = new ArrayList<>(); + final List guides = new ArrayList<>(); + final List paths = new ArrayList<>(); final List handles = new ArrayList<>(); - final List connections = new ArrayList<>(); + final List connections = new ArrayList<>(); Path textBounds; - public void addAdjustGuide(AdjustValue guide) { + public void addAdjustGuide(AdjustValueIf guide) { adjusts.add(guide); } - public void addGeomGuide(Guide guide) { + public void addGeomGuide(GuideIf guide) { guides.add(guide); } @@ -69,11 +69,11 @@ public final class CustomGeometry implements Iterable{ handles.add(handle); } - public void addConnectionSite(ConnectionSite connection) { + public void addConnectionSite(ConnectionSiteIf connection) { connections.add(connection); } - public void addPath(Path path) { + public void addPath(PathIf path) { paths.add(path); } @@ -106,7 +106,7 @@ public final class CustomGeometry implements Iterable{ @Override - public Iterator iterator() { + public Iterator iterator() { return paths.iterator(); } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/Guide.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/Guide.java index 77da392058..0a6af0730b 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/Guide.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/Guide.java @@ -19,10 +19,7 @@ package org.apache.poi.sl.draw.geom; -import static java.lang.Math.*; - import java.util.Objects; -import java.util.regex.Pattern; /** *

Java class for CT_GeomGuide complex type. @@ -44,12 +41,7 @@ import java.util.regex.Pattern; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_GeomGuide") -public class Guide implements Formula { - enum Op { - muldiv,addsub,adddiv,ifelse,val,abs,sqrt,max,min,at2,sin,cos,tan,cat2,sat2,pin,mod - } - - private static final Pattern WHITESPACE = Pattern.compile("\\s+"); +public class Guide implements GuideIf { // @XmlAttribute(name = "name", required = true) // @XmlJavaTypeAdapter(CollapsedStringAdapter.class) @@ -57,97 +49,27 @@ public class Guide implements Formula { // @XmlAttribute(name = "fmla", required = true) private String fmla; - private Op op; - private String[] operands; + @Override public String getName(){ return name; } + @Override public void setName(String name) { this.name = name; } + @Override public String getFmla() { return fmla; } + @Override public void setFmla(String fmla) { this.fmla = fmla; - operands = WHITESPACE.split(fmla); - switch (operands[0]) { - case "*/": op = Op.muldiv; break; - case "+-": op = Op.addsub; break; - case "+/": op = Op.adddiv; break; - case "?:": op = Op.ifelse; break; - default: op = Op.valueOf(operands[0]); break; - } } - @Override - public double evaluate(Context ctx) { - double x = (operands.length > 1) ? ctx.getValue(operands[1]) : 0; - double y = (operands.length > 2) ? ctx.getValue(operands[2]) : 0; - double z = (operands.length > 3) ? ctx.getValue(operands[3]) : 0; - switch (op) { - case abs: - // Absolute Value Formula - return abs(x); - case adddiv: - // Add Divide Formula - return (z == 0) ? 0 : (x + y) / z; - case addsub: - // Add Subtract Formula - return (x + y) - z; - case at2: - // ArcTan Formula: "at2 x y" = arctan( y / z ) = value of this guide - return toDegrees(atan2(y, x)) * OOXML_DEGREE; - case cos: - // Cosine Formula: "cos x y" = (x * cos( y )) = value of this guide - return x * cos(toRadians(y / OOXML_DEGREE)); - case cat2: - // Cosine ArcTan Formula: "cat2 x y z" = (x * cos(arctan(z / y) )) = value of this guide - return x * cos(atan2(z, y)); - case ifelse: - // If Else Formula: "?: x y z" = if (x > 0), then y = value of this guide, - // else z = value of this guide - return x > 0 ? y : z; - case val: - // Literal Value Expression - return x; - case max: - // Maximum Value Formula - return max(x, y); - case min: - // Minimum Value Formula - return min(x, y); - case mod: - // Modulo Formula: "mod x y z" = sqrt(x^2 + b^2 + c^2) = value of this guide - return sqrt(x*x + y*y + z*z); - case muldiv: - // Multiply Divide Formula - return (z == 0) ? 0 : (x * y) / z; - case pin: - // Pin To Formula: "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 - return max(x, min(y, z)); - case sat2: - // Sine ArcTan Formula: "sat2 x y z" = (x*sin(arctan(z / y))) = value of this guide - return x * sin(atan2(z, y)); - case sin: - // Sine Formula: "sin x y" = (x * sin( y )) = value of this guide - return x * sin(toRadians(y / OOXML_DEGREE)); - case sqrt: - // Square Root Formula: "sqrt x" = sqrt(x) = value of this guide - return sqrt(x); - case tan: - // Tangent Formula: "tan x y" = (x * tan( y )) = value of this guide - return x * tan(toRadians(y / OOXML_DEGREE)); - default: - return 0; - } - } @Override public boolean equals(Object o) { diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/GuideIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/GuideIf.java new file mode 100644 index 0000000000..cd6e26d457 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/GuideIf.java @@ -0,0 +1,120 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.sl.draw.geom; + +import static java.lang.Math.*; +import static java.lang.Math.toRadians; + +import java.util.regex.Pattern; + +public interface GuideIf extends Formula { + enum Op { + muldiv,addsub,adddiv,ifelse,val,abs,sqrt,max,min,at2,sin,cos,tan,cat2,sat2,pin,mod + } + + Pattern WHITESPACE = Pattern.compile("\\s+"); + + String getName(); + + void setName(String name); + + String getFmla(); + + void setFmla(String fmla); + + @Override + default double evaluate(Context ctx) { + return evaluateGuide(ctx); + } + + default double evaluateGuide(Context ctx) { + Guide.Op op; + String[] operands = WHITESPACE.split(getFmla()); + switch (operands[0]) { + case "*/": op = Guide.Op.muldiv; break; + case "+-": op = Guide.Op.addsub; break; + case "+/": op = Guide.Op.adddiv; break; + case "?:": op = Guide.Op.ifelse; break; + default: op = Guide.Op.valueOf(operands[0]); break; + } + + double x = (operands.length > 1) ? ctx.getValue(operands[1]) : 0; + double y = (operands.length > 2) ? ctx.getValue(operands[2]) : 0; + double z = (operands.length > 3) ? ctx.getValue(operands[3]) : 0; + switch (op) { + case abs: + // Absolute Value Formula + return abs(x); + case adddiv: + // Add Divide Formula + return (z == 0) ? 0 : (x + y) / z; + case addsub: + // Add Subtract Formula + return (x + y) - z; + case at2: + // ArcTan Formula: "at2 x y" = arctan( y / z ) = value of this guide + return toDegrees(atan2(y, x)) * OOXML_DEGREE; + case cos: + // Cosine Formula: "cos x y" = (x * cos( y )) = value of this guide + return x * cos(toRadians(y / OOXML_DEGREE)); + case cat2: + // Cosine ArcTan Formula: "cat2 x y z" = (x * cos(arctan(z / y) )) = value of this guide + return x * cos(atan2(z, y)); + case ifelse: + // If Else Formula: "?: x y z" = if (x > 0), then y = value of this guide, + // else z = value of this guide + return x > 0 ? y : z; + case val: + // Literal Value Expression + return x; + case max: + // Maximum Value Formula + return max(x, y); + case min: + // Minimum Value Formula + return min(x, y); + case mod: + // Modulo Formula: "mod x y z" = sqrt(x^2 + b^2 + c^2) = value of this guide + return sqrt(x*x + y*y + z*z); + case muldiv: + // Multiply Divide Formula + return (z == 0) ? 0 : (x * y) / z; + case pin: + // Pin To Formula: "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 + return max(x, min(y, z)); + case sat2: + // Sine ArcTan Formula: "sat2 x y z" = (x*sin(arctan(z / y))) = value of this guide + return x * sin(atan2(z, y)); + case sin: + // Sine Formula: "sin x y" = (x * sin( y )) = value of this guide + return x * sin(toRadians(y / OOXML_DEGREE)); + case sqrt: + // Square Root Formula: "sqrt x" = sqrt(x) = value of this guide + return sqrt(x); + case tan: + // Tangent Formula: "tan x y" = (x * tan( y )) = value of this guide + return x * tan(toRadians(y / OOXML_DEGREE)); + default: + return 0; + } + } +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/IAdjustableShape.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/IAdjustableShape.java index 3145507dca..7d6a2d1102 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/IAdjustableShape.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/IAdjustableShape.java @@ -31,5 +31,5 @@ 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); + GuideIf getAdjustValue(String name); } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommand.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommand.java index b1965fab87..b0ca664187 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommand.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommand.java @@ -19,7 +19,6 @@ package org.apache.poi.sl.draw.geom; -import java.awt.geom.Path2D; import java.util.Objects; /** @@ -43,29 +42,24 @@ import java.util.Objects; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2DLineTo", propOrder = {"pt"}) -public final class LineToCommand implements PathCommand { +public final class LineToCommand implements LineToCommandIf { // @XmlElement(required = true) private final AdjustPoint pt = new AdjustPoint(); + @Override public AdjustPoint getPt() { return pt; } - public void setPt(AdjustPoint pt) { + @Override + public void setPt(AdjustPointIf pt) { if (pt != null) { this.pt.setX(pt.getX()); this.pt.setY(pt.getY()); } } - @Override - public void execute(Path2D.Double path, Context ctx){ - double x = ctx.getValue(pt.getX()); - double y = ctx.getValue(pt.getY()); - path.lineTo(x, y); - } - @Override public boolean equals(Object o) { diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommandIf.java new file mode 100644 index 0000000000..d013e80373 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/LineToCommandIf.java @@ -0,0 +1,35 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +import java.awt.geom.Path2D; + +public interface LineToCommandIf extends PathCommand { + + AdjustPointIf getPt(); + + void setPt(AdjustPointIf pt); + + @Override + default void execute(Path2D.Double path, Context ctx){ + AdjustPointIf pt = getPt(); + double x = ctx.getValue(pt.getX()); + double y = ctx.getValue(pt.getY()); + path.lineTo(x, y); + } +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommand.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommand.java index 6ebaa206b3..a328c15bf6 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommand.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommand.java @@ -19,7 +19,6 @@ package org.apache.poi.sl.draw.geom; -import java.awt.geom.Path2D; import java.util.Objects; /** @@ -43,30 +42,24 @@ import java.util.Objects; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2DMoveTo", propOrder = {"pt"}) -public final class MoveToCommand implements PathCommand { +public final class MoveToCommand implements MoveToCommandIf { // @XmlElement(required = true) private final AdjustPoint pt = new AdjustPoint(); + @Override public AdjustPoint getPt() { return pt; } - public void setPt(AdjustPoint pt) { + @Override + public void setPt(AdjustPointIf pt) { if (pt != null) { this.pt.setX(pt.getX()); this.pt.setY(pt.getY()); } } - @Override - public void execute(Path2D.Double path, Context ctx){ - double x = ctx.getValue(pt.getX()); - double y = ctx.getValue(pt.getY()); - path.moveTo(x, y); - } - - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommandIf.java new file mode 100644 index 0000000000..a4232e117b --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/MoveToCommandIf.java @@ -0,0 +1,35 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +import java.awt.geom.Path2D; + +public interface MoveToCommandIf extends PathCommand { + + AdjustPointIf getPt(); + + void setPt(AdjustPointIf pt); + + @Override + default void execute(Path2D.Double path, Context ctx){ + AdjustPointIf pt = getPt(); + double x = ctx.getValue(pt.getX()); + double y = ctx.getValue(pt.getY()); + path.moveTo(x, y); + } +} diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/Outline.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/Outline.java index 11e643dad2..59a9241b01 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/Outline.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/Outline.java @@ -22,15 +22,15 @@ package org.apache.poi.sl.draw.geom; import java.awt.Shape; public class Outline { - private Shape shape; - private Path path; + private final Shape shape; + private final PathIf path; - public Outline(Shape shape, Path path){ + public Outline(Shape shape, PathIf path){ this.shape = shape; this.path = path; } - public Path getPath(){ + public PathIf getPath(){ return path; } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/Path.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/Path.java index d9b209c4de..5a06e7216e 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/Path.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/Path.java @@ -58,7 +58,7 @@ import org.apache.poi.sl.usermodel.PaintStyle.PaintModifier; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2D", propOrder = {"closeOrMoveToOrLnTo"}) -public final class Path { +public final class Path implements PathIf { // @XmlElements({ // @XmlElement(name = "close", type = CTPath2DClose.class), @@ -82,6 +82,7 @@ public final class Path { + @Override public void addCommand(PathCommand cmd){ commands.add(cmd); } @@ -89,6 +90,7 @@ public final class Path { /** * Convert the internal represenation to java.awt.geom.Path2D */ + @Override public Path2D.Double getPath(Context ctx) { Path2D.Double path = new Path2D.Double(); for(PathCommand cmd : commands) { @@ -97,46 +99,57 @@ public final class Path { return path; } + @Override public boolean isStroked(){ return stroke; } + @Override public void setStroke(boolean stroke) { this.stroke = stroke; } + @Override public boolean isFilled(){ return fill != PaintModifier.NONE; } + @Override public PaintModifier getFill() { return fill; } + @Override public void setFill(PaintModifier fill) { this.fill = fill; } + @Override public long getW(){ return w; } + @Override public void setW(long w) { this.w = w; } + @Override public long getH(){ return h; } + @Override public void setH(long h) { this.h = h; } + @Override public boolean isExtrusionOk() { return extrusionOk; } + @Override public void setExtrusionOk(boolean extrusionOk) { this.extrusionOk = extrusionOk; } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/PathIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/PathIf.java new file mode 100644 index 0000000000..a02551e21d --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/PathIf.java @@ -0,0 +1,55 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +import java.awt.geom.Path2D; + +import org.apache.poi.sl.usermodel.PaintStyle; + +public interface PathIf { + + void addCommand(PathCommand cmd); + + /** + * Convert the internal represenation to java.awt.geom.Path2D + */ + Path2D.Double getPath(Context ctx); + + boolean isStroked(); + + void setStroke(boolean stroke); + + boolean isFilled(); + + PaintStyle.PaintModifier getFill(); + + void setFill(PaintStyle.PaintModifier fill); + + long getW(); + + void setW(long w); + + long getH(); + + void setH(long h); + + boolean isExtrusionOk(); + + void setExtrusionOk(boolean extrusionOk); + +} \ No newline at end of file diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java index acde02c945..0f5a490274 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/PresetGeometries.java @@ -31,13 +31,9 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stream.StreamSource; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.apache.poi.util.XMLHelper; public final class PresetGeometries { - private static final Logger LOG = LogManager.getLogger(PresetGeometries.class); - private final Map map = new TreeMap<>(); private static class SingletonHelper{ @@ -57,7 +53,7 @@ public final class PresetGeometries { try { PresetParser p = new PresetParser(PresetParser.Mode.FILE); p.parse(sr); - p.getGeom().forEach(map::put); + map.putAll(p.getGeom()); } finally { sr.close(); } @@ -67,20 +63,6 @@ public final class PresetGeometries { } } - /** - * Convert a single CustomGeometry object, i.e. from xmlbeans - */ - public static CustomGeometry convertCustomGeometry(XMLStreamReader staxReader) { - try { - PresetParser p = new PresetParser(PresetParser.Mode.SHAPE); - p.parse(staxReader); - return p.getGeom().values().stream().findFirst().orElse(null); - } catch (XMLStreamException e) { - LOG.atError().withThrowable(e).log("Unable to parse single custom geometry"); - return null; - } - } - public CustomGeometry get(String name) { return name == null ? null : map.get(name); } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommand.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommand.java index 4278a00274..1ec2a1dc86 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommand.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommand.java @@ -19,7 +19,6 @@ package org.apache.poi.sl.draw.geom; -import java.awt.geom.Path2D; import java.util.Objects; /** @@ -43,36 +42,39 @@ import java.util.Objects; */ // @XmlAccessorType(XmlAccessType.FIELD) // @XmlType(name = "CT_Path2DQuadBezierTo", propOrder = {"pt"}) -public final class QuadToCommand implements PathCommand { +public final class QuadToCommand implements QuadToCommandIf { // @XmlElement(required = true) private final AdjustPoint pt1 = new AdjustPoint(); // @XmlElement(required = true) private final AdjustPoint pt2 = new AdjustPoint(); - public void setPt1(AdjustPoint pt1) { + @Override + public AdjustPoint getPt1() { + return pt1; + } + + @Override + public void setPt1(AdjustPointIf pt1) { if (pt1 != null) { this.pt1.setX(pt1.getX()); this.pt1.setY(pt1.getY()); } } - public void setPt2(AdjustPoint pt2) { + @Override + public AdjustPoint getPt2() { + return pt2; + } + + @Override + public void setPt2(AdjustPointIf pt2) { if (pt2 != null) { this.pt2.setX(pt2.getX()); this.pt2.setY(pt2.getY()); } } - @Override - public void execute(Path2D.Double path, Context ctx){ - double x1 = ctx.getValue(pt1.getX()); - double y1 = ctx.getValue(pt1.getY()); - double x2 = ctx.getValue(pt2.getX()); - double y2 = ctx.getValue(pt2.getY()); - path.quadTo(x1, y1, x2, y2); - } - @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommandIf.java b/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommandIf.java new file mode 100644 index 0000000000..db060c27e3 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/sl/draw/geom/QuadToCommandIf.java @@ -0,0 +1,42 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.sl.draw.geom; + +import java.awt.geom.Path2D; + +public interface QuadToCommandIf extends PathCommand { + + AdjustPointIf getPt1(); + + void setPt1(AdjustPointIf pt1); + + AdjustPointIf getPt2(); + + void setPt2(AdjustPointIf pt2); + + @Override + default void execute(Path2D.Double path, Context ctx){ + AdjustPointIf pt1 = getPt1(); + double x1 = ctx.getValue(pt1.getX()); + double y1 = ctx.getValue(pt1.getY()); + AdjustPointIf pt2 = getPt2(); + double x2 = ctx.getValue(pt2.getX()); + double y2 = ctx.getValue(pt2.getY()); + path.quadTo(x1, y1, x2, y2); + } +} diff --git a/poi/src/test/java/org/apache/poi/sl/draw/geom/TestPresetGeometries.java b/poi/src/test/java/org/apache/poi/sl/draw/geom/TestPresetGeometries.java index 28849f77e9..6cb3360b68 100644 --- a/poi/src/test/java/org/apache/poi/sl/draw/geom/TestPresetGeometries.java +++ b/poi/src/test/java/org/apache/poi/sl/draw/geom/TestPresetGeometries.java @@ -24,10 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertSame; import java.awt.geom.Path2D; import java.awt.geom.Rectangle2D; -import java.net.URL; -import java.util.Enumeration; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class TestPresetGeometries { @@ -40,7 +37,7 @@ class TestPresetGeometries { for(String name : shapes.keySet()) { CustomGeometry geom = shapes.get(name); Context ctx = new Context(geom, new Rectangle2D.Double(0, 0, 100, 100), presetName -> null); - for(Path p : geom){ + for(PathIf p : geom){ Path2D path = p.getPath(ctx); assertNotNull(path); } @@ -49,24 +46,4 @@ class TestPresetGeometries { // we get the same instance on further calls assertSame(shapes, PresetGeometries.getInstance()); } - - @Disabled("problem solved? Turn back on if this debugging is still in process.") - void testCheckXMLParser() throws Exception{ - // Gump reports a strange error because of an unavailable XML Parser, let's try to find out where - // this comes from - // - Enumeration resources = this.getClass().getClassLoader().getResources("META-INF/services/javax.xml.stream.XMLEventFactory"); - printURLs(resources); - resources = ClassLoader.getSystemResources("META-INF/services/javax.xml.stream.XMLEventFactory"); - printURLs(resources); - resources = ClassLoader.getSystemResources("org/apache/poi/sl/draw/geom/presetShapeDefinitions.xml"); - printURLs(resources); - } - - private void printURLs(Enumeration resources) { - while(resources.hasMoreElements()) { - URL url = resources.nextElement(); - System.out.println("URL: " + url); - } - } } -- 2.39.5