List of usage examples for java.awt.geom GeneralPath clone
public abstract Object clone();
From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.StackedAreaRenderer.java
/** * Draw a single data item.// ww w . ja v a 2 s .c o 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:de.saring.util.gui.jfreechart.StackedRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device./* ww w. j av a 2 s .c o m*/ * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color information * etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState information about crosshairs on a plot. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } TableXYDataset tdataset = (TableXYDataset) dataset; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1)) { y1 = 0.0; } double[] stack1 = getStackValues(tdataset, series, item); // get the previous point and the next point so we can calculate a // "hot spot" for the area (used by the chart entity)... double x0 = dataset.getXValue(series, Math.max(item - 1, 0)); double y0 = dataset.getYValue(series, Math.max(item - 1, 0)); if (Double.isNaN(y0)) { y0 = 0.0; } double[] stack0 = getStackValues(tdataset, series, Math.max(item - 1, 0)); int itemCount = dataset.getItemCount(series); double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1)); double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1)); if (Double.isNaN(y2)) { y2 = 0.0; } double[] stack2 = getStackValues(tdataset, series, Math.min(item + 1, itemCount - 1)); double xleft = (x0 + x1) / 2.0; double xright = (x1 + x2) / 2.0; double[] stackLeft = averageStackValues(stack0, stack1); double[] stackRight = averageStackValues(stack1, stack2); double[] adjStackLeft = adjustedStackValues(stack0, stack1); double[] adjStackRight = adjustedStackValues(stack1, stack2); RectangleEdge edge0 = plot.getDomainAxisEdge(); float transX1 = (float) domainAxis.valueToJava2D(x1, dataArea, edge0); float transXLeft = (float) domainAxis.valueToJava2D(xleft, dataArea, edge0); float transXRight = (float) domainAxis.valueToJava2D(xright, dataArea, edge0); if (this.roundXCoordinates) { transX1 = Math.round(transX1); transXLeft = Math.round(transXLeft); transXRight = Math.round(transXRight); } float transY1; RectangleEdge edge1 = plot.getRangeAxisEdge(); GeneralPath left = new GeneralPath(); GeneralPath right = new GeneralPath(); if (y1 >= 0.0) { // handle positive value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[1], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[1], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(stackLeft[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // LEFT POLYGON if (y0 >= 0.0) { double yleft = (y0 + y1) / 2.0 + stackLeft[1]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } else { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(stackRight[1], dataArea, edge1); // other than StackedXYAreaRenderer2! // RIGHT POLYGON if (y2 >= 0.0) { double yright = (y1 + y2) / 2.0 + stackRight[1]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } else { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } } else { // handle negative value transY1 = (float) rangeAxis.valueToJava2D(y1 + stack1[0], dataArea, edge1); float transStack1 = (float) rangeAxis.valueToJava2D(stack1[0], dataArea, edge1); float transStackLeft = (float) rangeAxis.valueToJava2D(adjStackLeft[0], dataArea, edge1); // LEFT POLYGON if (y0 >= 0.0) { left.moveTo(transX1, transStack1); left.lineTo(transX1, transY1); left.lineTo(transXLeft, transStackLeft); left.clone(); } else { double yleft = (y0 + y1) / 2.0 + stackLeft[0]; float transYLeft = (float) rangeAxis.valueToJava2D(yleft, dataArea, edge1); left.moveTo(transX1, transY1); left.lineTo(transX1, transStack1); left.lineTo(transXLeft, transStackLeft); left.lineTo(transXLeft, transYLeft); left.closePath(); } float transStackRight = (float) rangeAxis.valueToJava2D(adjStackRight[0], dataArea, edge1); // RIGHT POLYGON if (y2 >= 0.0) { right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transStackRight); right.closePath(); } else { double yright = (y1 + y2) / 2.0 + stackRight[0]; float transYRight = (float) rangeAxis.valueToJava2D(yright, dataArea, edge1); right.moveTo(transX1, transStack1); right.lineTo(transX1, transY1); right.lineTo(transXRight, transYRight); right.lineTo(transXRight, transStackRight); right.closePath(); } } // Get series Paint and Stroke Paint itemPaint = getItemPaint(series, item); if (pass == 0) { g2.setPaint(itemPaint); g2.fill(left); g2.fill(right); } else if (pass == 1) { if (item == 0 || (y1 == 0.0 && y0 == 0.0)) { return; } // get the data point... if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } if (Double.isNaN(y0) || Double.isNaN(x0)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0 + stack0[1], dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } state.workingLine.setLine(transX0, transY0, transX1, transY1); if (state.workingLine.intersects(dataArea)) { g2.setStroke(getItemStroke(series, item)); g2.setPaint(super.lookupSeriesPaint(series)); g2.draw(state.workingLine); } return; } // add an entity for the item... if (entities != null) { GeneralPath gp = new GeneralPath(left); gp.append(right, false); entityArea = gp; addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:org.apache.pdfbox.pdfviewer.font.TTFGlyph2D.java
/** * Returns the path describing the glyph for the given glyphId. * * @param glyphId the glyphId/*from w w w .j a v a 2 s. co m*/ * * @return the GeneralPath for the given glyphId */ public GeneralPath getPathForGlyphId(int glyphId) { GeneralPath glyphPath = null; if (glyphs.containsKey(glyphId)) { glyphPath = glyphs.get(glyphId); } else { GlyphData[] glyphData = font.getGlyph().getGlyphs(); if (glyphId < glyphData.length && glyphData[glyphId] != null) { GlyphData glyph = glyphData[glyphId]; GlyphDescription gd = glyph.getDescription(); Point[] points = describe(gd); glyphPath = calculatePath(points); if (hasScaling) { AffineTransform atScale = AffineTransform.getScaleInstance(scale, scale); glyphPath.transform(atScale); } glyphs.put(glyphId, glyphPath); } else { LOG.debug(name + ": Glyph not found:" + glyphId); } } return glyphPath != null ? (GeneralPath) glyphPath.clone() : null; }
From source file:org.apache.pdfbox.rendering.TTFGlyph2D.java
/** * Returns the path describing the glyph for the given glyphId. * * @param gid the GID/*from www .j av a2 s.c o m*/ * @param code the character code * * @return the GeneralPath for the given glyphId */ public GeneralPath getPathForGID(int gid, int code) throws IOException { GeneralPath glyphPath; if (glyphs.containsKey(gid)) { glyphPath = glyphs.get(gid); } else { if (gid == 0 || gid >= ttf.getMaximumProfile().getNumGlyphs()) { if (isCIDFont) { int cid = ((PDType0Font) font).codeToCID(code); String cidHex = String.format("%04x", cid); LOG.warn("No glyph for " + code + " (CID " + cidHex + ") in font " + font.getName()); } else { LOG.warn("No glyph for " + code + " in font " + font.getName()); } } GeneralPath glyph = vectorFont.getPath(code); // Acrobat only draws GID 0 for embedded or "Standard 14" fonts, see PDFBOX-2372 if (gid == 0 && !font.isEmbedded() && !font.isStandard14()) { glyph = null; } if (glyph == null) { // empty glyph (e.g. space, newline) glyphPath = new GeneralPath(); glyphs.put(gid, glyphPath); } else { glyphPath = glyph; if (hasScaling) { AffineTransform atScale = AffineTransform.getScaleInstance(scale, scale); glyphPath.transform(atScale); } glyphs.put(gid, glyphPath); } } return glyphPath != null ? (GeneralPath) glyphPath.clone() : null; // todo: expensive }