public PdfCell(Cell cell, int rownumber, float left, float right, float top, float cellspacing, float cellpadding) : base(left, top, right, top) {
// copying the other Rectangle attributes from class Cell
CloneNonPositionParameters(cell);
this.cellpadding = cellpadding;
this.cellspacing = cellspacing;
this.verticalAlignment = cell.VerticalAlignment;
this.useAscender = cell.UseAscender;
this.useDescender = cell.UseDescender;
this.useBorderPadding = cell.UseBorderPadding;
// initialisation of some parameters
PdfChunk chunk;
PdfChunk overflow;
lines = new ArrayList();
images = new ArrayList();
leading = cell.Leading;
int alignment = cell.HorizontalAlignment;
left += cellspacing + cellpadding;
right -= cellspacing + cellpadding;
left += GetBorderWidthInside(LEFT_BORDER);
right -= GetBorderWidthInside(RIGHT_BORDER);
contentHeight = 0;
rowspan = cell.Rowspan;
ArrayList allActions;
int aCounter;
// we loop over all the elements of the cell
foreach (IElement ele in cell.Elements) {
switch (ele.Type) {
case Element.JPEG:
case Element.JPEG2000:
case Element.JBIG2:
case Element.IMGRAW:
case Element.IMGTEMPLATE:
AddImage((Image)ele, 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)ele, left, right, alignment);
line = new PdfLine(left, right, alignment, leading);
break;
// if the element is something else
default:
allActions = new ArrayList();
ProcessActions(ele, null, allActions);
aCounter = 0;
float currentLineLeading = leading;
float currentLeft = left;
float currentRight = right;
if (ele is Phrase) {
currentLineLeading = ((Phrase) ele).Leading;
}
if (ele is Paragraph) {
Paragraph p = (Paragraph) ele;
currentLeft += p.IndentationLeft;
currentRight -= p.IndentationRight;
}
if (line == null) {
line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
}
// we loop over the chunks
ArrayList chunks = ele.Chunks;
if (chunks.Count == 0) {
AddLine(line); // add empty line - all cells need some lines even if they are empty
line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading);
}
else {
foreach (Chunk c in chunks) {
chunk = new PdfChunk(c, (PdfAction)allActions[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 (ele.Type) {
case Element.PARAGRAPH:
case Element.SECTION:
case Element.CHAPTER:
line.ResetAlignment();
FlushCurrentLine();
break;
}
break;
}
}
FlushCurrentLine();
if (lines.Count > cell.MaxLines) {
while (lines.Count > cell.MaxLines) {
RemoveLine(lines.Count - 1);
}
if (cell.MaxLines > 0) {
String more = cell.ShowTruncation;
if (more != null && more.Length > 0) {
// Denote that the content has been truncated
lastLine = (PdfLine) lines[lines.Count - 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.Value = lastChunk.ToString().Substring(0, lastChunk.Length - 1);
}
lastChunk.Value = lastChunk.ToString() + more;
} else {
lastLine.Add(new PdfChunk(new Chunk(more), null));
}
}
}
}
// we set some additional parameters
if (useDescender && lastLine != null) {
contentHeight -= lastLine.Descender;
}
// adjust first line height so that it touches the top
if (lines.Count > 0) {
firstLine = (PdfLine) lines[0];
float firstLineRealHeight = FirstLineRealHeight;
contentHeight -= firstLine.Height;
firstLine.height = firstLineRealHeight;
contentHeight += firstLineRealHeight;
}
float newBottom = top - contentHeight - (2f * Cellpadding) - (2f * Cellspacing);
newBottom -= GetBorderWidthInside(TOP_BORDER) + GetBorderWidthInside(BOTTOM_BORDER);
Bottom = newBottom;
this.rownumber = rownumber;
}