List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath()
From source file:Polygon2D.java
/** * Resets this <code>Polygon</code> object to an empty polygon. *//*from w w w .j a v a 2 s. co m*/ public void reset() { npoints = 0; bounds = null; path = new GeneralPath(); closedPath = null; }
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/* w w w. ja va 2 s . c o 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:CustomStrokes.java
public Shape createStrokedShape(Shape shape) { GeneralPath newshape = new GeneralPath(); // Start with an empty shape // Iterate through the specified shape, perturb its coordinates, and // use them to build up the new shape. float[] coords = new float[6]; for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) { int type = i.currentSegment(coords); switch (type) { case PathIterator.SEG_MOVETO: perturb(coords, 2);//from www. java 2 s .c o m newshape.moveTo(coords[0], coords[1]); break; case PathIterator.SEG_LINETO: perturb(coords, 2); newshape.lineTo(coords[0], coords[1]); break; case PathIterator.SEG_QUADTO: perturb(coords, 4); newshape.quadTo(coords[0], coords[1], coords[2], coords[3]); break; case PathIterator.SEG_CUBICTO: perturb(coords, 6); newshape.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]); break; case PathIterator.SEG_CLOSE: newshape.closePath(); break; } } // Finally, stroke the perturbed shape and return the result return stroke.createStrokedShape(newshape); }
From source file:Polygon2D.java
private void calculatePath() { path = new GeneralPath(); path.moveTo(xpoints[0], ypoints[0]); for (int i = 1; i < npoints; i++) { path.lineTo(xpoints[i], ypoints[i]); }// www . jav a2 s .c o m bounds = path.getBounds2D(); closedPath = null; }
From source file:longMethod.jfreechart.draw.XYPolygonAnnotation.java
/** * Draws the annotation. This method is usually called by the * {@link XYPlot} class, you shouldn't need to call it directly. * * @param g2 the graphics device./* w ww . j ava 2 s . co m*/ * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { // if we don't have at least 2 (x, y) coordinates, just return if (this.polygon.length < 4) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(plot.getRangeAxisLocation(), orientation); GeneralPath area = new GeneralPath(); double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge); double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { area.moveTo((float) y, (float) x); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) y, (float) x); } area.closePath(); } else if (orientation == PlotOrientation.VERTICAL) { area.moveTo((float) x, (float) y); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) x, (float) y); } area.closePath(); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(area); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(area); } addEntity(info, area, rendererIndex, getToolTipText(), getURL()); }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java
/*********************************************************************************************** * Set the shape for the Chart legend items. * * @param renderer/*from w w w . jav a2s . c o m*/ */ static void setLegendShape(final XYLineAndShapeRenderer renderer) { final GeneralPath pathBlock; pathBlock = new GeneralPath(); pathBlock.moveTo(-7.0f, -3.0f); pathBlock.lineTo(7.0f, -3.0f); pathBlock.moveTo(-7.0f, -2.0f); pathBlock.lineTo(7.0f, -2.0f); pathBlock.moveTo(-7.0f, -1.0f); pathBlock.lineTo(7.0f, -1.0f); pathBlock.moveTo(-7.0f, 0.0f); pathBlock.lineTo(7.0f, 0.0f); pathBlock.moveTo(-7.0f, 1.0f); pathBlock.lineTo(7.0f, 1.0f); pathBlock.moveTo(-7.0f, 2.0f); pathBlock.lineTo(7.0f, 2.0f); pathBlock.moveTo(-7.0f, 3.0f); pathBlock.lineTo(7.0f, 3.0f); renderer.setLegendLine(pathBlock); }
From source file:longMethod.jfreechart.drawItem.SamplingXYLineRenderer.java
/** * Initialises the renderer./*from w ww .j a v a 2 s . com*/ * <P> * This method will be called before the first item is rendered, giving the * renderer an opportunity to initialise any state information it wants to * maintain. The renderer can do nothing if it chooses. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param plot the plot. * @param data the data. * @param info an optional info collection object to return data back to * the caller. * * @return The renderer state. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset data, PlotRenderingInfo info) { double dpi = 72; // Integer dpiVal = (Integer) g2.getRenderingHint(HintKey.DPI); // if (dpiVal != null) { // dpi = dpiVal.intValue(); // } State state = new State(info); state.seriesPath = new GeneralPath(); state.intervalPath = new GeneralPath(); state.dX = 72.0 / dpi; return state; }
From source file:userinterface.graph.PrismErrorRenderer.java
/** * Initialises and returns a state object that can be passed to each * invocation of the {@link #drawItem} method. * * @param g2 the graphics target./* w ww . j a v a 2 s. c om*/ * @param dataArea the data area. * @param plot the plot. * @param dataset the dataset. * @param info the plot rendering info. * * @return A newly initialised state object. */ public XYItemRendererState initialise(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, PlotRenderingInfo info) { State state = new State(info); state.seriesPath = new GeneralPath(); state.setProcessVisibleItemsOnly(false); return state; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java
/** * Draw a single data item.//from ww w . ja v a 2 s.co m * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the data plot area. * @param plot the plot. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the data. * @param row the row index (zero-based). * @param column the column index (zero-based). * @param pass the pass index. */ public void drawItem(final Graphics2D g2, final CategoryItemRendererState state, final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis, final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column, final int pass) { if (!isSeriesVisible(row)) { return; } if ((pass == 1) && !isItemLabelVisible(row, column)) { return; } // setup for collecting optional entity info... Shape entityArea = null; final EntityCollection entities = state.getEntityCollection(); double y1 = 0.0; Number n = dataset.getValue(row, column); if (n != null) { y1 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, column); y1 = y1 / total; } } final double[] stack1 = getStackValues(dataset, row, column); // leave the y values (y1, y0) untranslated as it is going to be be // stacked up later by previous series values, after this it will be // translated. double xx1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double y0 = 0.0; n = dataset.getValue(row, Math.max(column - 1, 0)); if (n != null) { y0 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.max(column - 1, 0)); y0 = y0 / total; } } final double[] stack0 = getStackValues(dataset, row, Math.max(column - 1, 0)); // FIXME: calculate xx0 double xx0 = domainAxis.getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); final int itemCount = dataset.getColumnCount(); double y2 = 0.0; n = dataset.getValue(row, Math.min(column + 1, itemCount - 1)); if (n != null) { y2 = n.doubleValue(); if (this.renderAsPercentages) { final double total = DataUtilities.calculateColumnTotal(dataset, Math.min(column + 1, itemCount - 1)); y2 = y2 / total; } } final double[] stack2 = getStackValues(dataset, row, Math.min(column + 1, itemCount - 1)); double xx2 = domainAxis.getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); // This gets rid of the white lines between most category values // Doug Moran - Hitachi Vantara xx0 = Math.round(xx0); xx1 = Math.round(xx1); xx2 = Math.round(xx2); // FIXME: calculate xxLeft and xxRight final double xxLeft = xx0; final double xxRight = xx2; final double[] stackLeft = averageStackValues(stack0, stack1); final double[] stackRight = averageStackValues(stack1, stack2); final double[] adjStackLeft = adjustedStackValues(stack0, stack1); final double[] adjStackRight = adjustedStackValues(stack1, stack2); final float transY1; final RectangleEdge edge1 = plot.getRangeAxisEdge(); final GeneralPath left = new GeneralPath(); final GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[1], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { final double yleft = (y0 + y1) / 2.0 + stackLeft[1]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } else { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[1], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { final double yright = (y1 + y2) / 2.0 + stackRight[1]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); final float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); final float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo((float) xx1, transStack1); left.lineTo((float) xx1, transY1); left.lineTo((float) xxLeft, transStackLeft); left.clone(); } else { final double yleft = (y0 + y1) / 2.0 + stackLeft[0]; final float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo((float) xx1, transY1); left.lineTo((float) xx1, transStack1); left.lineTo((float) xxLeft, transStackLeft); left.lineTo((float) xxLeft, transYLeft); left.closePath(); } final float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transStackRight); right.closePath(); } else { final double yright = (y1 + y2) / 2.0 + stackRight[0]; final float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo((float) xx1, transStack1); right.lineTo((float) xx1, transY1); right.lineTo((float) xxRight, transYRight); right.lineTo((float) xxRight, transStackRight); right.closePath(); } } if (pass == 0) { final Paint itemPaint = getItemPaint(row, column); g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); // add an entity for the item... if (entities != null) { final GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addItemEntity(entities, dataset, row, column, entityArea); } } else if (pass == 1) { drawItemLabel(g2, plot.getOrientation(), dataset, row, column, xx1, transY1, y1 < 0.0); } }
From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java
private VisualPeakAnnotation generateTriangle(double startX, double startY, double apexX, double apexY, double stopX, double stopY) { GeneralPath path = new GeneralPath(); path.moveTo(startX, startY);//from w ww. ja v a 2 s. com path.lineTo(apexX, apexY); path.lineTo(stopX, stopY); path.closePath(); Rectangle2D r = path.getBounds2D(); return new VisualPeakAnnotation(path, new Point2D.Double(r.getCenterX(), r.getMaxY()), PeakAnnotationType.POINTER); }