/** * 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; }
/** * Write out the columns. After writing, use {@link #isOverflow()} to see if all text was written. * * @param canvas PdfContentByte to write with * @param document document to write to (only used to get page limit info) * @param documentY starting y position to begin writing at * @return the current height (y position) after writing the columns * @throws DocumentException on error */ public float write(PdfContentByte canvas, PdfDocument document, float documentY) throws DocumentException { this.document = document; columnText.setCanvas(canvas); if (columnDefs.isEmpty()) { throw new DocumentException("MultiColumnText has no columns"); } overflow = false; float currentHeight = 0; boolean done = false; try { while (!done) { if (top == AUTOMATIC) { top = document.getVerticalPosition( true); // RS - 07/07/2005 - Get current doc writing position for top of columns on // new page. } else if (nextY == AUTOMATIC) { nextY = document.getVerticalPosition( true); // RS - 07/07/2005 - - Get current doc writing position for top of columns // on new page. } ColumnDef currentDef = (ColumnDef) columnDefs.get(getCurrentColumn()); columnText.setYLine(top); float[] left = currentDef.resolvePositions(Rectangle.LEFT); float[] right = currentDef.resolvePositions(Rectangle.RIGHT); if (document.isMarginMirroring() && document.getPageNumber() % 2 == 0) { float delta = document.rightMargin() - document.left(); left = (float[]) left.clone(); right = (float[]) right.clone(); for (int i = 0; i < left.length; i += 2) { left[i] -= delta; } for (int i = 0; i < right.length; i += 2) { right[i] -= delta; } } currentHeight = Math.max(currentHeight, getHeight(left, right)); if (currentDef.isSimple()) { columnText.setSimpleColumn(left[2], left[3], right[0], right[1]); } else { columnText.setColumns(left, right); } int result = columnText.go(); if ((result & ColumnText.NO_MORE_TEXT) != 0) { done = true; top = columnText.getYLine(); } else if (shiftCurrentColumn()) { top = nextY; } else { // check if we are done because of height totalHeight += currentHeight; if ((desiredHeight != AUTOMATIC) && (totalHeight >= desiredHeight)) { overflow = true; break; } else { // need to start new page and reset the columns documentY = nextY; newPage(); currentHeight = 0; } } } } catch (DocumentException ex) { ex.printStackTrace(); throw ex; } if (desiredHeight == AUTOMATIC && columnDefs.size() == 1) { currentHeight = documentY - columnText.getYLine(); } return currentHeight; }