List of usage examples for java.awt Graphics2D translate
public abstract void translate(double tx, double ty);
From source file:MWC.GUI.JFreeChart.StepperChartPanel.java
/** * Paints the component by drawing the chart to fill the entire component, * but allowing for the insets (which will be non-zero if a border has been * set for this component). To increase performance (at the expense of * memory), an off-screen buffer image can be used. * * @param g the graphics device for drawing on. *//*w w w .ja va 2s . c o m*/ public void paintWMFComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; // first determine the size of the chart rendering area... final Dimension size = getSize(); final Insets insets = getInsets(); available.setRect(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); double scaleX = 1.0; double scaleY = 1.0; if (drawWidth < this.getMinimumDrawWidth()) { scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > this.getMaximumDrawWidth()) { scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < this.getMinimumDrawHeight()) { scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > this.getMaximumDrawHeight()) { scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } chartArea.setRect(0.0, 0.0, drawWidth, drawHeight); final AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.right); if (scale) { final AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY); g2.transform(st); } getChart().draw(g2, chartArea, this.getChartRenderingInfo()); g2.setTransform(saved); }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Draws borders. Borders are drawn in-memory and painted as a bitmap. * @param borderRect the border rectangle * @param bpsBefore the border specification on the before side * @param bpsAfter the border specification on the after side * @param bpsStart the border specification on the start side * @param bpsEnd the border specification on the end side *///from w w w. j ava 2 s . c o m protected void drawQualityBorders(Rectangle2D.Float borderRect, final BorderProps bpsBefore, final BorderProps bpsAfter, final BorderProps bpsStart, final BorderProps bpsEnd) { Graphics2DAdapter g2a = getGraphics2DAdapter(); final Rectangle.Float effBorderRect = new Rectangle2D.Float(0, 0, borderRect.width, borderRect.height); final Rectangle paintRect = new Rectangle(Math.round(borderRect.x * 1000f), Math.round(borderRect.y * 1000f), (int) Math.floor(borderRect.width * 1000f) + 1, (int) Math.floor(borderRect.height * 1000f) + 1); //Add one pixel wide safety margin around the paint area int pixelWidth = (int) Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution()); final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth; final int yoffset = pixelWidth; paintRect.x += xoffset; paintRect.y += yoffset; paintRect.width += 2 * pixelWidth; paintRect.height += 2 * pixelWidth; RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width, paintRect.height, null); Map atts = new java.util.HashMap(); atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); atts.put(SRC_TRANSPARENCY, "true"); rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(xoffset, yoffset); g2d.scale(1000, 1000); float startx = effBorderRect.x; float starty = effBorderRect.y; float width = effBorderRect.width; float height = effBorderRect.height; boolean[] b = new boolean[] { (bpsBefore != null), (bpsEnd != null), (bpsAfter != null), (bpsStart != null) }; if (!b[0] && !b[1] && !b[2] && !b[3]) { return; } float[] bw = new float[] { (b[0] ? bpsBefore.width / 1000f : 0.0f), (b[1] ? bpsEnd.width / 1000f : 0.0f), (b[2] ? bpsAfter.width / 1000f : 0.0f), (b[3] ? bpsStart.width / 1000f : 0.0f) }; float[] clipw = new float[] { BorderProps.getClippedWidth(bpsBefore) / 1000f, BorderProps.getClippedWidth(bpsEnd) / 1000f, BorderProps.getClippedWidth(bpsAfter) / 1000f, BorderProps.getClippedWidth(bpsStart) / 1000f }; starty += clipw[0]; height -= clipw[0]; height -= clipw[2]; startx += clipw[3]; width -= clipw[3]; width -= clipw[1]; boolean[] slant = new boolean[] { (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3]) }; if (bpsBefore != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty - clipw[0]; float clipy = outery + clipw[0]; float innery = outery + bw[0]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(sx1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(sx1a, outery); lineTo(ex1a, outery); } lineTo(ex1, clipy); lineTo(ex2, innery); lineTo(sx2, innery); closePath(); //clip(); g.clip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, outery, ex1a - sx1a, innery - outery); Java2DRenderer.drawBorderLine(lineRect, true, true, bpsBefore.style, bpsBefore.color, g); //restoreGraphicsState(); } if (bpsEnd != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = starty + height; float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx + width + clipw[1]; float clipx = outerx - clipw[1]; float innerx = outerx - bw[1]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, sy1); float sy1a = sy1; float ey1a = ey1; if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, sy1a); lineTo(outerx, ey1a); } lineTo(clipx, ey1); lineTo(innerx, ey2); lineTo(innerx, sy2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(innerx, sy1a, outerx - innerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsEnd.style, bpsEnd.color, g); //restoreGraphicsState(); } if (bpsAfter != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty + height + clipw[2]; float clipy = outery - clipw[2]; float innery = outery - bw[2]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(ex1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(ex1a, outery); lineTo(sx1a, outery); } lineTo(sx1, clipy); lineTo(sx2, innery); lineTo(ex2, innery); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, innery, ex1a - sx1a, outery - innery); Java2DRenderer.drawBorderLine(lineRect, true, false, bpsAfter.style, bpsAfter.color, g); //restoreGraphicsState(); } if (bpsStart != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = sy1 + height; float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx - clipw[3]; float clipx = outerx + clipw[3]; float innerx = outerx + bw[3]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, ey1); float sy1a = sy1; float ey1a = ey1; if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, ey1a); lineTo(outerx, sy1a); } lineTo(clipx, sy1); lineTo(innerx, sy2); lineTo(innerx, ey2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(outerx, sy1a, innerx - outerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsStart.style, bpsStart.color, g); //restoreGraphicsState(); } } public Dimension getImageSize() { return paintRect.getSize(); } }; try { g2a.paintImage(painter, rc, paintRect.x - xoffset, paintRect.y, paintRect.width, paintRect.height); } catch (IOException ioe) { handleIOTrouble(ioe); } }
From source file:JXTransformer.java
public void paint(Graphics g) { //repaint the whole transformer in case the view component was repainted Rectangle clipBounds = g.getClipBounds(); if (clipBounds != null && !clipBounds.equals(visibleRect)) { repaint();// w ww . ja v a 2 s . co m } //clear the background g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); if (view != null && at.getDeterminant() != 0) { Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); Rectangle bounds = getBounds(); //don't forget about insets bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; double centerX1 = bounds.getCenterX(); double centerY1 = bounds.getCenterY(); Rectangle tb = getTransformedSize(); double centerX2 = tb.getCenterX(); double centerY2 = tb.getCenterY(); //set antialiasing by default g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (renderingHints != null) { g2.addRenderingHints(renderingHints); } //translate it to the center of the view component again double tx = centerX1 - centerX2 - getX(); double ty = centerY1 - centerY2 - getY(); g2.translate((int) tx, (int) ty); g2.transform(at); view.paint(g2); g2.dispose(); } //paint the border paintBorder(g); }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
public void printImagePdf(String filename, DesignerCanvas canvas, Dimension graphsize) { try {/*from w w w. jav a 2 s . c o m*/ DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); mapper.insertDirectory("c:\\winnt\\fonts"); // mapper.insertDirectory("c:\\windows\\fonts"); // we create a template and a Graphics2D object that corresponds // with it int margin = 72; // 1 inch float scale = 0.5f; boolean multiple_page = true; Rectangle page_size; if (multiple_page) { page_size = PageSize.LETTER.rotate(); } else { page_size = new Rectangle((int) (graphsize.getWidth() * scale) + margin, (int) (graphsize.getHeight() * scale) + margin); } Document document = new Document(page_size); DocWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); document.setPageSize(page_size); int image_w = (int) page_size.getWidth() - margin; int image_h = (int) page_size.getHeight() - margin; boolean edsave = canvas.editable; canvas.editable = false; Color bgsave = canvas.getBackground(); canvas.setBackground(Color.white); if (multiple_page) { int horizontal_pages = (int) (graphsize.width * scale) / image_w + 1; int vertical_pages = (int) (graphsize.height * scale) / image_h + 1; for (int i = 0; i < horizontal_pages; i++) { for (int j = 0; j < vertical_pages; j++) { Image img; PdfContentByte cb = ((PdfWriter) writer).getDirectContent(); PdfTemplate tp = cb.createTemplate(image_w, image_h); Graphics2D g2 = tp.createGraphics(image_w, image_h, mapper); tp.setWidth(image_w); tp.setHeight(image_h); g2.scale(scale, scale); g2.translate(-i * image_w / scale, -j * image_h / scale); canvas.paintComponent(g2); g2.dispose(); img = new ImgTemplate(tp); document.add(img); } } } else { Image img; PdfContentByte cb = ((PdfWriter) writer).getDirectContent(); PdfTemplate tp = cb.createTemplate(image_w, image_h); Graphics2D g2 = tp.createGraphics(image_w, image_h, mapper); tp.setWidth(image_w); tp.setHeight(image_h); g2.scale(scale, scale); canvas.paintComponent(g2); g2.dispose(); img = new ImgTemplate(tp); document.add(img); } canvas.setBackground(bgsave); canvas.editable = edsave; document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
@SuppressWarnings("null") @Override/*from ww w. j av a 2s.c o m*/ public void paintComponent(Graphics g) { final Graphics2D g2D = (Graphics2D) g; // Renderer g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // Optimization card painting final MZone container = card.getContainer(); final boolean shortPaint = container == null || !container.isMustBePainted(card); // tap/reverse operation : PI/2, PI, -PI/2 rotation if (!shortPaint) { if (container.isMustBePaintedReversed(card)) { if (card.tapped) { g2D.translate(rotateTransformY, CardFactory.cardWidth + rotateTransformX); g2D.rotate(angle - Math.PI / 2); } else { g2D.translate(CardFactory.cardWidth + rotateTransformX, CardFactory.cardHeight + rotateTransformY); g2D.rotate(Math.PI - angle); } } else { if (card.tapped) { g2D.translate(CardFactory.cardHeight + rotateTransformY, rotateTransformX); g2D.rotate(Math.PI / 2 + angle); } else { g2D.translate(rotateTransformX, rotateTransformY); g2D.rotate(angle); } } } if (container != null) { if (container.isVisibleForOpponent() && !card.isVisibleForOpponent() && card.isVisibleForYou()) { /* * This card is visible for you but not for opponent in despite of the * fact the container is public. */ g2D.drawImage(card.scaledImage(), null, null); g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else if (!card.isVisibleForYou()) { g2D.drawImage(DatabaseFactory.scaledBackImage, null, null); } else { g2D.drawImage(card.scaledImage(), null, null); } } if (shortPaint) return; /* * The card picture is displayed as a rounded rectangle with 0,90,180 or * 270 */ if (card.isHighLighted && (card.isVisibleForYou() || StackManager.idHandedPlayer == 0)) { // Draw the rounded colored rectangle g2D.setColor(card.highLightColor); g2D.draw3DRect(0, 0, CardFactory.cardWidth - 2, CardFactory.cardHeight - 2, false); } // Draw the eventual progress bar card.database.updatePaintNotification(card, g); // Cursor for our pretty pictures int px = 3; int py = 3; int maxX = CardFactory.cardWidth - 2; // for in-play, visible cards if (card.isVisibleForYou() || (container != null && container.isVisibleForYou())) { // draw registers above the card's picture if (refreshToolTipFilter().powerANDtoughness) { // power / toughness final String powerANDtoughness = String.valueOf(card.getValue(IdTokens.POWER)) + "/" + card.getValue(IdTokens.TOUGHNESS); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 13)); final Rectangle2D stringDim = g2D.getFontMetrics().getStringBounds(powerANDtoughness, g2D); g2D.setColor(CardFactory.powerToughnessColor); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 5); g2D.setColor(Color.BLUE); g2D.drawString(powerANDtoughness, (int) (CardFactory.cardWidth - stringDim.getWidth() - 3), CardFactory.cardHeight - 6); } /* * START drawing additional pictures */ // draw state pictures for (StatePicture statePicture : CardFactory.statePictures) { if (px + 13 > maxX) { px = 3; py += 13; } if (statePicture.paint(card, g2D, px, py)) { px += 13; } } // draw properties if (card.cachedProperties != null) { for (Integer property : card.cachedProperties) { if (Configuration.getBoolean("card.property.picture", true) && CardFactory.propertyPictures.get(property) != null) { // There is an associated picture to this property if (px + 13 > maxX) { px = 3; py += 13; } g2D.drawImage(CardFactory.propertyPictures.get(property), px, py, 12, 12, null); px += 13; } } } } // draw attached objects int startX = 3; int startY = CardFactory.cardHeight - 18; if (card.registerModifiers != null) { for (int i = card.registerModifiers.length; i-- > 0;) { if (card.registerModifiers[i] != null) { startX = card.registerModifiers[i].paintObject(g, startX, startY); } } } if (card.propertyModifier != null) { startX = card.propertyModifier.paintObject(g, startX, startY); } if (card.idCardModifier != null) { card.idCardModifier.paintObject(g, startX, startY); /* * END drawing additional pictures */ } // Draw the target Id if helper said it final String id = TargetHelper.getInstance().getMyId(card); if (id != null) { if (px + 13 > maxX) { px = 3; py += 13; } if (id == TargetHelper.STR_CONTEXT1) { // TODO I am in the context 1, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id == TargetHelper.STR_CONTEXT2) { // TODO I am in the context 2, draw a picture g2D.setColor(Color.BLUE); g2D.setFont(g2D.getFont().deriveFont(Font.BOLD, 60 / id.length())); g2D.drawString(id, 5, CardFactory.cardHeight - 15); } else if (id != TargetHelper.STR_SOURCE) { // } else if (id == TargetHelper.STR_SOURCE) { // TODO I am the source, draw a picture // } else { // I am a target g2D.drawImage(TargetHelper.getInstance().getTargetPictureSml(), px, py, null); py += 12; } } g2D.dispose(); }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
public Image getThumbNailText(Image img, String text) { /*/*from w w w .ja v a2s . c om*/ * Create an image containing a thumbnail of the product image, * or default image. * * Then apply the text of the product name. Use text wrapping. * * If the product name is too big for the label, ensure that * the first part is displayed. */ img = getThumbNail(img); BufferedImage imgtext = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = imgtext.createGraphics(); // The text // <p style="width: 100px"> DOES NOT WORK PROPERLY. // use width= instead. String html = "<html><p style=\"text-align:center\" width=\"" + imgtext.getWidth() + "\">" + StringEscapeUtils.escapeHtml(text) + "</p>"; JLabel label = new JLabel(html); label.setOpaque(false); //label.setText("<html><center>Line1<br>Line2"); label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); label.setVerticalAlignment(javax.swing.SwingConstants.TOP); Dimension d = label.getPreferredSize(); label.setBounds(0, 0, imgtext.getWidth(), d.height); // The background Color c1 = new Color(0xff, 0xff, 0xff, 0x40); Color c2 = new Color(0xff, 0xff, 0xff, 0xd0); // Point2D center = new Point2D.Float(imgtext.getWidth() / 2, label.getHeight()); // float radius = imgtext.getWidth() / 3; // float[] dist = {0.1f, 1.0f}; // Color[] colors = {c2, c1}; // Paint gpaint = new RadialGradientPaint(center, radius, dist, colors); Paint gpaint = new GradientPaint(new Point(0, 0), c1, new Point(label.getWidth() / 2, 0), c2, true); g2d.drawImage(img, 0, 0, null); int ypos = imgtext.getHeight() - label.getHeight(); int ypos_min = -4; // todo: configurable if (ypos < ypos_min) ypos = ypos_min; // Clamp label g2d.translate(0, ypos); g2d.setPaint(gpaint); g2d.fillRect(0, 0, imgtext.getWidth(), label.getHeight()); label.paint(g2d); g2d.dispose(); return imgtext; }
From source file:MyJava3D.java
public int print(Graphics g, PageFormat pf, int pi) throws PrinterException { if (pi >= 1) { return Printable.NO_SUCH_PAGE; }/*from w w w .j a v a 2 s . c om*/ Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.translate(pf.getImageableWidth() / 2, pf.getImageableHeight() / 2); Dimension d = getSize(); double scale = Math.min(pf.getImageableWidth() / d.width, pf.getImageableHeight() / d.height); if (scale < 1.0) { g2d.scale(scale, scale); } g2d.translate(-d.width / 2.0, -d.height / 2.0); if (bimg == null) { Graphics2D g2 = createGraphics2D(d.width, d.height, null, g2d); render(d.width, d.height, g2); g2.dispose(); } else { g2d.drawImage(bimg, 0, 0, this); } return Printable.PAGE_EXISTS; }
From source file:jhplot.gui.GHPanel.java
/** * Print the canvas/*w ww . j a v a2s .c o m*/ * */ public void printGraph() { if (isBorderShown()) showBorders(false); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Thread t = new Thread() { public void run() { try { PrinterJob prnJob = PrinterJob.getPrinterJob(); // set the Printable to the PrinterJob prnJob.setPrintable(new Printable() { public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { if (pageIndex == 0) { Graphics2D g2d = (Graphics2D) graphics; double ratioX = pageFormat.getImageableWidth() / CanvasPanel.getSize().width; double ratioY = pageFormat.getImageableHeight() / CanvasPanel.getSize().height; double factor = Math.min(ratioX, ratioY); g2d.scale(factor, factor); g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); disableDoubleBuffering(CanvasPanel); CanvasPanel.print(g2d); enableDoubleBuffering(CanvasPanel); return Printable.PAGE_EXISTS; } return Printable.NO_SUCH_PAGE; } }); if (prnJob.printDialog()) { JHPlot.showStatusBarText("Printing.."); prnJob.print(); } } catch (PrinterException e) { e.printStackTrace(); } } }; t.start(); CanvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); }
From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java
/** {@inheritDoc} */ public IFPainter startPageContent() throws IFException { int bitmapWidth; int bitmapHeight; double scale; Point2D offset = null;/* ww w . j a va2s. co m*/ if (targetBitmapSize != null) { //Fit the generated page proportionally into the given rectangle (in pixels) double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth(); double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight(); bitmapWidth = targetBitmapSize.width; bitmapHeight = targetBitmapSize.height; //Centering the page in the given bitmap offset = new Point2D.Double(); if (scale2w < scale2h) { scale = scale2w; double h = this.currentPageDimensions.height * scale / 1000; offset.setLocation(0, (bitmapHeight - h) / 2.0); } else { scale = scale2h; double w = this.currentPageDimensions.width * scale / 1000; offset.setLocation((bitmapWidth - w) / 2.0, 0); } } else { //Normal case: just scale according to the target resolution scale = scaleFactor * getUserAgent().getTargetResolution() / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); } //Set up bitmap to paint on this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); Graphics2D graphics2D = this.currentImage.createGraphics(); // draw page background if (!getSettings().hasTransparentPageBackground()) { graphics2D.setBackground(getSettings().getPageBackgroundColor()); graphics2D.setPaint(getSettings().getPageBackgroundColor()); graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight); } //Set rendering hints graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (getSettings().isQualityRenderingEnabled()) { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } else { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); } graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); //Set up initial coordinate system for the page if (offset != null) { graphics2D.translate(offset.getX(), offset.getY()); } graphics2D.scale(scale / 1000f, scale / 1000f); return new Java2DPainter(graphics2D, getContext(), getFontInfo()); }
From source file:com.AandR.beans.plotting.imagePlotPanel.CanvasPanel.java
/** * *///from w ww .j ava 2s . c o m @Override public void scaleGraphicsContext(Graphics2D g2) throws IllegalArgumentException { if (currentScaleFactor > 0.0f) { g2.scale(currentScaleFactor, currentScaleFactor); g2.translate(currentTranslationX, currentTranslationY); } else { throw new IllegalArgumentException("An attempt was made to scale with a height or width value of 0"); } }