List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
private static AffineTransform findTranslation(AffineTransform at, BufferedImage bi) { Point2D p2din, p2dout;/*from w w w .jav a 2 s . com*/ p2din = new Point2D.Double(0.0, 0.0); p2dout = at.transform(p2din, null); double ytrans = p2dout.getY(); p2din = new Point2D.Double(0, bi.getHeight()); p2dout = at.transform(p2din, null); double xtrans = p2dout.getX(); AffineTransform tat = new AffineTransform(); tat.translate(-xtrans, -ytrans); return tat; }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * {@inheritDoc}//w w w. ja v a2 s.c om */ protected void renderBlockViewport(BlockViewport bv, List children) { // clip and position viewport if necessary // save positions int saveIP = currentIPPosition; int saveBP = currentBPPosition; CTM ctm = bv.getCTM(); int borderPaddingStart = bv.getBorderAndPaddingWidthStart(); int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore(); //This is the content-rect float width = bv.getIPD() / 1000f; float height = bv.getBPD() / 1000f; if (bv.getPositioning() == Block.ABSOLUTE || bv.getPositioning() == Block.FIXED) { //For FIXED, we need to break out of the current viewports to the //one established by the page. We save the state stack for restoration //after the block-container has been painted. See below. List breakOutList = null; if (bv.getPositioning() == Block.FIXED) { breakOutList = breakOutOfStateStack(); } AffineTransform positionTransform = new AffineTransform(); positionTransform.translate(bv.getXOffset(), bv.getYOffset()); //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle positionTransform.translate(-borderPaddingStart, -borderPaddingBefore); saveGraphicsState(); //Viewport position concatenateTransformationMatrix(UnitConv.mptToPt(positionTransform)); //Background and borders float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()) / 1000f; float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()) / 1000f; drawBackAndBorders(bv, 0, 0, width + bpwidth, height + bpheight); //Shift to content rectangle after border painting AffineTransform contentRectTransform = new AffineTransform(); contentRectTransform.translate(borderPaddingStart, borderPaddingBefore); concatenateTransformationMatrix(UnitConv.mptToPt(contentRectTransform)); //Clipping if (bv.getClip()) { clipRect(0f, 0f, width, height); } saveGraphicsState(); //Set up coordinate system for content rectangle AffineTransform contentTransform = ctm.toAffineTransform(); concatenateTransformationMatrix(UnitConv.mptToPt(contentTransform)); currentIPPosition = 0; currentBPPosition = 0; renderBlocks(bv, children); restoreGraphicsState(); restoreGraphicsState(); if (breakOutList != null) { restoreStateStackAfterBreakOut(breakOutList); } currentIPPosition = saveIP; currentBPPosition = saveBP; } else { currentBPPosition += bv.getSpaceBefore(); //borders and background in the old coordinate system handleBlockTraits(bv); //Advance to start of content area currentIPPosition += bv.getStartIndent(); CTM tempctm = new CTM(containingIPPosition, currentBPPosition); ctm = tempctm.multiply(ctm); //Now adjust for border/padding currentBPPosition += borderPaddingBefore; Rectangle2D clippingRect = null; if (bv.getClip()) { clippingRect = new Rectangle(currentIPPosition, currentBPPosition, bv.getIPD(), bv.getBPD()); } startVParea(ctm, clippingRect); currentIPPosition = 0; currentBPPosition = 0; renderBlocks(bv, children); endVParea(); currentIPPosition = saveIP; currentBPPosition = saveBP; currentBPPosition += (bv.getAllocBPD()); } //currentFontName = saveFontName; }
From source file:net.sf.jasperreports.swing.JRViewerPanel.java
protected Image getPageErrorImage() { PrintPageFormat pageFormat = viewerContext.getPageFormat(); Image image = new BufferedImage((int) (pageFormat.getPageWidth() * realZoom) + 1, (int) (pageFormat.getPageHeight() * realZoom) + 1, BufferedImage.TYPE_INT_RGB); AffineTransform transform = new AffineTransform(); transform.scale(realZoom, realZoom); Graphics2D grx = (Graphics2D) image.getGraphics(); try {//ww w .j a va2 s .co m grx.transform(transform); drawPageError(grx); } finally { grx.dispose(); } return image; }
From source file:SWTGraphics2D.java
/** * Returns the font render context./*from w w w.j av a 2s . com*/ * * @return The font render context. */ public FontRenderContext getFontRenderContext() { FontRenderContext fontRenderContext = new FontRenderContext(new AffineTransform(), true, true); return fontRenderContext; }
From source file:org.apache.fop.render.intermediate.IFRenderer.java
/** {@inheritDoc} */ protected void renderBlockViewport(BlockViewport bv, List children) { //Essentially the same code as in the super class but optimized for the IF //This is the content-rect Dimension dim = new Dimension(bv.getIPD(), bv.getBPD()); viewportDimensionStack.push(dim);//from w ww. j av a 2s .co m // save positions int saveIP = currentIPPosition; int saveBP = currentBPPosition; CTM ctm = bv.getCTM(); int borderPaddingStart = bv.getBorderAndPaddingWidthStart(); int borderPaddingBefore = bv.getBorderAndPaddingWidthBefore(); if (bv.getPositioning() == Block.ABSOLUTE || bv.getPositioning() == Block.FIXED) { //For FIXED, we need to break out of the current viewports to the //one established by the page. We save the state stack for restoration //after the block-container has been painted. See below. List breakOutList = null; if (bv.getPositioning() == Block.FIXED) { breakOutList = breakOutOfStateStack(); } AffineTransform positionTransform = new AffineTransform(); positionTransform.translate(bv.getXOffset(), bv.getYOffset()); //"left/"top" (bv.getX/YOffset()) specify the position of the content rectangle positionTransform.translate(-borderPaddingStart, -borderPaddingBefore); //Free transformation for the block-container viewport String transf; transf = bv.getForeignAttributeValue(FOX_TRANSFORM); if (transf != null) { AffineTransform freeTransform = AWTTransformProducer.createAffineTransform(transf); positionTransform.concatenate(freeTransform); } saveGraphicsState(); //Viewport position concatenateTransformationMatrixMpt(positionTransform, false); //Background and borders float bpwidth = (borderPaddingStart + bv.getBorderAndPaddingWidthEnd()); float bpheight = (borderPaddingBefore + bv.getBorderAndPaddingWidthAfter()); drawBackAndBorders(bv, 0, 0, (dim.width + bpwidth) / 1000f, (dim.height + bpheight) / 1000f); //Shift to content rectangle after border painting AffineTransform contentRectTransform = new AffineTransform(); contentRectTransform.translate(borderPaddingStart, borderPaddingBefore); concatenateTransformationMatrixMpt(contentRectTransform, false); //saveGraphicsState(); //Set up coordinate system for content rectangle AffineTransform contentTransform = ctm.toAffineTransform(); //concatenateTransformationMatrixMpt(contentTransform); startViewport(contentTransform, bv.getClipRectangle()); currentIPPosition = 0; currentBPPosition = 0; renderBlocks(bv, children); endViewport(); //restoreGraphicsState(); restoreGraphicsState(); if (breakOutList != null) { restoreStateStackAfterBreakOut(breakOutList); } currentIPPosition = saveIP; currentBPPosition = saveBP; } else { currentBPPosition += bv.getSpaceBefore(); //borders and background in the old coordinate system handleBlockTraits(bv); //Advance to start of content area currentIPPosition += bv.getStartIndent(); CTM tempctm = new CTM(containingIPPosition, currentBPPosition); ctm = tempctm.multiply(ctm); //Now adjust for border/padding currentBPPosition += borderPaddingBefore; startVParea(ctm, bv.getClipRectangle()); currentIPPosition = 0; currentBPPosition = 0; renderBlocks(bv, children); endVParea(); currentIPPosition = saveIP; currentBPPosition = saveBP; currentBPPosition += bv.getAllocBPD(); } viewportDimensionStack.pop(); }
From source file:lucee.runtime.img.Image.java
public void translate(int xtrans, int ytrans, Object interpolation) throws ExpressionException { RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, interpolation); if (interpolation != RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR) { hints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(1))); }/*from w ww. j a v a2 s .co m*/ ParameterBlock pb = new ParameterBlock(); pb.addSource(image()); BufferedImage img = JAI.create("translate", pb).getAsBufferedImage(); Graphics2D graphics = img.createGraphics(); graphics.clearRect(0, 0, img.getWidth(), img.getHeight()); AffineTransform at = new AffineTransform(); at.setToIdentity(); graphics.drawImage(image(), new AffineTransformOp(at, hints), xtrans, ytrans); graphics.dispose(); image(img); }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * Returns a transform to position the arrowhead on this edge shape at the * point where it intersects the passed vertex shape. */// ww w . j a v a 2 s . c o m public AffineTransform getArrowTransform(GeneralPath edgeShape, Shape vertexShape) { float[] seg = new float[6]; Point2D p1 = null; Point2D p2 = null; AffineTransform at = new AffineTransform(); // when the PathIterator is done, switch to the line-subdivide // method to get the arrowhead closer. for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) { int ret = i.currentSegment(seg); if (ret == PathIterator.SEG_MOVETO) { p2 = new Point2D.Float(seg[0], seg[1]); } else if (ret == PathIterator.SEG_LINETO) { p1 = p2; p2 = new Point2D.Float(seg[0], seg[1]); if (vertexShape.contains(p2)) { at = getArrowTransform(new Line2D.Float(p1, p2), vertexShape); break; } } } return at; }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** {@inheritDoc} */ protected void renderReferenceArea(Block block) { //TODO This is the same code as in AbstractPathOrientedRenderer //So there's some optimization potential but not otherwise PCLRenderer is a little //difficult to derive from AbstractPathOrientedRenderer. Maybe an additional layer //between PrintRenderer and AbstractPathOrientedRenderer is necessary. // save position and offset int saveIP = currentIPPosition; int saveBP = currentBPPosition; //Establish a new coordinate system AffineTransform at = new AffineTransform(); at.translate(currentIPPosition, currentBPPosition); at.translate(block.getXOffset(), block.getYOffset()); at.translate(0, block.getSpaceBefore()); if (!at.isIdentity()) { saveGraphicsState();/* w w w . j a va 2 s . co m*/ concatenateTransformationMatrix(UnitConv.mptToPt(at)); } currentIPPosition = 0; currentBPPosition = 0; handleBlockTraits(block); List children = block.getChildAreas(); if (children != null) { renderBlocks(block, children); } if (!at.isIdentity()) { restoreGraphicsState(); } // stacked and relative blocks effect stacking currentIPPosition = saveIP; currentBPPosition = saveBP; }
From source file:edu.uci.ics.jung.visualization.PluggableRenderer.java
/** * <p>Returns a transform to position the arrowhead on this edge shape at the * point where it intersects the passed vertex shape.</p> * /* w w w. j a v a2 s . co m*/ * <p>The Loop edge is a special case because its staring point is not inside * the vertex. The passedGo flag handles this case.</p> * * @param edgeShape * @param vertexShape * @param passedGo - used only for Loop edges */ public AffineTransform getReverseArrowTransform(GeneralPath edgeShape, Shape vertexShape, boolean passedGo) { float[] seg = new float[6]; Point2D p1 = null; Point2D p2 = null; AffineTransform at = new AffineTransform(); for (PathIterator i = edgeShape.getPathIterator(null, 1); !i.isDone(); i.next()) { int ret = i.currentSegment(seg); if (ret == PathIterator.SEG_MOVETO) { p2 = new Point2D.Float(seg[0], seg[1]); } else if (ret == PathIterator.SEG_LINETO) { p1 = p2; p2 = new Point2D.Float(seg[0], seg[1]); if (passedGo == false && vertexShape.contains(p2)) { passedGo = true; } else if (passedGo == true && vertexShape.contains(p2) == false) { at = getReverseArrowTransform(new Line2D.Float(p1, p2), vertexShape); break; } } } return at; }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** {@inheritDoc} */ protected void renderFlow(NormalFlow flow) { //TODO This is the same code as in AbstractPathOrientedRenderer //So there's some optimization potential but not otherwise PCLRenderer is a little //difficult to derive from AbstractPathOrientedRenderer. Maybe an additional layer //between PrintRenderer and AbstractPathOrientedRenderer is necessary. // save position and offset int saveIP = currentIPPosition; int saveBP = currentBPPosition; //Establish a new coordinate system AffineTransform at = new AffineTransform(); at.translate(currentIPPosition, currentBPPosition); if (!at.isIdentity()) { saveGraphicsState();/*w w w . j a va2 s . c o m*/ concatenateTransformationMatrix(UnitConv.mptToPt(at)); } currentIPPosition = 0; currentBPPosition = 0; super.renderFlow(flow); if (!at.isIdentity()) { restoreGraphicsState(); } // stacked and relative blocks effect stacking currentIPPosition = saveIP; currentBPPosition = saveBP; }