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

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

Introduction

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

Prototype


public void curveTo(final double x1, final double y1, final double x2, final double y2, final double x3,
        final double y3) 

Source Link

Document

Appends a Bêzier curve to the path, starting from the current point.

Usage

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

License:Open Source License

@Override
public void renderSelfLoop(Item nodeItem, float thickness, Color color, PreviewProperties properties,
        RenderTarget renderTarget) {//from   ww  w. j ava  2  s  .c o m
    Float x = nodeItem.getData(NodeItem.X);
    Float y = nodeItem.getData(NodeItem.Y);
    Float size = nodeItem.getData(NodeItem.SIZE);
    Node node = (Node) nodeItem.getSource();

    PVector v1 = new PVector(x, y);
    v1.add(size, -size, 0);

    PVector v2 = new PVector(x, y);
    v2.add(size, size, 0);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x, y, v1.x, v1.y, v1.x, v2.y, x, y);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;

        Element selfLoopElem = svgTarget.createElement("path");
        selfLoopElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x, y, v1.x,
                v1.y, v2.x, v2.y, x, y));
        selfLoopElem.setAttribute("class", node.getNodeData().getId());
        selfLoopElem.setAttribute("stroke", svgTarget.toHexString(color));
        selfLoopElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        selfLoopElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        selfLoopElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(selfLoopElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x, -y);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x, -y);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

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

License:Open Source License

@Override
public void renderCurvedEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color,
        PreviewProperties properties, RenderTarget renderTarget) {
    Edge edge = (Edge) edgeItem.getSource();
    Float x1 = sourceItem.getData(NodeItem.X);
    Float x2 = targetItem.getData(NodeItem.X);
    Float y1 = sourceItem.getData(NodeItem.Y);
    Float y2 = targetItem.getData(NodeItem.Y);

    //Curved edgs
    PVector direction = new PVector(x2, y2);
    direction.sub(new PVector(x1, y1));
    float length = direction.mag();
    direction.normalize();//from   w ww  . j  a v  a 2s .  c  o m

    float factor = properties.getFloatValue(BEZIER_CURVENESS) * length;

    // normal vector to the edge
    PVector n = new PVector(direction.y, -direction.x);
    n.mult(factor);

    // first control point
    PVector v1 = new PVector(direction.x, direction.y);
    v1.mult(factor);
    v1.add(new PVector(x1, y1));
    v1.add(n);

    // second control point
    PVector v2 = new PVector(direction.x, direction.y);
    v2.mult(-factor);
    v2.add(new PVector(x2, y2));
    v2.add(n);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;
        Element edgeElem = svgTarget.createElement("path");
        edgeElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId());
        edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x1, y1, v1.x,
                v1.y, v2.x, v2.y, x2, y2));
        edgeElem.setAttribute("stroke", svgTarget.toHexString(color));
        edgeElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        edgeElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x1, -y1);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x2, -y2);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

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;//from  ww  w.j ava  2 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();
    }
}

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

License:Open Source License

public void renderSelfLoop(Item nodeItem, float thickness, Color color, PreviewProperties properties,
        RenderTarget renderTarget) {/*w ww. j av  a  2  s. c  om*/
    Float x = nodeItem.getData(NodeItem.X);
    Float y = nodeItem.getData(NodeItem.Y);
    Float size = nodeItem.getData(NodeItem.SIZE);
    Node node = (Node) nodeItem.getSource();

    PVector v1 = new PVector(x, y);
    v1.add(size, -size, 0);

    PVector v2 = new PVector(x, y);
    v2.add(size, size, 0);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x, y, v1.x, v1.y, v1.x, v2.y, x, y);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;

        Element selfLoopElem = svgTarget.createElement("path");
        selfLoopElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x, y, v1.x,
                v1.y, v2.x, v2.y, x, y));
        selfLoopElem.setAttribute("class", node.getNodeData().getId());
        selfLoopElem.setAttribute("stroke", svgTarget.toHexString(color));
        selfLoopElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        selfLoopElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        selfLoopElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(selfLoopElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x, -y);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x, -y);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}

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

License:Open Source License

public void renderCurvedEdge(Item edgeItem, Item sourceItem, Item targetItem, float thickness, Color color,
        PreviewProperties properties, RenderTarget renderTarget) {
    Edge edge = (Edge) edgeItem.getSource();
    Float x1 = sourceItem.getData(NodeItem.X);
    Float x2 = targetItem.getData(NodeItem.X);
    Float y1 = sourceItem.getData(NodeItem.Y);
    Float y2 = targetItem.getData(NodeItem.Y);

    //Curved edgs
    PVector direction = new PVector(x2, y2);
    direction.sub(new PVector(x1, y1));
    float length = direction.mag();
    direction.normalize();//from w w  w .java 2  s . c om

    float factor = properties.getFloatValue(BEZIER_CURVENESS) * length;

    // normal vector to the edge
    PVector n = new PVector(direction.y, -direction.x);
    n.mult(factor);

    // first control point
    PVector v1 = new PVector(direction.x, direction.y);
    v1.mult(factor);
    v1.add(new PVector(x1, y1));
    v1.add(n);

    // second control point
    PVector v2 = new PVector(direction.x, direction.y);
    v2.mult(-factor);
    v2.add(new PVector(x2, y2));
    v2.add(n);

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.bezier(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2);
    } else if (renderTarget instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) renderTarget;
        Element edgeElem = svgTarget.createElement("path");
        edgeElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().getId());
        edgeElem.setAttribute("d", String.format(Locale.ENGLISH, "M %f,%f C %f,%f %f,%f %f,%f", x1, y1, v1.x,
                v1.y, v2.x, v2.y, x2, y2));
        edgeElem.setAttribute("stroke", svgTarget.toHexString(color));
        edgeElem.setAttribute("stroke-width", Float.toString(thickness * svgTarget.getScaleRatio()));
        edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
        edgeElem.setAttribute("fill", "none");
        svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
    } else if (renderTarget instanceof PDFTarget) {
        PDFTarget pdfTarget = (PDFTarget) renderTarget;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(x1, -y1);
        cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x2, -y2);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}