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

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

Introduction

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

Prototype


public void setLineWidth(final double w) 

Source Link

Document

Changes the line width.

Usage

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorizationB1606.java

private static void generateDocumentPage1(TrackingRecordScreeningLetter screeningLetter, Document document,
        PdfWriter writer) throws BadElementException, DocumentException, Exception {
    PdfPTable table = null;/*w  w  w.  j a v  a2  s  .co  m*/
    int headerwidths[] = {};
    Paragraph paragraph = null;
    List blist = null;
    ListItem item = null;
    ListItem subItem = null;
    SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
    StringBuilder sb;
    PdfContentByte over = writer.getDirectContent();

    // LS Authorization Letter Page 1
    addLetterIdentifier(document);

    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase("Office of Licensing Livescan Authorization", largefontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(30.0f);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase(df.format(screeningLetter.getLetterDate()), mediumfontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("Office of Licensing Information", mediumfontBU));
    paragraph.setSpacingBefore(20.0f);
    document.add(paragraph);

    /*
     * Start of Office of Licensing Information generation
     */
    table = new PdfPTable(2);
    // format the table
    headerwidths = new int[] { 60, 40 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);
    table.setSpacingBefore(pageSeparatorSpace);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    paragraph = new Paragraph(fixedLeadingLarge);
    paragraph.add(new Phrase("TYPE OF TRANSACTION: FANC", largefontB));
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(new Phrase("REASON FINGERPRINTED: UCA 53-10-108", largefontB));
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(new Phrase("BILLING CODE: B1606", largefontB));
    table.addCell(paragraph);
    paragraph = new Paragraph(fixedLeadingSmall);
    Calendar cal = Calendar.getInstance();
    cal.setTime(screeningLetter.getLetterDate());
    cal.add(Calendar.DAY_OF_MONTH, 16);
    paragraph.add(new Phrase("This Authorization Expires: " + df.format(cal.getTime()), smallfont));
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(paragraph);
    document.add(table);

    // Add Fee information
    paragraph = new Paragraph(fixedLeadingSmall);
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null
            && screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getScanFee() != null) {
        paragraph.add(new Phrase("Scan Fee = ", smallfont));
        paragraph
                .add(new Phrase(
                        CommonUtils.fromDoubleToCurrency(
                                screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getScanFee()),
                        smallfontB));
    } else {
        paragraph.add(new Phrase("Search Fee = ", smallfont));
        if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null
                && screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getSearchFee() != null) {
            paragraph.add(new Phrase(
                    CommonUtils.fromDoubleToCurrency(
                            screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getSearchFee()),
                    smallfontB));
        } else {
            paragraph.add(SMALL_BLANK);
        }
    }
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add Authorized Signature line
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase(
            "Office of Licensing Authorized Signature ___________________________________________________  Date ________________",
            smallfont));
    paragraph.setSpacingBefore(18.0f);
    document.add(paragraph);

    // Stamp the document date over the Date line above
    // NOTE: Use showColumnBorders as a diagnostic to display borders of column where date will be placed on document.
    //showColumnBorders(over);
    ColumnText ct = new ColumnText(over);
    ct.setLeading(fixedLeadingSmall);
    ct.addText(new Phrase(df.format(screeningLetter.getLetterDate()), smallfont));
    // Write column to document
    ct.setAlignment(Element.ALIGN_CENTER);
    ct.setSimpleColumn(COLUMNS[0][0], COLUMNS[0][1], COLUMNS[0][2], COLUMNS[0][3]);
    ct.go();

    over.setLineWidth(3.0f);
    over.setCMYKColorStroke(166, 92, 0, 145);
    over.moveTo(document.getPageSize().getLeft(65), BOTTOM_SEPARATOR_EDGE);
    over.lineTo(document.getPageSize().getRight(65), BOTTOM_SEPARATOR_EDGE);
    over.stroke();

    // Add Program & Applicatant header line
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("Program & Applicant Information and Instructions", smallfontBU));
    paragraph.setSpacingBefore((2 * pageSeparatorSpace) + fixedLeadingSmall);
    document.add(paragraph);

    /*
     * Start of Applicant information line generation
     */
    table = new PdfPTable(3);
    // format the table
    headerwidths = new int[] { 43, 20, 37 }; // percentage
    table.setWidths(headerwidths); // percentage
    table.setWidthPercentage(100);
    table.setSpacingBefore(pageSeparatorSpace);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_MIDDLE);

    // Add Applicant name
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("Applicant: ", smallfontB));
    if (screeningLetter.getTrackingRecordScreening().getPerson() != null
            && StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getFirstAndLastName())) {
        paragraph.add(
                new Phrase(screeningLetter.getTrackingRecordScreening().getFirstAndLastName(), smallfontB));
    }
    table.addCell(paragraph);

    // Add Applicant ID
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("ID: ", smallfontB));
    if (StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getPersonIdentifier())) {
        paragraph.add(
                new Phrase(screeningLetter.getTrackingRecordScreening().getPersonIdentifier(), smallfontB));
    }
    table.addCell(paragraph);

    // Add DOB information
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("DOB: ", smallfontB));
    try {
        paragraph.add(
                new Phrase(df.format(screeningLetter.getTrackingRecordScreening().getBirthday()), smallfontB));
    } catch (NullPointerException e) {

    }
    table.addCell(paragraph);
    // Add Applicant Information Line Table to document
    document.add(table);
    /*
     * End of Applicant information line generation
     */

    // Add Application program line
    paragraph = new Paragraph(fixedLeadingSmall);
    sb = new StringBuilder();
    sb.append("Applicant Program: ");
    if (screeningLetter.getTrackingRecordScreening().getFacility() != null
            && StringUtils.isNotBlank(screeningLetter.getTrackingRecordScreening().getFacility().getName())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getFacility().getName().toUpperCase());
    }
    paragraph.add(new Phrase(sb.toString(), smallfontB));
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add Payment information line
    paragraph = new Paragraph(fixedLeadingSmall);
    sb = new StringBuilder();
    sb.append("Payment issued by: ");
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null && StringUtils
            .isNotBlank(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getIssuedBy())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getIssuedBy().toUpperCase());
    }
    sb.append("    ");
    sb.append("Check Number: ");
    if (screeningLetter.getTrackingRecordScreening().getTrsDpsFbi() != null && StringUtils
            .isNotBlank(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getMoNumber())) {
        sb.append(screeningLetter.getTrackingRecordScreening().getTrsDpsFbi().getMoNumber().toUpperCase());
    }
    paragraph.add(new Phrase(sb.toString(), smallfontB));
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    // Add READ THIS CAREFULLY
    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("READ THIS CAREFULLY", largefontBU));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace + fixedLeadingLarge);
    document.add(paragraph);

    /*
     * Start of instructions list section
     */
    blist = new List(false, 20);
    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("1.", mediumfont));
    item.add(new Phrase(
            "The Office of Licensing authorizes the applicant to submit her/his fingerprints for an electronic applicant background check ",
            smallfont));
    item.add(new Phrase(
            "at various sites throughout Utah using the Live Scan system. Each site charges a fee for the electronic fingerprint scan. ",
            smallfont));
    item.add(new Phrase(
            "Scanning fees vary from site to site. This is a separate fee from the one submitted to the Department of Human Services for ",
            smallfont));
    item.add(new Phrase("the actual criminal background search.", smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("2.", mediumfont));
    item.add(new Phrase(
            "Complete electronic fingerprint submission within 15 days of the date of this authorization letter. If unused, ",
            smallfontB));
    item.add(new Phrase(
            "requests for refunds will not be considered after 30 days. Refund requests require a letter of explanation ",
            smallfontB));
    item.add(new Phrase(
            "from the licensed program accompanied by this original authorization letter. Failure to complete electronic ",
            smallfontB));
    item.add(new Phrase(
            "fingerprint submission within this time will result in the denial of the background screening clearance and ",
            smallfontB));
    item.add(new Phrase(
            "the applicant will not be permitted to have direct access to children or vulnerable adults, will not be eligible ",
            smallfontB));
    item.add(new Phrase(
            "to provide services to programs licensed by the Utah Department of Human Services, Office of Licensing, and will not be ",
            smallfontB));
    item.add(new Phrase("eligible to proceed with foster care or adoption.", smallfontB));
    item.setSpacingBefore(4.0f);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("3.", mediumfont));
    paragraph = new Paragraph(fixedLeadingSmall);
    paragraph.add(new Phrase("You will need to take with you:", smallfont));
    item.add(paragraph);
    List subList = new List(false, 10);
    subList.setIndentationLeft(10);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(new Phrase("This original letter. Photocopies and facsimile (FAX) copies will not be accepted.",
            smallfont));
    subList.add(subItem);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(new Phrase(
            "Photo I.D. in the form of your driver license or state identification card issued by the Division of Motor Vehicles.",
            smallfont));
    subList.add(subItem);
    subItem = new ListItem(fixedLeadingSmall);
    subItem.add(
            new Phrase("Cash or check as required (see site list for acceptable form of payment).", smallfont));
    subList.add(subItem);
    item.add(subList);
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("4.", mediumfont));
    item.add(new Phrase(
            "If the electronically submitted fingerprints are rejected, the Office of Licensing will notify the applicant/licensed program ",
            smallfont));
    item.add(new Phrase("of additional instructions for completing the nationwide background search.",
            smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);

    item = new ListItem(fixedLeadingSmall);
    item.setListSymbol(new Chunk("5.", mediumfont));
    item.add(new Phrase(
            "Applicant Signature ___________________________________________________  Date ________________",
            smallfont));
    item.setSpacingBefore(page1ListSpace);
    blist.add(item);
    document.add(blist);
    /*
     * End of instructions list section
     */

    paragraph = new Paragraph();
    paragraph.add(new Phrase(
            "A current list of Livescan sites is available at www.hslic.utah.gov/docs/livescan sites.pdf",
            smallfont));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);

    paragraph = new Paragraph(fixedLeadingMedium);
    paragraph.add(new Phrase("Live Scan Operator: Keep this original for auditing purposes.", mediumfontB));
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.setSpacingBefore(pageSeparatorSpace);
    document.add(paragraph);
}

From source file:nz.ac.waikato.cms.doc.SimplePDFOverlay.java

License:Open Source License

/**
 * Applies the instructions to the input PDF.
 *
 * @return      null if successful, otherwise error message
 *//* w w w .  ja v  a2s . c  om*/
public String execute() {
    String result;
    String line;
    BufferedReader breader;
    FileReader freader;
    int i;
    int lineNo;
    String units;
    int pageNo;
    PdfReader reader;
    PdfStamper stamper;
    PdfContentByte cb;
    ColumnText ct;
    Font font;
    String[] parts;
    StringBuilder text;

    result = null;

    freader = null;
    breader = null;
    try {
        reader = new PdfReader(new FileInputStream(m_Pdf.getAbsolutePath()));
        stamper = new PdfStamper(reader, new FileOutputStream(m_Output.getAbsolutePath()));
        freader = new FileReader(m_Instructions);
        breader = new BufferedReader(freader);
        lineNo = 0;
        units = "pt";
        pageNo = 1;
        cb = stamper.getOverContent(pageNo);
        font = null;
        while ((line = breader.readLine()) != null) {
            lineNo++;
            if (line.trim().startsWith(PREFIX_COMMENT))
                continue;
            if (line.trim().length() == 0)
                continue;
            if (line.startsWith(PREFIX_UNITS)) {
                units = line.substring(PREFIX_UNITS.length()).trim().toLowerCase();
            } else if (line.startsWith(PREFIX_PAGE)) {
                pageNo = Integer.parseInt(line.substring(PREFIX_PAGE.length()).trim());
                cb = stamper.getOverContent(pageNo);
            } else if (line.startsWith(PREFIX_FONT)) {
                parts = line.substring(PREFIX_FONT.length()).trim().split(" ");
                if (parts.length == 3)
                    font = FontFactory.getFont(parts[0], Float.parseFloat(parts[1]),
                            new BaseColor(parseColor(parts[2]).getRGB()));
                else
                    m_Logger.warning("Font instruction not in expected format (" + FORMAT_FONT + "):\n" + line);
            } else if (line.startsWith(PREFIX_TEXT)) {
                parts = line.substring(PREFIX_TEXT.length()).trim().split(" ");
                if (parts.length >= 7) {
                    ct = new ColumnText(cb);
                    ct.setSimpleColumn(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // llx
                            parseLocation(parts[1], reader.getPageSize(pageNo).getHeight(), units), // lly
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // urx
                            parseLocation(parts[3], reader.getPageSize(pageNo).getHeight(), units), // ury
                            Float.parseFloat(parts[4]), // leading
                            parseAlignment(parts[5])); // alignment
                    text = new StringBuilder();
                    for (i = 6; i < parts.length; i++) {
                        if (text.length() > 0)
                            text.append(" ");
                        text.append(parts[i]);
                    }
                    if (font == null)
                        ct.setText(new Phrase(text.toString()));
                    else
                        ct.setText(new Phrase(text.toString(), font));
                    ct.go();
                } else {
                    m_Logger.warning("Text instruction not in expected format (" + FORMAT_TEXT + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_LINE)) {
                parts = line.substring(PREFIX_LINE.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // color
                    cb.moveTo(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units)); // y
                    cb.lineTo(parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units)); // h
                    cb.stroke();
                    cb.restoreState();
                } else {
                    m_Logger.warning("Line instruction not in expected format (" + FORMAT_LINE + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_RECT)) {
                parts = line.substring(PREFIX_RECT.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.rectangle(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // h
                    );
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke
                    if (parts.length >= 7) {
                        cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill
                        cb.fillStroke();
                    } else {
                        cb.stroke();
                    }
                    cb.restoreState();
                } else {
                    m_Logger.warning(
                            "Rectangle instruction not in expected format (" + FORMAT_RECT + "):\n" + line);
                }
            } else if (line.startsWith(PREFIX_OVAL)) {
                parts = line.substring(PREFIX_OVAL.length()).trim().split(" ");
                if (parts.length >= 6) {
                    cb.saveState();
                    cb.ellipse(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x1
                            parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y1
                            parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // x2
                            parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // y2
                    );
                    cb.setLineWidth(Float.parseFloat(parts[4])); // line width
                    cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke
                    if (parts.length >= 7) {
                        cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill
                        cb.fillStroke();
                    } else {
                        cb.stroke();
                    }
                    cb.restoreState();
                } else {
                    m_Logger.warning("Oval instruction not in expected format (" + FORMAT_OVAL + "):\n" + line);
                }
            } else {
                m_Logger.warning("Unknown command on line #" + lineNo + ":\n" + line);
            }
        }
        stamper.close();
    } catch (Exception e) {
        result = "Failed to process!\n" + Utils.throwableToString(e);
    } finally {
        FileUtils.closeQuietly(breader);
        FileUtils.closeQuietly(freader);
    }

    return result;
}

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 w  w w .  j  a va  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  ww  w . ja v a 2  s . com*/

    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.NewEdgeRenderer.java

License:Open Source License

@Override
public void renderStraightEdge(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);

    //Target radius - to start at the base of the arrow
    Float targetRadius = edgeItem.getData(TARGET_RADIUS);
    //Avoid edge from passing the node's center:
    if (targetRadius != null && targetRadius < 0) {
        PVector direction = new PVector(x2, y2);
        direction.sub(new PVector(x1, y1));
        direction.normalize();/*  w w w  .j  ava2 s. c o m*/
        direction = new PVector(direction.x, direction.y);
        direction.mult(targetRadius);
        direction.add(new PVector(x2, y2));
        x2 = direction.x;
        y2 = direction.y;
    }
    //Source radius
    Float sourceRadius = edgeItem.getData(SOURCE_RADIUS);
    //Avoid edge from passing the node's center:
    if (sourceRadius != null && sourceRadius < 0) {
        PVector direction = new PVector(x1, y1);
        direction.sub(new PVector(x2, y2));
        direction.normalize();
        direction = new PVector(direction.x, direction.y);
        direction.mult(sourceRadius);
        direction.add(new PVector(x1, y1));
        x1 = direction.x;
        y1 = direction.y;
    }

    if (renderTarget instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) renderTarget).getGraphics();
        graphics.strokeWeight(thickness);
        graphics.strokeCap(PGraphics.SQUARE);
        graphics.stroke(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.noFill();
        graphics.line(x1, y1, 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 L %f,%f", x1, y1, 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.lineTo(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 .  ja v  a 2  s .c  om*/
    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.edgelayout.api.SubdividedEdgeRenderer.java

License:Open Source License

private void renderSimplePDFItem(SubdividedEdgeItem item, RenderTarget target, PreviewProperties properties,
        Point2D.Double[] points) {
    Color color = new Color(originalColor.getRed(), originalColor.getGreen(), originalColor.getBlue(),
            (int) (255 * alpha));
    PDFTarget pdfTarget = (PDFTarget) target;
    PdfContentByte cb = pdfTarget.getContentByte();
    for (int i = 0; i < points.length - 1; i++) {
        cb.moveTo((float) points[i].x, (float) points[i].y);
        cb.lineTo((float) points[i + 1].x, (float) points[i + 1].y);
    }/*from w  w  w  .  ja va2 s  . com*/
    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.edgelayout.api.SubdividedEdgeRenderer.java

License:Open Source License

private void renderBigPDFItem(SubdividedEdgeBigItem item, RenderTarget target, PreviewProperties properties) {
    for (SortedEdgeWrapper edgeWrapper : item.edges) {
        Edge edge = edgeWrapper.edge;/*from   w  w  w.  j a  v a2s.  co m*/
        EdgeLayoutData data = (EdgeLayoutData) edge.getEdgeData().getLayoutData();
        Point2D.Double[] points = data.getSubdivisonPoints();

        if (data.getEdgeColor() == null || points == null) {
            continue;
        }
        Color color = new Color(data.getEdgeColor().getRed(), data.getEdgeColor().getGreen(),
                data.getEdgeColor().getBlue(), (int) (255 * alpha));
        PDFTarget pdfTarget = (PDFTarget) target;
        PdfContentByte cb = pdfTarget.getContentByte();
        for (int i = 0; i < points.length - 1; i++) {
            cb.moveTo((float) points[i].x, (float) points[i].y);
            cb.lineTo((float) points[i + 1].x, (float) points[i + 1].y);
        }
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);

        float usedAlpha = (forceAlpha ? intAlpha : color.getAlpha());
        if (usedAlpha < 255) {
            cb.saveState();
            float alpha = usedAlpha / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (usedAlpha < 255) {
            cb.restoreState();
        }
    }
}

From source file:org.gephi.edgelayout.api.SubdividedEdgeRenderer.java

License:Open Source License

private void renderBigAndComplexPDFItem(SubdividedEdgeBigItem item, RenderTarget target,
        PreviewProperties properties) {// w w w. j  a va2  s . c o  m
    for (SortedEdgeWrapper edgeWrapper : item.edges) {
        Edge edge = edgeWrapper.edge;
        EdgeLayoutData data = (EdgeLayoutData) edge.getEdgeData().getLayoutData();
        Point2D.Double[] points = data.getSubdivisonPoints();

        if (data.getSubdivisionEdgeColor() == null || data.getSubdivisionEdgeColor()[edgeWrapper.id] == null
                || points == null) {
            continue;
        }

        Color color = data.getSubdivisionEdgeColor()[edgeWrapper.id];
        PDFTarget pdfTarget = (PDFTarget) target;
        PdfContentByte cb = pdfTarget.getContentByte();
        int i = edgeWrapper.id;
        if (i == points.length - 1) {
            continue;
        }
        cb.moveTo((float) points[i].x, (float) points[i].y);
        cb.lineTo((float) points[i + 1].x, (float) points[i + 1].y);
        cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
        cb.setLineWidth(thickness);

        float usedAlpha = (forceAlpha ? intAlpha : color.getAlpha());
        if (usedAlpha < 255) {
            cb.saveState();
            float alpha = usedAlpha / 255f;
            PdfGState gState = new PdfGState();
            gState.setStrokeOpacity(alpha);
            cb.setGState(gState);
        }
        cb.stroke();
        if (usedAlpha < 255) {
            cb.restoreState();
        }
    }
}

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) {/* w w  w .j  a  v a  2s  .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();
}