Example usage for com.lowagie.text.pdf PdfContentByte setLineCap

List of usage examples for com.lowagie.text.pdf PdfContentByte setLineCap

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte setLineCap.

Prototype


public void setLineCap(int style) 

Source Link

Document

Changes the Line cap style.

Usage

From source file:com.dlya.facturews.DlyaPdfExporter2.java

License:Open Source License

/**
 *
 *///from   www.j  a v  a 2s .  c o m
private static void preparePen(PdfContentByte pdfContentByte, JRPen pen, int lineCap) {
    float lineWidth = pen.getLineWidth().floatValue();

    if (lineWidth <= 0) {
        return;
    }

    pdfContentByte.setLineWidth(lineWidth);
    pdfContentByte.setLineCap(lineCap);

    Color color = pen.getLineColor();
    pdfContentByte.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());

    switch (pen.getLineStyleValue()) {
    case DOUBLE: {
        pdfContentByte.setLineWidth(lineWidth / 3);
        pdfContentByte.setLineDash(0f);
        break;
    }
    case DOTTED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(lineWidth, lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(0, 2 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case DASHED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(5 * lineWidth, 3 * lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(4 * lineWidth, 4 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case SOLID:
    default: {
        pdfContentByte.setLineDash(0f);
        break;
    }
    }
}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *///from   www .j ava  2  s.  c  o  m
private static void preparePen(PdfContentByte pdfContentByte, JRPen pen, int lineCap) {
    float lineWidth = pen.getLineWidth().floatValue();

    if (lineWidth <= 0) {
        return;
    }

    pdfContentByte.setLineWidth(lineWidth);
    pdfContentByte.setLineCap(lineCap);

    Color color = pen.getLineColor();
    pdfContentByte.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());

    switch (pen.getLineStyle().byteValue()) {
    case JRPen.LINE_STYLE_DOUBLE: {
        pdfContentByte.setLineWidth(lineWidth / 3);
        pdfContentByte.setLineDash(0f);
        break;
    }
    case JRPen.LINE_STYLE_DOTTED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(lineWidth, lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(0, 2 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case JRPen.LINE_STYLE_DASHED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(5 * lineWidth, 3 * lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(4 * lineWidth, 4 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case JRPen.LINE_STYLE_SOLID:
    default: {
        pdfContentByte.setLineDash(0f);
        break;
    }
    }
}

From source file:org.mapfish.print.map.renderers.vector.LineStringRenderer.java

License:Open Source License

protected static void applyStyle(RenderingContext context, PdfContentByte dc, PJsonObject style,
        PdfGState state) {//from w w w  .  j a  v  a 2s. c  o m
    if (style == null)
        return;
    if (style.optString("strokeColor") != null) {
        dc.setColorStroke(ColorWrapper.convertColor(style.getString("strokeColor")));
    }
    if (style.optString("strokeOpacity") != null) {
        state.setStrokeOpacity(style.getFloat("strokeOpacity"));
    }
    final float width = style.optFloat("strokeWidth", 1) * context.getStyleFactor();
    dc.setLineWidth(width);
    final String linecap = style.optString("strokeLinecap");
    if (linecap != null) {
        if (linecap.equalsIgnoreCase("butt")) {
            dc.setLineCap(PdfContentByte.LINE_CAP_BUTT);
        } else if (linecap.equalsIgnoreCase("round")) {
            dc.setLineCap(PdfContentByte.LINE_CAP_ROUND);
        } else if (linecap.equalsIgnoreCase("square")) {
            dc.setLineCap(PdfContentByte.LINE_CAP_PROJECTING_SQUARE);
        } else {
            throw new InvalidValueException("strokeLinecap", linecap);
        }
    }
    final String dashStyle = style.optString("strokeDashstyle");
    if (dashStyle != null) {
        if (dashStyle.equalsIgnoreCase("dot")) {
            final float[] def = new float[] { 0.1f, 2 * width };
            dc.setLineDash(def, 0);
        } else if (dashStyle.equalsIgnoreCase("dash")) {
            final float[] def = new float[] { 2 * width, 2 * width };
            dc.setLineDash(def, 0);
        } else if (dashStyle.equalsIgnoreCase("dashdot")) {
            final float[] def = new float[] { 3 * width, 2 * width, 0.1f, 2 * width };
            dc.setLineDash(def, 0);
        } else if (dashStyle.equalsIgnoreCase("longdash")) {
            final float[] def = new float[] { 4 * width, 2 * width };
            dc.setLineDash(def, 0);
        } else if (dashStyle.equalsIgnoreCase("longdashdot")) {
            final float[] def = new float[] { 5 * width, 2 * width, 0.1f, 2 * width };
            dc.setLineDash(def, 0);
        } else if (dashStyle.equalsIgnoreCase("solid")) {

        } else {
            throw new InvalidValueException("strokeDashstyle", dashStyle);
        }
    }
}

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

private void setStrokeDiff(Stroke newStroke, Stroke oldStroke) {
    PdfContentByte cb = _currentPage;
    if (newStroke == oldStroke)
        return;/*w ww  .  j a va 2 s.c  o  m*/
    if (!(newStroke instanceof BasicStroke))
        return;
    BasicStroke nStroke = (BasicStroke) newStroke;
    boolean oldOk = (oldStroke instanceof BasicStroke);
    BasicStroke oStroke = null;
    if (oldOk)
        oStroke = (BasicStroke) oldStroke;
    if (!oldOk || nStroke.getLineWidth() != oStroke.getLineWidth())
        cb.setLineWidth(nStroke.getLineWidth());
    if (!oldOk || nStroke.getEndCap() != oStroke.getEndCap()) {
        switch (nStroke.getEndCap()) {
        case BasicStroke.CAP_BUTT:
            cb.setLineCap(0);
            break;
        case BasicStroke.CAP_SQUARE:
            cb.setLineCap(2);
            break;
        default:
            cb.setLineCap(1);
        }
    }
    if (!oldOk || nStroke.getLineJoin() != oStroke.getLineJoin()) {
        switch (nStroke.getLineJoin()) {
        case BasicStroke.JOIN_MITER:
            cb.setLineJoin(0);
            break;
        case BasicStroke.JOIN_BEVEL:
            cb.setLineJoin(2);
            break;
        default:
            cb.setLineJoin(1);
        }
    }
    if (!oldOk || nStroke.getMiterLimit() != oStroke.getMiterLimit())
        cb.setMiterLimit(nStroke.getMiterLimit());
    boolean makeDash;
    if (oldOk) {
        if (nStroke.getDashArray() != null) {
            if (nStroke.getDashPhase() != oStroke.getDashPhase()) {
                makeDash = true;
            } else if (!java.util.Arrays.equals(nStroke.getDashArray(), oStroke.getDashArray())) {
                makeDash = true;
            } else
                makeDash = false;
        } else if (oStroke.getDashArray() != null) {
            makeDash = true;
        } else
            makeDash = false;
    } else {
        makeDash = true;
    }
    if (makeDash) {
        float dash[] = nStroke.getDashArray();
        if (dash == null)
            cb.setLiteral("[]0 d\n");
        else {
            cb.setLiteral('[');
            int lim = dash.length;
            for (int k = 0; k < lim; ++k) {
                cb.setLiteral(dash[k]);
                cb.setLiteral(' ');
            }
            cb.setLiteral(']');
            cb.setLiteral(nStroke.getDashPhase());
            cb.setLiteral(" d\n");
        }
    }
}