public void HandleEndingTags(String name) {
//System.err.Println("Stop: " + name);
if (ElementTags.IGNORE.Equals(name)) {
ignore = false;
return;
}
if (ignore) return;
// tags that don't have any content
if (IsNewpage(name) || ElementTags.ANNOTATION.Equals(name) || ElementTags.IMAGE.Equals(name) || IsNewline(name)) {
return;
}
try {
// titles of sections and chapters
if (ElementTags.TITLE.Equals(name)) {
Paragraph current = (Paragraph) stack.Pop();
if (currentChunk != null) {
current.Add(currentChunk);
currentChunk = null;
}
Section previous = (Section) stack.Pop();
previous.Title = current;
stack.Push(previous);
return;
}
// all other endtags
if (currentChunk != null) {
ITextElementArray current;
try {
current = (ITextElementArray) stack.Pop();
}
catch {
current = new Paragraph();
}
current.Add(currentChunk);
stack.Push(current);
currentChunk = null;
}
// chunks
if (ElementTags.CHUNK.Equals(name)) {
return;
}
// phrases, anchors, lists, tables
if (ElementTags.PHRASE.Equals(name) || ElementTags.ANCHOR.Equals(name) || ElementTags.LIST.Equals(name)
|| ElementTags.PARAGRAPH.Equals(name)) {
IElement current = (IElement) stack.Pop();
try {
ITextElementArray previous = (ITextElementArray) stack.Pop();
previous.Add(current);
stack.Push(previous);
}
catch {
document.Add(current);
}
return;
}
// listitems
if (ElementTags.LISTITEM.Equals(name)) {
ListItem listItem = (ListItem) stack.Pop();
List list = (List) stack.Pop();
list.Add(listItem);
stack.Push(list);
}
// tables
if (ElementTags.TABLE.Equals(name)) {
Table table = (Table) stack.Pop();
try {
ITextElementArray previous = (ITextElementArray) stack.Pop();
previous.Add(table);
stack.Push(previous);
}
catch {
document.Add(table);
}
return;
}
// rows
if (ElementTags.ROW.Equals(name)) {
ArrayList cells = new ArrayList();
int columns = 0;
Table table;
Cell cell;
while (true) {
IElement element = (IElement) stack.Pop();
if (element.Type == Element.CELL) {
cell = (Cell) element;
columns += cell.Colspan;
cells.Add(cell);
}
else {
table = (Table) element;
break;
}
}
if (table.Columns < columns) {
table.AddColumns(columns - table.Columns);
}
cells.Reverse(0, cells.Count);
String width;
float[] cellWidths = new float[columns];
bool[] cellNulls = new bool[columns];
for (int i = 0; i < columns; i++) {
cellWidths[i] = 0;
cellNulls[i] = true;
}
float total = 0;
int j = 0;
foreach (Cell c in cells) {
cell = c;
width = cell.GetWidthAsString();
if (cell.Width == 0) {
if (cell.Colspan == 1 && cellWidths[j] == 0) {
try {
cellWidths[j] = 100f / columns;
total += cellWidths[j];
}
catch {
// empty on purpose
}
}
else if (cell.Colspan == 1) {
cellNulls[j] = false;
}
}
else if (cell.Colspan == 1 && width.EndsWith("%")) {
try {
cellWidths[j] = float.Parse(width.Substring(0, width.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
total += cellWidths[j];
}
catch {
// empty on purpose
}
}
j += cell.Colspan;
table.AddCell(cell);
}
float[] widths = table.ProportionalWidths;
if (widths.Length == columns) {
float left = 0.0f;
for (int i = 0; i < columns; i++) {
if (cellNulls[i] && widths[i] != 0) {
left += widths[i];
cellWidths[i] = widths[i];
}
}
if (100.0 >= total) {
for (int i = 0; i < widths.Length; i++) {
if (cellWidths[i] == 0 && widths[i] != 0) {
cellWidths[i] = (widths[i] / left) * (100.0f - total);
}
}
}
table.Widths = cellWidths;
}
stack.Push(table);
}
// registerfont
if (name.Equals("registerfont")) {
return;
}
// header
if (ElementTags.HEADER.Equals(name)) {
document.Header = (HeaderFooter)stack.Pop();
return;
}
// footer
if (ElementTags.FOOTER.Equals(name)) {
document.Footer = (HeaderFooter)stack.Pop();
return;
}
// before
if (name.Equals("before")) {
return;
}
// after
if (name.Equals("after")) {
return;
}
// cells
if (ElementTags.CELL.Equals(name)) {
return;
}
// sections
if (ElementTags.SECTION.Equals(name)) {
stack.Pop();
return;
}
// chapters
if (ElementTags.CHAPTER.Equals(name)) {
document.Add((IElement) stack.Pop());
return;
}
// the documentroot
if (IsDocumentRoot(name)) {
try {
while (true) {
IElement element = (IElement) stack.Pop();
try {
ITextElementArray previous = (ITextElementArray) stack.Pop();
previous.Add(element);
stack.Push(previous);
}
catch {
document.Add(element);
}
}
}
catch {
// empty on purpose
}
if (controlOpenClose) document.Close();
return;
}
}
catch (DocumentException de) {
throw de;
}
}