public PdfCell(Cell cell,
int rownumber,
float left,
float right,
float top,
float cellspacing,
float cellpadding) {
// constructors
// constructs a Rectangle (the bottomvalue will be changed afterwards)
super(left, top, right, top);
// copying the other Rectangle attributes from class Cell
cloneNonPositionParameters(cell);
this.cellpadding = cellpadding;
this.cellspacing = cellspacing;
this.verticalAlignment = cell.getVerticalAlignment();
this.useAscender = cell.isUseAscender();
this.useDescender = cell.isUseDescender();
this.useBorderPadding = cell.isUseBorderPadding();
// initialization of some parameters
PdfChunk chunk;
Element element;
PdfChunk overflow;
lines = new ArrayList();
images = new ArrayList();
leading = cell.getLeading();
int alignment = cell.getHorizontalAlignment();
left += cellspacing + cellpadding;
right -= cellspacing + cellpadding;
left += getBorderWidthInside(LEFT);
right -= getBorderWidthInside(RIGHT);
contentHeight = 0;
rowspan = cell.getRowspan();
ArrayList allActions;
int aCounter;
// we loop over all the elements of the cell
for (Iterator i = cell.getElements(); i.hasNext();) {
element = (Element) i.next();
switch (element.type()) {
case Element.JPEG:
case Element.JPEG2000:
case Element.IMGRAW:
case Element.IMGTEMPLATE:
addImage((Image) element, left, right, 0.4f * leading, alignment); //
break;
// if the element is a list
case Element.LIST:
if (line != null && line.size() > 0) {
line.resetAlignment();
addLine(line);
}
// we loop over all the listitems
addList((List)element, left, right, alignment);
line = new PdfLine(left, right, alignment, leading);
break;
// if the element is something else
default:
allActions = new ArrayList();
processActions(element, null, allActions);
aCounter = 0;
float currentLineLeading = leading;
float currentLeft = left;
float currentRight = right;
if (element instanceof Phrase) {
currentLineLeading = ((Phrase) element).getLeading();
}
if (element instanceof Paragraph) {
Paragraph p = (Paragraph) element;
currentLeft += p.getIndentationLeft();
currentRight -= p.getIndentationRight();
}
if (line == null) {
line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
}
// we loop over the chunks
ArrayList chunks = element.getChunks();
if (chunks.isEmpty()) {
addLine(line); // add empty line - all cells need some lines even if they are empty
line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
}
else {
for (Iterator j = chunks.iterator(); j.hasNext();) {
Chunk c = (Chunk) j.next();
chunk = new PdfChunk(c, (PdfAction) (allActions.get(aCounter++)));
while ((overflow = line.add(chunk)) != null) {
addLine(line);
line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
chunk = overflow;
}
}
}
// if the element is a paragraph, section or chapter, we reset the alignment and add the line
switch (element.type()) {
case Element.PARAGRAPH:
case Element.SECTION:
case Element.CHAPTER:
line.resetAlignment();
flushCurrentLine();
}
}
}
flushCurrentLine();
if (lines.size() > cell.getMaxLines()) {
while (lines.size() > cell.getMaxLines()) {
removeLine(lines.size() - 1);
}
if (cell.getMaxLines() > 0) {
String more = cell.getShowTruncation();
if (more != null && more.length() > 0) {
// Denote that the content has been truncated
lastLine = (PdfLine) lines.get(lines.size() - 1);
if (lastLine.size() >= 0) {
PdfChunk lastChunk = lastLine.getChunk(lastLine.size() - 1);
float moreWidth = new PdfChunk(more, lastChunk).width();
while (lastChunk.toString().length() > 0 && lastChunk.width() + moreWidth > right - left) {
// Remove characters to leave room for the 'more' indicator
lastChunk.setValue(lastChunk.toString().substring(0, lastChunk.length() - 1));
}
lastChunk.setValue(lastChunk.toString() + more);
} else {
lastLine.add(new PdfChunk(new Chunk(more), null));
}
}
}
}
// we set some additional parameters
if (useDescender && lastLine != null) {
contentHeight -= lastLine.getDescender();
}
// adjust first line height so that it touches the top
if (!lines.isEmpty()) {
firstLine = (PdfLine) lines.get(0);
float firstLineRealHeight = firstLineRealHeight();
contentHeight -= firstLine.height();
firstLine.height = firstLineRealHeight;
contentHeight += firstLineRealHeight;
}
float newBottom = top - contentHeight - (2f * cellpadding()) - (2f * cellspacing());
newBottom -= getBorderWidthInside(TOP) + getBorderWidthInside(BOTTOM);
setBottom(newBottom);
this.rownumber = rownumber;
}
Constructs a PdfCell-object. Parameters:
cell - the original Cell
rownumber - the number of the Row the Cell was in.
left - the left border of the PdfCell
right - the right border of the PdfCell
top - the top border of the PdfCell
cellspacing - the cellspacing of the Table
cellpadding - the cellpadding of the Table
|