Example usage for com.lowagie.text.pdf PdfContentByte eoClip

List of usage examples for com.lowagie.text.pdf PdfContentByte eoClip

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte eoClip.

Prototype


public void eoClip() 

Source Link

Document

Modify the current clipping path by intersecting it with the current path, using the even-odd rule to determine which regions lie inside the clipping path.

Usage

From source file:classroom.newspaper_a.Newspaper02.java

public static void main(String[] args) {
    try {//w w w  .  ja  va  2  s  . com
        PdfReader reader = new PdfReader(NEWSPAPER);
        Document document = new Document(reader.getPageSizeWithRotation(1));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        PdfContentByte content = writer.getDirectContent();
        content.rectangle(document.left(), document.bottom(), document.right(), document.top());
        content.rectangle(LLX1, LLY1, W1, H1);
        content.rectangle(LLX2, LLY2, W2, H2);
        content.eoClip();
        content.newPath();
        PdfImportedPage page = writer.getImportedPage(reader, 1);
        content.addTemplate(page, 0, 0);
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java

License:Open Source License

private void followPath(Shape s, int drawType) {
    PdfContentByte cb = _currentPage;
    if (s == null)
        return;/*from ww w. ja  v a2 s . c om*/

    if (drawType == STROKE) {
        if (!(_stroke instanceof BasicStroke)) {
            s = _stroke.createStrokedShape(s);
            followPath(s, FILL);
            return;
        }
    }
    if (drawType == STROKE) {
        setStrokeDiff(_stroke, _oldStroke);
        _oldStroke = _stroke;
        ensureStrokeColor();
    } else if (drawType == FILL) {
        ensureFillColor();
    }

    PathIterator points;
    if (drawType == CLIP) {
        points = s.getPathIterator(IDENTITY);
    } else {
        points = s.getPathIterator(_transform);
    }
    float[] coords = new float[6];
    int traces = 0;
    while (!points.isDone()) {
        ++traces;
        int segtype = points.currentSegment(coords);
        normalizeY(coords);
        switch (segtype) {
        case PathIterator.SEG_CLOSE:
            cb.closePath();
            break;

        case PathIterator.SEG_CUBICTO:
            cb.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
            break;

        case PathIterator.SEG_LINETO:
            cb.lineTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_MOVETO:
            cb.moveTo(coords[0], coords[1]);
            break;

        case PathIterator.SEG_QUADTO:
            System.out.println("Quad to " + coords[0] + " " + coords[1] + " " + coords[2] + " " + coords[3]);
            cb.curveTo(coords[0], coords[1], coords[2], coords[3]);
            break;
        }
        points.next();
    }

    switch (drawType) {
    case FILL:
        if (traces > 0) {
            if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD)
                cb.eoFill();
            else
                cb.fill();
        }
        break;
    case STROKE:
        if (traces > 0)
            cb.stroke();
        break;
    default: // drawType==CLIP
        if (traces == 0)
            cb.rectangle(0, 0, 0, 0);
        if (points.getWindingRule() == PathIterator.WIND_EVEN_ODD)
            cb.eoClip();
        else
            cb.clip();
        cb.newPath();
    }
}