List of usage examples for java.awt.geom AffineTransform AffineTransform
public AffineTransform()
From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java
/** * Fit the image onto the canvas/*w w w .j a va 2 s .c om*/ */ public void fitCanvas() { if (sourceImage == null) return; Rectangle imageBound = sourceImage.getBounds(); Rectangle destRect = getClientArea(); double sx = (double) destRect.width / (double) imageBound.width; double sy = (double) destRect.height / (double) imageBound.height; double s = Math.min(sx, sy); double dx = 0.5 * destRect.width; double dy = 0.5 * destRect.height; centerZoom(dx, dy, s, new AffineTransform()); }
From source file:es.ucm.fdi.edd.ui.views.utils.SWTImageCanvas.java
/** * Show the image with the original size */// w ww . ja v a 2 s .c o m public void showOriginal() { if (sourceImage == null) return; transform = new AffineTransform(); syncScrollBars(); }
From source file:ExtendedGeneralPath.java
/** * Delegates to the enclosed <code>GeneralPath</code>. *//* ww w .j av a 2 s. c om*/ public void append(Shape s, boolean connect) { append(s.getPathIterator(new AffineTransform()), connect); }
From source file:org.alfresco.extension.countersign.action.executer.PDFSignatureProviderActionExecuter.java
/** * Scales the signature image to fit the provided signature field dimensions, * preserving the aspect ratio/* ww w . j a v a2 s . c o m*/ * * @param signatureImage * @param width * @param height * @return */ private BufferedImage scaleSignature(BufferedImage signatureImage, int width, int height) { if (signatureImage.getHeight() > height) { BufferedImage scaled = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); AffineTransform at = new AffineTransform(); at.scale(2.0, 2.0); AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); scaled = scaleOp.filter(signatureImage, scaled); return scaled; } else { return signatureImage; } }
From source file:at.gv.egiz.pdfas.lib.impl.pdfbox.placeholder.SignaturePlaceholderExtractor.java
@Override protected void processOperator(PDFOperator operator, List<COSBase> arguments) throws IOException { String operation = operator.getOperation(); if (operation.equals("Do")) { COSName objectName = (COSName) arguments.get(0); Map<?, ?> xobjects = getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject instanceof PDXObjectImage) { try { PDXObjectImage image = (PDXObjectImage) xobject; SignaturePlaceholderData data = checkImage(image); if (data != null) { PDPage page = getCurrentPage(); Matrix ctm = getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); pageRotation = pageRotation % 360; double rotationInRadians = Math.toRadians(pageRotation);//(page.findRotation() * Math.PI) / 180; AffineTransform rotation = new AffineTransform(); rotation.setToRotation(rotationInRadians); AffineTransform rotationInverse = rotation.createInverse(); Matrix rotationInverseMatrix = new Matrix(); rotationInverseMatrix.setFromAffineTransform(rotationInverse); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(rotation); Matrix unrotatedCTM = ctm.multiply(rotationInverseMatrix); float x = unrotatedCTM.getXPosition(); float yPos = unrotatedCTM.getYPosition(); float yScale = unrotatedCTM.getYScale(); float y = yPos + yScale; float w = unrotatedCTM.getXScale(); logger.debug("Page height: {}", page.findCropBox().getHeight()); logger.debug("Page width: {}", page.findCropBox().getWidth()); if (pageRotation == 90) { y = page.findCropBox().getWidth() - (y * (-1)); } else if (pageRotation == 180) { x = page.findCropBox().getWidth() + x; y = page.findCropBox().getHeight() - (y * (-1)); } else if (pageRotation == 270) { x = page.findCropBox().getHeight() + x; }//w w w. j av a 2s. c o m String posString = "p:" + currentPage + ";x:" + x + ";y:" + y + ";w:" + w; logger.debug("Found Placeholder at: {}", posString); try { data.setTablePos(new TablePos(posString)); data.setPlaceholderName(objectName.getName()); placeholders.add(data); } catch (PdfAsException e) { throw new WrappedIOException(e); } } } catch (NoninvertibleTransformException e) { throw new WrappedIOException(e); } } } else { super.processOperator(operator, arguments); } }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private void drawEntity(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel, boolean scale, float alpha) { if (entity != null) { //System.out.println("Drawing entity with bbox: "+entity.getBounds2D()); Shape savedClip = g2.getClip(); Rectangle2D dataArea = chartPanel.getScreenDataArea(); Color c = g2.getColor();// ww w. j av a 2 s .c om Composite comp = g2.getComposite(); g2.clip(dataArea); g2.setColor(fill); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); AffineTransform originalTransform = g2.getTransform(); Shape transformed = entity; FlatteningPathIterator iter = new FlatteningPathIterator( transformed.getPathIterator(new AffineTransform()), 1); Path2D.Float path = new Path2D.Float(); path.append(iter, false); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.fill(path); if (stroke != null) { g2.setColor(stroke); g2.draw(path); } g2.setComposite(comp); g2.setColor(c); g2.setClip(savedClip); } else { Logger.getLogger(getClass().getName()).info("Entity is null!"); } }
From source file:org.freecine.filmscan.ScanStrip.java
/** Calculate the affine transform from scanStrip to a single frame (frame rotated to straight position, top left corner translated to (0,0) @param frame//from w w w . j a v a 2 s . c o m @return */ AffineTransform getFrameXform(int frame) { /** Estimate film rotation from max 5 perforations */ int f1 = frame - 1; int f2 = frame + 1; int x1 = (f1 >= 0) ? perforations.get(f1).x : perforations.get(0).x; int x2 = (f2 < perforations.size()) ? perforations.get(f2).x : perforations.get(perforations.size() - 1).x; int y1 = (f1 >= 0) ? perforations.get(f1).y : perforations.get(0).y; int y2 = (f2 < perforations.size()) ? perforations.get(f2).y : perforations.get(perforations.size() - 1).y; double rot = Math.atan2((double) x2 - x1, (double) (y2 - y1)); // Translate the center of perforation to origin AffineTransform xform = new AffineTransform(); xform.translate(0, FRAME_HEIGHT / 2); xform.rotate(rot); xform.translate(-perforations.get(frame).x, -perforations.get(frame).y); // System.out.println( String.format( "frame %d: (%d, %d), rot %f", // frame,perforations.get(frame).x, -perforations.get(frame).y, rot )); return xform; }
From source file:org.apache.fop.render.pdf.PDFBoxAdapterTestCase.java
@Test public void testStream() throws Exception { PDFDocument pdfdoc = new PDFDocument(""); PDFPage pdfpage = new PDFPage(new PDFResources(pdfdoc), 0, r, r, r, r); pdfpage.setDocument(pdfdoc);//from www . j a v a2 s . com PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new HashMap<Integer, PDFArray>()); PDDocument doc = getResource(ROTATE); PDPage page = (PDPage) doc.getDocumentCatalog().getPages().get(0); AffineTransform at = new AffineTransform(); Rectangle r = new Rectangle(0, 1650, 842000, 595000); String stream = adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r); Assert.assertEquals(at, new AffineTransform(-0.0, 1.0000000554888686, 1.0000000554888686, 0.0, 0.0, -2.0742416381835938E-5)); Assert.assertTrue(stream.contains("/GS0106079 gs")); Assert.assertTrue(stream.contains("/TT0106079 1 Tf")); doc.close(); }
From source file:org.nekorp.workflow.desktop.servicio.reporte.orden.servicio.OrdenServicioDataFactory.java
private void generaSVGImagenDamage(ShapeView fondo, List<DamageDetailsVB> danios, File outputfile, int width, int height) { // Get a DOMImplementation. DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); // Create an instance of org.w3c.dom.Document. String svgNS = "http://www.w3.org/2000/svg"; Document document = domImpl.createDocument(svgNS, "svg", null); // Create an instance of the SVG Generator. SVGGraphics2D g2 = new SVGGraphics2D(document); // pintar./* ww w . ja v a 2s .c o m*/ g2.setSVGCanvasSize(new java.awt.Dimension(width, height)); Point contexto = new Point((width - fondo.getShapeWidth()) / 2, (height - fondo.getShapeHeight()) / 2); g2.setColor(Color.WHITE); g2.fillRect(0, 0, width, height); AffineTransform saveXform = g2.getTransform(); AffineTransform toCenterAt = new AffineTransform(); toCenterAt.translate(contexto.getX(), contexto.getY()); g2.transform(toCenterAt); fondo.paint(g2); g2.setTransform(saveXform); for (DamageDetailsVB x : danios) { DamageDetailGraphicsView obj = new DamageDetailGraphicsView(); obj.setFontSize(esquemaFontSize); obj.setPosicion(new Point(x.getX(), x.getY())); obj.setContexto(contexto); if (x.getX() <= fondo.getShapeWidth() / 2) { if (x.getY() <= fondo.getShapeHeight() / 2) { obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda); //obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha); } else { obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda); //obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha); } } else { if (x.getY() <= fondo.getShapeHeight() / 2) { obj.setOrientacion(DamageDetailGraphicsView.SuperiorDerecha); //obj.setOrientacion(DamageDetailGraphicsView.SuperiorIzquierda); } else { obj.setOrientacion(DamageDetailGraphicsView.InferiorDerecha); //obj.setOrientacion(DamageDetailGraphicsView.InferiorIzquierda); } } obj.setCategoria(x.getCategoria()); obj.setCaracteristica(x.getCaracteristica()); obj.paint(g2); } try { g2.stream(outputfile.getCanonicalPath()); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:org.apache.fop.render.pdf.PDFBoxAdapterTestCase.java
@Test public void testTaggedPDFWriter() throws IOException { PDFDocument pdfdoc = new PDFDocument(""); PDFPage pdfpage = new PDFPage(new PDFResources(pdfdoc), 0, r, r, r, r); pdfpage.setDocument(pdfdoc);/*from w w w .j a va 2 s .co m*/ PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new HashMap<Integer, PDFArray>()); adapter.setCurrentMCID(5); PDDocument doc = getResource(HELLOTagged); PDPage page = (PDPage) doc.getDocumentCatalog().getPages().get(0); AffineTransform at = new AffineTransform(); Rectangle r = new Rectangle(0, 1650, 842000, 595000); String stream = adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r); Assert.assertTrue(stream, stream.contains("/P <</MCID 5 >>BDC")); doc.close(); }