public void drawLine(float x0, float y0, float x1, float y1, Color color, float lineWidth) { template.saveState(); setStroke(color, lineWidth, null); template.moveTo(origX + x0, origY + y0); template.lineTo(origX + x1, origY + y1); template.stroke(); template.restoreState(); }
/** * Return the text box for the specified text and font. * * @param text text * @param font font * @return text box */ public Rectangle getTextSize(String text, Font font) { template.saveState(); // get the font DefaultFontMapper mapper = new DefaultFontMapper(); BaseFont bf = mapper.awtToPdf(font); template.setFontAndSize(bf, font.getSize()); // calculate text width and height float textWidth = template.getEffectiveStringWidth(text, false); float ascent = bf.getAscentPoint(text, font.getSize()); float descent = bf.getDescentPoint(text, font.getSize()); float textHeight = ascent - descent; template.restoreState(); return new Rectangle(0, 0, textWidth, textHeight); }
public void fillRoundRectangle(Rectangle rect, Color color, float r) { template.saveState(); setFill(color); template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(), r); template.fill(); template.restoreState(); }
/** * Draw a rectangle's interior with this color. * * @param rect rectangle * @param color colour */ public void fillRectangle(Rectangle rect, Color color) { template.saveState(); setFill(color); template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight()); template.fill(); template.restoreState(); }
public void strokeRectangle(Rectangle rect, Color color, float linewidth, float[] dashArray) { template.saveState(); setStroke(color, linewidth, dashArray); template.rectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight()); template.stroke(); template.restoreState(); }
/** * Draw an elliptical interior with this color. * * @param rect rectangle in which ellipse should fit * @param color colour to use for filling */ public void fillEllipse(Rectangle rect, Color color) { template.saveState(); setFill(color); template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(), origY + rect.getTop()); template.fill(); template.restoreState(); }
/** * Draw a rounded rectangular boundary. * * @param rect rectangle * @param color colour * @param linewidth line width * @param r radius for rounded corners */ public void strokeRoundRectangle(Rectangle rect, Color color, float linewidth, float r) { template.saveState(); setStroke(color, linewidth, null); template.roundRectangle(origX + rect.getLeft(), origY + rect.getBottom(), rect.getWidth(), rect.getHeight(), r); template.stroke(); template.restoreState(); }
/** * Draw an elliptical exterior with this color. * * @param rect rectangle in which ellipse should fit * @param color colour to use for stroking * @param linewidth line width */ public void strokeEllipse(Rectangle rect, Color color, float linewidth) { template.saveState(); setStroke(color, linewidth, null); template.ellipse(origX + rect.getLeft(), origY + rect.getBottom(), origX + rect.getRight(), origY + rect.getTop()); template.stroke(); template.restoreState(); }
/** * Draw a path specified by relative coordinates in [0,1] range wrt the specified rectangle. * * @param x x-ordinate * @param y y-ordinate * @param rect rectangle * @param color color to use * @param lineWidth line width * @param dashArray lengths for dashed and white area */ public void drawRelativePath(float[] x, float[] y, Rectangle rect, Color color, float lineWidth, float[] dashArray) { template.saveState(); setStroke(color, lineWidth, dashArray); template.moveTo(origX + getAbsoluteX(x[0], rect), origY + getAbsoluteY(y[0], rect)); for (int i = 1; i < x.length; i++) { template.lineTo(origX + getAbsoluteX(x[i], rect), origY + getAbsoluteY(y[i], rect)); } template.stroke(); template.restoreState(); }
/** * Draw text in the center of the specified box. * * @param text text * @param font font * @param box box to put text int * @param fontColor colour */ public void drawText(String text, Font font, Rectangle box, Color fontColor) { template.saveState(); // get the font DefaultFontMapper mapper = new DefaultFontMapper(); BaseFont bf = mapper.awtToPdf(font); template.setFontAndSize(bf, font.getSize()); // calculate descent float descent = 0; if (text != null) { descent = bf.getDescentPoint(text, font.getSize()); } // calculate the fitting size Rectangle fit = getTextSize(text, font); // draw text if necessary template.setColorFill(fontColor); template.beginText(); template.showTextAligned(PdfContentByte.ALIGN_LEFT, text, origX + box.getLeft() + 0.5f * (box.getWidth() - fit.getWidth()), origY + box.getBottom() + 0.5f * (box.getHeight() - fit.getHeight()) - descent, 0); template.endText(); template.restoreState(); }
/** * Draw the specified geometry. * * @param geometry geometry to draw * @param symbol symbol for geometry * @param fillColor fill colour * @param strokeColor stroke colour * @param lineWidth line width * @param clipRect clipping rectangle */ public void drawGeometry(Geometry geometry, SymbolInfo symbol, Color fillColor, Color strokeColor, float lineWidth, float[] dashArray, Rectangle clipRect) { template.saveState(); // clipping code if (clipRect != null) { template.rectangle(clipRect.getLeft() + origX, clipRect.getBottom() + origY, clipRect.getWidth(), clipRect .getHeight()); template.clip(); template.newPath(); } setStroke(strokeColor, lineWidth, dashArray); setFill(fillColor); drawGeometry(geometry, symbol); template.restoreState(); }