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

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

Introduction

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

Prototype


public void fill() 

Source Link

Document

Fills the path, using the non-zero winding number rule to determine the region to fill.

Usage

From source file:mkl.testarea.itext5.pdfcleanup.StrictPdfCleanUpProcessor.java

License:Open Source License

private void addColoredRectangle(PdfContentByte canvas, PdfCleanUpLocation cleanUpLocation) {
    Rectangle cleanUpRegion = cleanUpLocation.getRegion();

    canvas.saveState();/*from   w  w  w .ja v a  2s  . c o m*/
    canvas.setColorFill(cleanUpLocation.getCleanUpColor());
    canvas.moveTo(cleanUpRegion.getLeft(), cleanUpRegion.getBottom());
    canvas.lineTo(cleanUpRegion.getRight(), cleanUpRegion.getBottom());
    canvas.lineTo(cleanUpRegion.getRight(), cleanUpRegion.getTop());
    canvas.lineTo(cleanUpRegion.getLeft(), cleanUpRegion.getTop());
    canvas.closePath();
    canvas.fill();
    canvas.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;/*ww w.j  a  v a2s . 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.preview.plugin.renderers.ArrowRenderer.java

License:Open Source License

public void renderStraight(RenderTarget target, Item item, float x1, float y1, float x2, float y2, float radius,
        float size, Color color) {
    Edge edge = (Edge) item.getSource();
    PVector direction = new PVector(x2, y2);
    direction.sub(new PVector(x1, y1));
    direction.normalize();/*w ww  . j a v  a  2 s . c  o  m*/

    PVector p1 = new PVector(direction.x, direction.y);
    p1.mult(radius);
    p1.add(new PVector(x2, y2));

    PVector p1r = new PVector(direction.x, direction.y);
    p1r.mult(radius - size);
    p1r.add(new PVector(x2, y2));

    PVector p2 = new PVector(-direction.y, direction.x);
    p2.mult(size * BASE_RATIO);
    p2.add(p1r);

    PVector p3 = new PVector(direction.y, -direction.x);
    p3.mult(size * BASE_RATIO);
    p3.add(p1r);

    if (target instanceof ProcessingTarget) {
        PGraphics graphics = ((ProcessingTarget) target).getGraphics();
        graphics.noStroke();
        graphics.fill(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        graphics.triangle(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
    } else if (target instanceof SVGTarget) {
        SVGTarget svgTarget = (SVGTarget) target;
        Element arrowElem = svgTarget.createElement("polyline");
        arrowElem.setAttribute("points",
                String.format(Locale.ENGLISH, "%f,%f %f,%f %f,%f", p1.x, p1.y, p2.x, p2.y, p3.x, p3.y));
        arrowElem.setAttribute("class",
                edge.getSource().getNodeData().getId() + " " + edge.getTarget().getNodeData().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) {
        PDFTarget pdfTarget = (PDFTarget) target;
        PdfContentByte cb = pdfTarget.getContentByte();
        cb.moveTo(p1.x, -p1.y);
        cb.lineTo(p2.x, -p2.y);
        cb.lineTo(p3.x, -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();
        }
    }
}

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

License:Open Source License

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//www . j a v  a2  s.c o m
    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();
}

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

License:Open Source License

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;//w w w . j  av a2s  .  com
    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.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();
    }
}

From source file:org.javad.stamp.pdf.StampBox.java

License:Apache License

/**
 * Will draw a black frame shape for a given stamp box. The current
 * supported shapes include//from  w w  w  .  j  a v  a2  s .  c  o  m
 * <ul><li>rectangle</li>
 * <li>triangle</li>
 * <li>diamond</li>
 * </ul>
 *
 * @param content
 * @param rect
 */
void drawShape(PdfContentByte content, OutputBounds rect) {

    content.setColorFill(BaseColor.WHITE);
    drawPath(content, rect);
    content.fill();
    if (isBorder()) {
        content.setColorStroke(BaseColor.BLACK);
        content.setLineWidth(0.8f);
        drawPath(content, rect);
        content.stroke();
    }
    content.setColorFill(BaseColor.BLACK);
}

From source file:se.billes.pdf.renderer.model.QRCode.java

License:Open Source License

@SuppressWarnings("unchecked")
public void onRender(PdfContentByte cb) throws PdfRenderException {

    float[] positions = new BlockFactory().getBoundsInPs(this);

    try {//from w w w .  j  a va2  s . co  m
        @SuppressWarnings("rawtypes")
        Hashtable hintMap = new Hashtable();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        PdfDocument req = getPage().getPdfDocument();
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix byteMatrix = qrCodeWriter.encode(getText(), BarcodeFormat.QR_CODE, (int) (positions[2]),
                (int) (positions[3]), hintMap);
        int matrixWidth = byteMatrix.getWidth();
        int matrixHeight = byteMatrix.getHeight();
        float pageHeight = req.getSize()[1];
        float top = getPosition()[1];

        if (getPage().getPdfDocument().getCutmarks() != null) {
            pageHeight += SizeFactory.CUT_MARK * 2;
            top += SizeFactory.CUT_MARK;
        }

        cb.setColorFill(getBaseColor());
        float pageHeightInPs = SizeFactory.millimetersToPostscriptPoints(pageHeight);
        float topInPs = SizeFactory.millimetersToPostscriptPoints(top);
        for (int i = byteMatrix.getTopLeftOnBit()[0]; i < matrixWidth; i++) {
            for (int j = byteMatrix.getTopLeftOnBit()[0]; j < matrixHeight; j++) {
                if (byteMatrix.get(i, j)) {

                    cb.rectangle(positions[0] + (i - byteMatrix.getTopLeftOnBit()[0]),
                            pageHeightInPs - ((topInPs + 1) + (j - byteMatrix.getTopLeftOnBit()[0])), 1, 1);
                }
            }
        }

        cb.fill();
        cb.setColorFill(new ColorFactory().getBlack());

    } catch (Exception e) {

    }
}