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

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

Introduction

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

Prototype

public static ArrayList<double[]> bezierArc(double x1, double y1, double x2, double y2, final double startAng,
        final double extent) 

Source Link

Document

Generates an array of bezier curves to draw an arc.

Usage

From source file:com.chaschev.itext.CanvasBuilder.java

License:Apache License

public static ArrayList<float[]> bezierArc(float x1, float y1, float x2, float y2, float startAng,
        float extent) {
    return PdfContentByte.bezierArc(x1, y1, x2, y2, startAng, extent);
}

From source file:org.frobic.colorednodes.renderers.NewNodeRenderer.java

License:Open Source License

@Override
public void renderPDF(Item item, PDFTarget target, PreviewProperties properties) {
    Float x = item.getData(NodeItem.X);
    Float y = item.getData(NodeItem.Y);
    Float size = item.getData(NodeItem.SIZE);
    Float angle = item.getData(NodeItem.ANGLE);
    size /= 2f;//w  w  w  .java2  s .  c o  m
    Color color = item.getData(NodeItem.COLOR);
    Integer nbcolors = item.getData(NodeItem.NBCOLOR);
    Color[] colors = item.getData(NodeItem.COLORS);
    Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR))
            .getColor(color);
    float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
    float alpha = properties.getIntValue(PreviewProperty.NODE_OPACITY) / 100f;

    PdfContentByte cb = target.getContentByte();
    cb.setRGBColorStroke(borderColor.getRed(), borderColor.getGreen(), borderColor.getBlue());
    cb.setLineWidth(borderSize);
    cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
    if (alpha < 1f) {
        cb.saveState();
        PdfGState gState = new PdfGState();
        gState.setFillOpacity(alpha);
        gState.setStrokeOpacity(alpha);
        cb.setGState(gState);
    }
    for (int i = 0; i < nbcolors; i++) {
        cb.setRGBColorFill(colors[nbcolors - i - 1].getRed(), colors[nbcolors - i - 1].getGreen(),
                colors[nbcolors - i - 1].getBlue());
        if (size >= 0.5) {
            cb.newPath();
            ArrayList ar = cb.bezierArc(x - size, -y + size, x + size, 0 - size - y,
                    360f * (nbcolors - i - 1) / nbcolors + (360f / 6.28f) * angle, 360f * (1) / nbcolors);
            //cb.arc(x-size,-y+size,x+size,0-size-y,360f*(nbcolors-i-1)/nbcolors+angle,360f*(1)/nbcolors) ;
            cb.moveTo(x, -y);
            float pt[] = (float[]) ar.get(0);
            cb.moveTo(pt[0], pt[1]);
            for (int k = 0; k < ar.size(); ++k) {
                pt = (float[]) ar.get(k);
                cb.curveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
            }
            cb.lineTo(x, -y);
            //strokeAndFill();
            //            cb.ClosePathFillStroke();
            if (borderSize > 0) {
                cb.fill();
            } else {
                cb.fill();
            }

            if (borderSize > 0) {
                cb.circle(x, -y, size);
                cb.stroke();
            }
        }
    }
    if (alpha < 1f) {
        cb.restoreState();
    }
}