diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-03-06 11:53:17 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-03-06 11:53:17 +0000 |
commit | d0a5b622cad9fcb01c20beb6d5caa5b9e3fb3c5b (patch) | |
tree | 1edbefce2cdb3d34ffaf808c4d8dcdb7e0ed7e56 /poi-ooxml/src/main | |
parent | baae7b030106f3f5ff6b24216676d7bec8593e7b (diff) | |
download | poi-d0a5b622cad9fcb01c20beb6d5caa5b9e3fb3c5b.tar.gz poi-d0a5b622cad9fcb01c20beb6d5caa5b9e3fb3c5b.zip |
[github-604] XDGF: add support for poly lines. Thanks to Dmitrii Komarov. This closes #604
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1916146 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/main')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java index 70d652bda9..495a7d3f39 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/section/geometry/PolyLineTo.java @@ -27,6 +27,9 @@ import com.microsoft.schemas.office.visio.x2012.main.RowType; public class PolyLineTo implements GeometryRow { + private static final String POLYLINE_FORMULA_PREFIX = "POLYLINE("; + private static final String POLYLINE_FORMULA_SUFFIX = ")"; + PolyLineTo _master; // The x-coordinate of the ending vertex of a polyline. @@ -96,6 +99,39 @@ public class PolyLineTo implements GeometryRow { public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) { if (getDel()) return; - throw new POIXMLException("Polyline support not implemented"); + + // A polyline formula: POLYLINE(xType, yType, x1, y1, x2, y2, ...) + String formula = getA().trim(); + if (!formula.startsWith(POLYLINE_FORMULA_PREFIX) || !formula.endsWith(POLYLINE_FORMULA_SUFFIX)) { + throw new POIXMLException("Invalid POLYLINE formula: " + formula); + } + + String[] components = formula + .substring(POLYLINE_FORMULA_PREFIX.length(), formula.length() - POLYLINE_FORMULA_SUFFIX.length()) + .split(","); + + if (components.length < 2) { + throw new POIXMLException("Invalid POLYLINE formula (not enough arguments): " + formula); + } + + if (components.length % 2 != 0) { + throw new POIXMLException("Invalid POLYLINE formula -- need 2 + n*2 arguments, got " + components.length); + } + + if (components.length > 2) { + // If xType is zero, the X coordinates are interpreted as relative coordinates + double xScale = Integer.parseInt(components[0].trim()) == 0 ? parent.getWidth() : 1.0; + // If yType is zero, the Y coordinates are interpreted as relative coordinates + double yScale = Integer.parseInt(components[1].trim()) == 0 ? parent.getHeight() : 1.0; + + for (int i = 2; i < components.length - 1; i += 2) { + double x = Double.parseDouble(components[i].trim()); + double y = Double.parseDouble(components[i + 1].trim()); + + path.lineTo(x * xScale, y * yScale); + } + } + + path.lineTo(getX(), getY()); } } |