float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders) { if (includeHeaders) { firstRow = Math.max(firstRow, headerRows); lastRow = Math.max(lastRow, headerRows); } float widths[][] = new float[(includeHeaders ? headerRows : 0) + lastRow - firstRow][]; if (isColspan) { int n = 0; if (includeHeaders) { for (int k = 0; k < headerRows; ++k) { PdfPRow row = (PdfPRow) rows.get(k); if (row == null) ++n; else widths[n++] = row.getEventWidth(xPos); } } for (; firstRow < lastRow; ++firstRow) { PdfPRow row = (PdfPRow) rows.get(firstRow); if (row == null) ++n; else widths[n++] = row.getEventWidth(xPos); } } else { float width[] = new float[absoluteWidths.length + 1]; width[0] = xPos; for (int k = 0; k < absoluteWidths.length; ++k) width[k + 1] = width[k] + absoluteWidths[k]; for (int k = 0; k < widths.length; ++k) widths[k] = width; } return widths; }
public void calculateHeightsFast() { if (totalWidth <= 0) return; totalHeight = 0; for (PdfPRow row : rows) { if (row != null) totalHeight += row.getMaxHeights(); } }
/** * Adds a cell element. * * @param cell the cell element */ public void addCell(PdfPCell cell) { PdfPCell ncell = new PdfPCell(cell); int colspan = ncell.getColspan(); colspan = Math.max(colspan, 1); colspan = Math.min(colspan, currentRow.length - currentRowIdx); ncell.setColspan(colspan); if (colspan != 1) isColspan = true; int rdir = ncell.getRunDirection(); if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT) ncell.setRunDirection(runDirection); currentRow[currentRowIdx] = ncell; currentRowIdx += colspan; if (currentRowIdx >= currentRow.length) { if (runDirection == PdfWriter.RUN_DIRECTION_RTL) { PdfPCell rtlRow[] = new PdfPCell[absoluteWidths.length]; int rev = currentRow.length; for (int k = 0; k < currentRow.length; ++k) { PdfPCell rcell = currentRow[k]; int cspan = rcell.getColspan(); rev -= cspan; rtlRow[rev] = rcell; k += cspan - 1; } currentRow = rtlRow; } PdfPRow row = new PdfPRow(currentRow); if (totalWidth > 0) { row.setWidths(absoluteWidths); totalHeight += row.getMaxHeights(); } rows.add(row); currentRow = new PdfPCell[absoluteWidths.length]; currentRowIdx = 0; } }
/** Calculates the heights of the table. */ public void calculateHeightsFast() { if (totalWidth <= 0) return; totalHeight = 0; for (int k = 0; k < rows.size(); ++k) { PdfPRow row = (PdfPRow) rows.get(k); if (row != null) totalHeight += row.getMaxHeights(); } }
public float getHeaderHeight() { float total = 0; int size = Math.min(rows.size(), headerRows); for (PdfPRow row : rows) { if (row != null) total += row.getMaxHeights(); } return total; }
/** * Gets the height of the rows that constitute the header as defined by <CODE>setHeaderRows() * </CODE>. * * @return the height of the rows that constitute the header */ public float getHeaderHeight() { float total = 0; int size = Math.min(rows.size(), headerRows); for (int k = 0; k < size; ++k) { PdfPRow row = (PdfPRow) rows.get(k); if (row != null) total += row.getMaxHeights(); } return total; }
void calculateHeights() { if (totalWidth <= 0) return; totalHeight = 0; for (PdfPRow row : rows) { if (row != null) { row.setWidths(absoluteWidths); totalHeight += row.getMaxHeights(); } } }
/** * Deletes a row from the table. * * @param rowNumber the row to be deleted * @return <CODE>true</CODE> if the row was deleted */ public boolean deleteRow(int rowNumber) { if (rowNumber < 0 || rowNumber >= rows.size()) { return false; } if (totalWidth > 0) { PdfPRow row = (PdfPRow) rows.get(rowNumber); if (row != null) totalHeight -= row.getMaxHeights(); } rows.remove(rowNumber); return true; }
void calculateHeights() { if (totalWidth <= 0) return; totalHeight = 0; for (int k = 0; k < rows.size(); ++k) { PdfPRow row = (PdfPRow) rows.get(k); if (row != null) { row.setWidths(absoluteWidths); totalHeight += row.getMaxHeights(); } } }
/** * Writes the selected rows and columns to the document. This method does not clip the columns; * this is only important if there are columns with colspan at boundaries. * * <p><CODE>canvases</CODE> is obtained from <CODE>beginWritingRows()</CODE>. * * <p>The table event is only fired for complete rows. * * @param colStart the first column to be written, zero index * @param colEnd the last column to be written + 1. If it is -1 all the columns to the end are * written * @param rowStart the first row to be written, zero index * @param rowEnd the last row to be written + 1. If it is -1 all the rows to the end are written * @param xPos the x write coodinate * @param yPos the y write coodinate * @param canvases an array of 4 <CODE>PdfContentByte</CODE> obtained from <CODE> * beginWrittingRows()</CODE> * @return the y coordinate position of the bottom of the last row * @see #beginWritingRows(com.lowagie.text.pdf.PdfContentByte) */ public float writeSelectedRows( int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases) { if (totalWidth <= 0) throw new RuntimeException("The table width must be greater than zero."); int size = rows.size(); if (rowEnd < 0) rowEnd = size; rowEnd = Math.min(rowEnd, size); if (rowStart < 0) rowStart = 0; if (rowStart >= rowEnd) return yPos; if (colEnd < 0) colEnd = absoluteWidths.length; colEnd = Math.min(colEnd, absoluteWidths.length); if (colStart < 0) colStart = 0; colStart = Math.min(colStart, absoluteWidths.length); float yPosStart = yPos; for (int k = rowStart; k < rowEnd; ++k) { PdfPRow row = (PdfPRow) rows.get(k); if (row != null) { row.writeCells(colStart, colEnd, xPos, yPos, canvases); yPos -= row.getMaxHeights(); } } if (tableEvent != null && colStart == 0 && colEnd == absoluteWidths.length) { float heights[] = new float[rowEnd - rowStart + 1]; heights[0] = yPosStart; for (int k = rowStart; k < rowEnd; ++k) { PdfPRow row = (PdfPRow) rows.get(k); float hr = 0; if (row != null) hr = row.getMaxHeights(); heights[k - rowStart + 1] = heights[k - rowStart] - hr; } tableEvent.tableLayout( this, getEventWidths(xPos, rowStart, rowEnd, headersInEvent), heights, headersInEvent ? headerRows : 0, rowStart, canvases); } return yPos; }
/** * Returns the height of the cell. * * @return the height of the cell * @since 3.0.0 */ public float getMaxHeight() { boolean pivoted = getRotation() == 90 || getRotation() == 270; Image img = getImage(); if (img != null) { img.scalePercent(100); float refWidth = pivoted ? img.getScaledHeight() : img.getScaledWidth(); float scale = (getRight() - getEffectivePaddingRight() - getEffectivePaddingLeft() - getLeft()) / refWidth; img.scalePercent(scale * 100); float refHeight = pivoted ? img.getScaledWidth() : img.getScaledHeight(); setBottom(getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - refHeight); } else { if ((pivoted && hasFixedHeight()) || getColumn() == null) setBottom(getTop() - getFixedHeight()); else { ColumnText ct = ColumnText.duplicate(getColumn()); float right, top, left, bottom; if (pivoted) { right = PdfPRow.RIGHT_LIMIT; top = getRight() - getEffectivePaddingRight(); left = 0; bottom = getLeft() + getEffectivePaddingLeft(); } else { right = isNoWrap() ? PdfPRow.RIGHT_LIMIT : getRight() - getEffectivePaddingRight(); top = getTop() - getEffectivePaddingTop(); left = getLeft() + getEffectivePaddingLeft(); bottom = hasFixedHeight() ? getTop() + getEffectivePaddingBottom() - getFixedHeight() : PdfPRow.BOTTOM_LIMIT; } PdfPRow.setColumn(ct, left, bottom, right, top); try { ct.go(true); } catch (DocumentException e) { throw new ExceptionConverter(e); } if (pivoted) setBottom( getTop() - getEffectivePaddingTop() - getEffectivePaddingBottom() - ct.getFilledWidth()); else { float yLine = ct.getYLine(); if (isUseDescender()) yLine += ct.getDescender(); setBottom(yLine - getEffectivePaddingBottom()); } } } float height = getHeight(); if (height == getEffectivePaddingTop() + getEffectivePaddingBottom()) height = 0; if (hasFixedHeight()) height = getFixedHeight(); else if (hasMinimumHeight() && height < getMinimumHeight()) height = getMinimumHeight(); return height; }
/** * Gets the height of a particular row. * * @param idx the row index (starts at 0) * @return the height of a particular row */ public float getRowHeight(int idx) { if (totalWidth <= 0 || idx < 0 || idx >= rows.size()) return 0; PdfPRow row = (PdfPRow) rows.get(idx); if (row == null) return 0; return row.getMaxHeights(); }