Example usage for com.lowagie.text.pdf PdfPCell getRowspan

List of usage examples for com.lowagie.text.pdf PdfPCell getRowspan

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell getRowspan.

Prototype

public int getRowspan() 

Source Link

Document

Getter for property rowspan.

Usage

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java

License:Open Source License

/**
 * Gets the height of a particular row./*from   w  w  w .  j  a  va  2s. c om*/
 *
 * @param idx the row index (starts at 0)
 * @param firsttime is this the first time the row heigh is calculated?
 * @return the height of a particular row
 * @since 3.0.0
 */
public float getRowHeight(int idx, boolean firsttime) {
    if (totalWidth <= 0 || idx < 0 || idx >= rows.size())
        return 0;
    PdfPRow row = (PdfPRow) rows.get(idx);
    if (row == null)
        return 0;
    if (firsttime)
        row.setWidths(absoluteWidths);
    float height = row.getMaxHeights();
    PdfPCell cell;
    PdfPRow tmprow;
    for (int i = 0; i < relativeWidths.length; i++) {
        if (!rowSpanAbove(idx, i))
            continue;
        int rs = 1;
        while (rowSpanAbove(idx - rs, i)) {
            rs++;
        }
        tmprow = (PdfPRow) rows.get(idx - rs);
        cell = tmprow.getCells()[i];
        float tmp = 0;
        // AZERR patch : sometimes cell is null????
        // LP : cell may be null if colspan/rowspan occurs
        // create a dummy cell to avoid NullPointerException
        if (cell == null) {
            cell = new PdfPCell();
            tmprow.getCells()[i] = cell;
        }
        if (cell.getRowspan() == rs + 1) {
            tmp = cell.getMaxHeight();
            while (rs > 0) {
                tmp -= getRowHeight(idx - rs);
                rs--;
            }
        }
        if (tmp > height)
            height = tmp;
    }
    row.setMaxHeights(height);
    return height;
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPTable.java

License:Open Source License

/**
 * Checks if there are rows above belonging to a rowspan.
 *
 * @param currRow the current row to check
 * @param currCol the current column to check
 * @return true if there's a cell above that belongs to a rowspan
 * @since 2.1.6//w  ww .j  ava  2 s . c om
 */
@SuppressWarnings("all")
boolean rowSpanAbove(int currRow, int currCol) {
    if ((currCol >= getNumberOfColumns()) || (currCol < 0) || (currRow == 0))
        return false;

    int row = currRow - 1;
    PdfPRow aboveRow = (PdfPRow) rows.get(row);
    if (aboveRow == null)
        return false;
    PdfPCell aboveCell = (PdfPCell) aboveRow.getCells()[currCol];
    while ((aboveCell == null) && (row > 0)) {
        aboveRow = (PdfPRow) rows.get(--row);
        if (aboveRow == null)
            return false;
        aboveCell = (PdfPCell) aboveRow.getCells()[currCol];
    }

    int distance = currRow - row;

    if (aboveCell == null) {
        int col = currCol - 1;
        aboveCell = (PdfPCell) aboveRow.getCells()[col];
        while ((aboveCell == null) && (row > 0))
            aboveCell = (PdfPCell) aboveRow.getCells()[--col];
        return aboveCell != null && aboveCell.getRowspan() > distance;
    }

    if ((aboveCell.getRowspan() == 1) && (distance > 1)) {
        int col = currCol - 1;
        aboveRow = (PdfPRow) rows.get(row + 1);
        distance--;
        aboveCell = (PdfPCell) aboveRow.getCells()[col];
        while ((aboveCell == null) && (col > 0))
            aboveCell = (PdfPCell) aboveRow.getCells()[--col];
    }

    return aboveCell != null && aboveCell.getRowspan() > distance;
}