poi-visio import: reformat code to fit project standards, remove JRE 7isms
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1709355 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3bd2011924
commit
d70b8e8b88
@ -38,9 +38,12 @@ public class XDGFException {
|
|||||||
// some idea where the error was located
|
// some idea where the error was located
|
||||||
//
|
//
|
||||||
|
|
||||||
public static POIXMLException wrap(POIXMLDocumentPart part, POIXMLException e) {
|
public static POIXMLException wrap(POIXMLDocumentPart part,
|
||||||
return new POIXMLException(part.getPackagePart().getPartName().toString() + ": " + e.getMessage(),
|
POIXMLException e) {
|
||||||
e.getCause() == null ? e : e.getCause());
|
return new POIXMLException(part.getPackagePart().getPartName()
|
||||||
|
.toString()
|
||||||
|
+ ": " + e.getMessage(), e.getCause() == null ? e
|
||||||
|
: e.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static POIXMLException wrap(String where, POIXMLException e) {
|
public static POIXMLException wrap(String where, POIXMLException e) {
|
||||||
|
@ -20,19 +20,15 @@ package org.apache.poi.xdgf.geom;
|
|||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.functions.LookupUtils.ValueVector;
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot;
|
import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart;
|
import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart;
|
||||||
|
|
||||||
import com.graphbuilder.curve.ControlPath;
|
|
||||||
import com.graphbuilder.curve.ShapeMultiPath;
|
|
||||||
import com.graphbuilder.curve.ValueVector;
|
|
||||||
import com.graphbuilder.geom.PointFactory;
|
|
||||||
|
|
||||||
public class SplineCollector {
|
public class SplineCollector {
|
||||||
|
|
||||||
SplineStart _start;
|
SplineStart _start;
|
||||||
ArrayList<SplineKnot> _knots = new ArrayList<>();
|
ArrayList<SplineKnot> _knots = new ArrayList<SplineKnot>();
|
||||||
|
|
||||||
public SplineCollector(SplineStart start) {
|
public SplineCollector(SplineStart start) {
|
||||||
_start = start;
|
_start = start;
|
||||||
|
@ -17,18 +17,12 @@
|
|||||||
|
|
||||||
package org.apache.poi.xdgf.geom;
|
package org.apache.poi.xdgf.geom;
|
||||||
|
|
||||||
import com.graphbuilder.curve.ControlPath;
|
import org.apache.poi.ss.formula.functions.LookupUtils.ValueVector;
|
||||||
import com.graphbuilder.curve.GroupIterator;
|
|
||||||
import com.graphbuilder.curve.NURBSpline;
|
|
||||||
import com.graphbuilder.curve.ShapeMultiPath;
|
|
||||||
import com.graphbuilder.curve.ValueVector;
|
|
||||||
|
|
||||||
public class SplineRenderer {
|
public class SplineRenderer {
|
||||||
|
|
||||||
public static ShapeMultiPath createNurbsSpline(ControlPath controlPoints,
|
public static ShapeMultiPath createNurbsSpline(ControlPath controlPoints,
|
||||||
ValueVector knots,
|
ValueVector knots, ValueVector weights, int degree) {
|
||||||
ValueVector weights,
|
|
||||||
int degree) {
|
|
||||||
|
|
||||||
double firstKnot = knots.get(0);
|
double firstKnot = knots.get(0);
|
||||||
double lastKnot = knots.get(knots.size() - 1);
|
double lastKnot = knots.get(knots.size() - 1);
|
||||||
|
@ -47,9 +47,9 @@ public class XDGFBaseContents extends XDGFXMLDocumentPart {
|
|||||||
protected PageContentsType _pageContents;
|
protected PageContentsType _pageContents;
|
||||||
|
|
||||||
// shapes without parents
|
// shapes without parents
|
||||||
protected List<XDGFShape> _toplevelShapes = new ArrayList<>();
|
protected List<XDGFShape> _toplevelShapes = new ArrayList<XDGFShape>();
|
||||||
protected Map<Long, XDGFShape> _shapes = new HashMap<>();
|
protected Map<Long, XDGFShape> _shapes = new HashMap<Long, XDGFShape>();
|
||||||
protected List<XDGFConnection> _connections = new ArrayList<>();
|
protected List<XDGFConnection> _connections = new ArrayList<XDGFConnection>();
|
||||||
|
|
||||||
public XDGFBaseContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFBaseContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
||||||
super(part, rel, document);
|
super(part, rel, document);
|
||||||
|
@ -25,16 +25,17 @@ import org.apache.poi.util.Internal;
|
|||||||
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There are a lot of different cell types. Cell is really just an attribute
|
* There are a lot of different cell types. Cell is really just an attribute of
|
||||||
* of the thing that it's attached to. Will probably refactor this once I
|
* the thing that it's attached to. Will probably refactor this once I figure
|
||||||
* figure out a better way to use them
|
* out a better way to use them
|
||||||
*
|
*
|
||||||
* The various attributes of a Cell are constrained, and are better defined
|
* The various attributes of a Cell are constrained, and are better defined in
|
||||||
* in the XSD 1.1 visio schema
|
* the XSD 1.1 visio schema
|
||||||
*/
|
*/
|
||||||
public class XDGFCell {
|
public class XDGFCell {
|
||||||
|
|
||||||
public static Boolean maybeGetBoolean(Map<String, XDGFCell> cells, String name) {
|
public static Boolean maybeGetBoolean(Map<String, XDGFCell> cells,
|
||||||
|
String name) {
|
||||||
XDGFCell cell = cells.get(name);
|
XDGFCell cell = cells.get(name);
|
||||||
if (cell == null)
|
if (cell == null)
|
||||||
return null;
|
return null;
|
||||||
@ -44,7 +45,8 @@ public class XDGFCell {
|
|||||||
if (cell.getValue().equals("1"))
|
if (cell.getValue().equals("1"))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
throw new POIXMLException("Invalid boolean value for '" + cell.getName() + "'");
|
throw new POIXMLException("Invalid boolean value for '"
|
||||||
|
+ cell.getName() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Double maybeGetDouble(Map<String, XDGFCell> cells, String name) {
|
public static Double maybeGetDouble(Map<String, XDGFCell> cells, String name) {
|
||||||
@ -54,7 +56,8 @@ public class XDGFCell {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer maybeGetInteger(Map<String, XDGFCell> cells, String name) {
|
public static Integer maybeGetInteger(Map<String, XDGFCell> cells,
|
||||||
|
String name) {
|
||||||
XDGFCell cell = cells.get(name);
|
XDGFCell cell = cells.get(name);
|
||||||
if (cell != null)
|
if (cell != null)
|
||||||
return parseIntegerValue(cell._cell);
|
return parseIntegerValue(cell._cell);
|
||||||
@ -78,7 +81,8 @@ public class XDGFCell {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (cell.getV().equals("Themed"))
|
if (cell.getV().equals("Themed"))
|
||||||
return null;
|
return null;
|
||||||
throw new POIXMLException("Invalid float value for '" + cell.getN() + "': " + e);
|
throw new POIXMLException("Invalid float value for '" + cell.getN()
|
||||||
|
+ "': " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +92,8 @@ public class XDGFCell {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (cell.getV().equals("Themed"))
|
if (cell.getV().equals("Themed"))
|
||||||
return null;
|
return null;
|
||||||
throw new POIXMLException("Invalid integer value for '" + cell.getN() + "': " + e);
|
throw new POIXMLException("Invalid integer value for '"
|
||||||
|
+ cell.getN() + "': " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,11 +104,11 @@ public class XDGFCell {
|
|||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
if (cell.getV().equals("Themed"))
|
if (cell.getV().equals("Themed"))
|
||||||
return null;
|
return null;
|
||||||
throw new POIXMLException("Invalid float value for '" + cell.getN() + "': " + e);
|
throw new POIXMLException("Invalid float value for '" + cell.getN()
|
||||||
|
+ "': " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CellType _cell;
|
CellType _cell;
|
||||||
|
|
||||||
public XDGFCell(CellType cell) {
|
public XDGFCell(CellType cell) {
|
||||||
@ -130,10 +135,10 @@ public class XDGFCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the element’s formula. This attribute can contain one of the following strings:
|
* Represents the element's formula. This attribute can contain one of the
|
||||||
* - ‘(some formula)’ if the formula exists locally
|
* following strings: - '(some formula)' if the formula exists locally - No
|
||||||
* - No Formula if the formula is locally deleted or blocked
|
* Formula if the formula is locally deleted or blocked - Inh if the formula
|
||||||
* - Inh if the formula is inherited.
|
* is inherited.
|
||||||
*/
|
*/
|
||||||
public String getFormula() {
|
public String getFormula() {
|
||||||
return _cell.getF();
|
return _cell.getF();
|
||||||
|
@ -44,7 +44,9 @@ public class XDGFConnection {
|
|||||||
// visEnd 12
|
// visEnd 12
|
||||||
// visFromAngle 13
|
// visFromAngle 13
|
||||||
// visFromPin 14
|
// visFromPin 14
|
||||||
// visControlPoint 100 + zero-based row index (for example, visControlPoint = 100 if the control point is in row 0; visControlPoint = 101 if the control point is in row 1)
|
// visControlPoint 100 + zero-based row index (for example, visControlPoint
|
||||||
|
// = 100 if the control point is in row 0; visControlPoint = 101 if the
|
||||||
|
// control point is in row 1)
|
||||||
|
|
||||||
public static final int visConnectFromError = -1;
|
public static final int visConnectFromError = -1;
|
||||||
public static final int visFromNone = 0;
|
public static final int visFromNone = 0;
|
||||||
@ -63,10 +65,11 @@ public class XDGFConnection {
|
|||||||
public static final int visFromAngle = 13;
|
public static final int visFromAngle = 13;
|
||||||
public static final int visFromPin = 14;
|
public static final int visFromPin = 14;
|
||||||
|
|
||||||
|
|
||||||
// The ToPart property identifies the part of a shape to which another
|
// The ToPart property identifies the part of a shape to which another
|
||||||
// shape is glued, such as its begin point or endpoint, one of its edges,
|
// shape is glued, such as its begin point or endpoint, one of its edges,
|
||||||
// or a connection point. The following constants declared by the Visio type library in member VisToParts show possible return values for the ToPart property.
|
// or a connection point. The following constants declared by the Visio type
|
||||||
|
// library in member VisToParts show possible return values for the ToPart
|
||||||
|
// property.
|
||||||
// Constant Value
|
// Constant Value
|
||||||
// visConnectToError -1
|
// visConnectToError -1
|
||||||
// visToNone 0
|
// visToNone 0
|
||||||
@ -89,7 +92,6 @@ public class XDGFConnection {
|
|||||||
private XDGFShape _from;
|
private XDGFShape _from;
|
||||||
private XDGFShape _to;
|
private XDGFShape _to;
|
||||||
|
|
||||||
|
|
||||||
public XDGFConnection(ConnectType connect, XDGFShape from, XDGFShape to) {
|
public XDGFConnection(ConnectType connect, XDGFShape from, XDGFShape to) {
|
||||||
_connect = connect;
|
_connect = connect;
|
||||||
_from = from;
|
_from = from;
|
||||||
|
@ -34,7 +34,7 @@ public class XDGFDocument {
|
|||||||
|
|
||||||
protected VisioDocumentType _document;
|
protected VisioDocumentType _document;
|
||||||
|
|
||||||
Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<>();
|
Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<Long, XDGFStyleSheet>();
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
long _defaultFillStyle = 0;
|
long _defaultFillStyle = 0;
|
||||||
|
@ -30,7 +30,8 @@ import org.apache.poi.util.POILogger;
|
|||||||
|
|
||||||
public class XDGFFactory extends POIXMLFactory {
|
public class XDGFFactory extends POIXMLFactory {
|
||||||
|
|
||||||
private static final POILogger logger = POILogFactory.getLogger(XDGFFactory.class);
|
private static final POILogger logger = POILogFactory
|
||||||
|
.getLogger(XDGFFactory.class);
|
||||||
|
|
||||||
private XDGFDocument _document;
|
private XDGFDocument _document;
|
||||||
|
|
||||||
@ -41,19 +42,27 @@ public class XDGFFactory extends POIXMLFactory {
|
|||||||
@Override
|
@Override
|
||||||
public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent,
|
public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent,
|
||||||
PackageRelationship rel, PackagePart part) {
|
PackageRelationship rel, PackagePart part) {
|
||||||
POIXMLRelation descriptor = XDGFRelation.getInstance(rel.getRelationshipType());
|
POIXMLRelation descriptor = XDGFRelation.getInstance(rel
|
||||||
|
.getRelationshipType());
|
||||||
if (descriptor == null || descriptor.getRelationClass() == null) {
|
if (descriptor == null || descriptor.getRelationClass() == null) {
|
||||||
logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
|
logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for "
|
||||||
|
+ rel.getRelationshipType());
|
||||||
return new POIXMLDocumentPart(part, rel);
|
return new POIXMLDocumentPart(part, rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
|
Class<? extends POIXMLDocumentPart> cls = descriptor
|
||||||
|
.getRelationClass();
|
||||||
try {
|
try {
|
||||||
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(POIXMLDocumentPart.class, PackagePart.class, PackageRelationship.class, XDGFDocument.class);
|
Constructor<? extends POIXMLDocumentPart> constructor = cls
|
||||||
|
.getDeclaredConstructor(POIXMLDocumentPart.class,
|
||||||
|
PackagePart.class, PackageRelationship.class,
|
||||||
|
XDGFDocument.class);
|
||||||
return constructor.newInstance(parent, part, rel, _document);
|
return constructor.newInstance(parent, part, rel, _document);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class, XDGFDocument.class);
|
Constructor<? extends POIXMLDocumentPart> constructor = cls
|
||||||
|
.getDeclaredConstructor(PackagePart.class,
|
||||||
|
PackageRelationship.class, XDGFDocument.class);
|
||||||
return constructor.newInstance(part, rel, _document);
|
return constructor.newInstance(part, rel, _document);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -64,8 +73,10 @@ public class XDGFFactory extends POIXMLFactory {
|
|||||||
@Override
|
@Override
|
||||||
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor) {
|
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor) {
|
||||||
try {
|
try {
|
||||||
Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
|
Class<? extends POIXMLDocumentPart> cls = descriptor
|
||||||
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
|
.getRelationClass();
|
||||||
|
Constructor<? extends POIXMLDocumentPart> constructor = cls
|
||||||
|
.getDeclaredConstructor();
|
||||||
return constructor.newInstance();
|
return constructor.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
|
@ -30,7 +30,8 @@ public class XDGFMaster {
|
|||||||
private XDGFMasterContents _content;
|
private XDGFMasterContents _content;
|
||||||
XDGFSheet _pageSheet = null;
|
XDGFSheet _pageSheet = null;
|
||||||
|
|
||||||
public XDGFMaster(MasterType master, XDGFMasterContents content, XDGFDocument document) {
|
public XDGFMaster(MasterType master, XDGFMasterContents content,
|
||||||
|
XDGFDocument document) {
|
||||||
_master = master;
|
_master = master;
|
||||||
_content = content;
|
_content = content;
|
||||||
content.setMaster(this);
|
content.setMaster(this);
|
||||||
|
@ -31,7 +31,8 @@ public class XDGFMasterContents extends XDGFBaseContents {
|
|||||||
|
|
||||||
private XDGFMaster _master;
|
private XDGFMaster _master;
|
||||||
|
|
||||||
public XDGFMasterContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFMasterContents(PackagePart part, PackageRelationship rel,
|
||||||
|
XDGFDocument document) {
|
||||||
super(part, rel, document);
|
super(part, rel, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,9 @@ public class XDGFMasterContents extends XDGFBaseContents {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
_pageContents = MasterContentsDocument.Factory.parse(getPackagePart().getInputStream()).getMasterContents();
|
_pageContents = MasterContentsDocument.Factory.parse(getPackagePart().getInputStream()).getMasterContents();
|
||||||
} catch (XmlException | IOException e) {
|
} catch (XmlException e) {
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
|
|||||||
MastersType _mastersObject;
|
MastersType _mastersObject;
|
||||||
|
|
||||||
// key: id of master
|
// key: id of master
|
||||||
Map<Long, XDGFMaster> _masters = new HashMap<>();
|
Map<Long, XDGFMaster> _masters = new HashMap<Long, XDGFMaster>();
|
||||||
|
|
||||||
public XDGFMasters(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFMasters(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
||||||
super(part, rel, document);
|
super(part, rel, document);
|
||||||
@ -57,11 +57,13 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
|
|||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
_mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
|
_mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
|
||||||
} catch (XmlException | IOException e) {
|
} catch (XmlException e) {
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, MasterType> masterSettings = new HashMap<>();
|
Map<String, MasterType> masterSettings = new HashMap<String, MasterType>();
|
||||||
for (MasterType master: _mastersObject.getMasterArray()) {
|
for (MasterType master: _mastersObject.getMasterArray()) {
|
||||||
masterSettings.put(master.getRel().getId(), master);
|
masterSettings.put(master.getRel().getId(), master);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,8 @@ public class XDGFPage {
|
|||||||
XDGFPages _pages;
|
XDGFPages _pages;
|
||||||
XDGFSheet _pageSheet = null;
|
XDGFSheet _pageSheet = null;
|
||||||
|
|
||||||
public XDGFPage(PageType page, XDGFPageContents content, XDGFDocument document, XDGFPages pages) {
|
public XDGFPage(PageType page, XDGFPageContents content,
|
||||||
|
XDGFDocument document, XDGFPages pages) {
|
||||||
_page = page;
|
_page = page;
|
||||||
_content = content;
|
_content = content;
|
||||||
_pages = pages;
|
_pages = pages;
|
||||||
@ -105,9 +106,7 @@ public class XDGFPage {
|
|||||||
Dimension2dDouble sz = getPageSize();
|
Dimension2dDouble sz = getPageSize();
|
||||||
Point2D.Double offset = getPageOffset();
|
Point2D.Double offset = getPageOffset();
|
||||||
|
|
||||||
return new Rectangle2D.Double(-offset.getX(),
|
return new Rectangle2D.Double(-offset.getX(), -offset.getY(),
|
||||||
-offset.getY(),
|
sz.getWidth(), sz.getHeight());
|
||||||
sz.getWidth(),
|
|
||||||
sz.getHeight());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ import com.microsoft.schemas.office.visio.x2012.main.PageContentsDocument;
|
|||||||
|
|
||||||
public class XDGFPageContents extends XDGFBaseContents {
|
public class XDGFPageContents extends XDGFBaseContents {
|
||||||
|
|
||||||
Map<Long, XDGFMaster> _masters = new HashMap<>();
|
Map<Long, XDGFMaster> _masters = new HashMap<Long, XDGFMaster>();
|
||||||
XDGFPage _page;
|
XDGFPage _page;
|
||||||
|
|
||||||
public XDGFPageContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFPageContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
||||||
@ -44,7 +44,9 @@ public class XDGFPageContents extends XDGFBaseContents {
|
|||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
_pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
|
_pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
|
||||||
} catch (XmlException | IOException e) {
|
} catch (XmlException e) {
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public class XDGFPages extends XDGFXMLDocumentPart {
|
|||||||
PagesType _pagesObject;
|
PagesType _pagesObject;
|
||||||
|
|
||||||
// ordered by page number
|
// ordered by page number
|
||||||
List<XDGFPage> _pages = new ArrayList<>();
|
List<XDGFPage> _pages = new ArrayList<XDGFPage>();
|
||||||
|
|
||||||
public XDGFPages(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFPages(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
||||||
super(part, rel, document);
|
super(part, rel, document);
|
||||||
@ -59,7 +59,9 @@ public class XDGFPages extends XDGFXMLDocumentPart {
|
|||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
|
_pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
|
||||||
} catch (XmlException | IOException e) {
|
} catch (XmlException e) {
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,62 +34,50 @@ public class XDGFRelation extends POIXMLRelation {
|
|||||||
public static final XDGFRelation DOCUMENT = new XDGFRelation(
|
public static final XDGFRelation DOCUMENT = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.drawing.main+xml",
|
"application/vnd.ms-visio.drawing.main+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/document",
|
"http://schemas.microsoft.com/visio/2010/relationships/document",
|
||||||
"/visio/document.xml",
|
"/visio/document.xml", null);
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XDGFRelation MASTERS = new XDGFRelation(
|
public static final XDGFRelation MASTERS = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.masters+xml",
|
"application/vnd.ms-visio.masters+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/masters",
|
"http://schemas.microsoft.com/visio/2010/relationships/masters",
|
||||||
"/visio/masters/masters.xml",
|
"/visio/masters/masters.xml", XDGFMasters.class);
|
||||||
XDGFMasters.class
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XDGFRelation MASTER = new XDGFRelation(
|
public static final XDGFRelation MASTER = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.master+xml",
|
"application/vnd.ms-visio.master+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/master",
|
"http://schemas.microsoft.com/visio/2010/relationships/master",
|
||||||
"/visio/masters/master#.xml",
|
"/visio/masters/master#.xml", XDGFMasterContents.class);
|
||||||
XDGFMasterContents.class
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XDGFRelation IMAGES = new XDGFRelation(
|
public static final XDGFRelation IMAGES = new XDGFRelation(null,
|
||||||
null,
|
PackageRelationshipTypes.IMAGE_PART, null, null // XSSFPictureData.class
|
||||||
PackageRelationshipTypes.IMAGE_PART,
|
|
||||||
null,
|
|
||||||
null // XSSFPictureData.class
|
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final XDGFRelation PAGES = new XDGFRelation(
|
public static final XDGFRelation PAGES = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.pages+xml",
|
"application/vnd.ms-visio.pages+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/pages",
|
"http://schemas.microsoft.com/visio/2010/relationships/pages",
|
||||||
"/visio/pages/pages.xml",
|
"/visio/pages/pages.xml", XDGFPages.class);
|
||||||
XDGFPages.class
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XDGFRelation PAGE = new XDGFRelation(
|
public static final XDGFRelation PAGE = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.page+xml",
|
"application/vnd.ms-visio.page+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/page",
|
"http://schemas.microsoft.com/visio/2010/relationships/page",
|
||||||
"/visio/pages/page#.xml",
|
"/visio/pages/page#.xml", XDGFPageContents.class);
|
||||||
XDGFPageContents.class
|
|
||||||
);
|
|
||||||
|
|
||||||
public static final XDGFRelation WINDOW = new XDGFRelation(
|
public static final XDGFRelation WINDOW = new XDGFRelation(
|
||||||
"application/vnd.ms-visio.windows+xml",
|
"application/vnd.ms-visio.windows+xml",
|
||||||
"http://schemas.microsoft.com/visio/2010/relationships/windows",
|
"http://schemas.microsoft.com/visio/2010/relationships/windows",
|
||||||
"/visio/windows.xml",
|
"/visio/windows.xml", null);
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
private XDGFRelation(String type, String rel, String defaultName, Class<? extends XDGFXMLDocumentPart> cls) {
|
private XDGFRelation(String type, String rel, String defaultName,
|
||||||
|
Class<? extends XDGFXMLDocumentPart> cls) {
|
||||||
super(type, rel, defaultName, cls);
|
super(type, rel, defaultName, cls);
|
||||||
|
|
||||||
if (cls != null && !_table.containsKey(rel)) _table.put(rel, this);
|
if (cls != null && !_table.containsKey(rel))
|
||||||
|
_table.put(rel, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get POIXMLRelation by relation type
|
* Get POIXMLRelation by relation type
|
||||||
*
|
*
|
||||||
* @param rel relation type, for example,
|
* @param rel
|
||||||
|
* relation type, for example,
|
||||||
* <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
|
* <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
|
||||||
* @return registered POIXMLRelation or null if not found
|
* @return registered POIXMLRelation or null if not found
|
||||||
*/
|
*/
|
||||||
|
@ -41,8 +41,8 @@ import com.microsoft.schemas.office.visio.x2012.main.ShapeSheetType;
|
|||||||
import com.microsoft.schemas.office.visio.x2012.main.TextType;
|
import com.microsoft.schemas.office.visio.x2012.main.TextType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A shape is a collection of Geometry Visualization, Format, Text, Images,
|
* A shape is a collection of Geometry Visualization, Format, Text, Images, and
|
||||||
* and Shape Data in a Drawing Page.
|
* Shape Data in a Drawing Page.
|
||||||
*/
|
*/
|
||||||
public class XDGFShape extends XDGFSheet {
|
public class XDGFShape extends XDGFSheet {
|
||||||
|
|
||||||
@ -102,11 +102,13 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
Double _txtWidth = null;
|
Double _txtWidth = null;
|
||||||
Double _txtHeight = null;
|
Double _txtHeight = null;
|
||||||
|
|
||||||
public XDGFShape(ShapeSheetType shapeSheet, XDGFBaseContents parentPage, XDGFDocument document) {
|
public XDGFShape(ShapeSheetType shapeSheet, XDGFBaseContents parentPage,
|
||||||
|
XDGFDocument document) {
|
||||||
this(null, shapeSheet, parentPage, document);
|
this(null, shapeSheet, parentPage, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet, XDGFBaseContents parentPage, XDGFDocument document) {
|
public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet,
|
||||||
|
XDGFBaseContents parentPage, XDGFDocument document) {
|
||||||
|
|
||||||
super(shapeSheet, document);
|
super(shapeSheet, document);
|
||||||
|
|
||||||
@ -168,21 +170,22 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
/**
|
/**
|
||||||
* Setup top level shapes
|
* Setup top level shapes
|
||||||
*
|
*
|
||||||
* Shapes that have a 'Master' attribute refer to a specific master in
|
* Shapes that have a 'Master' attribute refer to a specific master in the
|
||||||
* the page, whereas shapes with a 'MasterShape' attribute refer to a
|
* page, whereas shapes with a 'MasterShape' attribute refer to a subshape
|
||||||
* subshape of a Master.
|
* of a Master.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected void setupMaster(XDGFPageContents pageContents, XDGFMasterContents master) {
|
protected void setupMaster(XDGFPageContents pageContents,
|
||||||
|
XDGFMasterContents master) {
|
||||||
|
|
||||||
ShapeSheetType obj = getXmlObject();
|
ShapeSheetType obj = getXmlObject();
|
||||||
|
|
||||||
if (obj.isSetMaster()) {
|
if (obj.isSetMaster()) {
|
||||||
_master = pageContents.getMasterById(obj.getMaster());
|
_master = pageContents.getMasterById(obj.getMaster());
|
||||||
if (_master == null)
|
if (_master == null)
|
||||||
throw XDGFException.error("refers to non-existant master " + obj.getMaster(),
|
throw XDGFException.error("refers to non-existant master "
|
||||||
this);
|
+ obj.getMaster(), this);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If a master has one top-level shape, a shape that inherits from
|
* If a master has one top-level shape, a shape that inherits from
|
||||||
@ -192,11 +195,14 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
* subshapes.
|
* subshapes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Collection<XDGFShape> masterShapes = _master.getContent().getTopLevelShapes();
|
Collection<XDGFShape> masterShapes = _master.getContent()
|
||||||
|
.getTopLevelShapes();
|
||||||
|
|
||||||
switch (masterShapes.size()) {
|
switch (masterShapes.size()) {
|
||||||
case 0:
|
case 0:
|
||||||
throw XDGFException.error("Could not retrieve master shape from " + _master, this);
|
throw XDGFException
|
||||||
|
.error("Could not retrieve master shape from "
|
||||||
|
+ _master, this);
|
||||||
case 1:
|
case 1:
|
||||||
_masterShape = masterShapes.iterator().next();
|
_masterShape = masterShapes.iterator().next();
|
||||||
break;
|
break;
|
||||||
@ -207,8 +213,9 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
} else if (obj.isSetMasterShape()) {
|
} else if (obj.isSetMasterShape()) {
|
||||||
_masterShape = master.getShapeById(obj.getMasterShape());
|
_masterShape = master.getShapeById(obj.getMasterShape());
|
||||||
if (_masterShape == null)
|
if (_masterShape == null)
|
||||||
throw XDGFException.error("refers to non-existant master shape " + obj.getMasterShape(),
|
throw XDGFException.error(
|
||||||
this);
|
"refers to non-existant master shape "
|
||||||
|
+ obj.getMasterShape(), this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,8 +223,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
|
|
||||||
if (_shapes != null) {
|
if (_shapes != null) {
|
||||||
for (XDGFShape shape : _shapes) {
|
for (XDGFShape shape : _shapes) {
|
||||||
shape.setupMaster(pageContents,
|
shape.setupMaster(pageContents, _master == null ? master
|
||||||
_master == null ? master : _master.getContent());
|
: _master.getContent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,7 +242,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<Long, GeometrySection> section : _geometry.entrySet()) {
|
for (Entry<Long, GeometrySection> section : _geometry.entrySet()) {
|
||||||
GeometrySection master = _masterShape.getGeometryByIdx(section.getKey());
|
GeometrySection master = _masterShape.getGeometryByIdx(section
|
||||||
|
.getKey());
|
||||||
if (master != null)
|
if (master != null)
|
||||||
section.getValue().setupMaster(master);
|
section.getValue().setupMaster(master);
|
||||||
}
|
}
|
||||||
@ -244,6 +252,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Internal
|
@Internal
|
||||||
public ShapeSheetType getXmlObject() {
|
public ShapeSheetType getXmlObject() {
|
||||||
return (ShapeSheetType) _sheet;
|
return (ShapeSheetType) _sheet;
|
||||||
@ -266,7 +275,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasText() {
|
public boolean hasText() {
|
||||||
return _text != null || (_masterShape != null && _masterShape._text != null);
|
return _text != null
|
||||||
|
|| (_masterShape != null && _masterShape._text != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -485,8 +495,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getTxtPinX() {
|
public Double getTxtPinX() {
|
||||||
if (_txtPinX == null &&
|
if (_txtPinX == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtPinX != null)
|
&& _masterShape._txtPinX != null)
|
||||||
return _masterShape._txtPinX;
|
return _masterShape._txtPinX;
|
||||||
|
|
||||||
if (_txtPinX == null)
|
if (_txtPinX == null)
|
||||||
@ -495,10 +505,9 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return _txtPinX;
|
return _txtPinX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getTxtPinY() {
|
public Double getTxtPinY() {
|
||||||
if (_txtLocPinY == null &&
|
if (_txtLocPinY == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtLocPinY != null)
|
&& _masterShape._txtLocPinY != null)
|
||||||
return _masterShape._txtLocPinY;
|
return _masterShape._txtLocPinY;
|
||||||
|
|
||||||
if (_txtPinY == null)
|
if (_txtPinY == null)
|
||||||
@ -507,10 +516,9 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return _txtPinY;
|
return _txtPinY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getTxtLocPinX() {
|
public Double getTxtLocPinX() {
|
||||||
if (_txtLocPinX == null &&
|
if (_txtLocPinX == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtLocPinX != null)
|
&& _masterShape._txtLocPinX != null)
|
||||||
return _masterShape._txtLocPinX;
|
return _masterShape._txtLocPinX;
|
||||||
|
|
||||||
if (_txtLocPinX == null)
|
if (_txtLocPinX == null)
|
||||||
@ -519,10 +527,9 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return _txtLocPinX;
|
return _txtLocPinX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getTxtLocPinY() {
|
public Double getTxtLocPinY() {
|
||||||
if (_txtLocPinY == null &&
|
if (_txtLocPinY == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtLocPinY != null)
|
&& _masterShape._txtLocPinY != null)
|
||||||
return _masterShape._txtLocPinY;
|
return _masterShape._txtLocPinY;
|
||||||
|
|
||||||
if (_txtLocPinY == null)
|
if (_txtLocPinY == null)
|
||||||
@ -539,8 +546,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Double getTxtWidth() {
|
public Double getTxtWidth() {
|
||||||
if (_txtWidth == null &&
|
if (_txtWidth == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtWidth != null)
|
&& _masterShape._txtWidth != null)
|
||||||
return _masterShape._txtWidth;
|
return _masterShape._txtWidth;
|
||||||
|
|
||||||
if (_txtWidth == null)
|
if (_txtWidth == null)
|
||||||
@ -549,10 +556,9 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return _txtWidth;
|
return _txtWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Double getTxtHeight() {
|
public Double getTxtHeight() {
|
||||||
if (_txtHeight == null &&
|
if (_txtHeight == null && _masterShape != null
|
||||||
_masterShape != null && _masterShape._txtHeight != null)
|
&& _masterShape._txtHeight != null)
|
||||||
return _masterShape._txtHeight;
|
return _masterShape._txtHeight;
|
||||||
|
|
||||||
if (_txtHeight == null)
|
if (_txtHeight == null)
|
||||||
@ -641,6 +647,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Color getFontColor() {
|
public Color getFontColor() {
|
||||||
|
|
||||||
Color fontColor = super.getFontColor();
|
Color fontColor = super.getFontColor();
|
||||||
@ -660,6 +667,7 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Double getFontSize() {
|
public Double getFontSize() {
|
||||||
|
|
||||||
Double fontSize = super.getFontSize();
|
Double fontSize = super.getFontSize();
|
||||||
@ -790,21 +798,18 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return new BasicStroke(lineWeight, cap, join, miterlimit, dash, 0);
|
return new BasicStroke(lineWeight, cap, join, miterlimit, dash, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Geometry
|
// Geometry
|
||||||
//
|
//
|
||||||
|
|
||||||
public Iterable<GeometrySection> getGeometrySections() {
|
public Iterable<GeometrySection> getGeometrySections() {
|
||||||
return new CombinedIterable<>(_geometry,
|
return new CombinedIterable<GeometrySection>(_geometry,
|
||||||
_masterShape != null ? _masterShape._geometry : null);
|
_masterShape != null ? _masterShape._geometry : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// returns a rectangle in local coordinates
|
// returns a rectangle in local coordinates
|
||||||
public Rectangle2D.Double getBounds() {
|
public Rectangle2D.Double getBounds() {
|
||||||
return new Rectangle2D.Double(0, 0, getWidth(),
|
return new Rectangle2D.Double(0, 0, getWidth(), getHeight());
|
||||||
getHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns bounds as a path in local coordinates
|
// returns bounds as a path in local coordinates
|
||||||
@ -849,8 +854,8 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a transform that can translate shape-local coordinates
|
* Returns a transform that can translate shape-local coordinates to the
|
||||||
* to the coordinates of its parent shape
|
* coordinates of its parent shape
|
||||||
*/
|
*/
|
||||||
protected AffineTransform getParentTransform() {
|
protected AffineTransform getParentTransform() {
|
||||||
// TODO: There's probably a better way to do this
|
// TODO: There's probably a better way to do this
|
||||||
@ -886,8 +891,6 @@ public class XDGFShape extends XDGFSheet {
|
|||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The visitor will first visit this shape, then it's children
|
* The visitor will first visit this shape, then it's children
|
||||||
*
|
*
|
||||||
|
@ -43,13 +43,13 @@ public abstract class XDGFSheet {
|
|||||||
protected SheetType _sheet;
|
protected SheetType _sheet;
|
||||||
|
|
||||||
// cells
|
// cells
|
||||||
protected Map<String, XDGFCell> _cells = new HashMap<>();
|
protected Map<String, XDGFCell> _cells = new HashMap<String, XDGFCell>();
|
||||||
|
|
||||||
// sections
|
// sections
|
||||||
protected Map<String, XDGFSection> _sections = new HashMap<>();
|
protected Map<String, XDGFSection> _sections = new HashMap<String, XDGFSection>();
|
||||||
|
|
||||||
// special: geometry sections (key: index, value: section)
|
// special: geometry sections (key: index, value: section)
|
||||||
protected SortedMap<Long, GeometrySection> _geometry = new TreeMap<>();
|
protected SortedMap<Long, GeometrySection> _geometry = new TreeMap<Long, GeometrySection>();
|
||||||
|
|
||||||
// special: character section
|
// special: character section
|
||||||
protected CharacterSection _character = null;
|
protected CharacterSection _character = null;
|
||||||
|
@ -27,10 +27,10 @@ public class XDGFStyleSheet extends XDGFSheet {
|
|||||||
super(styleSheet, document);
|
super(styleSheet, document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Internal
|
@Internal
|
||||||
public StyleSheetType getXmlObject() {
|
public StyleSheetType getXmlObject() {
|
||||||
return (StyleSheetType) _sheet;
|
return (StyleSheetType) _sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,8 @@ public class XDGFText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// these are in the shape coordinate system
|
// these are in the shape coordinate system
|
||||||
// -> See https://msdn.microsoft.com/en-us/library/hh644132(v=office.12).aspx
|
// -> See
|
||||||
|
// https://msdn.microsoft.com/en-us/library/hh644132(v=office.12).aspx
|
||||||
public Rectangle2D.Double getTextBounds() {
|
public Rectangle2D.Double getTextBounds() {
|
||||||
|
|
||||||
double txtPinX = _parent.getTxtPinX();
|
double txtPinX = _parent.getTxtPinX();
|
||||||
@ -92,7 +93,8 @@ public class XDGFText {
|
|||||||
|
|
||||||
// center of text in local coordinates
|
// center of text in local coordinates
|
||||||
public Point2D.Double getTextCenter() {
|
public Point2D.Double getTextCenter() {
|
||||||
return new Point2D.Double(_parent.getTxtLocPinX(), _parent.getTxtLocPinY());
|
return new Point2D.Double(_parent.getTxtLocPinX(),
|
||||||
|
_parent.getTxtLocPinY());
|
||||||
}
|
}
|
||||||
|
|
||||||
// assumes graphics is set properly to draw in the right style
|
// assumes graphics is set properly to draw in the right style
|
||||||
@ -110,14 +112,17 @@ public class XDGFText {
|
|||||||
|
|
||||||
AffineTransform oldTr = graphics.getTransform();
|
AffineTransform oldTr = graphics.getTransform();
|
||||||
|
|
||||||
// visio is in flipped coordinates, so translate the text to be in the right place
|
// visio is in flipped coordinates, so translate the text to be in the
|
||||||
|
// right place
|
||||||
Boolean flipX = _parent.getFlipX();
|
Boolean flipX = _parent.getFlipX();
|
||||||
Boolean flipY = _parent.getFlipY();
|
Boolean flipY = _parent.getFlipY();
|
||||||
|
|
||||||
if (flipY == null || !_parent.getFlipY()) {
|
if (flipY == null || !_parent.getFlipY()) {
|
||||||
graphics.translate(bounds.x, bounds.y);
|
graphics.translate(bounds.x, bounds.y);
|
||||||
graphics.scale(1, -1);
|
graphics.scale(1, -1);
|
||||||
graphics.translate(0, -bounds.height + graphics.getFontMetrics().getMaxCharBounds(graphics).getHeight());
|
graphics.translate(0, -bounds.height
|
||||||
|
+ graphics.getFontMetrics().getMaxCharBounds(graphics)
|
||||||
|
.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flipX != null && _parent.getFlipX()) {
|
if (flipX != null && _parent.getFlipX()) {
|
||||||
@ -140,9 +145,11 @@ public class XDGFText {
|
|||||||
if (layout.isLeftToRight())
|
if (layout.isLeftToRight())
|
||||||
layout.draw(graphics, 0, nextY);
|
layout.draw(graphics, 0, nextY);
|
||||||
else
|
else
|
||||||
layout.draw(graphics, (float)(bounds.width - layout.getAdvance()), nextY);
|
layout.draw(graphics,
|
||||||
|
(float) (bounds.width - layout.getAdvance()), nextY);
|
||||||
|
|
||||||
nextY += layout.getAscent() + layout.getDescent() + layout.getLeading();
|
nextY += layout.getAscent() + layout.getDescent()
|
||||||
|
+ layout.getLeading();
|
||||||
}
|
}
|
||||||
|
|
||||||
graphics.setTransform(oldTr);
|
graphics.setTransform(oldTr);
|
||||||
|
@ -42,7 +42,6 @@ public class XmlVisioDocument extends POIXMLDocument {
|
|||||||
XDGFMasters _masters;
|
XDGFMasters _masters;
|
||||||
XDGFDocument _document;
|
XDGFDocument _document;
|
||||||
|
|
||||||
|
|
||||||
public XmlVisioDocument(OPCPackage pkg) throws IOException {
|
public XmlVisioDocument(OPCPackage pkg) throws IOException {
|
||||||
super(pkg, CORE_DOCUMENT);
|
super(pkg, CORE_DOCUMENT);
|
||||||
|
|
||||||
@ -50,7 +49,9 @@ public class XmlVisioDocument extends POIXMLDocument {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
document = VisioDocumentDocument1.Factory.parse(getPackagePart().getInputStream()).getVisioDocument();
|
document = VisioDocumentDocument1.Factory.parse(getPackagePart().getInputStream()).getVisioDocument();
|
||||||
} catch (XmlException | IOException e) {
|
} catch (XmlException e) {
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +65,6 @@ public class XmlVisioDocument extends POIXMLDocument {
|
|||||||
this(PackageHelper.open(is));
|
this(PackageHelper.open(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDocumentRead() throws IOException {
|
protected void onDocumentRead() throws IOException {
|
||||||
|
|
||||||
@ -90,8 +90,6 @@ public class XmlVisioDocument extends POIXMLDocument {
|
|||||||
_pages.onDocumentRead();
|
_pages.onDocumentRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
|
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
throw new UnsupportedOperationException("Not implemented");
|
||||||
@ -105,7 +103,6 @@ public class XmlVisioDocument extends POIXMLDocument {
|
|||||||
return _pages.getPageList();
|
return _pages.getPageList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public XDGFStyleSheet getStyleById(long id) {
|
public XDGFStyleSheet getStyleById(long id) {
|
||||||
return _document.getStyleById(id);
|
return _document.getStyleById(id);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class CharacterSection extends XDGFSection {
|
|||||||
Double _fontSize = null;
|
Double _fontSize = null;
|
||||||
Color _fontColor = null;
|
Color _fontColor = null;
|
||||||
|
|
||||||
Map<String, XDGFCell> _characterCells = new HashMap<>();
|
Map<String, XDGFCell> _characterCells = new HashMap<String, XDGFCell>();
|
||||||
|
|
||||||
public CharacterSection(SectionType section, XDGFSheet containingSheet) {
|
public CharacterSection(SectionType section, XDGFSheet containingSheet) {
|
||||||
super(section, containingSheet);
|
super(section, containingSheet);
|
||||||
|
@ -19,9 +19,9 @@ package org.apache.poi.xdgf.usermodel.section;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
// iterates over the base and master
|
// iterates over the base and master
|
||||||
public class CombinedIterable<T> implements Iterable<T> {
|
public class CombinedIterable<T> implements Iterable<T> {
|
||||||
@ -58,7 +58,8 @@ public class CombinedIterable<T> implements Iterable<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
return currentBase != null || currentMaster != null || baseI.hasNext() || masterI.hasNext();
|
return currentBase != null || currentMaster != null
|
||||||
|
|| baseI.hasNext() || masterI.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,9 +29,9 @@ import org.apache.poi.xdgf.usermodel.XDGFCell;
|
|||||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFSheet;
|
import org.apache.poi.xdgf.usermodel.XDGFSheet;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.Ellipse;
|
import org.apache.poi.xdgf.usermodel.section.geometry.Ellipse;
|
||||||
|
import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRowFactory;
|
import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRowFactory;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine;
|
import org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow;
|
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot;
|
import org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot;
|
||||||
import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart;
|
import org.apache.poi.xdgf.usermodel.section.geometry.SplineStart;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class GeometrySection extends XDGFSection {
|
|||||||
GeometrySection _master = null;
|
GeometrySection _master = null;
|
||||||
|
|
||||||
// rows
|
// rows
|
||||||
SortedMap<Long, GeometryRow> _rows = new TreeMap<>();
|
SortedMap<Long, GeometryRow> _rows = new TreeMap<Long, GeometryRow>();
|
||||||
|
|
||||||
public GeometrySection(SectionType section, XDGFSheet containingSheet) {
|
public GeometrySection(SectionType section, XDGFSheet containingSheet) {
|
||||||
super(section, containingSheet);
|
super(section, containingSheet);
|
||||||
@ -89,7 +89,7 @@ public class GeometrySection extends XDGFSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<GeometryRow> getCombinedRows() {
|
public Iterable<GeometryRow> getCombinedRows() {
|
||||||
return new CombinedIterable<>(_rows,
|
return new CombinedIterable<GeometryRow>(_rows,
|
||||||
_master == null ? null : _master._rows);
|
_master == null ? null : _master._rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public abstract class XDGFSection {
|
|||||||
static final ObjectFactory<XDGFSection, SectionType> _sectionTypes;
|
static final ObjectFactory<XDGFSection, SectionType> _sectionTypes;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_sectionTypes = new ObjectFactory<>();
|
_sectionTypes = new ObjectFactory<XDGFSection, SectionType>();
|
||||||
try {
|
try {
|
||||||
_sectionTypes.put("LineGradient", GenericSection.class, SectionType.class, XDGFSheet.class);
|
_sectionTypes.put("LineGradient", GenericSection.class, SectionType.class, XDGFSheet.class);
|
||||||
_sectionTypes.put("FillGradient", GenericSection.class, SectionType.class, XDGFSheet.class);
|
_sectionTypes.put("FillGradient", GenericSection.class, SectionType.class, XDGFSheet.class);
|
||||||
@ -55,7 +55,9 @@ public abstract class XDGFSection {
|
|||||||
_sectionTypes.put("Reviewer", GenericSection.class, SectionType.class, XDGFSheet.class);
|
_sectionTypes.put("Reviewer", GenericSection.class, SectionType.class, XDGFSheet.class);
|
||||||
_sectionTypes.put("Annotation", GenericSection.class, SectionType.class, XDGFSheet.class);
|
_sectionTypes.put("Annotation", GenericSection.class, SectionType.class, XDGFSheet.class);
|
||||||
_sectionTypes.put("ActionTag", GenericSection.class, SectionType.class, XDGFSheet.class);
|
_sectionTypes.put("ActionTag", GenericSection.class, SectionType.class, XDGFSheet.class);
|
||||||
} catch (NoSuchMethodException | SecurityException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new POIXMLException("Internal error");
|
||||||
|
} catch (SecurityException e) {
|
||||||
throw new POIXMLException("Internal error");
|
throw new POIXMLException("Internal error");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +71,7 @@ public abstract class XDGFSection {
|
|||||||
protected SectionType _section;
|
protected SectionType _section;
|
||||||
protected XDGFSheet _containingSheet;
|
protected XDGFSheet _containingSheet;
|
||||||
|
|
||||||
protected Map<String, XDGFCell> _cells = new HashMap<>();
|
protected Map<String, XDGFCell> _cells = new HashMap<String, XDGFCell>();
|
||||||
|
|
||||||
|
|
||||||
public XDGFSection(SectionType section, XDGFSheet containingSheet) {
|
public XDGFSection(SectionType section, XDGFSheet containingSheet) {
|
||||||
|
@ -48,7 +48,8 @@ public class ArcTo implements GeometryRow {
|
|||||||
|
|
||||||
public ArcTo(RowType row) {
|
public ArcTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -60,7 +61,8 @@ public class ArcTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("A")) {
|
} else if (cellName.equals("A")) {
|
||||||
a = XDGFCell.parseDoubleValue(cell);
|
a = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in ArcTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in ArcTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +97,8 @@ public class ArcTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(Path2D.Double path, XDGFShape parent) {
|
public void addToPath(Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
Point2D last = path.getCurrentPoint();
|
Point2D last = path.getCurrentPoint();
|
||||||
|
|
||||||
@ -113,7 +116,8 @@ public class ArcTo implements GeometryRow {
|
|||||||
double y0 = last.getY();
|
double y0 = last.getY();
|
||||||
|
|
||||||
double chordLength = Math.hypot(y - y0, x - x0);
|
double chordLength = Math.hypot(y - y0, x - x0);
|
||||||
double radius = (4 * a * a + chordLength * chordLength) / (8 * Math.abs(a));
|
double radius = (4 * a * a + chordLength * chordLength)
|
||||||
|
/ (8 * Math.abs(a));
|
||||||
|
|
||||||
// center point
|
// center point
|
||||||
double cx = x0 + (x - x0) / 2.0;
|
double cx = x0 + (x - x0) / 2.0;
|
||||||
@ -121,11 +125,10 @@ public class ArcTo implements GeometryRow {
|
|||||||
|
|
||||||
double rotate = Math.atan2(y - cy, x - cx);
|
double rotate = Math.atan2(y - cy, x - cx);
|
||||||
|
|
||||||
Arc2D arc = new Arc2D.Double(x0, y0 - radius,
|
Arc2D arc = new Arc2D.Double(x0, y0 - radius, chordLength, 2 * radius,
|
||||||
chordLength, 2*radius,
|
180, x0 < x ? 180 : -180, Arc2D.OPEN);
|
||||||
180, x0 < x ? 180 : -180,
|
|
||||||
Arc2D.OPEN);
|
|
||||||
|
|
||||||
path.append(AffineTransform.getRotateInstance(rotate, x0, y0).createTransformedShape(arc), true);
|
path.append(AffineTransform.getRotateInstance(rotate, x0, y0)
|
||||||
|
.createTransformedShape(arc), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,8 @@ public class Ellipse implements GeometryRow {
|
|||||||
|
|
||||||
public Ellipse(RowType row) {
|
public Ellipse(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -71,7 +72,8 @@ public class Ellipse implements GeometryRow {
|
|||||||
} else if (cellName.equals("D")) {
|
} else if (cellName.equals("D")) {
|
||||||
d = XDGFCell.parseDoubleValue(cell);
|
d = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in Ellipse row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in Ellipse row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +119,8 @@ public class Ellipse implements GeometryRow {
|
|||||||
|
|
||||||
public Path2D.Double getPath() {
|
public Path2D.Double getPath() {
|
||||||
|
|
||||||
if (getDel()) return null;
|
if (getDel())
|
||||||
|
return null;
|
||||||
|
|
||||||
// intentionally shadowing variables here
|
// intentionally shadowing variables here
|
||||||
double cx = getX(); // center
|
double cx = getX(); // center
|
||||||
@ -132,11 +135,12 @@ public class Ellipse implements GeometryRow {
|
|||||||
double ry = Math.hypot(c - cx, d - cy);
|
double ry = Math.hypot(c - cx, d - cy);
|
||||||
|
|
||||||
// compute angle of ellipse
|
// compute angle of ellipse
|
||||||
double angle = (2.0*Math.PI + (cy > b ? 1.0 : -1.0) * Math.acos((cx - a) / rx)) % (2.0*Math.PI);
|
double angle = (2.0 * Math.PI + (cy > b ? 1.0 : -1.0)
|
||||||
|
* Math.acos((cx - a) / rx))
|
||||||
|
% (2.0 * Math.PI);
|
||||||
|
|
||||||
// create ellipse
|
// create ellipse
|
||||||
Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx,
|
Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx, cy - ry,
|
||||||
cy - ry,
|
|
||||||
rx * 2, ry * 2);
|
rx * 2, ry * 2);
|
||||||
|
|
||||||
// create a path, rotate it about its center
|
// create a path, rotate it about its center
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.poi.xdgf.usermodel.section.geometry;
|
|||||||
|
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.Arc2D;
|
import java.awt.geom.Arc2D;
|
||||||
import java.awt.geom.Path2D;
|
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
@ -49,7 +48,8 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
// The y-coordinate of an arc's control point.
|
// The y-coordinate of an arc's control point.
|
||||||
Double b = null;
|
Double b = null;
|
||||||
|
|
||||||
// The angle of an arc's major axis relative to the x-axis of its parent shape.
|
// The angle of an arc's major axis relative to the x-axis of its parent
|
||||||
|
// shape.
|
||||||
Double c = null;
|
Double c = null;
|
||||||
|
|
||||||
// The ratio of an arc's major axis to its minor axis. Despite the usual
|
// The ratio of an arc's major axis to its minor axis. Despite the usual
|
||||||
@ -65,7 +65,8 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
|
|
||||||
public EllipticalArcTo(RowType row) {
|
public EllipticalArcTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -83,7 +84,8 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("D")) {
|
} else if (cellName.equals("D")) {
|
||||||
d = XDGFCell.parseDoubleValue(cell);
|
d = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in EllipticalArcTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in EllipticalArcTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +124,6 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
return d == null ? _master.d : d;
|
return d == null ? _master.d : d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupMaster(GeometryRow row) {
|
public void setupMaster(GeometryRow row) {
|
||||||
_master = (EllipticalArcTo) row;
|
_master = (EllipticalArcTo) row;
|
||||||
@ -133,7 +134,8 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
// intentionally shadowing variables here
|
// intentionally shadowing variables here
|
||||||
double x = getX();
|
double x = getX();
|
||||||
@ -146,17 +148,18 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
createEllipticalArc(x, y, a, b, c, d, path);
|
createEllipticalArc(x, y, a, b, c, d, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createEllipticalArc(double x, double y, double a, double b,
|
public static void createEllipticalArc(double x, double y, double a,
|
||||||
double c, double d,
|
double b, double c, double d, java.awt.geom.Path2D.Double path) {
|
||||||
java.awt.geom.Path2D.Double path) {
|
|
||||||
|
|
||||||
// Formula for center of ellipse by Junichi Yoda & nashwaan:
|
// Formula for center of ellipse by Junichi Yoda & nashwaan:
|
||||||
// -> From http://visguy.com/vgforum/index.php?topic=2464.0
|
// -> From http://visguy.com/vgforum/index.php?topic=2464.0
|
||||||
//
|
//
|
||||||
// x1,y1 = start; x2,y2 = end; x3,y3 = control point
|
// x1,y1 = start; x2,y2 = end; x3,y3 = control point
|
||||||
//
|
//
|
||||||
// x0 = ((x1-x2)*(x1+x2)*(y2-y3)-(x2-x3)*(x2+x3)*(y1-y2)+D^2*(y1-y2)*(y2-y3)*(y1-y3))/(2*((x1-x2)*(y2-y3)-(x2-x3)*(y1-y2)))
|
// x0 =
|
||||||
// y0 = ((x1-x2)*(x2-x3)*(x1-x3)/D^2+(x2-x3)*(y1-y2)*(y1+y2)-(x1-x2)*(y2-y3)*(y2+y3))/(2*((x2-x3)*(y1-y2)-(x1-x2)*(y2-y3)))
|
// ((x1-x2)*(x1+x2)*(y2-y3)-(x2-x3)*(x2+x3)*(y1-y2)+D^2*(y1-y2)*(y2-y3)*(y1-y3))/(2*((x1-x2)*(y2-y3)-(x2-x3)*(y1-y2)))
|
||||||
|
// y0 =
|
||||||
|
// ((x1-x2)*(x2-x3)*(x1-x3)/D^2+(x2-x3)*(y1-y2)*(y1+y2)-(x1-x2)*(y2-y3)*(y2+y3))/(2*((x2-x3)*(y1-y2)-(x1-x2)*(y2-y3)))
|
||||||
// radii along axis: a = sqrt{ (x1-x0)^2 + (y1-y0)^2 * D^2 }
|
// radii along axis: a = sqrt{ (x1-x0)^2 + (y1-y0)^2 * D^2 }
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -169,41 +172,53 @@ public class EllipticalArcTo implements GeometryRow {
|
|||||||
double[] pts = new double[] { x0, y0, x, y, a, b };
|
double[] pts = new double[] { x0, y0, x, y, a, b };
|
||||||
at.transform(pts, 0, pts, 0, 3);
|
at.transform(pts, 0, pts, 0, 3);
|
||||||
|
|
||||||
|
x0 = pts[0];
|
||||||
x0 = pts[0]; y0 = pts[1];
|
y0 = pts[1];
|
||||||
x = pts[2]; y = pts[3];
|
x = pts[2];
|
||||||
a = pts[4]; b = pts[5];
|
y = pts[3];
|
||||||
|
a = pts[4];
|
||||||
|
b = pts[5];
|
||||||
|
|
||||||
// nasty math time
|
// nasty math time
|
||||||
|
|
||||||
double d2 = d * d;
|
double d2 = d * d;
|
||||||
double cx = ((x0-x)*(x0+x)*(y-b)-(x-a)*(x+a)*(y0-y)+d2*(y0-y)*(y-b)*(y0-b))/(2.0*((x0-x)*(y-b)-(x-a)*(y0-y)));
|
double cx = ((x0 - x) * (x0 + x) * (y - b) - (x - a) * (x + a)
|
||||||
double cy = ((x0-x)*(x-a)*(x0-a)/d2+(x-a)*(y0-y)*(y0+y)-(x0-x)*(y-b)*(y+b))/(2.0*((x-a)*(y0-y)-(x0-x)*(y-b)));
|
* (y0 - y) + d2 * (y0 - y) * (y - b) * (y0 - b))
|
||||||
|
/ (2.0 * ((x0 - x) * (y - b) - (x - a) * (y0 - y)));
|
||||||
|
double cy = ((x0 - x) * (x - a) * (x0 - a) / d2 + (x - a) * (y0 - y)
|
||||||
|
* (y0 + y) - (x0 - x) * (y - b) * (y + b))
|
||||||
|
/ (2.0 * ((x - a) * (y0 - y) - (x0 - x) * (y - b)));
|
||||||
|
|
||||||
// calculate radii of ellipse
|
// calculate radii of ellipse
|
||||||
double rx = Math.sqrt(Math.pow(x0 - cx, 2) + Math.pow(y0 - cy, 2) * d2);
|
double rx = Math.sqrt(Math.pow(x0 - cx, 2) + Math.pow(y0 - cy, 2) * d2);
|
||||||
double ry = rx / d;
|
double ry = rx / d;
|
||||||
|
|
||||||
// Arc2D requires us to draw an arc from one point to another, so we
|
// Arc2D requires us to draw an arc from one point to another, so we
|
||||||
// need to calculate the angle of the start point and end point along the ellipse
|
// need to calculate the angle of the start point and end point along
|
||||||
// - Derived from parametric form of ellipse: x = h + a*cos(t); y = k + b*sin(t)
|
// the ellipse
|
||||||
|
// - Derived from parametric form of ellipse: x = h + a*cos(t); y = k +
|
||||||
|
// b*sin(t)
|
||||||
|
|
||||||
double ctrlAngle = Math.toDegrees(Math.atan2((b-cy)/ry, (a-cx)/rx));
|
double ctrlAngle = Math.toDegrees(Math.atan2((b - cy) / ry, (a - cx)
|
||||||
double startAngle = Math.toDegrees(Math.atan2((y0-cy)/ry, (x0-cx)/rx));
|
/ rx));
|
||||||
double endAngle = Math.toDegrees(Math.atan2((y-cy)/ry, (x-cx)/rx));
|
double startAngle = Math.toDegrees(Math.atan2((y0 - cy) / ry, (x0 - cx)
|
||||||
|
/ rx));
|
||||||
|
double endAngle = Math.toDegrees(Math.atan2((y - cy) / ry, (x - cx)
|
||||||
|
/ rx));
|
||||||
|
|
||||||
double sweep = computeSweep(startAngle, endAngle, ctrlAngle);
|
double sweep = computeSweep(startAngle, endAngle, ctrlAngle);
|
||||||
|
|
||||||
// Now we have enough information to go on. Create the arc.
|
// Now we have enough information to go on. Create the arc.
|
||||||
Arc2D arc = new Arc2D.Double(cx-rx, cy-ry,
|
Arc2D arc = new Arc2D.Double(cx - rx, cy - ry, rx * 2, ry * 2,
|
||||||
rx*2, ry*2, -startAngle, sweep, Arc2D.OPEN);
|
-startAngle, sweep, Arc2D.OPEN);
|
||||||
|
|
||||||
// rotate the arc back to the original coordinate system
|
// rotate the arc back to the original coordinate system
|
||||||
at.setToRotation(c);
|
at.setToRotation(c);
|
||||||
path.append(at.createTransformedShape(arc), false);
|
path.append(at.createTransformedShape(arc), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static double computeSweep(double startAngle, double endAngle, double ctrlAngle) {
|
protected static double computeSweep(double startAngle, double endAngle,
|
||||||
|
double ctrlAngle) {
|
||||||
double sweep;
|
double sweep;
|
||||||
|
|
||||||
startAngle = (360.0 + startAngle) % 360.0;
|
startAngle = (360.0 + startAngle) % 360.0;
|
||||||
|
@ -21,7 +21,6 @@ import java.awt.geom.Path2D;
|
|||||||
|
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||||
|
|
||||||
|
|
||||||
public interface GeometryRow {
|
public interface GeometryRow {
|
||||||
|
|
||||||
public void setupMaster(GeometryRow row);
|
public void setupMaster(GeometryRow row);
|
||||||
|
@ -27,24 +27,28 @@ public class GeometryRowFactory {
|
|||||||
static final ObjectFactory<GeometryRow, RowType> _rowTypes;
|
static final ObjectFactory<GeometryRow, RowType> _rowTypes;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
_rowTypes = new ObjectFactory<>();
|
_rowTypes = new ObjectFactory<GeometryRow, RowType>();
|
||||||
try {
|
try {
|
||||||
_rowTypes.put("ArcTo", ArcTo.class, RowType.class);
|
_rowTypes.put("ArcTo", ArcTo.class, RowType.class);
|
||||||
_rowTypes.put("Ellipse", Ellipse.class, RowType.class);
|
_rowTypes.put("Ellipse", Ellipse.class, RowType.class);
|
||||||
_rowTypes.put("EllipticalArcTo", EllipticalArcTo.class, RowType.class);
|
_rowTypes.put("EllipticalArcTo", EllipticalArcTo.class,
|
||||||
|
RowType.class);
|
||||||
_rowTypes.put("InfiniteLine", InfiniteLine.class, RowType.class);
|
_rowTypes.put("InfiniteLine", InfiniteLine.class, RowType.class);
|
||||||
_rowTypes.put("LineTo", LineTo.class, RowType.class);
|
_rowTypes.put("LineTo", LineTo.class, RowType.class);
|
||||||
_rowTypes.put("MoveTo", MoveTo.class, RowType.class);
|
_rowTypes.put("MoveTo", MoveTo.class, RowType.class);
|
||||||
_rowTypes.put("NURBSTo", NURBSTo.class, RowType.class);
|
_rowTypes.put("NURBSTo", NURBSTo.class, RowType.class);
|
||||||
_rowTypes.put("PolyLineTo", PolyLineTo.class, RowType.class);
|
_rowTypes.put("PolyLineTo", PolyLineTo.class, RowType.class);
|
||||||
_rowTypes.put("RelCubBezTo", RelCubBezTo.class, RowType.class);
|
_rowTypes.put("RelCubBezTo", RelCubBezTo.class, RowType.class);
|
||||||
_rowTypes.put("RelEllipticalArcTo", RelEllipticalArcTo.class, RowType.class);
|
_rowTypes.put("RelEllipticalArcTo", RelEllipticalArcTo.class,
|
||||||
|
RowType.class);
|
||||||
_rowTypes.put("RelLineTo", RelLineTo.class, RowType.class);
|
_rowTypes.put("RelLineTo", RelLineTo.class, RowType.class);
|
||||||
_rowTypes.put("RelMoveTo", RelMoveTo.class, RowType.class);
|
_rowTypes.put("RelMoveTo", RelMoveTo.class, RowType.class);
|
||||||
_rowTypes.put("RelQuadBezTo", RelQuadBezTo.class, RowType.class);
|
_rowTypes.put("RelQuadBezTo", RelQuadBezTo.class, RowType.class);
|
||||||
_rowTypes.put("SplineKnot", SplineKnot.class, RowType.class);
|
_rowTypes.put("SplineKnot", SplineKnot.class, RowType.class);
|
||||||
_rowTypes.put("SplineStart", SplineStart.class, RowType.class);
|
_rowTypes.put("SplineStart", SplineStart.class, RowType.class);
|
||||||
} catch (NoSuchMethodException | SecurityException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new POIXMLException("Internal error", e);
|
||||||
|
} catch (SecurityException e) {
|
||||||
throw new POIXMLException("Internal error", e);
|
throw new POIXMLException("Internal error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,14 +18,9 @@
|
|||||||
package org.apache.poi.xdgf.usermodel.section.geometry;
|
package org.apache.poi.xdgf.usermodel.section.geometry;
|
||||||
|
|
||||||
import java.awt.geom.Path2D;
|
import java.awt.geom.Path2D;
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.geom.Rectangle2D;
|
|
||||||
|
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.poi.xdgf.geom.Dimension2dDouble;
|
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFCell;
|
import org.apache.poi.xdgf.usermodel.XDGFCell;
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFDocument;
|
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFPage;
|
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||||
|
|
||||||
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
||||||
@ -38,16 +33,20 @@ public class InfiniteLine implements GeometryRow {
|
|||||||
|
|
||||||
InfiniteLine _master = null;
|
InfiniteLine _master = null;
|
||||||
|
|
||||||
// An x-coordinate of a point on the infinite line; paired with y-coordinate represented by the Y cell.
|
// An x-coordinate of a point on the infinite line; paired with y-coordinate
|
||||||
|
// represented by the Y cell.
|
||||||
Double x = null;
|
Double x = null;
|
||||||
|
|
||||||
// A y-coordinate of a point on the infinite line; paired with x-coordinate represented by the X cell.
|
// A y-coordinate of a point on the infinite line; paired with x-coordinate
|
||||||
|
// represented by the X cell.
|
||||||
Double y = null;
|
Double y = null;
|
||||||
|
|
||||||
// An x-coordinate of a point on the infinite line; paired with y-coordinate represented by the B cell.
|
// An x-coordinate of a point on the infinite line; paired with y-coordinate
|
||||||
|
// represented by the B cell.
|
||||||
Double a = null;
|
Double a = null;
|
||||||
|
|
||||||
// A y-coordinate of a point on an infinite line; paired with x-coordinate represented by the A cell.
|
// A y-coordinate of a point on an infinite line; paired with x-coordinate
|
||||||
|
// represented by the A cell.
|
||||||
Double b = null;
|
Double b = null;
|
||||||
|
|
||||||
Boolean deleted = null;
|
Boolean deleted = null;
|
||||||
@ -56,7 +55,8 @@ public class InfiniteLine implements GeometryRow {
|
|||||||
|
|
||||||
public InfiniteLine(RowType row) {
|
public InfiniteLine(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -70,7 +70,8 @@ public class InfiniteLine implements GeometryRow {
|
|||||||
} else if (cellName.equals("B")) {
|
} else if (cellName.equals("B")) {
|
||||||
b = XDGFCell.parseDoubleValue(cell);
|
b = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in InfiniteLine row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in InfiniteLine row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,9 +110,11 @@ public class InfiniteLine implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
throw new POIXMLException("InfiniteLine elements cannot be part of a path");
|
throw new POIXMLException(
|
||||||
|
"InfiniteLine elements cannot be part of a path");
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns this object as a line that extends between the boundaries of
|
// returns this object as a line that extends between the boundaries of
|
||||||
|
@ -37,7 +37,8 @@ public class LineTo implements GeometryRow {
|
|||||||
|
|
||||||
public LineTo(RowType row) {
|
public LineTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -47,7 +48,8 @@ public class LineTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("Y")) {
|
} else if (cellName.equals("Y")) {
|
||||||
y = XDGFCell.parseDoubleValue(cell);
|
y = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in LineTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in LineTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +84,8 @@ public class LineTo implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
path.lineTo(getX(), getY());
|
path.lineTo(getX(), getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,8 @@ public class MoveTo implements GeometryRow {
|
|||||||
|
|
||||||
public MoveTo(RowType row) {
|
public MoveTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -52,7 +53,8 @@ public class MoveTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("Y")) {
|
} else if (cellName.equals("Y")) {
|
||||||
y = XDGFCell.parseDoubleValue(cell);
|
y = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in MoveTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in MoveTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +89,8 @@ public class MoveTo implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
path.moveTo(getX(), getY());
|
path.moveTo(getX(), getY());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,11 @@ package org.apache.poi.xdgf.usermodel.section.geometry;
|
|||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
|
import org.apache.poi.ss.formula.functions.LookupUtils.ValueVector;
|
||||||
import org.apache.poi.xdgf.geom.SplineRenderer;
|
import org.apache.poi.xdgf.geom.SplineRenderer;
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFCell;
|
import org.apache.poi.xdgf.usermodel.XDGFCell;
|
||||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||||
|
|
||||||
import com.graphbuilder.curve.ControlPath;
|
|
||||||
import com.graphbuilder.curve.ShapeMultiPath;
|
|
||||||
import com.graphbuilder.curve.ValueVector;
|
|
||||||
import com.graphbuilder.geom.PointFactory;
|
|
||||||
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
||||||
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
||||||
|
|
||||||
@ -62,7 +59,8 @@ public class NURBSTo implements GeometryRow {
|
|||||||
|
|
||||||
public NURBSTo(RowType row) {
|
public NURBSTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -82,7 +80,8 @@ public class NURBSTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("E")) {
|
} else if (cellName.equals("E")) {
|
||||||
e = cell.getV();
|
e = cell.getV();
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in NURBS row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in NURBS row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,22 +131,28 @@ public class NURBSTo implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
Point2D last = path.getCurrentPoint();
|
Point2D last = path.getCurrentPoint();
|
||||||
|
|
||||||
// A NURBS formula: knotLast, degree, xType, yType, x1, y1, knot1, weight1, ..
|
// A NURBS formula: knotLast, degree, xType, yType, x1, y1, knot1,
|
||||||
|
// weight1, ..
|
||||||
String formula = getE().trim();
|
String formula = getE().trim();
|
||||||
if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
|
if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
|
||||||
throw new POIXMLException("Invalid NURBS formula: " + formula);
|
throw new POIXMLException("Invalid NURBS formula: " + formula);
|
||||||
|
|
||||||
String [] components = formula.substring(6, formula.length()-1).split(",");
|
String[] components = formula.substring(6, formula.length() - 1).split(
|
||||||
|
",");
|
||||||
|
|
||||||
if (components.length < 8)
|
if (components.length < 8)
|
||||||
throw new POIXMLException("Invalid NURBS formula (not enough arguments)");
|
throw new POIXMLException(
|
||||||
|
"Invalid NURBS formula (not enough arguments)");
|
||||||
|
|
||||||
if ((components.length - 4) % 4 != 0)
|
if ((components.length - 4) % 4 != 0)
|
||||||
throw new POIXMLException("Invalid NURBS formula -- need 4 + n*4 arguments, got " + components.length);
|
throw new POIXMLException(
|
||||||
|
"Invalid NURBS formula -- need 4 + n*4 arguments, got "
|
||||||
|
+ components.length);
|
||||||
|
|
||||||
double lastControlX = getX();
|
double lastControlX = getX();
|
||||||
double lastControlY = getY();
|
double lastControlY = getY();
|
||||||
@ -199,7 +204,8 @@ public class NURBSTo implements GeometryRow {
|
|||||||
|
|
||||||
controlPath.addPoint(PointFactory.create(lastControlX, lastControlY));
|
controlPath.addPoint(PointFactory.create(lastControlX, lastControlY));
|
||||||
|
|
||||||
ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath, knots, weights, degree);
|
ShapeMultiPath shape = SplineRenderer.createNurbsSpline(controlPath,
|
||||||
|
knots, weights, degree);
|
||||||
path.append(shape, true);
|
path.append(shape, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ public class PolyLineTo implements GeometryRow {
|
|||||||
|
|
||||||
public PolyLineTo(RowType row) {
|
public PolyLineTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -55,7 +56,8 @@ public class PolyLineTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("A")) {
|
} else if (cellName.equals("A")) {
|
||||||
a = cell.getV();
|
a = cell.getV();
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in ArcTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in ArcTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +91,8 @@ public class PolyLineTo implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
throw new POIXMLException("Polyline support not implemented");
|
throw new POIXMLException("Polyline support not implemented");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,22 +28,30 @@ public class RelCubBezTo implements GeometryRow {
|
|||||||
|
|
||||||
RelCubBezTo _master = null;
|
RelCubBezTo _master = null;
|
||||||
|
|
||||||
// The x-coordinate of the ending vertex of a cubic Bézier curve relative to the width of the shape.
|
// The x-coordinate of the ending vertex of a cubic Bezier curve relative to
|
||||||
|
// the width of the shape.
|
||||||
Double x = null;
|
Double x = null;
|
||||||
|
|
||||||
// The y-coordinate of the ending vertex of a cubic Bézier curve relative to the height of the shape.
|
// The y-coordinate of the ending vertex of a cubic Bezier curve relative to
|
||||||
|
// the height of the shape.
|
||||||
Double y = null;
|
Double y = null;
|
||||||
|
|
||||||
// The x-coordinate of the curve’s beginning control point relative to the shape’s width; a point on the arc. The control point is best located between the beginning and ending vertices of the arc.
|
// The x-coordinate of the curve's beginning control point relative to the
|
||||||
|
// shape's width; a point on the arc. The control point is best located
|
||||||
|
// between the beginning and ending vertices of the arc.
|
||||||
Double a = null;
|
Double a = null;
|
||||||
|
|
||||||
// The y-coordinate of a curve’s beginning control point relative to the shape’s height.
|
// The y-coordinate of a curve's beginning control point relative to the
|
||||||
|
// shape's height.
|
||||||
Double b = null;
|
Double b = null;
|
||||||
|
|
||||||
// The x-coordinate of the curve’s ending control point relative to the shape’s width; a point on the arc. The control point is best located between the beginning control point and ending vertices of the arc.
|
// The x-coordinate of the curve's ending control point relative to the
|
||||||
|
// shape's width; a point on the arc. The control point is best located
|
||||||
|
// between the beginning control point and ending vertices of the arc.
|
||||||
Double c = null;
|
Double c = null;
|
||||||
|
|
||||||
// The y-coordinate of a curve's ending control point relative to the shape’s height.
|
// The y-coordinate of a curve's ending control point relative to the
|
||||||
|
// shape's height.
|
||||||
Double d = null;
|
Double d = null;
|
||||||
|
|
||||||
Boolean deleted = null;
|
Boolean deleted = null;
|
||||||
@ -52,7 +60,8 @@ public class RelCubBezTo implements GeometryRow {
|
|||||||
|
|
||||||
public RelCubBezTo(RowType row) {
|
public RelCubBezTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -70,7 +79,8 @@ public class RelCubBezTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("D")) {
|
} else if (cellName.equals("D")) {
|
||||||
d = XDGFCell.parseDoubleValue(cell);
|
d = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in RelCubBezTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in RelCubBezTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,11 +127,13 @@ public class RelCubBezTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
double w = parent.getWidth();
|
double w = parent.getWidth();
|
||||||
double h = parent.getHeight();
|
double h = parent.getHeight();
|
||||||
|
|
||||||
path.curveTo(getA()*w, getB()*h, getC()*w, getD()*h, getX()*w, getY()*h);
|
path.curveTo(getA() * w, getB() * h, getC() * w, getD() * h,
|
||||||
|
getX() * w, getY() * h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,11 +36,11 @@ public class RelEllipticalArcTo implements GeometryRow {
|
|||||||
// the shape.
|
// the shape.
|
||||||
Double y = null;
|
Double y = null;
|
||||||
|
|
||||||
// The x-coordinate of the arc's control point relative to the shape’s
|
// The x-coordinate of the arc's control point relative to the shape's
|
||||||
// width; a point on the arc.
|
// width; a point on the arc.
|
||||||
Double a = null;
|
Double a = null;
|
||||||
|
|
||||||
// The y-coordinate of an arc's control point relative to the shape’s width.
|
// The y-coordinate of an arc's control point relative to the shape's width.
|
||||||
Double b = null;
|
Double b = null;
|
||||||
|
|
||||||
// The angle of an arc's major axis relative to the x-axis of its parent.
|
// The angle of an arc's major axis relative to the x-axis of its parent.
|
||||||
@ -57,7 +57,8 @@ public class RelEllipticalArcTo implements GeometryRow {
|
|||||||
|
|
||||||
public RelEllipticalArcTo(RowType row) {
|
public RelEllipticalArcTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -75,7 +76,8 @@ public class RelEllipticalArcTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("D")) {
|
} else if (cellName.equals("D")) {
|
||||||
d = XDGFCell.parseDoubleValue(cell);
|
d = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in RelEllipticalArcTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in RelEllipticalArcTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +124,8 @@ public class RelEllipticalArcTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
double w = parent.getWidth();
|
double w = parent.getWidth();
|
||||||
double h = parent.getHeight();
|
double h = parent.getHeight();
|
||||||
|
@ -26,7 +26,7 @@ import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains x-and y-coordinates of the ending vertex of a straight line segment
|
* Contains x-and y-coordinates of the ending vertex of a straight line segment
|
||||||
* relative to a shape’s width and height.
|
* relative to a shape's width and height.
|
||||||
*/
|
*/
|
||||||
public class RelLineTo implements GeometryRow {
|
public class RelLineTo implements GeometryRow {
|
||||||
|
|
||||||
@ -41,7 +41,8 @@ public class RelLineTo implements GeometryRow {
|
|||||||
|
|
||||||
public RelLineTo(RowType row) {
|
public RelLineTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -51,7 +52,8 @@ public class RelLineTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("Y")) {
|
} else if (cellName.equals("Y")) {
|
||||||
y = XDGFCell.parseDoubleValue(cell);
|
y = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in RelLineTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in RelLineTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,9 +84,9 @@ public class RelLineTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
path.lineTo(getX()*parent.getWidth(),
|
path.lineTo(getX() * parent.getWidth(), getY() * parent.getHeight());
|
||||||
getY()*parent.getHeight());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ public class RelMoveTo implements GeometryRow {
|
|||||||
|
|
||||||
public RelMoveTo(RowType row) {
|
public RelMoveTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -47,7 +48,8 @@ public class RelMoveTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("Y")) {
|
} else if (cellName.equals("Y")) {
|
||||||
y = XDGFCell.parseDoubleValue(cell);
|
y = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in RelMoveTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in RelMoveTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,9 +80,9 @@ public class RelMoveTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
path.moveTo(getX()*parent.getWidth(),
|
path.moveTo(getX() * parent.getWidth(), getY() * parent.getHeight());
|
||||||
getY()*parent.getHeight());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,24 +25,29 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
|||||||
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the x- and y-coordinates of the endpoint of a quadratic Bézier curve
|
* Contains the x- and y-coordinates of the endpoint of a quadratic Bezier curve
|
||||||
* relative to the shape’s width and height and the x- and y-coordinates of the
|
* relative to the shape's width and height and the x- and y-coordinates of the
|
||||||
* control point of the curve relative shape’s width and height.
|
* control point of the curve relative shape's width and height.
|
||||||
*/
|
*/
|
||||||
public class RelQuadBezTo implements GeometryRow {
|
public class RelQuadBezTo implements GeometryRow {
|
||||||
|
|
||||||
RelQuadBezTo _master = null;
|
RelQuadBezTo _master = null;
|
||||||
|
|
||||||
// The x-coordinate of the ending vertex of a quadratic Bézier curve relative to the width of the shape.
|
// The x-coordinate of the ending vertex of a quadratic Bezier curve
|
||||||
|
// relative to the width of the shape.
|
||||||
Double x = null;
|
Double x = null;
|
||||||
|
|
||||||
// The y-coordinate of the ending vertex of a quadratic Bézier curve relative to the height of the shape.
|
// The y-coordinate of the ending vertex of a quadratic Bezier curve
|
||||||
|
// relative to the height of the shape.
|
||||||
Double y = null;
|
Double y = null;
|
||||||
|
|
||||||
// The x-coordinate of the curve’s control point relative to the shape’s width; a point on the arc. The control point is best located about halfway between the beginning and ending vertices of the arc.
|
// The x-coordinate of the curve's control point relative to the shape's
|
||||||
|
// width; a point on the arc. The control point is best located about
|
||||||
|
// halfway between the beginning and ending vertices of the arc.
|
||||||
Double a = null;
|
Double a = null;
|
||||||
|
|
||||||
// The y-coordinate of a curve’s control point relative to the shape’s height.
|
// The y-coordinate of a curve's control point relative to the shape's
|
||||||
|
// height.
|
||||||
Double b = null;
|
Double b = null;
|
||||||
|
|
||||||
Boolean deleted = null;
|
Boolean deleted = null;
|
||||||
@ -51,7 +56,8 @@ public class RelQuadBezTo implements GeometryRow {
|
|||||||
|
|
||||||
public RelQuadBezTo(RowType row) {
|
public RelQuadBezTo(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -65,7 +71,8 @@ public class RelQuadBezTo implements GeometryRow {
|
|||||||
} else if (cellName.equals("B")) {
|
} else if (cellName.equals("B")) {
|
||||||
b = XDGFCell.parseDoubleValue(cell);
|
b = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in RelQuadBezTo row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in RelQuadBezTo row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,7 +111,8 @@ public class RelQuadBezTo implements GeometryRow {
|
|||||||
@Override
|
@Override
|
||||||
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
|
||||||
|
|
||||||
if (getDel()) return;
|
if (getDel())
|
||||||
|
return;
|
||||||
|
|
||||||
double w = parent.getWidth();
|
double w = parent.getWidth();
|
||||||
double h = parent.getHeight();
|
double h = parent.getHeight();
|
||||||
|
@ -25,7 +25,8 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType;
|
|||||||
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
import com.microsoft.schemas.office.visio.x2012.main.RowType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains x- and y-coordinates for a spline's control point and a spline's knot.
|
* Contains x- and y-coordinates for a spline's control point and a spline's
|
||||||
|
* knot.
|
||||||
*/
|
*/
|
||||||
public class SplineKnot implements GeometryRow {
|
public class SplineKnot implements GeometryRow {
|
||||||
|
|
||||||
@ -46,7 +47,8 @@ public class SplineKnot implements GeometryRow {
|
|||||||
|
|
||||||
public SplineKnot(RowType row) {
|
public SplineKnot(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -58,7 +60,8 @@ public class SplineKnot implements GeometryRow {
|
|||||||
} else if (cellName.equals("A")) {
|
} else if (cellName.equals("A")) {
|
||||||
a = XDGFCell.parseDoubleValue(cell);
|
a = XDGFCell.parseDoubleValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in SplineKnot row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in SplineKnot row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,6 +100,7 @@ public class SplineKnot implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA() + "}";
|
return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA()
|
||||||
|
+ "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,8 @@ public class SplineStart implements GeometryRow {
|
|||||||
|
|
||||||
public SplineStart(RowType row) {
|
public SplineStart(RowType row) {
|
||||||
|
|
||||||
if (row.isSetDel()) deleted = row.getDel();
|
if (row.isSetDel())
|
||||||
|
deleted = row.getDel();
|
||||||
|
|
||||||
for (CellType cell : row.getCellArray()) {
|
for (CellType cell : row.getCellArray()) {
|
||||||
String cellName = cell.getN();
|
String cellName = cell.getN();
|
||||||
@ -73,7 +74,8 @@ public class SplineStart implements GeometryRow {
|
|||||||
} else if (cellName.equals("D")) {
|
} else if (cellName.equals("D")) {
|
||||||
d = XDGFCell.parseIntegerValue(cell);
|
d = XDGFCell.parseIntegerValue(cell);
|
||||||
} else {
|
} else {
|
||||||
throw new POIXMLException("Invalid cell '" + cellName + "' in SplineStart row");
|
throw new POIXMLException("Invalid cell '" + cellName
|
||||||
|
+ "' in SplineStart row");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,9 +126,7 @@ public class SplineStart implements GeometryRow {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "{SplineStart x=" + getX() + " y=" + getY() +
|
return "{SplineStart x=" + getX() + " y=" + getY() + " a=" + getA()
|
||||||
" a=" + getA() + " b=" + getB() +
|
+ " b=" + getB() + " c=" + getC() + " d=" + getD() + "}";
|
||||||
" c=" + getC() + " d=" + getD() +
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,13 @@ import org.apache.poi.xdgf.usermodel.XDGFShape;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This acceptor only allows traversal to shapes that have useful data
|
* This acceptor only allows traversal to shapes that have useful data
|
||||||
* associated with them, and tries to elide details that aren't useful
|
* associated with them, and tries to elide details that aren't useful when
|
||||||
* when analyzing the content of a document.
|
* analyzing the content of a document.
|
||||||
*
|
*
|
||||||
* Useful is subjective of course, and is defined as any of:
|
* Useful is subjective of course, and is defined as any of:
|
||||||
*
|
*
|
||||||
* - Has non-empty text
|
* - Has non-empty text - Is a 1d shape, such as a line - User specified shapes
|
||||||
* - Is a 1d shape, such as a line
|
* - The outline of stencil objects - TODO
|
||||||
* - User specified shapes
|
|
||||||
* - The outline of stencil objects
|
|
||||||
* - TODO
|
|
||||||
*/
|
*/
|
||||||
public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
|
public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
|
||||||
|
|
||||||
@ -65,5 +62,4 @@ public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ public class ShapeDebuggerRenderer extends ShapeRenderer {
|
|||||||
shapeOffset -= 0.15F;
|
shapeOffset -= 0.15F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_graphics.drawString(shapeId, shapeOffset, 0);
|
_graphics.drawString(shapeId, shapeOffset, 0);
|
||||||
_graphics.setFont(f);
|
_graphics.setFont(f);
|
||||||
_graphics.scale(1, -1);
|
_graphics.scale(1, -1);
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
package org.apache.poi.xdgf.usermodel.shape;
|
package org.apache.poi.xdgf.usermodel.shape;
|
||||||
|
|
||||||
import java.awt.BasicStroke;
|
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
@ -47,7 +46,8 @@ public class ShapeRenderer extends ShapeVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
|
public void visit(XDGFShape shape, AffineTransform globalTransform,
|
||||||
|
int level) {
|
||||||
|
|
||||||
AffineTransform savedTr = _graphics.getTransform();
|
AffineTransform savedTr = _graphics.getTransform();
|
||||||
_graphics.transform(globalTransform);
|
_graphics.transform(globalTransform);
|
||||||
@ -82,7 +82,8 @@ public class ShapeRenderer extends ShapeVisitor {
|
|||||||
|
|
||||||
Font oldFont = _graphics.getFont();
|
Font oldFont = _graphics.getFont();
|
||||||
|
|
||||||
_graphics.setFont(oldFont.deriveFont(shape.getFontSize().floatValue()));
|
_graphics.setFont(oldFont.deriveFont(shape.getFontSize()
|
||||||
|
.floatValue()));
|
||||||
_graphics.setColor(shape.getFontColor());
|
_graphics.setColor(shape.getFontColor());
|
||||||
|
|
||||||
text.draw(_graphics);
|
text.draw(_graphics);
|
||||||
|
@ -27,8 +27,8 @@ import org.apache.poi.xdgf.usermodel.XDGFShape;
|
|||||||
* To change the behavior of a particular visitor, you can override either
|
* To change the behavior of a particular visitor, you can override either
|
||||||
* accept() or getAcceptor() [preferred]
|
* accept() or getAcceptor() [preferred]
|
||||||
*
|
*
|
||||||
* If accept() or visit() throw StopVisitingThisBranch, the iteration will
|
* If accept() or visit() throw StopVisitingThisBranch, the iteration will not
|
||||||
* not visit subshapes of the shape.
|
* visit subshapes of the shape.
|
||||||
*/
|
*/
|
||||||
public abstract class ShapeVisitor {
|
public abstract class ShapeVisitor {
|
||||||
|
|
||||||
@ -53,16 +53,20 @@ public abstract class ShapeVisitor{
|
|||||||
_acceptor = acceptor;
|
_acceptor = acceptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean accept(XDGFShape shape) {
|
public boolean accept(XDGFShape shape) {
|
||||||
return _acceptor.accept(shape);
|
return _acceptor.accept(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param shape Current shape
|
* @param shape
|
||||||
* @param globalTransform A transform that can convert the shapes points to global coordinates
|
* Current shape
|
||||||
* @param level Level in the tree (0 is topmost, 1 is next level...
|
* @param globalTransform
|
||||||
|
* A transform that can convert the shapes points to global
|
||||||
|
* coordinates
|
||||||
|
* @param level
|
||||||
|
* Level in the tree (0 is topmost, 1 is next level...
|
||||||
*/
|
*/
|
||||||
public abstract void visit(XDGFShape shape, AffineTransform globalTransform, int level);
|
public abstract void visit(XDGFShape shape,
|
||||||
|
AffineTransform globalTransform, int level);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,11 @@ import org.apache.poi.xdgf.usermodel.shape.ShapeVisitor;
|
|||||||
|
|
||||||
public class HierarchyPrinter {
|
public class HierarchyPrinter {
|
||||||
|
|
||||||
public static void printHierarchy(XDGFPage page, File outDir) throws FileNotFoundException {
|
public static void printHierarchy(XDGFPage page, File outDir)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
|
||||||
File pageFile = new File(outDir, "page" + page.getPageNumber() + "-" + Util.sanitizeFilename(page.getName()) + ".txt");
|
File pageFile = new File(outDir, "page" + page.getPageNumber() + "-"
|
||||||
|
+ Util.sanitizeFilename(page.getName()) + ".txt");
|
||||||
|
|
||||||
OutputStream os = new FileOutputStream(pageFile);
|
OutputStream os = new FileOutputStream(pageFile);
|
||||||
PrintStream pos = new PrintStream(os);
|
PrintStream pos = new PrintStream(os);
|
||||||
@ -49,17 +51,22 @@ public class HierarchyPrinter {
|
|||||||
page.getContent().visitShapes(new ShapeVisitor() {
|
page.getContent().visitShapes(new ShapeVisitor() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
|
public void visit(XDGFShape shape, AffineTransform globalTransform,
|
||||||
|
int level) {
|
||||||
for (int i = 0; i < level; i++) {
|
for (int i = 0; i < level; i++) {
|
||||||
os.append(" ");
|
os.append(" ");
|
||||||
}
|
}
|
||||||
// TODO: write text?
|
// TODO: write text?
|
||||||
os.println(shape.toString() + " [" + shape.getShapeType() + ", " + shape.getSymbolName() + "] " + shape.getMasterShape() + " " + shape.getTextAsString().trim());
|
os.println(shape.toString() + " [" + shape.getShapeType()
|
||||||
|
+ ", " + shape.getSymbolName() + "] "
|
||||||
|
+ shape.getMasterShape() + " "
|
||||||
|
+ shape.getTextAsString().trim());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void printHierarchy(XmlVisioDocument document, String outDirname) throws FileNotFoundException {
|
public static void printHierarchy(XmlVisioDocument document,
|
||||||
|
String outDirname) throws FileNotFoundException {
|
||||||
|
|
||||||
File outDir = new File(outDirname);
|
File outDir = new File(outDirname);
|
||||||
|
|
||||||
@ -68,7 +75,6 @@ public class HierarchyPrinter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println("Usage: in.vsdx outdir");
|
System.err.println("Usage: in.vsdx outdir");
|
||||||
@ -78,7 +84,8 @@ public class HierarchyPrinter {
|
|||||||
String inFilename = args[0];
|
String inFilename = args[0];
|
||||||
String outDir = args[1];
|
String outDir = args[1];
|
||||||
|
|
||||||
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
|
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
|
||||||
|
inFilename));
|
||||||
printHierarchy(doc, outDir);
|
printHierarchy(doc, outDir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import org.apache.xmlbeans.XmlObject;
|
|||||||
|
|
||||||
public class ObjectFactory<T, X extends XmlObject> {
|
public class ObjectFactory<T, X extends XmlObject> {
|
||||||
|
|
||||||
Map<String, Constructor<? extends T>> _types = new HashMap<>();
|
Map<String, Constructor<? extends T>> _types = new HashMap<String, Constructor<? extends T>>();
|
||||||
|
|
||||||
public void put(String typeName, Class<? extends T> cls, Class<?>... varargs) throws NoSuchMethodException, SecurityException {
|
public void put(String typeName, Class<? extends T> cls, Class<?>... varargs) throws NoSuchMethodException, SecurityException {
|
||||||
_types.put(typeName, cls.getDeclaredConstructor(varargs));
|
_types.put(typeName, cls.getDeclaredConstructor(varargs));
|
||||||
|
@ -20,7 +20,6 @@ package org.apache.poi.xdgf.util;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.geom.Point2D;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -37,35 +36,43 @@ import org.apache.poi.xdgf.usermodel.shape.ShapeRenderer;
|
|||||||
|
|
||||||
public class VsdxToPng {
|
public class VsdxToPng {
|
||||||
|
|
||||||
|
public static void renderToPng(XDGFPage page, String outFilename,
|
||||||
public static void renderToPng(XDGFPage page, String outFilename, double scale, ShapeRenderer renderer) throws IOException {
|
double scale, ShapeRenderer renderer) throws IOException {
|
||||||
renderToPng(page, new File(outFilename), scale, renderer);
|
renderToPng(page, new File(outFilename), scale, renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderToPngDir(XDGFPage page, File outDir, double scale, ShapeRenderer renderer) throws IOException {
|
public static void renderToPngDir(XDGFPage page, File outDir, double scale,
|
||||||
|
ShapeRenderer renderer) throws IOException {
|
||||||
|
|
||||||
File pageFile = new File(outDir, "page" + page.getPageNumber() + "-" + Util.sanitizeFilename(page.getName()) + ".png");
|
File pageFile = new File(outDir, "page" + page.getPageNumber() + "-"
|
||||||
|
+ Util.sanitizeFilename(page.getName()) + ".png");
|
||||||
System.out.println("** Writing image to " + pageFile);
|
System.out.println("** Writing image to " + pageFile);
|
||||||
|
|
||||||
renderToPng(page, pageFile, scale, renderer);
|
renderToPng(page, pageFile, scale, renderer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderToPng(XDGFPage page, File outFile, double scale, ShapeRenderer renderer) throws IOException {
|
public static void renderToPng(XDGFPage page, File outFile, double scale,
|
||||||
|
ShapeRenderer renderer) throws IOException {
|
||||||
|
|
||||||
Dimension2dDouble sz = page.getPageSize();
|
Dimension2dDouble sz = page.getPageSize();
|
||||||
|
|
||||||
int width = (int) (scale * sz.getWidth());
|
int width = (int) (scale * sz.getWidth());
|
||||||
int height = (int) (scale * sz.getHeight());
|
int height = (int) (scale * sz.getHeight());
|
||||||
|
|
||||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
BufferedImage img = new BufferedImage(width, height,
|
||||||
|
BufferedImage.TYPE_INT_RGB);
|
||||||
final Graphics2D graphics = img.createGraphics();
|
final Graphics2D graphics = img.createGraphics();
|
||||||
|
|
||||||
// default rendering options
|
// default rendering options
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
|
||||||
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
RenderingHints.VALUE_RENDER_QUALITY);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
|
||||||
|
RenderingHints.VALUE_INTERPOLATION_BICUBIC);
|
||||||
|
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
|
||||||
|
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
||||||
|
|
||||||
graphics.setColor(Color.black);
|
graphics.setColor(Color.black);
|
||||||
graphics.setBackground(Color.white);
|
graphics.setBackground(Color.white);
|
||||||
@ -86,7 +93,9 @@ public class VsdxToPng {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void renderToPng(XmlVisioDocument document, String outDirname, double scale, ShapeRenderer renderer) throws IOException {
|
public static void renderToPng(XmlVisioDocument document,
|
||||||
|
String outDirname, double scale, ShapeRenderer renderer)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
File outDir = new File(outDirname);
|
File outDir = new File(outDirname);
|
||||||
|
|
||||||
@ -112,7 +121,8 @@ public class VsdxToPng {
|
|||||||
renderer = new ShapeDebuggerRenderer();
|
renderer = new ShapeDebuggerRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
|
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
|
||||||
|
inFilename));
|
||||||
renderToPng(doc, pngDir, 2000 / 11.0, renderer);
|
renderToPng(doc, pngDir, 2000 / 11.0, renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@ public class XDGFXMLDocumentPart extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
protected XDGFDocument _document;
|
protected XDGFDocument _document;
|
||||||
|
|
||||||
public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel, XDGFDocument document) {
|
public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel,
|
||||||
|
XDGFDocument document) {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
_document = document;
|
_document = document;
|
||||||
}
|
}
|
||||||
|
@ -41,119 +41,117 @@ public class CombinedIteratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullMaster() {
|
public void testNullMaster() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(2L, "B2");
|
base.put(2L, "B2");
|
||||||
base.put(3L, "B3");
|
base.put(3L, "B3");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, null),
|
testIteration(new CombinedIterable<String>(base, null), "B1", "B2",
|
||||||
"B1", "B2", "B3");
|
"B3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoMatchesBaseFirst() {
|
public void testNoMatchesBaseFirst() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(2L, "B2");
|
base.put(2L, "B2");
|
||||||
base.put(3L, "B3");
|
base.put(3L, "B3");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(4L, "M4");
|
master.put(4L, "M4");
|
||||||
master.put(5L, "M5");
|
master.put(5L, "M5");
|
||||||
master.put(6L, "M6");
|
master.put(6L, "M6");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
|
||||||
"B1", "B2", "B3", "M4", "M5", "M6");
|
"B3", "M4", "M5", "M6");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoMatchesMasterFirst() {
|
public void testNoMatchesMasterFirst() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(4L, "B4");
|
base.put(4L, "B4");
|
||||||
base.put(5L, "B5");
|
base.put(5L, "B5");
|
||||||
base.put(6L, "B6");
|
base.put(6L, "B6");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(1L, "M1");
|
master.put(1L, "M1");
|
||||||
master.put(2L, "M2");
|
master.put(2L, "M2");
|
||||||
master.put(3L, "M3");
|
master.put(3L, "M3");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "M1", "M2",
|
||||||
"M1", "M2", "M3", "B4", "B5", "B6");
|
"M3", "B4", "B5", "B6");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterleaved1() {
|
public void testInterleaved1() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(3L, "B3");
|
base.put(3L, "B3");
|
||||||
base.put(5L, "B5");
|
base.put(5L, "B5");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(2L, "M2");
|
master.put(2L, "M2");
|
||||||
master.put(4L, "M4");
|
master.put(4L, "M4");
|
||||||
master.put(6L, "M6");
|
master.put(6L, "M6");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "B1", "M2",
|
||||||
"B1", "M2", "B3", "M4", "B5", "M6");
|
"B3", "M4", "B5", "M6");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInterleaved2() {
|
public void testInterleaved2() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(2L, "B2");
|
base.put(2L, "B2");
|
||||||
base.put(5L, "B5");
|
base.put(5L, "B5");
|
||||||
base.put(6L, "B6");
|
base.put(6L, "B6");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(3L, "M3");
|
master.put(3L, "M3");
|
||||||
master.put(4L, "M4");
|
master.put(4L, "M4");
|
||||||
master.put(7L, "M7");
|
master.put(7L, "M7");
|
||||||
master.put(8L, "M8");
|
master.put(8L, "M8");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
|
||||||
"B1", "B2", "M3", "M4", "B5", "B6", "M7", "M8");
|
"M3", "M4", "B5", "B6", "M7", "M8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllMatching() {
|
public void testAllMatching() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(2L, "B2");
|
base.put(2L, "B2");
|
||||||
base.put(3L, "B3");
|
base.put(3L, "B3");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(1L, "M1");
|
master.put(1L, "M1");
|
||||||
master.put(2L, "M2");
|
master.put(2L, "M2");
|
||||||
master.put(3L, "M3");
|
master.put(3L, "M3");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
|
||||||
"B1", "B2", "B3");
|
"B3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllMatching2() {
|
public void testAllMatching2() {
|
||||||
|
|
||||||
SortedMap<Long, String> base = new TreeMap<>();
|
SortedMap<Long, String> base = new TreeMap<Long, String>();
|
||||||
base.put(1L, "B1");
|
base.put(1L, "B1");
|
||||||
base.put(2L, "B2");
|
base.put(2L, "B2");
|
||||||
base.put(3L, "B3");
|
base.put(3L, "B3");
|
||||||
|
|
||||||
SortedMap<Long, String> master = new TreeMap<>();
|
SortedMap<Long, String> master = new TreeMap<Long, String>();
|
||||||
master.put(1L, "M1");
|
master.put(1L, "M1");
|
||||||
master.put(2L, "M2");
|
master.put(2L, "M2");
|
||||||
master.put(3L, "M3");
|
master.put(3L, "M3");
|
||||||
master.put(4L, "M4");
|
master.put(4L, "M4");
|
||||||
|
|
||||||
testIteration(new CombinedIterable<>(base, master),
|
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
|
||||||
"B1", "B2", "B3", "M4");
|
"B3", "M4");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user