Example usage for com.itextpdf.text Phrase getTotalLeading

List of usage examples for com.itextpdf.text Phrase getTotalLeading

Introduction

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

Prototype

public float getTotalLeading() 

Source Link

Document

Gets the total leading.

Usage

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

License:Apache License

public Iterator<AtomicIncreaseResult> newAtomicIteratorFor(@Nullable Element element,
        final RectangleBuilder modifiableRectangle, RectangleBuilder originalRectangle) {
    if (element != null) {
        addElement(element);//from   w w  w  . j av  a  2s.  c  o m
    }

    final GrowStrategy growStrategy;

    if (element == null) {
        growStrategy = DEFAULT_GROW_STRATEGY;
    } else if (element instanceof Phrase) {
        Phrase phrase = (Phrase) element;
        final float approxHeight = phrase.getTotalLeading();

        growStrategy = new SimpleGrowStrategy(approxHeight);
    } else if (element instanceof com.itextpdf.text.List) {
        com.itextpdf.text.List list = (com.itextpdf.text.List) element;

        float lineHeight = 10f;

        final ListItem item = list.getFirstItem();

        if (item != null) {
            lineHeight = item.getTotalLeading();
        }

        growStrategy = new SimpleGrowStrategy(lineHeight);
    } else if (element instanceof PdfPTable) {
        PdfPTable table = (PdfPTable) element;

        float lineHeight = Float.MAX_VALUE;

        ArrayList<PdfPRow> rows = table.getRows();
        for (int i = 0; i < rows.size(); i++) {
            lineHeight = Math.min(lineHeight, table.getRowHeight(i));
        }

        if (lineHeight == Float.MAX_VALUE) {
            lineHeight = 10f;
        }

        growStrategy = new SimpleGrowStrategy(lineHeight);
    } else {
        throw new UnsupportedOperationException("todo: support element: " + element.getClass().getSimpleName());
    }

    return newAtomicIteratorFor(modifiableRectangle, growStrategy, originalRectangle);
}