List of usage examples for java.awt.geom AffineTransform concatenate
@SuppressWarnings("fallthrough") public void concatenate(AffineTransform Tx)
From source file:WorldMapGraphDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features./*w w w . ja v a 2 s .com*/ * */ public WorldMapGraphDemo() { setLayout(new BorderLayout()); map.put("TYO", new String[] { "35 40 N", "139 45 E" }); map.put("PEK", new String[] { "39 55 N", "116 26 E" }); map.put("MOW", new String[] { "55 45 N", "37 42 E" }); map.put("JRS", new String[] { "31 47 N", "35 13 E" }); map.put("CAI", new String[] { "30 03 N", "31 15 E" }); map.put("CPT", new String[] { "33 55 S", "18 22 E" }); map.put("PAR", new String[] { "48 52 N", "2 20 E" }); map.put("LHR", new String[] { "51 30 N", "0 10 W" }); map.put("HNL", new String[] { "21 18 N", "157 51 W" }); map.put("NYC", new String[] { "40 77 N", "73 98 W" }); map.put("SFO", new String[] { "37 62 N", "122 38 W" }); map.put("AKL", new String[] { "36 55 S", "174 47 E" }); map.put("BNE", new String[] { "27 28 S", "153 02 E" }); map.put("HKG", new String[] { "22 15 N", "114 10 E" }); map.put("KTM", new String[] { "27 42 N", "85 19 E" }); map.put("IST", new String[] { "41 01 N", "28 58 E" }); map.put("STO", new String[] { "59 20 N", "18 03 E" }); map.put("RIO", new String[] { "22 54 S", "43 14 W" }); map.put("LIM", new String[] { "12 03 S", "77 03 W" }); map.put("YTO", new String[] { "43 39 N", "79 23 W" }); cityList = new ArrayList<String>(map.keySet()); // create a simple graph for the demo graph = new DirectedSparseMultigraph<String, Number>(); createVertices(); createEdges(); ImageIcon mapIcon = null; String imageLocation = "/images/political_world_map.jpg"; try { mapIcon = new ImageIcon(getClass().getResource(imageLocation)); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = mapIcon; Dimension layoutSize = new Dimension(2000, 1000); Layout<String, Number> layout = new StaticLayout<String, Number>(graph, new ChainedTransformer(new Transformer[] { new CityTransformer(map), new LatLonPixelTransformer(new Dimension(2000, 1000)) })); layout.setSize(layoutSize); vv = new VisualizationViewer<String, Number>(layout, new Dimension(800, 400)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }); } vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); // vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); add(controls, BorderLayout.SOUTH); }
From source file:GrafosTroleBus.java
public GrafosTroleBus() { setLayout(new BorderLayout()); //definir puntos de trolebus (latitude y longitude) @autor sa map.put("RECREO", new String[] { "-0.2516682", "-78.521524" }); //Recreo map.put("P14", new String[] { "-0.2445098", "-78.51902" }); //Villaflora map.put("P15", new String[] { "-0.2396436", "-78.51698" }); //Chimbacalle N-S map.put("P16", new String[] { "-0.2378458", "-78.515976" }); //Chimbacalle S-N map.put("P17", new String[] { "-0.2356805", "-78.514816" }); //Colina map.put("P18", new String[] { "-0.234052", "-78.514237" }); //Jefferson Perez map.put("P19", new String[] { "-0.2312856", "-78.513627" }); //Recoleta N-S map.put("P20", new String[] { "-0.2307005", "-78.513051" }); //Recoleta S-N map.put("P21", new String[] { "-0.2263919", "-78.513011" }); //P21 Cumanda N-S map.put("P22", new String[] { "-0.226424", "-78.512803" }); //P22 Cumanda S-N map.put("P23", new String[] { "-0.2234658", "-78.512542" }); //P23 Santo Domingo map.put("P24", new String[] { "-0.2185857", "-78.508601" }); //P24 Plaza del Teatro N-S map.put("P25", new String[] { "-0.219605", "-78.50813" }); //P25 Plaza del Teatro S-N map.put("P26", new String[] { "-0.2177808", "-78.505977" }); //P26 Hermano Miguel map.put("P27", new String[] { "-0.2169088", "-78.50521" }); //P27 Banco Central map.put("P28", new String[] { "-0.214267", "-78.502999" }); //P28 La Alameda S-N map.put("P29", new String[] { "-0.2137705", "-78.50293" }); //P29 La Alameda N-S map.put("P30", new String[] { "-0.2084939", "-78.500255" }); //P30 Ejido N-S map.put("P31", new String[] { "-0.2088076", "-78.500032" }); //P31 Ejido S-N map.put("P32", new String[] { "-0.2047989", "-78.4988" }); //P32 La Mariscal N-S map.put("P33", new String[] { "-0.2041972", "-78.498491" }); //P33 La Mariscal S-N map.put("P34", new String[] { "-0.2009718", "-78.49715" }); //P34 Santa Clara S-N map.put("P35", new String[] { "-0.201056", "-78.496979" }); //P35 Santa Clara N-S map.put("P36", new String[] { "-0.1986325", "-78.496141" }); //P36 La Colon S-N map.put("P37", new String[] { "-0.1978432", "-78.495563" }); //P37 La Colon N-S map.put("P38", new String[] { "-0.1921587", "-78.493445" }); //P38 Cuero y Caicedo S-N map.put("P39", new String[] { "-0.1915098", "-78.493001" }); //P39 Cuero y Caicedo N-S map.put("P40", new String[] { "-0.1889467", "-78.492149" }); //P40 Mariana de Jess S-N map.put("P41", new String[] { "-0.1875567", "-78.491303" }); //P41 Mariana de Jesus N-S map.put("P42", new String[] { "-0.1853693", "-78.490878" }); //P42 El Floron S-N map.put("P43", new String[] { "-0.1846687", "-78.490403" }); //P43 El Floron N-S map.put("P44", new String[] { "-0.1817679", "-78.489808" }); //P44 Carolina S-N map.put("P45", new String[] { "-0.1810849", "-78.489336" }); //P45 Carolina N-S map.put("P46", new String[] { "-0.1787274", "-78.488954" }); //P46 Estadio S-N map.put("P47", new String[] { "-0.1780172", "-78.488621" }); //P47 Estadio N-S map.put("P48", new String[] { "-0.172087", "-78.487589" }); //P48 La Y S-N map.put("P49", new String[] { "-0.1713146", "-78.487277" }); //P49 La Y N-S map.put("LA Y", new String[] { "-0.1635504", "-78.485374" }); //Estacin La Y nodoList = new ArrayList<String>(map.keySet()); // create a simple graph for the demo graph = new DirectedSparseMultigraph<String, Number>(); createVertices();//from w ww . j a v a 2 s . c o m createEdges(); ImageIcon mapIcon = null; String imageLocation = "/mapa_quito.png"; try { mapIcon = new ImageIcon(getClass().getResource(imageLocation)); ImageWidth = mapIcon.getIconWidth(); ImageHeight = mapIcon.getIconHeight(); } catch (Exception ex) { System.err.println("Can't load \"" + imageLocation + "\""); } final ImageIcon icon = mapIcon; Dimension layoutSize = new Dimension(ImageWidth, ImageHeight); Layout<String, Number> layout = new StaticLayout<String, Number>(graph, new ChainedTransformer<String, Point2D>(new Transformer[] { new CityTransformer(map), new LatLonPixelTransformer(new Dimension(ImageWidth, ImageHeight)) })); layout.setSize(layoutSize); vv = new VisualizationViewer<String, Number>(layout, new Dimension(MonitorWidth, MonitorHeight)); if (icon != null) { vv.addPreRenderPaintable(new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat); at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }); } vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.white, Color.red, Color.white, Color.blue, vv.getPickedVertexState(), false)); // add my listeners for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); vv.setEdgeToolTipTransformer(new Transformer<Number, String>() { public String transform(Number edge) { return "E" + graph.getEndpoints(edge).toString(); } }); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); add(panel); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Object, Object>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); final ScalingControl scaler = new CrossoverScalingControl(); vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(reset); add(controls, BorderLayout.SOUTH); }
From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java
public void updateBackgroundImage(final ImageIcon icon, final int x, final int y) { if (paintableAssociatedToBackgroundImage != null) vv.removePreRenderPaintable(paintableAssociatedToBackgroundImage); paintableAssociatedToBackgroundImage = null; if (icon != null) { this.paintableAssociatedToBackgroundImage = new VisualizationViewer.Paintable() { public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AffineTransform oldXform = g2d.getTransform(); AffineTransform lat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.LAYOUT).getTransform(); AffineTransform vat = vv.getRenderContext().getMultiLayerTransformer() .getTransformer(Layer.VIEW).getTransform(); AffineTransform at = new AffineTransform(); at.concatenate(g2d.getTransform()); at.concatenate(vat);/* w ww . j a v a 2 s . com*/ at.concatenate(lat); g2d.setTransform(at); g.drawImage(icon.getImage(), x, y, icon.getIconWidth(), icon.getIconHeight(), vv); g2d.setTransform(oldXform); } public boolean useTransform() { return false; } }; vv.addPreRenderPaintable(paintableAssociatedToBackgroundImage); } }
From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java
/** * Method used for merging the input Rasters into a 2 images, one for human targets and the other for not human targets * //from w w w .j a v a2s . co m * @param humanTargets * @param notHumanTargets * @param bandPerTargetH * @param bandPerTargetNH * @throws IOException * @throws java.awt.geom.NoninvertibleTransformException * @throws TransformException * @throws MismatchedDimensionException */ public RenderedImage[] rasterCalculation(Map<Integer, TargetInfo> bandPerTargetH, Map<Integer, TargetInfo> bandPerTargetNH) throws IOException, java.awt.geom.NoninvertibleTransformException, MismatchedDimensionException, TransformException { // Initialization of the images RenderedImage humanTargets = null; RenderedImage notHumanTargets = null; String basePath = System.getProperty(RASTER_PATH_PROP, ""); if (!basePath.equals("")) { basePath = basePath + File.separator + codicePartner; } // Read of the resources Map vulnerabilityConf = (Map) readResourceFromXML("/vulnerability.xml"); // Vulnerability engine used for extracting the Targets VulnerabilityStatsEngine vsengine = new VulnerabilityStatsEngine(basePath, vulnerabilityConf, dataStore, DISTANCE_TYPE_NAME, pixelArea); // Target Map Map<String, TargetInfo> targetInfo = vsengine.getTargetInfo(); /* * Creation of 2 images: one for the HUMAN TARGETS and the other for NOT HUMAN TARGETS */ // List of Human Targets List<RenderedImage> humanList = new ArrayList<RenderedImage>(); // List of Not Human Targets List<RenderedImage> notHumanList = new ArrayList<RenderedImage>(); // Counters indicating which band is associated to the TargetInfo and // Image int humanBandCounter = 0; int notHumanBandCounter = 0; // Iterator on all the targets Iterator<String> rasterIter = targetInfo.keySet().iterator(); // Initializations of the parameters for merging the input rasters Envelope2D globalBBOXHuman = null; Envelope2D globalBBOXNotHuman = null; List<AffineTransform> tfHuman = new ArrayList<AffineTransform>(); List<AffineTransform> tfNotHuman = new ArrayList<AffineTransform>(); AffineTransform g2WHuman = null; AffineTransform g2WNotHuman = null; // Cycle on all the rasters while (rasterIter.hasNext()) { // save the ID of this target String targetID = rasterIter.next(); // Load the target manager, init its status and check if the actual // distance is a valid distance for it TargetInfo info = targetInfo.get(targetID); // Getting of the transformation parameters GridGeometry2D gg2D = info.getGG2D(); Envelope2D envelope = gg2D.getEnvelope2D(); AffineTransform w2g = (AffineTransform) gg2D.getCRSToGrid2D(PixelOrientation.UPPER_LEFT); // getting information about current Target TargetManager manager = info.getManager(); // Image associated to the current target RenderedImage newImage = info.getRaster(); // Image data type int imgDataType = newImage.getSampleModel().getDataType(); // Check if the image really exists if (newImage != null) { // If the target is human if (manager.isHumanTarget()) { // Other check for ensuring the target is correct if (imgDataType != DataBuffer.TYPE_FLOAT) { System.out.println("Wrong data type"); } // perform union if (globalBBOXHuman == null) { globalBBOXHuman = new Envelope2D(envelope); } else { globalBBOXHuman.include(envelope); } // Selection of the first g2w transform as the global one if (g2WHuman == null) { g2WHuman = (AffineTransform) gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT); } // Creation of the transformation from destination Raster space to source Raster space AffineTransform temp = new AffineTransform(w2g); temp.concatenate(g2WHuman); tfHuman.add(temp); // Addition of the TargetInfo of this target bandPerTargetH.put(humanBandCounter, info); // Update of the bandCounter humanBandCounter++; // Addition of the image to the associated list humanList.add(newImage); } else { // Other check for ensuring the target is correct if (imgDataType != DataBuffer.TYPE_BYTE) { System.out.println("Wrong data type"); } // perform union if (globalBBOXNotHuman == null) { globalBBOXNotHuman = envelope; } else { globalBBOXNotHuman.include(envelope); } // Selection of the first g2w transform as the global one if (g2WNotHuman == null) { g2WNotHuman = (AffineTransform) gg2D.getGridToCRS2D(PixelOrientation.UPPER_LEFT); } // Creation of the transformation from destination Raster space to source Raster space AffineTransform temp = new AffineTransform(w2g); temp.concatenate(g2WNotHuman); tfNotHuman.add(temp); // Addition of the TargetInfo of this target bandPerTargetNH.put(notHumanBandCounter, info); // Update of the bandCounter notHumanBandCounter++; // Addition of the image to the associated list notHumanList.add(newImage); } } } // computing final raster space for the two targets GridGeometry2D humanGG2D = new GridGeometry2D(PixelInCell.CELL_CORNER, new AffineTransform2D(g2WHuman), globalBBOXHuman, null); globalBBOXHuman = humanGG2D.getEnvelope2D(); // take into account integer pixel roundings GridGeometry2D noHumanGG2D = new GridGeometry2D(PixelInCell.CELL_CORNER, new AffineTransform2D(g2WNotHuman), globalBBOXNotHuman, null); globalBBOXNotHuman = noHumanGG2D.getEnvelope2D(); // take into account integer pixel roundings // BandMerge of the images RenderedImage[] imagesHuman = new RenderedImage[humanList.size()]; RenderedImage[] imagesNotHuman = new RenderedImage[notHumanList.size()]; // Setting of the final layout ImageLayout layoutH = new ImageLayout2(); GridEnvelope2D gridRange2D = humanGG2D.getGridRange2D(); layoutH.setMinX(gridRange2D.x); layoutH.setMinY(gridRange2D.y); layoutH.setWidth(gridRange2D.width); layoutH.setHeight(gridRange2D.height); // Definition of the TileCache RenderingHints hintsH = new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache()); // Setting of the layout as hint hintsH.put(JAI.KEY_IMAGE_LAYOUT, layoutH); // Merging of the input human targets humanTargets = BandMergeDescriptor.create(null, 0, hintsH, tfHuman, humanList.toArray(imagesHuman)); // Setting of the final layout ImageLayout layoutNH = new ImageLayout2(); gridRange2D = noHumanGG2D.getGridRange2D(); layoutNH.setMinX(gridRange2D.x); layoutNH.setMinY(gridRange2D.y); layoutNH.setWidth(gridRange2D.width); layoutNH.setHeight(gridRange2D.height); // Definition of the TileCache RenderingHints hintsNH = new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache()); hintsNH.put(JAI.KEY_IMAGE_LAYOUT, layoutNH); // Merging of the input not human targets notHumanTargets = BandMergeDescriptor.create(null, 0, hintsNH, tfNotHuman, notHumanList.toArray(imagesNotHuman)); // cache the final images humanTargets = NullDescriptor.create(humanTargets, new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache())); notHumanTargets = NullDescriptor.create(notHumanTargets, new RenderingHints(JAI.KEY_TILE_CACHE, JAI.getDefaultInstance().getTileCache())); // Clearing of the initial lists notHumanList.clear(); humanList.clear(); // create a new array of the new images return new RenderedImage[] { humanTargets, notHumanTargets }; }
From source file:DefaultGraphics2D.java
/** * Multiplies two 2x3 matrices of double precision values *//* w w w . ja va 2s.c o m*/ private double[] matrixMultiply(double[] matrix1, double[] matrix2) { double[] product = new double[6]; AffineTransform transform1 = new AffineTransform(matrix1); transform1.concatenate(new AffineTransform(matrix2)); transform1.getMatrix(product); return product; }
From source file:org.apache.fop.render.intermediate.AbstractIFPainter.java
private AffineTransform combine(AffineTransform[] transforms) { AffineTransform at = new AffineTransform(); for (int i = 0, c = transforms.length; i < c; i++) { at.concatenate(transforms[i]); }// w w w. j ava2 s .c o m return at; }
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 ww w. j a va 2s . c o 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:org.apache.fop.render.pdf.PDFImageHandlerSVG.java
/** {@inheritDoc} */ public void handleImage(RenderingContext context, // CSOK: MethodLength Image image, Rectangle pos) throws IOException { PDFRenderingContext pdfContext = (PDFRenderingContext) context; PDFContentGenerator generator = pdfContext.getGenerator(); ImageXMLDOM imageSVG = (ImageXMLDOM) image; FOUserAgent userAgent = context.getUserAgent(); final float deviceResolution = userAgent.getTargetResolution(); if (log.isDebugEnabled()) { log.debug("Generating SVG at " + deviceResolution + "dpi."); }//from www.j av a 2s . c om final float uaResolution = userAgent.getSourceResolution(); SVGUserAgent ua = new SVGUserAgent(userAgent, new AffineTransform()); GVTBuilder builder = new GVTBuilder(); //Controls whether text painted by Batik is generated using text or path operations boolean strokeText = false; //TODO connect with configuration elsewhere. BridgeContext ctx = new PDFBridgeContext(ua, (strokeText ? null : pdfContext.getFontInfo()), userAgent.getFactory().getImageManager(), userAgent.getImageSessionContext(), new AffineTransform()); //Cloning SVG DOM as Batik attaches non-thread-safe facilities (like the CSS engine) //to it. Document clonedDoc = BatikUtil.cloneSVGDocument(imageSVG.getDocument()); GraphicsNode root; try { root = builder.build(ctx, clonedDoc); builder = null; } catch (Exception e) { SVGEventProducer eventProducer = SVGEventProducer.Provider .get(context.getUserAgent().getEventBroadcaster()); eventProducer.svgNotBuilt(this, e, image.getInfo().getOriginalURI()); return; } // get the 'width' and 'height' attributes of the SVG document float w = image.getSize().getWidthMpt(); float h = image.getSize().getHeightMpt(); float sx = pos.width / w; float sy = pos.height / h; //Scaling and translation for the bounding box of the image AffineTransform scaling = new AffineTransform(sx, 0, 0, sy, pos.x / 1000f, pos.y / 1000f); double sourceScale = UnitConv.IN2PT / uaResolution; scaling.scale(sourceScale, sourceScale); //Scale for higher resolution on-the-fly images from Batik AffineTransform resolutionScaling = new AffineTransform(); double targetScale = uaResolution / deviceResolution; resolutionScaling.scale(targetScale, targetScale); resolutionScaling.scale(1.0 / sx, 1.0 / sy); //Transformation matrix that establishes the local coordinate system for the SVG graphic //in relation to the current coordinate system AffineTransform imageTransform = new AffineTransform(); imageTransform.concatenate(scaling); imageTransform.concatenate(resolutionScaling); if (log.isTraceEnabled()) { log.trace("nat size: " + w + "/" + h); log.trace("req size: " + pos.width + "/" + pos.height); log.trace("source res: " + uaResolution + ", targetRes: " + deviceResolution + " --> target scaling: " + targetScale); log.trace(image.getSize()); log.trace("sx: " + sx + ", sy: " + sy); log.trace("scaling: " + scaling); log.trace("resolution scaling: " + resolutionScaling); log.trace("image transform: " + resolutionScaling); } /* * Clip to the svg area. * Note: To have the svg overlay (under) a text area then use * an fo:block-container */ if (log.isTraceEnabled()) { generator.comment("SVG setup"); } generator.saveGraphicsState(); if (context.getUserAgent().isAccessibilityEnabled()) { MarkedContentInfo mci = pdfContext.getMarkedContentInfo(); generator.beginMarkedContentSequence(mci.tag, mci.mcid); } generator.updateColor(Color.black, false, null); generator.updateColor(Color.black, true, null); if (!scaling.isIdentity()) { if (log.isTraceEnabled()) { generator.comment("viewbox"); } generator.add(CTMHelper.toPDFString(scaling, false) + " cm\n"); } //SVGSVGElement svg = ((SVGDocument)doc).getRootElement(); PDFGraphics2D graphics = new PDFGraphics2D(true, pdfContext.getFontInfo(), generator.getDocument(), generator.getResourceContext(), pdfContext.getPage().referencePDF(), "", 0); graphics.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); if (!resolutionScaling.isIdentity()) { if (log.isTraceEnabled()) { generator.comment("resolution scaling for " + uaResolution + " -> " + deviceResolution); } generator.add(CTMHelper.toPDFString(resolutionScaling, false) + " cm\n"); graphics.scale(1.0 / resolutionScaling.getScaleX(), 1.0 / resolutionScaling.getScaleY()); } if (log.isTraceEnabled()) { generator.comment("SVG start"); } //Save state and update coordinate system for the SVG image generator.getState().save(); generator.getState().concatenate(imageTransform); //Now that we have the complete transformation matrix for the image, we can update the //transformation matrix for the AElementBridge. PDFAElementBridge aBridge = (PDFAElementBridge) ctx.getBridge(SVGDOMImplementation.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG); aBridge.getCurrentTransform().setTransform(generator.getState().getTransform()); graphics.setPaintingState(generator.getState()); graphics.setOutputStream(generator.getOutputStream()); try { root.paint(graphics); ctx.dispose(); generator.add(graphics.getString()); } catch (Exception e) { SVGEventProducer eventProducer = SVGEventProducer.Provider .get(context.getUserAgent().getEventBroadcaster()); eventProducer.svgRenderingError(this, e, image.getInfo().getOriginalURI()); } generator.getState().restore(); if (context.getUserAgent().isAccessibilityEnabled()) { generator.restoreGraphicsStateAccess(); } else { generator.restoreGraphicsState(); } if (log.isTraceEnabled()) { generator.comment("SVG end"); } }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
@Override protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, String unicode, Vector displacement) throws IOException { AffineTransform at = textRenderingMatrix.createAffineTransform(); at.concatenate(font.getFontMatrix().createAffineTransform()); Glyph2D glyph2D = createGlyph2D(font); drawGlyph2D(glyph2D, font, code, displacement, at); }
From source file:org.apache.pdfbox.rendering.TilingPaint.java
/** * Not called in TexturePaint subclasses, which is why we wrap TexturePaint. *//* ww w .ja v a2s . c om*/ @Override public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints) { AffineTransform xformPattern = (AffineTransform) xform.clone(); // applies the pattern matrix with scaling removed AffineTransform patternNoScale = patternMatrix.createAffineTransform(); patternNoScale.scale(1 / patternMatrix.getScalingFactorX(), 1 / patternMatrix.getScalingFactorY()); xformPattern.concatenate(patternNoScale); return paint.createContext(cm, deviceBounds, userBounds, xformPattern, hints); }