/// <summary> /// Writes the XML representation of a section. /// </summary> /// <param name="section">the section to write</param> /// <param name="indent">the indentation</param> private void writeSection(Section section, int indent) { write(ElementTags.NUMBERDEPTH, section.NumberDepth.ToString()); write(ElementTags.DEPTH, section.Depth.ToString()); write(ElementTags.INDENT, section.Indentation.ToString("0.0")); if (section.IndentationLeft != 0) { write(ElementTags.INDENTATIONLEFT, section.IndentationLeft.ToString("0.0")); } if (section.IndentationRight != 0) { write(ElementTags.INDENTATIONRIGHT, section.IndentationRight.ToString("0.0")); } os.WriteByte(GT); if (section.Title != null) { addTabs(indent + 1); writeStart(ElementTags.TITLE); write(ElementTags.LEADING, section.Title.Leading.ToString("0.0")); write(ElementTags.ALIGN, ElementTags.getAlignment(section.Title.Alignment)); if (section.Title.IndentationLeft != 0) { write(ElementTags.INDENTATIONLEFT, section.Title.IndentationLeft.ToString("0.0")); } if (section.Title.IndentationRight != 0) { write(ElementTags.INDENTATIONRIGHT, section.Title.IndentationRight.ToString("0.0")); } write(section.Title.Font); os.WriteByte(GT); IEnumerator i = section.Title.GetEnumerator(); if (i.MoveNext()) { // if (section.Depth > 0) { // i.MoveNext(); // } while (i.MoveNext()) { write((IElement)i.Current, indent + 2); } } addTabs(indent + 1); writeEnd(ElementTags.TITLE); } foreach (IElement ele in section) { write(ele, indent + 1); } addTabs(indent); }
// methods /// <summary> /// Writes the XML representation of an element. /// </summary> /// <param name="element">the element</param> /// <param name="indent">the indentation</param> private void write(IElement element, int indent) { switch (element.Type) { case Element.CHUNK: { Chunk chunk = (Chunk)element; // if the chunk contains an image, return the image representation try { Image image = chunk.Image; write(image, indent); return; } catch { // empty on purpose } addTabs(indent); Hashmap attributes = chunk.Attributes; if (chunk.Font.isStandardFont() && attributes == null && !(hasMarkupAttributes(chunk))) { write(encode(chunk.Content, indent)); return; } else { if (attributes != null && attributes[Chunk.NEWPAGE] != null) { writeStart(ElementTags.NEWPAGE); writeEnd(); return; } writeStart(ElementTags.CHUNK); if (!chunk.Font.isStandardFont()) { write(chunk.Font); } if (attributes != null) { foreach (string key in attributes.Keys) { if (key.Equals(Chunk.LOCALGOTO) || key.Equals(Chunk.LOCALDESTINATION) || key.Equals(Chunk.GENERICTAG)) { string value = (String)attributes[key]; write(key.ToLower(), value); } if (key.Equals(Chunk.SUBSUPSCRIPT)) { write(key.ToLower(), ((float)attributes[key]).ToString("0.0")); } } } if (hasMarkupAttributes(chunk)) { writeMarkupAttributes((IMarkupAttributes)chunk); } os.WriteByte(GT); write(encode(chunk.Content, indent)); writeEnd(ElementTags.CHUNK); } return; } case Element.PHRASE: { Phrase phrase = (Phrase)element; addTabs(indent); writeStart(ElementTags.PHRASE); write(ElementTags.LEADING, phrase.Leading.ToString("0.0")); write(phrase.Font); if (hasMarkupAttributes(phrase)) { writeMarkupAttributes((IMarkupAttributes)phrase); } os.WriteByte(GT); foreach (IElement ele in phrase) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.PHRASE); return; } case Element.ANCHOR: { Anchor anchor = (Anchor)element; addTabs(indent); writeStart(ElementTags.ANCHOR); write(ElementTags.LEADING, anchor.Leading.ToString("0.0")); write(anchor.Font); if (anchor.Name != null) { write(ElementTags.NAME, anchor.Name); } if (anchor.Reference != null) { write(ElementTags.REFERENCE, anchor.Reference); } if (hasMarkupAttributes(anchor)) { writeMarkupAttributes((IMarkupAttributes)anchor); } os.WriteByte(GT); foreach (IElement ele in anchor) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.ANCHOR); return; } case Element.PARAGRAPH: { Paragraph paragraph = (Paragraph)element; addTabs(indent); writeStart(ElementTags.PARAGRAPH); write(ElementTags.LEADING, paragraph.Leading.ToString("0.0")); write(paragraph.Font); write(ElementTags.ALIGN, ElementTags.getAlignment(paragraph.Alignment)); if (paragraph.IndentationLeft != 0) { write(ElementTags.INDENTATIONLEFT, paragraph.IndentationLeft.ToString("0.0")); } if (paragraph.IndentationRight != 0) { write(ElementTags.INDENTATIONRIGHT, paragraph.IndentationRight.ToString("0.0")); } if (hasMarkupAttributes(paragraph)) { writeMarkupAttributes((IMarkupAttributes)paragraph); } os.WriteByte(GT); foreach (IElement ele in paragraph) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.PARAGRAPH); return; } case Element.SECTION: { Section section = (Section)element; addTabs(indent); writeStart(ElementTags.SECTION); writeSection(section, indent); writeEnd(ElementTags.SECTION); return; } case Element.CHAPTER: { Chapter chapter = (Chapter)element; addTabs(indent); writeStart(ElementTags.CHAPTER); if (hasMarkupAttributes(chapter)) { writeMarkupAttributes((IMarkupAttributes)chapter); } writeSection(chapter, indent); writeEnd(ElementTags.CHAPTER); return; } case Element.LIST: { List list = (List)element; addTabs(indent); writeStart(ElementTags.LIST); write(ElementTags.NUMBERED, list.isNumbered().ToString().ToLower()); write(ElementTags.SYMBOLINDENT, list.SymbolIndent.ToString()); if (list.First != 1) { write(ElementTags.FIRST, list.First.ToString()); } if (list.IndentationLeft != 0) { write(ElementTags.INDENTATIONLEFT, list.IndentationLeft.ToString("0.0")); } if (list.IndentationRight != 0) { write(ElementTags.INDENTATIONRIGHT, list.IndentationRight.ToString("0.0")); } if (!list.isNumbered()) { write(ElementTags.LISTSYMBOL, list.Symbol.Content); } write(list.Symbol.Font); if (hasMarkupAttributes(list)) { writeMarkupAttributes((IMarkupAttributes)list); } os.WriteByte(GT); foreach (IElement ele in list.Items) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.LIST); return; } case Element.LISTITEM: { ListItem listItem = (ListItem)element; addTabs(indent); writeStart(ElementTags.LISTITEM); write(ElementTags.LEADING, listItem.Leading.ToString("0.0")); write(listItem.Font); write(ElementTags.ALIGN, ElementTags.getAlignment(listItem.Alignment)); if (listItem.IndentationLeft != 0) { write(ElementTags.INDENTATIONLEFT, listItem.IndentationLeft.ToString("0.0")); } if (listItem.IndentationRight != 0) { write(ElementTags.INDENTATIONRIGHT, listItem.IndentationRight.ToString("0.0")); } if (hasMarkupAttributes(listItem)) { writeMarkupAttributes((IMarkupAttributes)listItem); } os.WriteByte(GT); foreach (IElement ele in listItem) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.LISTITEM); return; } case Element.CELL: { Cell cell = (Cell)element; addTabs(indent); writeStart(ElementTags.CELL); write((Rectangle)cell); write(ElementTags.HORIZONTALALIGN, ElementTags.getAlignment(cell.HorizontalAlignment)); write(ElementTags.VERTICALALIGN, ElementTags.getAlignment(cell.VerticalAlignment)); if (cell.CellWidth != null) { write(ElementTags.WIDTH, cell.CellWidth); } if (cell.Colspan != 1) { write(ElementTags.COLSPAN, cell.Colspan.ToString()); } if (cell.Rowspan != 1) { write(ElementTags.ROWSPAN, cell.Rowspan.ToString()); } if (cell.Header) { write(ElementTags.HEADER, bool.TrueString.ToLower()); } if (cell.NoWrap) { write(ElementTags.NOWRAP, bool.TrueString.ToLower()); } if (cell.Leading != -1) { write(ElementTags.LEADING, cell.Leading.ToString("0.0")); } if (hasMarkupAttributes(cell)) { writeMarkupAttributes((IMarkupAttributes)cell); } os.WriteByte(GT); foreach (IElement ele in cell.Elements) { write(ele, indent + 1); } addTabs(indent); writeEnd(ElementTags.CELL); return; } case Element.ROW: { Row row = (Row)element; addTabs(indent); writeStart(ElementTags.ROW); if (hasMarkupAttributes(row)) { writeMarkupAttributes((IMarkupAttributes)row); } os.WriteByte(GT); IElement cell; for (int i = 0; i < row.Columns; i++) { if ((cell = (IElement)row.getCell(i)) != null) { write(cell, indent + 1); } } addTabs(indent); writeEnd(ElementTags.ROW); return; } case Element.TABLE: { Table table = (Table)element; table.complete(); addTabs(indent); writeStart(ElementTags.TABLE); write(ElementTags.COLUMNS, table.Columns.ToString()); os.WriteByte(SPACE); write(ElementTags.WIDTH); os.WriteByte(EQUALS); os.WriteByte(QUOTE); if (!"".Equals(table.AbsWidth)) { write(table.AbsWidth); } else { write(table.WidthPercentage.ToString()); write("%"); } os.WriteByte(QUOTE); write(ElementTags.ALIGN, ElementTags.getAlignment(table.Alignment)); write(ElementTags.CELLPADDING, table.Cellpadding.ToString("0.0")); write(ElementTags.CELLSPACING, table.Cellspacing.ToString("0.0")); os.WriteByte(SPACE); write(ElementTags.WIDTHS); os.WriteByte(EQUALS); os.WriteByte(QUOTE); float[] widths = table.ProportionalWidths; write(widths[0].ToString()); for (int i = 1; i < widths.Length; i++) { write(";"); write(widths[i].ToString()); } os.WriteByte(QUOTE); write((Rectangle)table); if (hasMarkupAttributes(table)) { writeMarkupAttributes((IMarkupAttributes)table); } os.WriteByte(GT); foreach (Row row in table) { write(row, indent + 1); } addTabs(indent); writeEnd(ElementTags.TABLE); return; } case Element.ANNOTATION: { Annotation annotation = (Annotation)element; addTabs(indent); writeStart(ElementTags.ANNOTATION); if (annotation.Title != null) { write(ElementTags.TITLE, annotation.Title); } if (annotation.Content != null) { write(ElementTags.CONTENT, annotation.Content); } if (hasMarkupAttributes(annotation)) { writeMarkupAttributes((IMarkupAttributes)annotation); } writeEnd(); return; } case Element.GIF: case Element.JPEG: case Element.PNG: { Image image = (Image)element; if (image.Url == null) { return; } addTabs(indent); writeStart(ElementTags.IMAGE); write(ElementTags.URL, image.Url.ToString()); if ((image.Alignment & Image.LEFT) > 0) { write(ElementTags.ALIGN, ElementTags.ALIGN_LEFT); } else if ((image.Alignment & Image.RIGHT) > 0) { write(ElementTags.ALIGN, ElementTags.ALIGN_RIGHT); } else if ((image.Alignment & Image.MIDDLE) > 0) { write(ElementTags.ALIGN, ElementTags.ALIGN_MIDDLE); } if ((image.Alignment & Image.UNDERLYING) > 0) { write(ElementTags.UNDERLYING, bool.TrueString.ToLower()); } if ((image.Alignment & Image.TEXTWRAP) > 0) { write(ElementTags.TEXTWRAP, bool.TrueString.ToLower()); } if (image.Alt != null) { write(ElementTags.ALT, image.Alt); } if (image.hasAbsolutePosition()) { write(ElementTags.ABSOLUTEX, image.AbsoluteX.ToString("0.0")); write(ElementTags.ABSOLUTEY, image.AbsoluteY.ToString("0.0")); } write(ElementTags.PLAINWIDTH, image.PlainWidth.ToString("0.0")); write(ElementTags.PLAINHEIGHT, image.PlainHeight.ToString("0.0")); if (hasMarkupAttributes(image)) { writeMarkupAttributes((IMarkupAttributes)image); } writeEnd(); return; } default: return; } }