Example usage for com.itextpdf.text Rectangle Rectangle

List of usage examples for com.itextpdf.text Rectangle Rectangle

Introduction

In this page you can find the example usage for com.itextpdf.text Rectangle Rectangle.

Prototype

public Rectangle(com.itextpdf.awt.geom.Rectangle rect) 

Source Link

Document

Constructs a Rectangle-object based on a com.itextpdf.awt.geom.Rectangle object

Usage

From source file:at.laborg.briss.CropManager.java

License:Open Source License

private static Rectangle calculateScaledRectangle(List<Rectangle> boxes, Float[] ratios, int rotation) {
    if (ratios == null || boxes.size() == 0)
        return null;
    Rectangle smallestBox = null;
    // find smallest box
    float smallestSquare = Float.MAX_VALUE;
    for (Rectangle box : boxes) {
        if (box != null) {
            if (smallestBox == null) {
                smallestBox = box;/*  w ww  .  j  a  va  2  s .c  om*/
            }
            if (smallestSquare > box.getWidth() * box.getHeight()) {
                // set new smallest box
                smallestSquare = box.getWidth() * box.getHeight();
                smallestBox = box;
            }
        }
    }
    if (smallestBox == null)
        return null; // no useable box was found

    // rotate the ratios according to the rotation of the page
    float[] rotRatios = rotateRatios(ratios, rotation);

    // use smallest box as basis for calculation
    Rectangle scaledBox = new Rectangle(smallestBox);

    scaledBox.setLeft(smallestBox.getLeft() + (smallestBox.getWidth() * rotRatios[0]));
    scaledBox.setBottom(smallestBox.getBottom() + (smallestBox.getHeight() * rotRatios[1]));
    scaledBox.setRight(smallestBox.getLeft() + (smallestBox.getWidth() * (1 - rotRatios[2])));
    scaledBox.setTop(smallestBox.getBottom() + (smallestBox.getHeight() * (1 - rotRatios[3])));

    return scaledBox;
}

From source file:br.com.ifrn.panfleto.gui.PainelCadastrar.java

public Rectangle tamanhoDaPagina() {
    if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A0")) {
        return new Rectangle(PageSize.A0);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A1")) {
        return new Rectangle(PageSize.A1);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A2")) {
        return new Rectangle(PageSize.A2);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A3")) {
        return new Rectangle(PageSize.A3);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A4")) {
        return new Rectangle(PageSize.A4);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("A5")) {
        return new Rectangle(PageSize.A5);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B0")) {
        return new Rectangle(PageSize.B0);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B1")) {
        return new Rectangle(PageSize.B1);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B2")) {
        return new Rectangle(PageSize.B2);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B3")) {
        return new Rectangle(PageSize.B3);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B4")) {
        return new Rectangle(PageSize.B4);
    } else if (comboxSelecionarTamanhoPaginaPainelGerarPdf.getSelectedItem().equals("B5")) {
        return new Rectangle(PageSize.B5);
    }//from  w  ww. jav  a  2  s  .  co  m

    //caso erro, retorna o tamanho a4 como padrao
    return new Rectangle(PageSize.A4);
}

From source file:com.chaschev.itext.columns.BalancedColumnsBuilder.java

License:Apache License

private BalancingResult applyBestResult() {
    final float hCenter = horCenter();
    List<Element> elements = sequence.getElements();

    setColumn((float) bestResult.leftColumnHeight, hCenter, true, true, singleColumnRect, leftCTB);
    setColumn((float) bestResult.rightColumnHeight, hCenter, false, false, singleColumnRect, rightCTB);

    if (b.drawBorders) {
        b.getCanvasBuilder().drawGrayRectangle(leftCTB.getSimpleColumnRectangle(), BaseColor.RED);
        b.getCanvasBuilder().drawGrayRectangle(rightCTB.getSimpleColumnRectangle(), BaseColor.GREEN);
    }//from   www.  j  ava 2 s . c  o m

    leftCTB.clearContent();
    rightCTB.clearContent();

    final DirectContentAdder.Result addResult = new DirectContentAdder(leftCTB).setStartWith(initialLeftCTB)
            .setStartAtIndex(startAtElement).setSwitchToRightCTB(rightCTB).setSimulate(false).go();

    float yLine = Math.min(leftCTB.getYLine(), rightCTB.getYLine());

    final BalancingResult r;

    if (addResult.hasContentLeft(elements.size())) {
        final ColumnTextBuilder contentCopy = addResult.contentLeft == null ? null
                : b.newColumnTextBuilder().setACopy(addResult.contentLeft);

        r = startWithANewPage(contentCopy, addResult.index);
    } else {
        r = new BalancingResult(yLine);

        //            if(updateAfterRun != null){
        //                updateAfterRun.growBottom(origRectangle.getTop() - yLine);
        //            }
    }

    if (updateAfterRun != null) {
        updateAfterRun.setSimpleColumn(b.reuseRectangleBuilder(new Rectangle(origRectangle.get())).setTop(yLine)
                .setBottom(b.getDocument().bottom()).get());
    }

    return r;
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public ColumnTextBuilder setACopy(ColumnTextBuilder source) {
    clearContent(); //content is saved after setACopy

    setSimpleColumn(new Rectangle(source.simpleColumnRectangle));

    columnText.setACopy(source.columnText);

    this.pageBottom = source.pageBottom;
    this.pageTop = source.pageTop;

    return this;
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public ColumnTextBuilder goGo() throws DocumentException {
    while (ColumnText.hasMoreText(go())) {
        iTextBuilder.document.newPage();

        simpleColumnRectangle = new Rectangle(simpleColumnRectangle);

        simpleColumnRectangle.setBottom(pageBottom);
        simpleColumnRectangle.setTop(pageTop);

        columnText.setSimpleColumn(simpleColumnRectangle);

        iTextBuilder.defaultColumnTextSettings.apply(this);
    }/*from  w  ww  . j a v  a2  s .  co m*/

    return this;
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public ColumnTextBuilder dup() {
    final ColumnTextBuilder b = new ColumnTextBuilder(iTextBuilder);

    b.simpleColumnRectangle = new Rectangle(simpleColumnRectangle);
    b.columnText = ColumnText.duplicate(columnText);
    b.pageBottom = pageBottom;//from www .ja  v  a2  s . c om
    b.pageTop = pageTop;

    return b;
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public RectangleBuilder getCurrentRectangle() {
    return iTextBuilder.newRectangleBuilder(new Rectangle(simpleColumnRectangle)).setTop(getYLine());
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public ColumnTextBuilder addTruncatedLine(Chunk chunk, boolean addEllipsis) {
    final float pixelsForEllipsis = 6;

    try {//from   www.ja va 2 s . com
        ColumnText dup = ColumnText.duplicate(columnText);

        final Rectangle oneLineRectangle = new Rectangle(simpleColumnRectangle);

        oneLineRectangle.setTop(dup.getYLine());

        final float fontHeight = calcApproximateFontHeight(chunk.getFont()) * 1.6f;

        oneLineRectangle.setBottom(dup.getYLine() - fontHeight);

        if (addEllipsis) {
            oneLineRectangle.setRight(oneLineRectangle.getRight() - pixelsForEllipsis);
        }

        dup.setSimpleColumn(oneLineRectangle);
        dup.addText(chunk);

        final int status = dup.go();

        float yLine;

        if (addEllipsis && ColumnText.hasMoreText(status)) {
            oneLineRectangle.setLeft(dup.getLastX() + 2);
            oneLineRectangle.setRight(oneLineRectangle.getRight() + pixelsForEllipsis * 2);

            dup = ColumnText.duplicate(dup);

            dup.setSimpleColumn(oneLineRectangle);

            final Chunk ellipses = new Chunk("...\n", chunk.getFont());

            dup.setText(new Phrase(ellipses));
            dup.go();
            yLine = dup.getYLine();
        } else {
            yLine = dup.getYLine();
        }

        setYLine(yLine);

        return this;

    } catch (DocumentException e) {
        throw Exceptions.runtime(e);
    }
}

From source file:com.chaschev.itext.ITextBuilder.java

License:Apache License

public RectangleBuilder newCopyRectangleBuilder(Rectangle r) {
    return new RectangleBuilder().reuse(new Rectangle(r));
}

From source file:com.chaschev.itext.TwoColumnsSectionBuilder.java

License:Apache License

public TwoColumnsSectionBuilder(Rectangle rectangle, ITextBuilder b, ContentAdder contentAdder) {
    this.rectangle = rectangle;
    this.b = b;//from  w  w w.  j a v a 2  s .  co m
    this.contentAdder = contentAdder;

    tempR = new Rectangle(rectangle);
}