List of usage examples for java.awt.geom Dimension2D getWidth
public abstract double getWidth();
From source file:ShapeTransform.java
/** * Translates the given shape. The shape is translated to the origin supplied * in <code>point</code>. If scaling is requested, the shape will also be * scaled using an AffineTransform.//from ww w . j ava2 s .co m * * @param s * the shape that should be transformed * @param scale * true, if the shape should be scaled, false otherwise * @param keepAR * true, if the scaled shape should keep the aspect ratio * @param dim * the target dimension. * @return the transformed shape */ public static Shape transformShape(final Shape s, final boolean scale, final boolean keepAR, final Dimension2D dim) { return transformShape(s, scale, keepAR, dim.getWidth(), dim.getHeight()); }
From source file:net.sf.jasperreports.customizers.shape.LineDotShapeCustomizer.java
@Override protected Point getOffset(Dimension2D size) { return new Point((int) (size.getWidth() / 2), (int) (size.getHeight() / 2)); }
From source file:net.sf.jasperreports.customizers.shape.AbstractShapeCustomizer.java
/** * Builds an ellipse shape./* w w w . ja v a 2s . c om*/ * * @return the ellipse or null if its size is not specified */ protected Shape buildEllipse() { Ellipse2D ellipse = null; Dimension2D size = getSize(); if (size != null) { Point offset = getOffset(size); ellipse = new Ellipse2D.Float(-offset.getX(), -offset.getY(), (float) size.getWidth(), (float) size.getHeight()); } return ellipse; }
From source file:net.sf.jasperreports.customizers.shape.AbstractShapeCustomizer.java
/** * Builds a rectangle shape./*from ww w.ja va 2 s . c o m*/ * * @return the rectangle or null if its size is not specified */ protected Shape buildRectangle() { Rectangle2D rectangle = null; Dimension2D size = getSize(); if (size != null) { Point offset = getOffset(size); rectangle = new Rectangle2D.Float(-offset.getX(), -offset.getY(), (float) size.getWidth(), (float) size.getHeight()); } return rectangle; }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Transform the tree layout so that it fits nicely in the given image * dimensions/*w ww .jav a2 s. com*/ * @param treeLayout * the layout to transform * @param imageWidth * the image width * @param imageHeight * the image height */ private void transformTreeLayout(VisualTreeNode treeLayout, int imageWidth, int imageHeight, FontRenderContext frc) { Dimension2D maximalNodeLabelDimension = this.calculateMaximalNodeDimension(treeLayout, frc); double widthBuffer = maximalNodeLabelDimension.getWidth() + BORDER_WHITE_SPACE; double heightBuffer = maximalNodeLabelDimension.getHeight() + BORDER_WHITE_SPACE; // perform rotation to improve the use of space { // center around 0, 0 VisualTreeNode[] mostDistantPair = this.getMostDistantNodePair(treeLayout); Point2D distantPoint1 = mostDistantPair[0].getPosition(); Point2D distantPoint2 = mostDistantPair[1].getPosition(); double xDiff = distantPoint1.getX() - distantPoint2.getX(); double yDiff = distantPoint1.getY() - distantPoint2.getY(); this.translateTreeLayout(treeLayout, (xDiff / 2.0) - distantPoint1.getX(), (yDiff / 2.0) - distantPoint2.getY()); // rotate double thetaRadians = Math.atan2(yDiff, xDiff); if (imageWidth >= imageHeight) { this.rotateTreeLayout(treeLayout, -thetaRadians); } else { this.rotateTreeLayout(treeLayout, (Math.PI / 2.0 - thetaRadians)); } } Rectangle2D boundingRectangle = this.calculateBounds(treeLayout, null); // center around the middle of the display area this.translateTreeLayout(treeLayout, -boundingRectangle.getX(), -boundingRectangle.getY()); // grow the image to fill a larger area double xScale = (imageWidth - widthBuffer) / boundingRectangle.getWidth(); double yScale = (imageHeight - heightBuffer) / boundingRectangle.getHeight(); double smallerScale = Math.min(xScale, yScale); this.scaleTreeLayout(treeLayout, smallerScale); // center around the middle of the display area boundingRectangle = this.calculateBounds(treeLayout, null); this.translateTreeLayout(treeLayout, ((imageWidth - boundingRectangle.getWidth()) / 2.0) - boundingRectangle.getX(), ((imageHeight - boundingRectangle.getHeight()) / 2.0) - boundingRectangle.getY()); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public static BufferedImage renderMindMapAsImage(final MindMap model, final MindMapPanelConfig cfg, final boolean expandAll) { final MindMap workMap = new MindMap(model, null); workMap.resetPayload();//from w w w . j av a 2s.co m if (expandAll) { MindMapUtils.removeCollapseAttr(workMap); } final Dimension2D blockSize = calculateSizeOfMapInPixels(workMap, cfg, expandAll); if (blockSize == null) { return null; } final BufferedImage img = new BufferedImage((int) blockSize.getWidth(), (int) blockSize.getHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D gfx = img.createGraphics(); try { Utils.prepareGraphicsForQuality(gfx); gfx.setClip(0, 0, img.getWidth(), img.getHeight()); layoutFullDiagramWithCenteringToPaper(gfx, workMap, cfg, blockSize); drawOnGraphicsForConfiguration(gfx, cfg, workMap, false, null); } finally { gfx.dispose(); } return img; }
From source file:net.sf.jasperreports.engine.fill.JRFillImage.java
protected boolean fitImage(Dimension2D imageSize, int availableHeight, boolean overflowAllowed, HorizontalImageAlignEnum hAlign) throws JRException { imageHeight = null;//from ww w .j a v a2 s . co m imageWidth = null; imageX = null; int realHeight = (int) imageSize.getHeight(); int realWidth = (int) imageSize.getWidth(); boolean fitted; int reducedHeight = realHeight; int reducedWidth = realWidth; if (realWidth > getWidth()) { double wRatio = ((double) getWidth()) / realWidth; reducedHeight = (int) (wRatio * realHeight); reducedWidth = getWidth(); } if (reducedHeight <= availableHeight) { imageHeight = reducedHeight; if (getScaleImageValue() == ScaleImageEnum.REAL_SIZE) { imageWidth = reducedWidth; } fitted = true; } else if (overflowAllowed) { fitted = false; } else { imageHeight = availableHeight; if (getScaleImageValue() == ScaleImageEnum.REAL_SIZE) { double hRatio = ((double) availableHeight) / realHeight; imageWidth = (int) (hRatio * realWidth); } fitted = true; } if (imageWidth != null && imageWidth != getWidth()) { switch (hAlign) { case RIGHT: imageX = getX() + getWidth() - imageWidth; break; case CENTER: imageX = getX() + (getWidth() - imageWidth) / 2; break; default: break; } } if (log.isDebugEnabled()) { log.debug("Fitted image of dimension " + imageSize + " on " + availableHeight + ", overflow allowed " + overflowAllowed + ": " + fitted); } return fitted; }
From source file:de.kiwiwings.jasperreports.exporter.PptxShapeExporter.java
/** * *///from ww w .j a v a2 s .c o m public void exportImage(JRPrintImage image) throws JRException { int leftPadding = image.getLineBox().getLeftPadding().intValue(); int topPadding = image.getLineBox().getTopPadding().intValue();//FIXMEDOCX maybe consider border thickness int rightPadding = image.getLineBox().getRightPadding().intValue(); int bottomPadding = image.getLineBox().getBottomPadding().intValue(); double availableImageWidth = image.getWidth() - leftPadding - rightPadding; availableImageWidth = availableImageWidth < 0 ? 0 : availableImageWidth; double availableImageHeight = image.getHeight() - topPadding - bottomPadding; availableImageHeight = availableImageHeight < 0 ? 0 : availableImageHeight; Renderable renderer = image.getRenderable(); if (renderer == null || availableImageWidth == 0 || availableImageHeight == 0) return; if (renderer.getTypeValue() == RenderableTypeEnum.IMAGE) { // Non-lazy image renderers are all asked for their image data at some point. // Better to test and replace the renderer now, in case of lazy load error. renderer = RenderableUtil.getInstance(jasperReportsContext).getOnErrorRendererForImageData(renderer, image.getOnErrorTypeValue()); if (renderer == null) return; } double normalWidth = availableImageWidth; double normalHeight = availableImageHeight; // Image load might fail. Renderable tmpRenderer = RenderableUtil.getInstance(jasperReportsContext) .getOnErrorRendererForDimension(renderer, image.getOnErrorTypeValue()); Dimension2D dimension = tmpRenderer == null ? null : tmpRenderer.getDimension(jasperReportsContext); // If renderer was replaced, ignore image dimension. if (tmpRenderer == renderer && dimension != null) { normalWidth = dimension.getWidth(); normalHeight = dimension.getHeight(); } double cropTop = 0; double cropLeft = 0; double cropBottom = 0; double cropRight = 0; switch (image.getScaleImageValue()) { case FILL_FRAME: // width = availableImageWidth; // height = availableImageHeight; break; default: case RETAIN_SHAPE: if (availableImageWidth > 0 && availableImageHeight > 0) { if (normalWidth > availableImageWidth) { normalHeight /= normalWidth / availableImageWidth; normalWidth = availableImageWidth; } if (normalHeight > availableImageHeight) { normalWidth /= normalHeight / availableImageHeight; normalHeight = availableImageHeight; } } // nobreak case CLIP: if (availableImageWidth > 0 && availableImageHeight > 0) { double reducedWidth = getOffsetInPercent(normalWidth, availableImageWidth); switch (image.getHorizontalAlignmentValue()) { default: case LEFT: cropRight = reducedWidth; break; case RIGHT: cropLeft = reducedWidth; break; case CENTER: cropLeft = cropRight = reducedWidth / 2d; break; } double reducedHeight = getOffsetInPercent(normalHeight, availableImageHeight); switch (image.getVerticalAlignmentValue()) { default: case BOTTOM: cropTop = reducedHeight; break; case TOP: cropBottom = reducedHeight; break; case MIDDLE: cropTop = cropBottom = reducedHeight / 2; break; } } break; } XSLFSimpleShape backgroundShape; XSLFShape hyperlinkShape; if (renderer instanceof DrawChartRenderer) { Rectangle2D rect = new Rectangle2D.Double(image.getX(), image.getY(), image.getWidth(), image.getHeight()); PptxGraphics2D grx2 = new PptxGraphics2D(rect, this, slide); // Background color is applied to whole Image backgroundShape = grx2.getShape(rect); renderer.render(jasperReportsContext, grx2, rect); // hyperlinks are only available for visible elements of the chart XSLFGroupShape grp = grx2.getShapeGroup(); CTNonVisualDrawingProps cp = grp.getXmlObject().getNvGrpSpPr().getCNvPr(); cp.setName(cp.getName().replaceFirst("[^ ]+", "JFreeChart")); hyperlinkShape = grp; } else { // if (image.isLazy())//FIXMEDOCX learn how to link images Renderable imgRenderer = image.getRenderable(); if (imgRenderer.getTypeValue() == RenderableTypeEnum.SVG) { imgRenderer = new JRWrappingSvgRenderer(imgRenderer, new Dimension(image.getWidth(), image.getHeight()), ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null); } ImageTypeEnum mimeType = imgRenderer.getImageTypeValue(); if (mimeType == null) mimeType = ImageTypeEnum.JPEG; int xsMime; switch (mimeType) { default: case UNKNOWN: case JPEG: xsMime = XSLFPictureData.PICTURE_TYPE_JPEG; break; case GIF: xsMime = XSLFPictureData.PICTURE_TYPE_GIF; break; case PNG: xsMime = XSLFPictureData.PICTURE_TYPE_PNG; break; case TIFF: xsMime = XSLFPictureData.PICTURE_TYPE_TIFF; break; } byte pictureData[] = imgRenderer.getImageData(jasperReportsContext); int idx = ppt.addPicture(pictureData, xsMime); backgroundShape = slide.createPicture(idx); hyperlinkShape = backgroundShape; CTPicture ct = (CTPicture) backgroundShape.getXmlObject(); if (cropTop != 0 || cropRight != 0 || cropBottom != 0 || cropLeft != 0) { // CTRelativeRect rrect = ct.getBlipFill().getStretch().getFillRect(); CTRelativeRect rrect = ct.getBlipFill().addNewSrcRect(); rrect.setT((int) cropTop); rrect.setR((int) cropRight); rrect.setB((int) cropBottom); rrect.setL((int) cropLeft); } Rectangle2D rect = new Rectangle2D.Double(image.getX() + getOffsetX() + leftPadding, image.getY() + getOffsetY() + topPadding, availableImageWidth, availableImageHeight); backgroundShape.setAnchor(rect); } exportElementAttributes(backgroundShape, image, image.getLinePen(), image, hyperlinkShape); }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public static Dimension2D calculateSizeOfMapInPixels(final MindMap model, final MindMapPanelConfig cfg, final boolean expandAll) { final MindMap workMap = new MindMap(model, null); workMap.resetPayload();/*w ww. j av a 2 s.c o m*/ BufferedImage img = new BufferedImage(32, 32, cfg.isDrawBackground() ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB); Dimension2D blockSize = null; Graphics2D gfx = img.createGraphics(); try { Utils.prepareGraphicsForQuality(gfx); if (calculateElementSizes(gfx, workMap, cfg)) { if (expandAll) { final AbstractElement root = (AbstractElement) workMap.getRoot().getPayload(); root.collapseOrExpandAllChildren(false); calculateElementSizes(gfx, workMap, cfg); } blockSize = layoutModelElements(workMap, cfg); final double paperMargin = cfg.getPaperMargins() * cfg.getScale(); blockSize.setSize(blockSize.getWidth() + paperMargin * 2, blockSize.getHeight() + paperMargin * 2); } } finally { gfx.dispose(); } return blockSize; }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
public static Dimension layoutFullDiagramWithCenteringToPaper(final Graphics2D gfx, final MindMap map, final MindMapPanelConfig cfg, final Dimension2D paperSize) { Dimension resultSize = null;//ww w . j a v a 2s . c o m if (calculateElementSizes(gfx, map, cfg)) { Dimension2D rootBlockSize = layoutModelElements(map, cfg); final double paperMargin = cfg.getPaperMargins() * cfg.getScale(); if (rootBlockSize != null) { if (paperSize != null) { final ElementRoot rootElement = (ElementRoot) map.getRoot().getPayload(); double rootOffsetXInBlock = rootElement.getLeftBlockSize().getWidth(); double rootOffsetYInBlock = (rootBlockSize.getHeight() - rootElement.getBounds().getHeight()) / 2; rootOffsetXInBlock += paperSize.getWidth() - rootBlockSize.getWidth() <= paperMargin ? paperMargin : (paperSize.getWidth() - rootBlockSize.getWidth()) / 2; rootOffsetYInBlock += paperSize.getHeight() - rootBlockSize.getHeight() <= paperMargin ? paperMargin : (paperSize.getHeight() - rootBlockSize.getHeight()) / 2; moveDiagram(map, rootOffsetXInBlock, rootOffsetYInBlock); } resultSize = new Dimension((int) Math.round(rootBlockSize.getWidth() + paperMargin * 2), (int) Math.round(rootBlockSize.getHeight() + paperMargin * 2)); } } return resultSize; }