List of usage examples for java.awt.geom Area Area
public Area(Shape s)
From source file:VASSAL.build.module.map.MapShader.java
public void draw(Graphics g, Map map) { if (shadingVisible) { double zoom = map.getZoom(); buildStroke(zoom);/*w ww. ja v a2s. c o m*/ final Graphics2D g2 = (Graphics2D) g; final Composite oldComposite = g2.getComposite(); final Color oldColor = g2.getColor(); final Paint oldPaint = g2.getPaint(); final Stroke oldStroke = g2.getStroke(); g2.setComposite(getComposite()); g2.setColor(getColor()); g2.setPaint(scaleImage && pattern.equals(TYPE_IMAGE) && imageName != null ? getTexture(zoom) : getTexture()); Area area = getShadeShape(map); if (zoom != 1.0) { area = new Area(AffineTransform.getScaleInstance(zoom, zoom).createTransformedShape(area)); } g2.fill(area); if (border) { g2.setComposite(getBorderComposite()); g2.setStroke(getStroke(map.getZoom())); g2.setColor(getBorderColor()); g2.draw(area); } g2.setComposite(oldComposite); g2.setColor(oldColor); g2.setPaint(oldPaint); g2.setStroke(oldStroke); } }
From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java
/** * Draws the frame. This method is called by the {@link DialPlot} class, * you shouldn't need to call it directly. * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the plot (<code>null</code> not permitted). * @param frame the frame (<code>null</code> not permitted). * @param view the view (<code>null</code> not permitted). *///from w w w .j a va2 s . c o m public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Shape window = getWindow(frame); Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02); Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight()); Area area = new Area(e); Area area2 = new Area(window); area.subtract(area2); g2.setPaint(this.backgroundPaint); g2.fill(area); g2.setStroke(this.stroke); g2.setPaint(this.foregroundPaint); g2.draw(window); g2.draw(e); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
/** * Constructor for PDFGraphics2D.//from ww w .j a v a2 s .co m */ public PdfGraphics2D(final PdfContentByte cb, final float width, final float height, final PdfOutputProcessorMetaData metaData) { this.metaData = metaData; dg2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); this.transform = new AffineTransform(); paint = Color.black; background = Color.white; setFont(new Font("sanserif", Font.PLAIN, 12)); this.cb = cb; cb.saveState(); this.width = width; this.height = height; clip = new Area(new Rectangle2D.Float(0, 0, width, height)); clip(clip); oldStroke = strokeOne; stroke = strokeOne; originalStroke = strokeOne; setStrokeDiff(stroke, null); cb.saveState(); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Paint the given tree layout//w w w. j a v a2 s . c o m * @param graphics * the graphics to paint with * @param treeLayout * the layout to paint */ private void paintPhylogenyTree(Graphics2D graphics, VisualTreeNode treeLayout) { int childNodeCount = treeLayout.getChildNodes().size(); for (int i = 0; i < childNodeCount; i++) { VisualTreeNode visualChild = treeLayout.getChildNodes().get(i); Shape branchShape = new Line2D.Double(treeLayout.getPosition(), visualChild.getPosition()); Shape branchShadowShape = SHADOW_TRANSFORM.createTransformedShape(branchShape); graphics.setColor(SHADOW_COLOR); graphics.draw(branchShadowShape); if (this.paintScale != null) { PhylogenyTreeEdge phylogenyEdge = treeLayout.getPhylogenyTreeNode().getChildEdges().get(i); if (phylogenyEdge instanceof PhylogenyTreeEdgeWithRealValue) { PhylogenyTreeEdgeWithRealValue phylogenyEdgeWithValue = (PhylogenyTreeEdgeWithRealValue) phylogenyEdge; Paint paint = this.paintScale.getPaint(phylogenyEdgeWithValue.getRealValue()); graphics.setPaint(paint); } else { graphics.setColor(FOREGROUND_COLOR); } } else { graphics.setColor(FOREGROUND_COLOR); } graphics.draw(branchShape); // recurse this.paintPhylogenyTree(graphics, visualChild); } if (!treeLayout.getPhylogenyTreeNode().getStrains().isEmpty()) { Shape textShape = this.getLabelShape(treeLayout, graphics.getFontRenderContext()); Shape borderShape = this.getLabelBorder(textShape); graphics.setColor(BACKGROUND_COLOR); graphics.fill(borderShape); graphics.setColor(SHADOW_COLOR); Area borderShadowShape = new Area(SHADOW_TRANSFORM.createTransformedShape(borderShape)); borderShadowShape.subtract(new Area(borderShape)); graphics.draw(borderShadowShape); graphics.setColor(FOREGROUND_COLOR); graphics.draw(borderShape); graphics.fill(textShape); } }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * * @param operator The operator that is being executed. * @param arguments List/*ww w . j a v a 2 s .co m*/ * @throws IOException If there is an error invoking the sub object. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); COSName objectName = (COSName) arguments.get(0); Map<String, PDXObject> xobjects = extractor.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { LOG.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { if (image.getImageMask()) { // set the current non stroking colorstate, so that it can // be used to create a stencil masked image image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor()); } BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { LOG.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) { angle = (-1) * angle; } ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); extractor.drawImage(awtImage, ctmAT); } catch (Exception e) { LOG.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream formContentstream = form.getCOSStream(); // find some optional resources, instead of using the current resources PDResources pdResources = form.getResources(); // if there is an optional form matrix, we have to map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } if (form.getBBox() != null) { PDGraphicsState graphicsState = context.getGraphicsState(); PDRectangle bBox = form.getBBox(); float x1 = bBox.getLowerLeftX(); float y1 = bBox.getLowerLeftY(); float x2 = bBox.getUpperRightX(); float y2 = bBox.getUpperRightY(); Point2D p0 = extractor.transformedPoint(x1, y1); Point2D p1 = extractor.transformedPoint(x2, y1); Point2D p2 = extractor.transformedPoint(x2, y2); Point2D p3 = extractor.transformedPoint(x1, y2); GeneralPath bboxPath = new GeneralPath(); bboxPath.moveTo((float) p0.getX(), (float) p0.getY()); bboxPath.lineTo((float) p1.getX(), (float) p1.getY()); bboxPath.lineTo((float) p2.getX(), (float) p2.getY()); bboxPath.lineTo((float) p3.getX(), (float) p3.getY()); bboxPath.closePath(); Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath()); Area newArea = new Area(bboxPath); resultClippingArea.intersect(newArea); graphicsState.setCurrentClippingPath(resultClippingArea); } getContext().processSubStream(page, pdResources, formContentstream); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:ShapeTransform.java
/** * Clips the given shape to the given bounds. If the shape is a Line2D, manual * clipping is performed, as the built in Area does not handle lines. * // w w w . ja va2 s . co m * @param s * the shape to be clipped * @param bounds * the bounds to which the shape should be clipped * @return the clipped shape. */ public static Shape performCliping(final Shape s, final Rectangle2D bounds) { if (s instanceof Line2D) { final Line2D line = (Line2D) s; final Point2D[] clipped = getClipped(line.getX1(), line.getY1(), line.getX2(), line.getY2(), -DELTA, DELTA + bounds.getWidth(), -DELTA, DELTA + bounds.getHeight()); if (clipped == null) { return new GeneralPath(); } return new Line2D.Float(clipped[0], clipped[1]); } final Rectangle2D boundsCorrected = bounds.getBounds2D(); boundsCorrected.setRect(-DELTA, -DELTA, DELTA + boundsCorrected.getWidth(), DELTA + boundsCorrected.getHeight()); final Area a = new Area(boundsCorrected); if (a.isEmpty()) { // don't clip ... Area does not like lines // operations with lines always result in an empty Bounds:(0,0,0,0) area return new GeneralPath(); } final Area clipArea = new Area(s); a.intersect(clipArea); return a; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
private AbstractImageMapEntry createMapEntry(final Shape area, final Rectangle2D dataArea) { if (buggyDrawArea) { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX() + dataArea.getX()), (float) (ellipse2D.getCenterY() + dataArea.getY()), (float) (ellipse2D.getWidth() / 2)); }/*w ww.j a v a 2 s . c o m*/ } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX() + dataArea.getX()), (float) (rect.getY() + dataArea.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } else { if (area instanceof Ellipse2D) { final Ellipse2D ellipse2D = (Ellipse2D) area; if (ellipse2D.getWidth() == ellipse2D.getHeight()) { return new CircleImageMapEntry((float) (ellipse2D.getCenterX()), (float) (ellipse2D.getCenterY()), (float) (ellipse2D.getWidth() / 2)); } } else if (area instanceof Rectangle2D) { final Rectangle2D rect = (Rectangle2D) area; return (new RectangleImageMapEntry((float) (rect.getX()), (float) (rect.getY()), (float) (rect.getX() + rect.getWidth()), (float) (rect.getY() + rect.getHeight()))); } } final Area a = new Area(area); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } if (dataArea.isEmpty() == false) { a.intersect(new Area(dataArea)); } final PathIterator pathIterator = a.getPathIterator(null, 2); final FloatList floats = new FloatList(100); final float[] coords = new float[6]; while (pathIterator.isDone() == false) { final int retval = pathIterator.currentSegment(coords); if (retval == PathIterator.SEG_MOVETO || retval == PathIterator.SEG_LINETO) { floats.add(coords[0]); floats.add(coords[1]); } pathIterator.next(); } if (floats.size() == 0) { return null; } return (new PolygonImageMapEntry(floats.toArray())); }
From source file:net.technicpack.ui.lang.ResourceLoader.java
public BufferedImage getCircleClippedImage(BufferedImage contentImage) { // copy the picture to an image with transparency capabilities BufferedImage outputImage = new BufferedImage(contentImage.getWidth(), contentImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) outputImage.getGraphics(); g2.drawImage(contentImage, 0, 0, null); // Create the area around the circle to cut out Area cutOutArea = new Area(new Rectangle(0, 0, outputImage.getWidth(), outputImage.getHeight())); int diameter = (outputImage.getWidth() < outputImage.getHeight()) ? outputImage.getWidth() : outputImage.getHeight();// w w w . ja v a2 s. c o m cutOutArea.subtract(new Area(new Ellipse2D.Float((outputImage.getWidth() - diameter) / 2, (outputImage.getHeight() - diameter) / 2, diameter, diameter))); // Set the fill color to an opaque color g2.setColor(Color.WHITE); // Set the composite to clear pixels g2.setComposite(AlphaComposite.Clear); // Turn on antialiasing g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Clear the cut out area g2.fill(cutOutArea); // dispose of the graphics object g2.dispose(); return outputImage; }
From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java
/** * Draws the frame./*ww w .j ava2 s.com*/ * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view rectangle. */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Shape window = getWindow(frame); Shape outerWindow = getOuterWindow(frame); Area area1 = new Area(outerWindow); Area area2 = new Area(window); area1.subtract(area2); g2.setPaint(Color.lightGray); g2.fill(area1); g2.setStroke(this.stroke); g2.setPaint(this.foregroundPaint); g2.draw(window); g2.draw(outerWindow); }
From source file:org.apache.pdfbox.rendering.PageDrawer.java
/** * Render the font using the Glyph2D interface. * // w w w . j a v a2 s.c om * @param glyph2D the Glyph2D implementation provided a GeneralPath for each glyph * @param font the font * @param code character code * @param displacement the glyph's displacement (advance) * @param at the transformation * @throws IOException if something went wrong */ private void drawGlyph2D(Glyph2D glyph2D, PDFont font, int code, Vector displacement, AffineTransform at) throws IOException { PDGraphicsState state = getGraphicsState(); RenderingMode renderingMode = state.getTextState().getRenderingMode(); GeneralPath path = glyph2D.getPathForCharacterCode(code); if (path != null) { // stretch non-embedded glyph if it does not match the width contained in the PDF if (!font.isEmbedded()) { float fontWidth = font.getWidthFromFont(code); if (fontWidth > 0 && // ignore spaces Math.abs(fontWidth - displacement.getX() * 1000) > 0.0001) { float pdfWidth = displacement.getX() * 1000; at.scale(pdfWidth / fontWidth, 1); } } // render glyph Shape glyph = at.createTransformedShape(path); if (renderingMode.isFill()) { graphics.setComposite(state.getNonStrokingJavaComposite()); graphics.setPaint(getNonStrokingPaint()); setClip(); graphics.fill(glyph); } if (renderingMode.isStroke()) { graphics.setComposite(state.getStrokingJavaComposite()); graphics.setPaint(getStrokingPaint()); graphics.setStroke(getStroke()); setClip(); graphics.draw(glyph); } if (renderingMode.isClip()) { textClippingArea.add(new Area(glyph)); } } }