Example usage for com.itextpdf.text.pdf PdfContentByte LINE_CAP_ROUND

List of usage examples for com.itextpdf.text.pdf PdfContentByte LINE_CAP_ROUND

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte LINE_CAP_ROUND.

Prototype

int LINE_CAP_ROUND

To view the source code for com.itextpdf.text.pdf PdfContentByte LINE_CAP_ROUND.

Click Source Link

Document

A possible line cap value

Usage

From source file:ihm.panneaux.GenererPdf.java

public void applyLineDash(PdfContentByte canvas) {
    canvas.setLineCap(PdfContentByte.LINE_CAP_ROUND);
    canvas.setLineDash(0, 4, 2);
}

From source file:org.gephi.preview.plugin.renderers.EdgeLabelRenderer.java

License:Open Source License

public void renderPDF(PDFTarget target, String label, float x, float y, Color color, float outlineSize,
        Color outlineColor) {/*from  w w w.  j av a 2  s.  c  o  m*/
    PdfContentByte cb = target.getContentByte();
    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    BaseFont bf = target.getBaseFont(font);
    float textHeight = getTextHeight(bf, font.getSize(), label);
    if (outlineSize > 0) {
        cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
        cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue());
        cb.setLineWidth(outlineSize);
        cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
        cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
        if (outlineColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = outlineColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.beginText();
        cb.setFontAndSize(bf, font.getSize());
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
        cb.endText();
        if (outlineColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }
    cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    cb.beginText();
    cb.setFontAndSize(bf, font.getSize());
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
    cb.endText();
}

From source file:org.gephi.preview.plugin.renderers.NodeLabelRenderer.java

License:Open Source License

public void renderPDF(PDFTarget target, Node node, String label, float x, float y, int fontSize, Color color,
        float outlineSize, Color outlineColor, boolean showBox, Color boxColor) {
    Font font = fontCache.get(fontSize);
    PdfContentByte cb = target.getContentByte();
    BaseFont bf = target.getBaseFont(font);

    //Box// www . j av  a 2 s.  com
    if (showBox) {
        cb.setRGBColorFill(boxColor.getRed(), boxColor.getGreen(), boxColor.getBlue());
        if (boxColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = boxColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setFillOpacity(alpha);
            cb.setGState(gState);
        }
        float textWidth = getTextWidth(bf, fontSize, label);
        float textHeight = getTextHeight(bf, fontSize, label);

        //A height of just textHeight seems to be half the text height sometimes
        //BaseFont getAscentPoint and getDescentPoint may be not very precise
        cb.rectangle(x - textWidth / 2f - outlineSize / 2f, -y - outlineSize / 2f - textHeight,
                textWidth + outlineSize, textHeight * 2f + outlineSize);

        cb.fill();
        if (boxColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }

    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    float textHeight = getTextHeight(bf, fontSize, label);
    if (outlineSize > 0) {
        cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_STROKE);
        cb.setRGBColorStroke(outlineColor.getRed(), outlineColor.getGreen(), outlineColor.getBlue());
        cb.setLineWidth(outlineSize);
        cb.setLineJoin(PdfContentByte.LINE_JOIN_ROUND);
        cb.setLineCap(PdfContentByte.LINE_CAP_ROUND);
        if (outlineColor.getAlpha() < 255) {
            cb.saveState();
            float alpha = outlineColor.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.beginText();
        cb.setFontAndSize(bf, font.getSize());
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
        cb.endText();
        if (outlineColor.getAlpha() < 255) {
            cb.restoreState();
        }
    }
    cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
    cb.beginText();
    cb.setFontAndSize(bf, font.getSize());
    cb.showTextAligned(PdfContentByte.ALIGN_CENTER, label, x, -y - (textHeight / 2f), 0f);
    cb.endText();
}