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:
Dustin Spicuzza 2015-10-19 05:59:37 +00:00
parent 3bd2011924
commit d70b8e8b88
57 changed files with 4526 additions and 4418 deletions

View File

@ -38,9 +38,12 @@ public class XDGFException {
// some idea where the error was located
//
public static POIXMLException wrap(POIXMLDocumentPart part, POIXMLException e) {
return new POIXMLException(part.getPackagePart().getPartName().toString() + ": " + e.getMessage(),
e.getCause() == null ? e : e.getCause());
public static POIXMLException wrap(POIXMLDocumentPart part,
POIXMLException e) {
return new POIXMLException(part.getPackagePart().getPartName()
.toString()
+ ": " + e.getMessage(), e.getCause() == null ? e
: e.getCause());
}
public static POIXMLException wrap(String where, POIXMLException e) {

View File

@ -20,19 +20,15 @@ package org.apache.poi.xdgf.geom;
import java.awt.geom.Point2D;
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.section.geometry.SplineKnot;
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 {
SplineStart _start;
ArrayList<SplineKnot> _knots = new ArrayList<>();
ArrayList<SplineKnot> _knots = new ArrayList<SplineKnot>();
public SplineCollector(SplineStart start) {
_start = start;

View File

@ -17,18 +17,12 @@
package org.apache.poi.xdgf.geom;
import com.graphbuilder.curve.ControlPath;
import com.graphbuilder.curve.GroupIterator;
import com.graphbuilder.curve.NURBSpline;
import com.graphbuilder.curve.ShapeMultiPath;
import com.graphbuilder.curve.ValueVector;
import org.apache.poi.ss.formula.functions.LookupUtils.ValueVector;
public class SplineRenderer {
public static ShapeMultiPath createNurbsSpline(ControlPath controlPoints,
ValueVector knots,
ValueVector weights,
int degree) {
ValueVector knots, ValueVector weights, int degree) {
double firstKnot = knots.get(0);
double lastKnot = knots.get(knots.size() - 1);

View File

@ -47,9 +47,9 @@ public class XDGFBaseContents extends XDGFXMLDocumentPart {
protected PageContentsType _pageContents;
// shapes without parents
protected List<XDGFShape> _toplevelShapes = new ArrayList<>();
protected Map<Long, XDGFShape> _shapes = new HashMap<>();
protected List<XDGFConnection> _connections = new ArrayList<>();
protected List<XDGFShape> _toplevelShapes = new ArrayList<XDGFShape>();
protected Map<Long, XDGFShape> _shapes = new HashMap<Long, XDGFShape>();
protected List<XDGFConnection> _connections = new ArrayList<XDGFConnection>();
public XDGFBaseContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
super(part, rel, document);

View File

@ -25,16 +25,17 @@ import org.apache.poi.util.Internal;
import com.microsoft.schemas.office.visio.x2012.main.CellType;
/**
* There are a lot of different cell types. Cell is really just an attribute
* of the thing that it's attached to. Will probably refactor this once I
* figure out a better way to use them
* There are a lot of different cell types. Cell is really just an attribute of
* the thing that it's attached to. Will probably refactor this once I figure
* out a better way to use them
*
* The various attributes of a Cell are constrained, and are better defined
* in the XSD 1.1 visio schema
* The various attributes of a Cell are constrained, and are better defined in
* the XSD 1.1 visio schema
*/
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);
if (cell == null)
return null;
@ -44,7 +45,8 @@ public class XDGFCell {
if (cell.getValue().equals("1"))
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) {
@ -54,7 +56,8 @@ public class XDGFCell {
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);
if (cell != null)
return parseIntegerValue(cell._cell);
@ -78,7 +81,8 @@ public class XDGFCell {
} catch (NumberFormatException e) {
if (cell.getV().equals("Themed"))
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) {
if (cell.getV().equals("Themed"))
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) {
if (cell.getV().equals("Themed"))
return null;
throw new POIXMLException("Invalid float value for '" + cell.getN() + "': " + e);
throw new POIXMLException("Invalid float value for '" + cell.getN()
+ "': " + e);
}
}
CellType _cell;
public XDGFCell(CellType cell) {
@ -130,10 +135,10 @@ public class XDGFCell {
}
/**
* Represents the elements formula. This attribute can contain one of the following strings:
* - (some formula) if the formula exists locally
* - No Formula if the formula is locally deleted or blocked
* - Inh if the formula is inherited.
* Represents the element's formula. This attribute can contain one of the
* following strings: - '(some formula)' if the formula exists locally - No
* Formula if the formula is locally deleted or blocked - Inh if the formula
* is inherited.
*/
public String getFormula() {
return _cell.getF();

View File

@ -44,7 +44,9 @@ public class XDGFConnection {
// visEnd 12
// visFromAngle 13
// 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 visFromNone = 0;
@ -63,10 +65,11 @@ public class XDGFConnection {
public static final int visFromAngle = 13;
public static final int visFromPin = 14;
// 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,
// 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
// visConnectToError -1
// visToNone 0
@ -89,7 +92,6 @@ public class XDGFConnection {
private XDGFShape _from;
private XDGFShape _to;
public XDGFConnection(ConnectType connect, XDGFShape from, XDGFShape to) {
_connect = connect;
_from = from;

View File

@ -34,7 +34,7 @@ public class XDGFDocument {
protected VisioDocumentType _document;
Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<>();
Map<Long, XDGFStyleSheet> _styleSheets = new HashMap<Long, XDGFStyleSheet>();
// defaults
long _defaultFillStyle = 0;

View File

@ -30,7 +30,8 @@ import org.apache.poi.util.POILogger;
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;
@ -41,19 +42,27 @@ public class XDGFFactory extends POIXMLFactory {
@Override
public POIXMLDocumentPart createDocumentPart(POIXMLDocumentPart parent,
PackageRelationship rel, PackagePart part) {
POIXMLRelation descriptor = XDGFRelation.getInstance(rel.getRelationshipType());
POIXMLRelation descriptor = XDGFRelation.getInstance(rel
.getRelationshipType());
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);
}
try {
Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
Class<? extends POIXMLDocumentPart> cls = descriptor
.getRelationClass();
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);
} 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);
}
} catch (Exception e) {
@ -64,8 +73,10 @@ public class XDGFFactory extends POIXMLFactory {
@Override
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor) {
try {
Class<? extends POIXMLDocumentPart> cls = descriptor.getRelationClass();
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
Class<? extends POIXMLDocumentPart> cls = descriptor
.getRelationClass();
Constructor<? extends POIXMLDocumentPart> constructor = cls
.getDeclaredConstructor();
return constructor.newInstance();
} catch (Exception e) {
throw new POIXMLException(e);

View File

@ -30,7 +30,8 @@ public class XDGFMaster {
private XDGFMasterContents _content;
XDGFSheet _pageSheet = null;
public XDGFMaster(MasterType master, XDGFMasterContents content, XDGFDocument document) {
public XDGFMaster(MasterType master, XDGFMasterContents content,
XDGFDocument document) {
_master = master;
_content = content;
content.setMaster(this);

View File

@ -31,7 +31,8 @@ public class XDGFMasterContents extends XDGFBaseContents {
private XDGFMaster _master;
public XDGFMasterContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
public XDGFMasterContents(PackagePart part, PackageRelationship rel,
XDGFDocument document) {
super(part, rel, document);
}
@ -42,7 +43,9 @@ public class XDGFMasterContents extends XDGFBaseContents {
try {
_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);
}

View File

@ -41,7 +41,7 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
MastersType _mastersObject;
// 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) {
super(part, rel, document);
@ -57,11 +57,13 @@ public class XDGFMasters extends XDGFXMLDocumentPart {
try {
try {
_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);
}
Map<String, MasterType> masterSettings = new HashMap<>();
Map<String, MasterType> masterSettings = new HashMap<String, MasterType>();
for (MasterType master: _mastersObject.getMasterArray()) {
masterSettings.put(master.getRel().getId(), master);
}

View File

@ -36,7 +36,8 @@ public class XDGFPage {
XDGFPages _pages;
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;
_content = content;
_pages = pages;
@ -105,9 +106,7 @@ public class XDGFPage {
Dimension2dDouble sz = getPageSize();
Point2D.Double offset = getPageOffset();
return new Rectangle2D.Double(-offset.getX(),
-offset.getY(),
sz.getWidth(),
sz.getHeight());
return new Rectangle2D.Double(-offset.getX(), -offset.getY(),
sz.getWidth(), sz.getHeight());
}
}

View File

@ -32,7 +32,7 @@ import com.microsoft.schemas.office.visio.x2012.main.PageContentsDocument;
public class XDGFPageContents extends XDGFBaseContents {
Map<Long, XDGFMaster> _masters = new HashMap<>();
Map<Long, XDGFMaster> _masters = new HashMap<Long, XDGFMaster>();
XDGFPage _page;
public XDGFPageContents(PackagePart part, PackageRelationship rel, XDGFDocument document) {
@ -44,7 +44,9 @@ public class XDGFPageContents extends XDGFBaseContents {
try {
try {
_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);
}

View File

@ -43,7 +43,7 @@ public class XDGFPages extends XDGFXMLDocumentPart {
PagesType _pagesObject;
// ordered by page number
List<XDGFPage> _pages = new ArrayList<>();
List<XDGFPage> _pages = new ArrayList<XDGFPage>();
public XDGFPages(PackagePart part, PackageRelationship rel, XDGFDocument document) {
super(part, rel, document);
@ -59,7 +59,9 @@ public class XDGFPages extends XDGFXMLDocumentPart {
try {
try {
_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);
}

View File

@ -34,62 +34,50 @@ public class XDGFRelation extends POIXMLRelation {
public static final XDGFRelation DOCUMENT = new XDGFRelation(
"application/vnd.ms-visio.drawing.main+xml",
"http://schemas.microsoft.com/visio/2010/relationships/document",
"/visio/document.xml",
null
);
"/visio/document.xml", null);
public static final XDGFRelation MASTERS = new XDGFRelation(
"application/vnd.ms-visio.masters+xml",
"http://schemas.microsoft.com/visio/2010/relationships/masters",
"/visio/masters/masters.xml",
XDGFMasters.class
);
"/visio/masters/masters.xml", XDGFMasters.class);
public static final XDGFRelation MASTER = new XDGFRelation(
"application/vnd.ms-visio.master+xml",
"http://schemas.microsoft.com/visio/2010/relationships/master",
"/visio/masters/master#.xml",
XDGFMasterContents.class
);
"/visio/masters/master#.xml", XDGFMasterContents.class);
public static final XDGFRelation IMAGES = new XDGFRelation(
null,
PackageRelationshipTypes.IMAGE_PART,
null,
null // XSSFPictureData.class
public static final XDGFRelation IMAGES = new XDGFRelation(null,
PackageRelationshipTypes.IMAGE_PART, null, null // XSSFPictureData.class
);
public static final XDGFRelation PAGES = new XDGFRelation(
"application/vnd.ms-visio.pages+xml",
"http://schemas.microsoft.com/visio/2010/relationships/pages",
"/visio/pages/pages.xml",
XDGFPages.class
);
"/visio/pages/pages.xml", XDGFPages.class);
public static final XDGFRelation PAGE = new XDGFRelation(
"application/vnd.ms-visio.page+xml",
"http://schemas.microsoft.com/visio/2010/relationships/page",
"/visio/pages/page#.xml",
XDGFPageContents.class
);
"/visio/pages/page#.xml", XDGFPageContents.class);
public static final XDGFRelation WINDOW = new XDGFRelation(
"application/vnd.ms-visio.windows+xml",
"http://schemas.microsoft.com/visio/2010/relationships/windows",
"/visio/windows.xml",
null
);
"/visio/windows.xml", 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);
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
*
* @param rel relation type, for example,
* @param rel
* relation type, for example,
* <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
* @return registered POIXMLRelation or null if not found
*/

View File

@ -41,8 +41,8 @@ import com.microsoft.schemas.office.visio.x2012.main.ShapeSheetType;
import com.microsoft.schemas.office.visio.x2012.main.TextType;
/**
* A shape is a collection of Geometry Visualization, Format, Text, Images,
* and Shape Data in a Drawing Page.
* A shape is a collection of Geometry Visualization, Format, Text, Images, and
* Shape Data in a Drawing Page.
*/
public class XDGFShape extends XDGFSheet {
@ -102,11 +102,13 @@ public class XDGFShape extends XDGFSheet {
Double _txtWidth = 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);
}
public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet, XDGFBaseContents parentPage, XDGFDocument document) {
public XDGFShape(XDGFShape parent, ShapeSheetType shapeSheet,
XDGFBaseContents parentPage, XDGFDocument document) {
super(shapeSheet, document);
@ -168,21 +170,22 @@ public class XDGFShape extends XDGFSheet {
/**
* Setup top level shapes
*
* Shapes that have a 'Master' attribute refer to a specific master in
* the page, whereas shapes with a 'MasterShape' attribute refer to a
* subshape of a Master.
* Shapes that have a 'Master' attribute refer to a specific master in the
* page, whereas shapes with a 'MasterShape' attribute refer to a subshape
* of a Master.
*
*
*/
protected void setupMaster(XDGFPageContents pageContents, XDGFMasterContents master) {
protected void setupMaster(XDGFPageContents pageContents,
XDGFMasterContents master) {
ShapeSheetType obj = getXmlObject();
if (obj.isSetMaster()) {
_master = pageContents.getMasterById(obj.getMaster());
if (_master == null)
throw XDGFException.error("refers to non-existant master " + obj.getMaster(),
this);
throw XDGFException.error("refers to non-existant master "
+ obj.getMaster(), this);
/*
* If a master has one top-level shape, a shape that inherits from
@ -192,11 +195,14 @@ public class XDGFShape extends XDGFSheet {
* subshapes.
*/
Collection<XDGFShape> masterShapes = _master.getContent().getTopLevelShapes();
Collection<XDGFShape> masterShapes = _master.getContent()
.getTopLevelShapes();
switch (masterShapes.size()) {
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:
_masterShape = masterShapes.iterator().next();
break;
@ -207,8 +213,9 @@ public class XDGFShape extends XDGFSheet {
} else if (obj.isSetMasterShape()) {
_masterShape = master.getShapeById(obj.getMasterShape());
if (_masterShape == null)
throw XDGFException.error("refers to non-existant master shape " + obj.getMasterShape(),
this);
throw XDGFException.error(
"refers to non-existant master shape "
+ obj.getMasterShape(), this);
}
@ -216,8 +223,8 @@ public class XDGFShape extends XDGFSheet {
if (_shapes != null) {
for (XDGFShape shape : _shapes) {
shape.setupMaster(pageContents,
_master == null ? master : _master.getContent());
shape.setupMaster(pageContents, _master == null ? master
: _master.getContent());
}
}
}
@ -235,7 +242,8 @@ public class XDGFShape extends XDGFSheet {
}
for (Entry<Long, GeometrySection> section : _geometry.entrySet()) {
GeometrySection master = _masterShape.getGeometryByIdx(section.getKey());
GeometrySection master = _masterShape.getGeometryByIdx(section
.getKey());
if (master != null)
section.getValue().setupMaster(master);
}
@ -244,6 +252,7 @@ public class XDGFShape extends XDGFSheet {
}
}
@Override
@Internal
public ShapeSheetType getXmlObject() {
return (ShapeSheetType) _sheet;
@ -266,7 +275,8 @@ public class XDGFShape extends XDGFSheet {
}
public boolean hasText() {
return _text != null || (_masterShape != null && _masterShape._text != null);
return _text != null
|| (_masterShape != null && _masterShape._text != null);
}
@Override
@ -485,8 +495,8 @@ public class XDGFShape extends XDGFSheet {
}
public Double getTxtPinX() {
if (_txtPinX == null &&
_masterShape != null && _masterShape._txtPinX != null)
if (_txtPinX == null && _masterShape != null
&& _masterShape._txtPinX != null)
return _masterShape._txtPinX;
if (_txtPinX == null)
@ -495,10 +505,9 @@ public class XDGFShape extends XDGFSheet {
return _txtPinX;
}
public Double getTxtPinY() {
if (_txtLocPinY == null &&
_masterShape != null && _masterShape._txtLocPinY != null)
if (_txtLocPinY == null && _masterShape != null
&& _masterShape._txtLocPinY != null)
return _masterShape._txtLocPinY;
if (_txtPinY == null)
@ -507,10 +516,9 @@ public class XDGFShape extends XDGFSheet {
return _txtPinY;
}
public Double getTxtLocPinX() {
if (_txtLocPinX == null &&
_masterShape != null && _masterShape._txtLocPinX != null)
if (_txtLocPinX == null && _masterShape != null
&& _masterShape._txtLocPinX != null)
return _masterShape._txtLocPinX;
if (_txtLocPinX == null)
@ -519,10 +527,9 @@ public class XDGFShape extends XDGFSheet {
return _txtLocPinX;
}
public Double getTxtLocPinY() {
if (_txtLocPinY == null &&
_masterShape != null && _masterShape._txtLocPinY != null)
if (_txtLocPinY == null && _masterShape != null
&& _masterShape._txtLocPinY != null)
return _masterShape._txtLocPinY;
if (_txtLocPinY == null)
@ -539,8 +546,8 @@ public class XDGFShape extends XDGFSheet {
}
public Double getTxtWidth() {
if (_txtWidth == null &&
_masterShape != null && _masterShape._txtWidth != null)
if (_txtWidth == null && _masterShape != null
&& _masterShape._txtWidth != null)
return _masterShape._txtWidth;
if (_txtWidth == null)
@ -549,10 +556,9 @@ public class XDGFShape extends XDGFSheet {
return _txtWidth;
}
public Double getTxtHeight() {
if (_txtHeight == null &&
_masterShape != null && _masterShape._txtHeight != null)
if (_txtHeight == null && _masterShape != null
&& _masterShape._txtHeight != null)
return _masterShape._txtHeight;
if (_txtHeight == null)
@ -641,6 +647,7 @@ public class XDGFShape extends XDGFSheet {
return null;
}
@Override
public Color getFontColor() {
Color fontColor = super.getFontColor();
@ -660,6 +667,7 @@ public class XDGFShape extends XDGFSheet {
return null;
}
@Override
public Double getFontSize() {
Double fontSize = super.getFontSize();
@ -790,21 +798,18 @@ public class XDGFShape extends XDGFSheet {
return new BasicStroke(lineWeight, cap, join, miterlimit, dash, 0);
}
//
// Geometry
//
public Iterable<GeometrySection> getGeometrySections() {
return new CombinedIterable<>(_geometry,
return new CombinedIterable<GeometrySection>(_geometry,
_masterShape != null ? _masterShape._geometry : null);
}
// returns a rectangle in local coordinates
public Rectangle2D.Double getBounds() {
return new Rectangle2D.Double(0, 0, getWidth(),
getHeight());
return new Rectangle2D.Double(0, 0, getWidth(), getHeight());
}
// 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
* to the coordinates of its parent shape
* Returns a transform that can translate shape-local coordinates to the
* coordinates of its parent shape
*/
protected AffineTransform getParentTransform() {
// TODO: There's probably a better way to do this
@ -886,8 +891,6 @@ public class XDGFShape extends XDGFSheet {
return tr;
}
/**
* The visitor will first visit this shape, then it's children
*

View File

@ -43,13 +43,13 @@ public abstract class XDGFSheet {
protected SheetType _sheet;
// cells
protected Map<String, XDGFCell> _cells = new HashMap<>();
protected Map<String, XDGFCell> _cells = new HashMap<String, XDGFCell>();
// sections
protected Map<String, XDGFSection> _sections = new HashMap<>();
protected Map<String, XDGFSection> _sections = new HashMap<String, XDGFSection>();
// 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
protected CharacterSection _character = null;

View File

@ -27,10 +27,10 @@ public class XDGFStyleSheet extends XDGFSheet {
super(styleSheet, document);
}
@Override
@Internal
public StyleSheetType getXmlObject() {
return (StyleSheetType) _sheet;
}
}

View File

@ -54,7 +54,8 @@ public class XDGFText {
}
// 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() {
double txtPinX = _parent.getTxtPinX();
@ -92,7 +93,8 @@ public class XDGFText {
// center of text in local coordinates
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
@ -110,14 +112,17 @@ public class XDGFText {
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 flipY = _parent.getFlipY();
if (flipY == null || !_parent.getFlipY()) {
graphics.translate(bounds.x, bounds.y);
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()) {
@ -140,9 +145,11 @@ public class XDGFText {
if (layout.isLeftToRight())
layout.draw(graphics, 0, nextY);
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);

View File

@ -42,7 +42,6 @@ public class XmlVisioDocument extends POIXMLDocument {
XDGFMasters _masters;
XDGFDocument _document;
public XmlVisioDocument(OPCPackage pkg) throws IOException {
super(pkg, CORE_DOCUMENT);
@ -50,7 +49,9 @@ public class XmlVisioDocument extends POIXMLDocument {
try {
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);
}
@ -64,7 +65,6 @@ public class XmlVisioDocument extends POIXMLDocument {
this(PackageHelper.open(is));
}
@Override
protected void onDocumentRead() throws IOException {
@ -90,8 +90,6 @@ public class XmlVisioDocument extends POIXMLDocument {
_pages.onDocumentRead();
}
@Override
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
throw new UnsupportedOperationException("Not implemented");
@ -105,7 +103,6 @@ public class XmlVisioDocument extends POIXMLDocument {
return _pages.getPageList();
}
public XDGFStyleSheet getStyleById(long id) {
return _document.getStyleById(id);
}

View File

@ -33,7 +33,7 @@ public class CharacterSection extends XDGFSection {
Double _fontSize = null;
Color _fontColor = null;
Map<String, XDGFCell> _characterCells = new HashMap<>();
Map<String, XDGFCell> _characterCells = new HashMap<String, XDGFCell>();
public CharacterSection(SectionType section, XDGFSheet containingSheet) {
super(section, containingSheet);

View File

@ -19,9 +19,9 @@ package org.apache.poi.xdgf.usermodel.section;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.SortedMap;
import java.util.Map.Entry;
// iterates over the base and master
public class CombinedIterable<T> implements Iterable<T> {
@ -58,7 +58,8 @@ public class CombinedIterable<T> implements Iterable<T> {
@Override
public boolean hasNext() {
return currentBase != null || currentMaster != null || baseI.hasNext() || masterI.hasNext();
return currentBase != null || currentMaster != null
|| baseI.hasNext() || masterI.hasNext();
}
@Override

View File

@ -29,9 +29,9 @@ import org.apache.poi.xdgf.usermodel.XDGFCell;
import org.apache.poi.xdgf.usermodel.XDGFShape;
import org.apache.poi.xdgf.usermodel.XDGFSheet;
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.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.SplineStart;
@ -43,7 +43,7 @@ public class GeometrySection extends XDGFSection {
GeometrySection _master = null;
// rows
SortedMap<Long, GeometryRow> _rows = new TreeMap<>();
SortedMap<Long, GeometryRow> _rows = new TreeMap<Long, GeometryRow>();
public GeometrySection(SectionType section, XDGFSheet containingSheet) {
super(section, containingSheet);
@ -89,7 +89,7 @@ public class GeometrySection extends XDGFSection {
}
public Iterable<GeometryRow> getCombinedRows() {
return new CombinedIterable<>(_rows,
return new CombinedIterable<GeometryRow>(_rows,
_master == null ? null : _master._rows);
}

View File

@ -34,7 +34,7 @@ public abstract class XDGFSection {
static final ObjectFactory<XDGFSection, SectionType> _sectionTypes;
static {
_sectionTypes = new ObjectFactory<>();
_sectionTypes = new ObjectFactory<XDGFSection, SectionType>();
try {
_sectionTypes.put("LineGradient", 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("Annotation", 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");
}
@ -69,7 +71,7 @@ public abstract class XDGFSection {
protected SectionType _section;
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) {

View File

@ -48,7 +48,8 @@ public class ArcTo implements GeometryRow {
public ArcTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -60,7 +61,8 @@ public class ArcTo implements GeometryRow {
} else if (cellName.equals("A")) {
a = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
Point2D last = path.getCurrentPoint();
@ -113,7 +116,8 @@ public class ArcTo implements GeometryRow {
double y0 = last.getY();
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
double cx = x0 + (x - x0) / 2.0;
@ -121,11 +125,10 @@ public class ArcTo implements GeometryRow {
double rotate = Math.atan2(y - cy, x - cx);
Arc2D arc = new Arc2D.Double(x0, y0 - radius,
chordLength, 2*radius,
180, x0 < x ? 180 : -180,
Arc2D.OPEN);
Arc2D arc = new Arc2D.Double(x0, y0 - radius, chordLength, 2 * radius,
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);
}
}

View File

@ -53,7 +53,8 @@ public class Ellipse implements GeometryRow {
public Ellipse(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -71,7 +72,8 @@ public class Ellipse implements GeometryRow {
} else if (cellName.equals("D")) {
d = XDGFCell.parseDoubleValue(cell);
} 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() {
if (getDel()) return null;
if (getDel())
return null;
// intentionally shadowing variables here
double cx = getX(); // center
@ -132,11 +135,12 @@ public class Ellipse implements GeometryRow {
double ry = Math.hypot(c - cx, d - cy);
// 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
Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx,
cy - ry,
Ellipse2D.Double ellipse = new Ellipse2D.Double(cx - rx, cy - ry,
rx * 2, ry * 2);
// create a path, rotate it about its center

View File

@ -19,7 +19,6 @@ package org.apache.poi.xdgf.usermodel.section.geometry;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import org.apache.poi.POIXMLException;
@ -49,7 +48,8 @@ public class EllipticalArcTo implements GeometryRow {
// The y-coordinate of an arc's control point.
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;
// 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) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -83,7 +84,8 @@ public class EllipticalArcTo implements GeometryRow {
} else if (cellName.equals("D")) {
d = XDGFCell.parseDoubleValue(cell);
} 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;
}
@Override
public void setupMaster(GeometryRow row) {
_master = (EllipticalArcTo) row;
@ -133,7 +134,8 @@ public class EllipticalArcTo implements GeometryRow {
@Override
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
// intentionally shadowing variables here
double x = getX();
@ -146,17 +148,18 @@ public class EllipticalArcTo implements GeometryRow {
createEllipticalArc(x, y, a, b, c, d, path);
}
public static void createEllipticalArc(double x, double y, double a, double b,
double c, double d,
java.awt.geom.Path2D.Double path) {
public static void createEllipticalArc(double x, double y, double a,
double b, double c, double d, java.awt.geom.Path2D.Double path) {
// Formula for center of ellipse by Junichi Yoda & nashwaan:
// -> From http://visguy.com/vgforum/index.php?topic=2464.0
//
// 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)))
// 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)))
// 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)))
// 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 }
//
@ -169,41 +172,53 @@ public class EllipticalArcTo implements GeometryRow {
double[] pts = new double[] { x0, y0, x, y, a, b };
at.transform(pts, 0, pts, 0, 3);
x0 = pts[0]; y0 = pts[1];
x = pts[2]; y = pts[3];
a = pts[4]; b = pts[5];
x0 = pts[0];
y0 = pts[1];
x = pts[2];
y = pts[3];
a = pts[4];
b = pts[5];
// nasty math time
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 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)));
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 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
double rx = Math.sqrt(Math.pow(x0 - cx, 2) + Math.pow(y0 - cy, 2) * d2);
double ry = rx / d;
// 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
// - Derived from parametric form of ellipse: x = h + a*cos(t); y = k + b*sin(t)
// need to calculate the angle of the start point and end point along
// 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 startAngle = Math.toDegrees(Math.atan2((y0-cy)/ry, (x0-cx)/rx));
double endAngle = Math.toDegrees(Math.atan2((y-cy)/ry, (x-cx)/rx));
double ctrlAngle = Math.toDegrees(Math.atan2((b - cy) / ry, (a - 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);
// Now we have enough information to go on. Create the arc.
Arc2D arc = new Arc2D.Double(cx-rx, cy-ry,
rx*2, ry*2, -startAngle, sweep, Arc2D.OPEN);
Arc2D arc = new Arc2D.Double(cx - rx, cy - ry, rx * 2, ry * 2,
-startAngle, sweep, Arc2D.OPEN);
// rotate the arc back to the original coordinate system
at.setToRotation(c);
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;
startAngle = (360.0 + startAngle) % 360.0;

View File

@ -21,7 +21,6 @@ import java.awt.geom.Path2D;
import org.apache.poi.xdgf.usermodel.XDGFShape;
public interface GeometryRow {
public void setupMaster(GeometryRow row);

View File

@ -27,24 +27,28 @@ public class GeometryRowFactory {
static final ObjectFactory<GeometryRow, RowType> _rowTypes;
static {
_rowTypes = new ObjectFactory<>();
_rowTypes = new ObjectFactory<GeometryRow, RowType>();
try {
_rowTypes.put("ArcTo", ArcTo.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("LineTo", LineTo.class, RowType.class);
_rowTypes.put("MoveTo", MoveTo.class, RowType.class);
_rowTypes.put("NURBSTo", NURBSTo.class, RowType.class);
_rowTypes.put("PolyLineTo", PolyLineTo.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("RelMoveTo", RelMoveTo.class, RowType.class);
_rowTypes.put("RelQuadBezTo", RelQuadBezTo.class, RowType.class);
_rowTypes.put("SplineKnot", SplineKnot.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);
}

View File

@ -18,14 +18,9 @@
package org.apache.poi.xdgf.usermodel.section.geometry;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
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.XDGFDocument;
import org.apache.poi.xdgf.usermodel.XDGFPage;
import org.apache.poi.xdgf.usermodel.XDGFShape;
import com.microsoft.schemas.office.visio.x2012.main.CellType;
@ -38,16 +33,20 @@ public class InfiniteLine implements GeometryRow {
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;
// 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;
// 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;
// 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;
Boolean deleted = null;
@ -56,7 +55,8 @@ public class InfiniteLine implements GeometryRow {
public InfiniteLine(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -70,7 +70,8 @@ public class InfiniteLine implements GeometryRow {
} else if (cellName.equals("B")) {
b = XDGFCell.parseDoubleValue(cell);
} 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
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

View File

@ -37,7 +37,8 @@ public class LineTo implements GeometryRow {
public LineTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -47,7 +48,8 @@ public class LineTo implements GeometryRow {
} else if (cellName.equals("Y")) {
y = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
path.lineTo(getX(), getY());
}
}

View File

@ -42,7 +42,8 @@ public class MoveTo implements GeometryRow {
public MoveTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -52,7 +53,8 @@ public class MoveTo implements GeometryRow {
} else if (cellName.equals("Y")) {
y = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
path.moveTo(getX(), getY());
}
}

View File

@ -20,14 +20,11 @@ package org.apache.poi.xdgf.usermodel.section.geometry;
import java.awt.geom.Point2D;
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.usermodel.XDGFCell;
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.RowType;
@ -62,7 +59,8 @@ public class NURBSTo implements GeometryRow {
public NURBSTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -82,7 +80,8 @@ public class NURBSTo implements GeometryRow {
} else if (cellName.equals("E")) {
e = cell.getV();
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
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();
if (!formula.startsWith("NURBS(") || !formula.endsWith(")"))
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)
throw new POIXMLException("Invalid NURBS formula (not enough arguments)");
throw new POIXMLException(
"Invalid NURBS formula (not enough arguments)");
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 lastControlY = getY();
@ -199,7 +204,8 @@ public class NURBSTo implements GeometryRow {
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);
}
}

View File

@ -43,7 +43,8 @@ public class PolyLineTo implements GeometryRow {
public PolyLineTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -55,7 +56,8 @@ public class PolyLineTo implements GeometryRow {
} else if (cellName.equals("A")) {
a = cell.getV();
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
throw new POIXMLException("Polyline support not implemented");
}
}

View File

@ -28,22 +28,30 @@ public class RelCubBezTo implements GeometryRow {
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;
// 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;
// The x-coordinate of the curves beginning control point relative to the shapes 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;
// The y-coordinate of a curves beginning control point relative to the shapes height.
// The y-coordinate of a curve's beginning control point relative to the
// shape's height.
Double b = null;
// The x-coordinate of the curves ending control point relative to the shapes 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;
// The y-coordinate of a curve's ending control point relative to the shapes height.
// The y-coordinate of a curve's ending control point relative to the
// shape's height.
Double d = null;
Boolean deleted = null;
@ -52,7 +60,8 @@ public class RelCubBezTo implements GeometryRow {
public RelCubBezTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -70,7 +79,8 @@ public class RelCubBezTo implements GeometryRow {
} else if (cellName.equals("D")) {
d = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
double w = parent.getWidth();
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);
}
}

View File

@ -36,11 +36,11 @@ public class RelEllipticalArcTo implements GeometryRow {
// the shape.
Double y = null;
// The x-coordinate of the arc's control point relative to the shapes
// The x-coordinate of the arc's control point relative to the shape's
// width; a point on the arc.
Double a = null;
// The y-coordinate of an arc's control point relative to the shapes width.
// The y-coordinate of an arc's control point relative to the shape's width.
Double b = null;
// 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) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -75,7 +76,8 @@ public class RelEllipticalArcTo implements GeometryRow {
} else if (cellName.equals("D")) {
d = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
double w = parent.getWidth();
double h = parent.getHeight();

View File

@ -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
* relative to a shapes width and height.
* relative to a shape's width and height.
*/
public class RelLineTo implements GeometryRow {
@ -41,7 +41,8 @@ public class RelLineTo implements GeometryRow {
public RelLineTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -51,7 +52,8 @@ public class RelLineTo implements GeometryRow {
} else if (cellName.equals("Y")) {
y = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
path.lineTo(getX()*parent.getWidth(),
getY()*parent.getHeight());
path.lineTo(getX() * parent.getWidth(), getY() * parent.getHeight());
}
}

View File

@ -37,7 +37,8 @@ public class RelMoveTo implements GeometryRow {
public RelMoveTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -47,7 +48,8 @@ public class RelMoveTo implements GeometryRow {
} else if (cellName.equals("Y")) {
y = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
path.moveTo(getX()*parent.getWidth(),
getY()*parent.getHeight());
path.moveTo(getX() * parent.getWidth(), getY() * parent.getHeight());
}
}

View File

@ -25,24 +25,29 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType;
import com.microsoft.schemas.office.visio.x2012.main.RowType;
/**
* Contains the x- and y-coordinates of the endpoint of a quadratic Bézier curve
* relative to the shapes width and height and the x- and y-coordinates of the
* control point of the curve relative shapes width and height.
* 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
* control point of the curve relative shape's width and height.
*/
public class RelQuadBezTo implements GeometryRow {
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;
// 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;
// The x-coordinate of the curves control point relative to the shapes 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;
// The y-coordinate of a curves control point relative to the shapes height.
// The y-coordinate of a curve's control point relative to the shape's
// height.
Double b = null;
Boolean deleted = null;
@ -51,7 +56,8 @@ public class RelQuadBezTo implements GeometryRow {
public RelQuadBezTo(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -65,7 +71,8 @@ public class RelQuadBezTo implements GeometryRow {
} else if (cellName.equals("B")) {
b = XDGFCell.parseDoubleValue(cell);
} 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
public void addToPath(java.awt.geom.Path2D.Double path, XDGFShape parent) {
if (getDel()) return;
if (getDel())
return;
double w = parent.getWidth();
double h = parent.getHeight();

View File

@ -25,7 +25,8 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType;
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 {
@ -46,7 +47,8 @@ public class SplineKnot implements GeometryRow {
public SplineKnot(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -58,7 +60,8 @@ public class SplineKnot implements GeometryRow {
} else if (cellName.equals("A")) {
a = XDGFCell.parseDoubleValue(cell);
} 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
public String toString() {
return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA() + "}";
return "{SplineKnot x=" + getX() + " y=" + getY() + " a=" + getA()
+ "}";
}
}

View File

@ -55,7 +55,8 @@ public class SplineStart implements GeometryRow {
public SplineStart(RowType row) {
if (row.isSetDel()) deleted = row.getDel();
if (row.isSetDel())
deleted = row.getDel();
for (CellType cell : row.getCellArray()) {
String cellName = cell.getN();
@ -73,7 +74,8 @@ public class SplineStart implements GeometryRow {
} else if (cellName.equals("D")) {
d = XDGFCell.parseIntegerValue(cell);
} 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
public String toString() {
return "{SplineStart x=" + getX() + " y=" + getY() +
" a=" + getA() + " b=" + getB() +
" c=" + getC() + " d=" + getD() +
"}";
return "{SplineStart x=" + getX() + " y=" + getY() + " a=" + getA()
+ " b=" + getB() + " c=" + getC() + " d=" + getD() + "}";
}
}

View File

@ -21,16 +21,13 @@ import org.apache.poi.xdgf.usermodel.XDGFShape;
/**
* This acceptor only allows traversal to shapes that have useful data
* associated with them, and tries to elide details that aren't useful
* when analyzing the content of a document.
* associated with them, and tries to elide details that aren't useful when
* analyzing the content of a document.
*
* Useful is subjective of course, and is defined as any of:
*
* - Has non-empty text
* - Is a 1d shape, such as a line
* - User specified shapes
* - The outline of stencil objects
* - TODO
* - Has non-empty text - Is a 1d shape, such as a line - User specified shapes
* - The outline of stencil objects - TODO
*/
public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
@ -65,5 +62,4 @@ public class ShapeDataAcceptor implements ShapeVisitorAcceptor {
return false;
}
}

View File

@ -58,7 +58,6 @@ public class ShapeDebuggerRenderer extends ShapeRenderer {
shapeOffset -= 0.15F;
}
_graphics.drawString(shapeId, shapeOffset, 0);
_graphics.setFont(f);
_graphics.scale(1, -1);

View File

@ -17,7 +17,6 @@
package org.apache.poi.xdgf.usermodel.shape;
import java.awt.BasicStroke;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
@ -47,7 +46,8 @@ public class ShapeRenderer extends ShapeVisitor {
}
@Override
public void visit(XDGFShape shape, AffineTransform globalTransform, int level) {
public void visit(XDGFShape shape, AffineTransform globalTransform,
int level) {
AffineTransform savedTr = _graphics.getTransform();
_graphics.transform(globalTransform);
@ -82,7 +82,8 @@ public class ShapeRenderer extends ShapeVisitor {
Font oldFont = _graphics.getFont();
_graphics.setFont(oldFont.deriveFont(shape.getFontSize().floatValue()));
_graphics.setFont(oldFont.deriveFont(shape.getFontSize()
.floatValue()));
_graphics.setColor(shape.getFontColor());
text.draw(_graphics);

View File

@ -27,8 +27,8 @@ import org.apache.poi.xdgf.usermodel.XDGFShape;
* To change the behavior of a particular visitor, you can override either
* accept() or getAcceptor() [preferred]
*
* If accept() or visit() throw StopVisitingThisBranch, the iteration will
* not visit subshapes of the shape.
* If accept() or visit() throw StopVisitingThisBranch, the iteration will not
* visit subshapes of the shape.
*/
public abstract class ShapeVisitor {
@ -53,16 +53,20 @@ public abstract class ShapeVisitor{
_acceptor = acceptor;
}
public boolean accept(XDGFShape shape) {
return _acceptor.accept(shape);
}
/**
* @param shape Current shape
* @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...
* @param shape
* Current shape
* @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);
}

View File

@ -32,9 +32,11 @@ import org.apache.poi.xdgf.usermodel.shape.ShapeVisitor;
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);
PrintStream pos = new PrintStream(os);
@ -49,17 +51,22 @@ public class HierarchyPrinter {
page.getContent().visitShapes(new ShapeVisitor() {
@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++) {
os.append(" ");
}
// 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);
@ -68,7 +75,6 @@ public class HierarchyPrinter {
}
}
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: in.vsdx outdir");
@ -78,7 +84,8 @@ public class HierarchyPrinter {
String inFilename = args[0];
String outDir = args[1];
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
inFilename));
printHierarchy(doc, outDir);
}
}

View File

@ -28,7 +28,7 @@ import org.apache.xmlbeans.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 {
_types.put(typeName, cls.getDeclaredConstructor(varargs));

View File

@ -20,7 +20,6 @@ package org.apache.poi.xdgf.util;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
@ -37,35 +36,43 @@ import org.apache.poi.xdgf.usermodel.shape.ShapeRenderer;
public class VsdxToPng {
public static void renderToPng(XDGFPage page, String outFilename, double scale, ShapeRenderer renderer) throws IOException {
public static void renderToPng(XDGFPage page, String outFilename,
double scale, ShapeRenderer renderer) throws IOException {
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);
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();
int width = (int) (scale * sz.getWidth());
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();
// default rendering options
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
graphics.setRenderingHint(RenderingHints.KEY_RENDERING,
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.setBackground(Color.white);
@ -86,7 +93,9 @@ public class VsdxToPng {
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);
@ -112,7 +121,8 @@ public class VsdxToPng {
renderer = new ShapeDebuggerRenderer();
}
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(inFilename));
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream(
inFilename));
renderToPng(doc, pngDir, 2000 / 11.0, renderer);
}
}

View File

@ -25,7 +25,8 @@ public class XDGFXMLDocumentPart extends POIXMLDocumentPart {
protected XDGFDocument _document;
public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel, XDGFDocument document) {
public XDGFXMLDocumentPart(PackagePart part, PackageRelationship rel,
XDGFDocument document) {
super(part, rel);
_document = document;
}

View File

@ -41,119 +41,117 @@ public class CombinedIteratorTest {
@Test
public void testNullMaster() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(2L, "B2");
base.put(3L, "B3");
testIteration(new CombinedIterable<>(base, null),
"B1", "B2", "B3");
testIteration(new CombinedIterable<String>(base, null), "B1", "B2",
"B3");
}
@Test
public void testNoMatchesBaseFirst() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(2L, "B2");
base.put(3L, "B3");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(4L, "M4");
master.put(5L, "M5");
master.put(6L, "M6");
testIteration(new CombinedIterable<>(base, master),
"B1", "B2", "B3", "M4", "M5", "M6");
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
"B3", "M4", "M5", "M6");
}
@Test
public void testNoMatchesMasterFirst() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(4L, "B4");
base.put(5L, "B5");
base.put(6L, "B6");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(1L, "M1");
master.put(2L, "M2");
master.put(3L, "M3");
testIteration(new CombinedIterable<>(base, master),
"M1", "M2", "M3", "B4", "B5", "B6");
testIteration(new CombinedIterable<String>(base, master), "M1", "M2",
"M3", "B4", "B5", "B6");
}
@Test
public void testInterleaved1() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(3L, "B3");
base.put(5L, "B5");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(2L, "M2");
master.put(4L, "M4");
master.put(6L, "M6");
testIteration(new CombinedIterable<>(base, master),
"B1", "M2", "B3", "M4", "B5", "M6");
testIteration(new CombinedIterable<String>(base, master), "B1", "M2",
"B3", "M4", "B5", "M6");
}
@Test
public void testInterleaved2() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(2L, "B2");
base.put(5L, "B5");
base.put(6L, "B6");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(3L, "M3");
master.put(4L, "M4");
master.put(7L, "M7");
master.put(8L, "M8");
testIteration(new CombinedIterable<>(base, master),
"B1", "B2", "M3", "M4", "B5", "B6", "M7", "M8");
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
"M3", "M4", "B5", "B6", "M7", "M8");
}
@Test
public void testAllMatching() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(2L, "B2");
base.put(3L, "B3");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(1L, "M1");
master.put(2L, "M2");
master.put(3L, "M3");
testIteration(new CombinedIterable<>(base, master),
"B1", "B2", "B3");
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
"B3");
}
@Test
public void testAllMatching2() {
SortedMap<Long, String> base = new TreeMap<>();
SortedMap<Long, String> base = new TreeMap<Long, String>();
base.put(1L, "B1");
base.put(2L, "B2");
base.put(3L, "B3");
SortedMap<Long, String> master = new TreeMap<>();
SortedMap<Long, String> master = new TreeMap<Long, String>();
master.put(1L, "M1");
master.put(2L, "M2");
master.put(3L, "M3");
master.put(4L, "M4");
testIteration(new CombinedIterable<>(base, master),
"B1", "B2", "B3", "M4");
testIteration(new CombinedIterable<String>(base, master), "B1", "B2",
"B3", "M4");
}
}