use of org.apache.poi.xdgf.geom.Dimension2dDouble in project poi by apache.
the class XDGFPage method getBoundingBox.
/**
* @return bounding box of page
*/
public Rectangle2D getBoundingBox() {
Dimension2dDouble sz = getPageSize();
Point2D.Double offset = getPageOffset();
return new Rectangle2D.Double(-offset.getX(), -offset.getY(), sz.getWidth(), sz.getHeight());
}
use of org.apache.poi.xdgf.geom.Dimension2dDouble in project poi by apache.
the class XDGFPage method getPageSize.
/**
* @return width/height of page
*/
public Dimension2dDouble getPageSize() {
XDGFCell w = _pageSheet.getCell("PageWidth");
XDGFCell h = _pageSheet.getCell("PageHeight");
if (w == null || h == null)
throw new POIXMLException("Cannot determine page size");
return new Dimension2dDouble(Double.parseDouble(w.getValue()), Double.parseDouble(h.getValue()));
}
use of org.apache.poi.xdgf.geom.Dimension2dDouble in project poi by apache.
the class VsdxToPng method renderToPng.
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);
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.setColor(Color.black);
graphics.setBackground(Color.white);
graphics.clearRect(0, 0, width, height);
// Visio's coordinate system is flipped, so flip the image vertically
graphics.translate(0, img.getHeight());
graphics.scale(scale, -scale);
// toplevel shapes only
renderer.setGraphics(graphics);
page.getContent().visitShapes(renderer);
graphics.dispose();
OutputStream out = new FileOutputStream(outFile);
try {
ImageIO.write(img, "png", out);
} finally {
out.close();
}
}
Aggregations