Search in sources :

Example 1 with PdfGState

use of com.itextpdf.text.pdf.PdfGState in project gephi by gephi.

the class EdgeLabelRenderer method renderPDF.

public void renderPDF(PDFTarget target, String label, float x, float y, Color color, float outlineSize, Color outlineColor) {
    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();
}
Also used : BaseFont(com.itextpdf.text.pdf.BaseFont) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) PdfGState(com.itextpdf.text.pdf.PdfGState)

Example 2 with PdfGState

use of com.itextpdf.text.pdf.PdfGState in project gephi by gephi.

the class NodeRenderer method renderPDF.

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);
    size /= 2f;
    Color color = item.getData(NodeItem.COLOR);
    Color borderColor = ((DependantColor) properties.getValue(PreviewProperty.NODE_BORDER_COLOR)).getColor(color);
    float borderSize = properties.getFloatValue(PreviewProperty.NODE_BORDER_WIDTH);
    float alpha = properties.getBooleanValue(PreviewProperty.NODE_PER_NODE_OPACITY) ? color.getAlpha() / 255f : properties.getFloatValue(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);
    }
    cb.circle(x, -y, size);
    if (borderSize > 0) {
        cb.fillStroke();
    } else {
        cb.fill();
    }
    if (alpha < 1f) {
        cb.restoreState();
    }
}
Also used : DependantColor(org.gephi.preview.types.DependantColor) Color(java.awt.Color) DependantColor(org.gephi.preview.types.DependantColor) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) PdfGState(com.itextpdf.text.pdf.PdfGState)

Example 3 with PdfGState

use of com.itextpdf.text.pdf.PdfGState in project gephi by gephi.

the class NodeLabelRenderer method renderPDF.

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
    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();
}
Also used : BaseFont(com.itextpdf.text.pdf.BaseFont) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) BaseFont(com.itextpdf.text.pdf.BaseFont) Font(java.awt.Font) PdfGState(com.itextpdf.text.pdf.PdfGState)

Example 4 with PdfGState

use of com.itextpdf.text.pdf.PdfGState in project gephi by gephi.

the class ArrowRenderer method render.

@Override
public void render(final Item item, final RenderTarget target, final PreviewProperties properties) {
    final Helper h = new Helper(item, properties);
    final Color color = EdgeRenderer.getColor(item, properties);
    if (target instanceof G2DTarget) {
        Graphics2D graphics = ((G2DTarget) target).getGraphics();
        graphics.setColor(color);
        final GeneralPath gpath = new GeneralPath();
        gpath.moveTo(h.p1.x, h.p1.y);
        gpath.lineTo(h.p2.x, h.p2.y);
        gpath.lineTo(h.p3.x, h.p3.y);
        gpath.closePath();
        graphics.fill(gpath);
    } else if (target instanceof SVGTarget) {
        final SVGTarget svgTarget = (SVGTarget) target;
        final Element arrowElem = svgTarget.createElement("polyline");
        arrowElem.setAttribute("points", String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", h.p1.x, h.p1.y, h.p2.x, h.p2.y, h.p3.x, h.p3.y));
        arrowElem.setAttribute("class", String.format("%s %s", SVGUtils.idAsClassAttribute(((Node) h.sourceItem.getSource()).getId()), SVGUtils.idAsClassAttribute(((Node) h.targetItem.getSource()).getId())));
        arrowElem.setAttribute("fill", svgTarget.toHexString(color));
        arrowElem.setAttribute("fill-opacity", (color.getAlpha() / 255f) + "");
        arrowElem.setAttribute("stroke", "none");
        svgTarget.getTopElement(SVGTarget.TOP_ARROWS).appendChild(arrowElem);
    } else if (target instanceof PDFTarget) {
        final PDFTarget pdfTarget = (PDFTarget) target;
        final PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(h.p1.x, -h.p1.y);
        cb.lineTo(h.p2.x, -h.p2.y);
        cb.lineTo(h.p3.x, -h.p3.y);
        cb.closePath();
        cb.setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());
        if (color.getAlpha() < 255) {
            cb.saveState();
            float alpha = color.getAlpha() / 255f;
            PdfGState gState = new PdfGState();
            gState.setFillOpacity(alpha);
            cb.setGState(gState);
        }
        cb.fill();
        if (color.getAlpha() < 255) {
            cb.restoreState();
        }
    }
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Element(org.w3c.dom.Element) Node(org.gephi.graph.api.Node) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) Graphics2D(java.awt.Graphics2D) PdfGState(com.itextpdf.text.pdf.PdfGState)

Aggregations

PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)4 PdfGState (com.itextpdf.text.pdf.PdfGState)4 BaseFont (com.itextpdf.text.pdf.BaseFont)2 Color (java.awt.Color)2 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 Node (org.gephi.graph.api.Node)1 DependantColor (org.gephi.preview.types.DependantColor)1 Element (org.w3c.dom.Element)1