List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:org.csstudio.utility.batik.SVGHandler.java
protected void doRender() { if (disposed) { return;/* w w w. j av a2 s.c o m*/ } updateMatrix(); changeColor(colorToChange, colorToApply); gvtRoot = builder.build(bridgeContext, svgDocument); // get the 'width' and 'height' attributes of the SVG document float width = 400, height = 400; float docWidth = (float) bridgeContext.getDocumentSize().getWidth(); float docHeight = (float) bridgeContext.getDocumentSize().getHeight(); if (canvasWidth > 0 && canvasHeight > 0) { width = canvasWidth; height = canvasHeight; } else if (canvasHeight > 0) { width = (docWidth * canvasHeight) / docHeight; height = canvasHeight; } else if (canvasWidth > 0) { width = canvasWidth; height = (docHeight * canvasWidth) / docWidth; } else { width = docWidth; height = docHeight; } // compute the preserveAspectRatio matrix AffineTransform renderingTransform = null; AffineTransform Px = null; SVGSVGElement root = svgDocument.getRootElement(); String viewBox = root.getAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE); if (viewBox != null && viewBox.length() != 0) { String aspectRatio = root.getAttributeNS(null, SVGConstants.SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE); Px = ViewBox.getPreserveAspectRatioTransform(root, viewBox, aspectRatio, width, height, bridgeContext); } else { // no viewBox has been specified, create a scale transform float xscale = width / docWidth; float yscale = height / docHeight; float scale = Math.min(xscale, yscale); Px = AffineTransform.getScaleInstance(scale, scale); } Shape curAOI = new Rectangle2D.Float(0, 0, width, height); CanvasGraphicsNode cgn = getCanvasGraphicsNode(gvtRoot); if (cgn != null) { cgn.setViewingTransform(Px); renderingTransform = new AffineTransform(); } else { renderingTransform = Px; } if (renderer != null) { renderer.dispose(); renderer = null; } renderer = createImageRenderer(); int w = (int) (curAOI.getBounds().width + 0.5); int h = (int) (curAOI.getBounds().height + 0.5); renderer.updateOffScreen(w, h); renderer.setTree(gvtRoot); renderer.setTransform(renderingTransform); renderer.setDoubleBuffered(false); renderer.clearOffScreen(); renderer.repaint(curAOI); if (updateManager != null) { updateManager.setGVTRoot(gvtRoot); } needRender = false; }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static BufferedImage translateImage(BufferedImage img, double dx, double dy, int type, Color fillBgColor) {/* w w w . j a v a 2 s . c o m*/ if (img == null) { return null; } int w = img.getWidth(); int h = img.getHeight(); BufferedImage out = null; AffineTransform tr = new AffineTransform(); tr.translate(dx, dy); BufferedImageOp op = new AffineTransformOp(tr, type); out = new BufferedImage(w, h, img.getType()); Graphics2D g2d = (Graphics2D) out.getGraphics(); Rectangle clear = new Rectangle(0, 0, out.getWidth(), out.getHeight()); g2d.setPaint(fillBgColor); g2d.fill(clear); op.filter(img, out); return out; }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox.PDFAsVisualSignatureBuilder.java
public void createAppearanceDictionary(PDXObjectForm holderForml, PDSignatureField signatureField, float degrees) throws IOException { PDAppearanceDictionary appearance = new PDAppearanceDictionary(); appearance.getCOSObject().setDirect(true); PDAppearanceStream appearanceStream = new PDAppearanceStream(holderForml.getCOSStream()); AffineTransform transform = new AffineTransform(); transform.setToIdentity();//w ww . jav a 2 s. c om transform.rotate(Math.toRadians(degrees)); appearanceStream.setMatrix(transform); appearance.setNormalAppearance(appearanceStream); signatureField.getWidget().setAppearance(appearance); getStructure().setAppearanceDictionary(appearance); logger.debug("PDF appearance Dictionary has been created"); }
From source file:at.gv.egiz.pdfas.lib.impl.stamping.pdfbox2.PDFAsVisualSignatureBuilder.java
public void createAppearanceDictionary(PDFormXObject holderForml, PDSignatureField signatureField, float degrees) throws IOException { PDAppearanceDictionary appearance = new PDAppearanceDictionary(); appearance.getCOSObject().setDirect(true); PDAppearanceStream appearanceStream = new PDAppearanceStream(holderForml.getCOSStream()); AffineTransform transform = new AffineTransform(); transform.setToIdentity();/*from w ww. ja va 2s. c o m*/ transform.rotate(Math.toRadians(degrees)); appearanceStream.setMatrix(transform); appearance.setNormalAppearance(appearanceStream); signatureField.getWidget().setAppearance(appearance); getStructure().setAppearanceDictionary(appearance); logger.debug("PDF appereance Dictionary has been created"); }
From source file:org.pentaho.di.core.gui.SwingDirectGC.java
public void setTransform(float translationX, float translationY, int shadowsize, float magnification) { AffineTransform transform = new AffineTransform(); transform.translate(translationX + shadowsize * magnification, translationY + shadowsize * magnification); transform.scale(magnification, magnification); gc.setTransform(transform);// w w w.j ava2 s .co m }
From source file:org.apache.fop.render.pcl.PCLGenerator.java
private RenderedImage getMask(RenderedImage img, Dimension targetDim) { ColorModel cm = img.getColorModel(); if (cm.hasAlpha()) { BufferedImage alpha = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Raster raster = img.getData(); GraphicsUtil.copyBand(raster, cm.getNumColorComponents(), alpha.getRaster(), 0); BufferedImageOp op1 = new LookupOp(new ByteLookupTable(0, THRESHOLD_TABLE), null); BufferedImage alphat = op1.filter(alpha, null); BufferedImage mask;/* w w w . j a v a 2 s .c o m*/ if (true) { mask = new BufferedImage(targetDim.width, targetDim.height, BufferedImage.TYPE_BYTE_BINARY); } else { byte[] arr = { (byte) 0, (byte) 0xff }; ColorModel colorModel = new IndexColorModel(1, 2, arr, arr, arr); WritableRaster wraster = Raster.createPackedRaster(DataBuffer.TYPE_BYTE, targetDim.width, targetDim.height, 1, 1, null); mask = new BufferedImage(colorModel, wraster, false, null); } Graphics2D g2d = mask.createGraphics(); try { AffineTransform at = new AffineTransform(); double sx = targetDim.getWidth() / img.getWidth(); double sy = targetDim.getHeight() / img.getHeight(); at.scale(sx, sy); g2d.drawRenderedImage(alphat, at); } finally { g2d.dispose(); } /* try { BatchDiffer.saveAsPNG(alpha, new java.io.File("D:/out-alpha.png")); BatchDiffer.saveAsPNG(mask, new java.io.File("D:/out-mask.png")); } catch (IOException e) { e.printStackTrace(); }*/ return mask; } else { return null; } }
From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java
protected Image getPageErrorImage() { Image image = new BufferedImage((int) (viewerContext.getJasperPrint().getPageWidth() * realZoom) + 1, (int) (viewerContext.getJasperPrint().getPageHeight() * realZoom) + 1, BufferedImage.TYPE_INT_RGB); Graphics2D grx = (Graphics2D) image.getGraphics(); AffineTransform transform = new AffineTransform(); transform.scale(realZoom, realZoom); grx.transform(transform);//from w w w.j a v a 2 s. c o m drawPageError(grx); return image; }
From source file:JXTransformer.java
public void stateChanged(ChangeEvent e) { AffineTransform at = new AffineTransform(); at.rotate(rotationSlider.getValue() * Math.PI / 180); double scale = scalingSlider.getValue() / 100.0; at.scale(scale, scale);// w w w . j a va 2 s . com double shear = shearingSlider.getValue() / 10.0; at.shear(shear, 0); for (JXTransformer t : transformers) { t.setTransform(at); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * @see Graphics2D#getFontRenderContext() *//* w ww. ja v a2 s .co m*/ @Override public FontRenderContext getFontRenderContext() { final boolean antialias = RenderingHints.VALUE_TEXT_ANTIALIAS_ON .equals(getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING)); final boolean fractions = RenderingHints.VALUE_FRACTIONALMETRICS_ON .equals(getRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS)); return new FontRenderContext(new AffineTransform(), antialias, fractions); }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java
/** * Creates a continuous legend item for one item in dimensionSet, i.e. dimensionSet must be a * set containing exactly one value./*from w w w . ja v a 2s .c o m*/ * * @param dateFormat * format used to format minValue and maxValue as dates, or null if they should be * displayed numerically instead of as dates * @throws ChartPlottimeException */ private LegendItem createContinuousLegendItem(PlotInstance plotInstance, Set<PlotDimension> dimensionSet, double minValue, double maxValue, DateFormat dateFormat) { PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone(); PlotDimension dimension = dimensionSet.iterator().next(); DefaultDimensionConfig dimensionConfig = (DefaultDimensionConfig) plotConfiguration .getDimensionConfig(dimension); DimensionConfigData dimensionConfigData = plotInstance.getPlotData() .getDimensionConfigData(dimensionConfig); // String label = dimensionConfig.getLabel(); // if(label == null) { // label = I18N.getGUILabel("plotter.unnamed_value_label"); // } String label = ""; if (dimension == PlotDimension.COLOR) { ColorProvider colorProvider = dimensionConfigData.getColorProvider(); if (!colorProvider.supportsNumericalValues()) { throw new RuntimeException( "Color provider for continuous legend item does not support numerical values."); } // shape dimensions final int width = 50; final int height = 10; // create item paint // first disable logarithmic scale on color provider ( -> linear gradient in legend) // ContinuousColorProvider continuousColorProvider = null; // if (dimensionConfig.isLogarithmic() && colorProvider instanceof // ContinuousColorProvider) { // continuousColorProvider = (ContinuousColorProvider)colorProvider; // continuousColorProvider.setLogarithmic(false); // } // calculate gradient float fractions[] = new float[width]; Color colors[] = new Color[width]; for (int i = 0; i < width; ++i) { float fraction = i / (width - 1.0f); double fractionValue; if (colorProvider instanceof ContinuousColorProvider && ((ContinuousColorProvider) colorProvider).isColorMinMaxValueDifferentFromOriginal( ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue())) { fractionValue = ((ContinuousColorProvider) colorProvider).getMinValue() + fraction * (((ContinuousColorProvider) colorProvider).getMaxValue() - ((ContinuousColorProvider) colorProvider).getMinValue()); } else { fractionValue = minValue + fraction * (maxValue - minValue); } colors[i] = colorProvider.getColorForValue(fractionValue); fractions[i] = fraction; } LinearGradientPaint shapeFillPaint = new LinearGradientPaint(new Point(0, 0), new Point(width, 0), fractions, colors, CycleMethod.REPEAT); // reset color provider to logarithmic if necessary // if (continuousColorProvider != null && dimensionConfig.isLogarithmic()) { // continuousColorProvider.setLogarithmic(true); // } // create item shape Rectangle itemShape = new Rectangle(width, height); if (colorProvider instanceof ContinuousColorProvider) { return createFlankedShapeLegendItem(label, ((ContinuousColorProvider) colorProvider).getMinValue(), ((ContinuousColorProvider) colorProvider).getMaxValue(), itemShape, shapeFillPaint, true, dateFormat); } else { return createFlankedShapeLegendItem(label, minValue, maxValue, itemShape, shapeFillPaint, true, dateFormat); } } else if (dimension == PlotDimension.SHAPE) { // shape provider probably never supports numerical values return null; } else if (dimension == PlotDimension.SIZE) { SizeProvider sizeProvider = dimensionConfigData.getSizeProvider(); if (!sizeProvider.supportsNumericalValues()) { throw new RuntimeException( "Size provider for continuous legend item does not support numerical values."); } double minScalingFactor = sizeProvider.getMinScalingFactor(); double maxScalingFactor = sizeProvider.getMaxScalingFactor(); ContinuousSizeProvider legendSizeProvider = new ContinuousSizeProvider(minScalingFactor, maxScalingFactor, MIN_LEGEND_ITEM_SCALING_FACTOR, MAX_LEGEND_ITEM_SCALING_FACTOR, false); int legendItemCount = 4; Area composedShape = new Area(); Shape originalShape = UNDEFINED_SHAPE; if (dimensionSet.contains(PlotDimension.SIZE) && dimensionSet.size() == 1) { originalShape = UNDEFINED_SHAPE_AND_COLOR; } double maxHeight = originalShape.getBounds().getHeight() * MAX_LEGEND_ITEM_SCALING_FACTOR; for (int i = 0; i < legendItemCount; ++i) { double fraction = minScalingFactor + ((double) i / legendItemCount * (maxScalingFactor - minScalingFactor)); double legendScalingFactor = legendSizeProvider.getScalingFactorForValue(fraction); double composedWidth = composedShape.getBounds().getWidth(); AffineTransform t = new AffineTransform(); t.scale(legendScalingFactor, legendScalingFactor); Shape shape = t.createTransformedShape(originalShape); t = new AffineTransform(); double shapeWidth = shape.getBounds().getWidth(); double shapeHeight = shape.getBounds().getHeight(); t.translate(composedWidth + shapeWidth * .1, (maxHeight - shapeHeight) / 2.0); t.translate(-shape.getBounds().getMinX(), -shape.getBounds().getMinY()); shape = t.createTransformedShape(shape); composedShape.add(new Area(shape)); } return createFlankedShapeLegendItem(label, minValue, maxValue, composedShape, UNDEFINED_COLOR_PAINT, false, dateFormat); } else { throw new RuntimeException("Unsupported dimension. Execution path should never reach this line."); } }