/// <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.GetImage(); Write(image, indent); return; } catch { // empty on purpose } AddTabs(indent); Hashtable 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; try { table = (Table)element; } catch (InvalidCastException) { table = ((SimpleTable)element).CreateTable(); } 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.JPEG: case Element.IMGRAW: case Element.IMGTEMPLATE: { Image image = (Image)element; if (image.Url == null) { return; } AddTabs(indent); WriteStart(ElementTags.IMAGE); Write(ElementTags.URL, image.Url.ToString()); if ((image.Alignment & Image.RIGHT_ALIGN) > 0) { Write(ElementTags.ALIGN, ElementTags.ALIGN_RIGHT); } else if ((image.Alignment & Image.MIDDLE_ALIGN) > 0) { Write(ElementTags.ALIGN, ElementTags.ALIGN_MIDDLE); } else { Write(ElementTags.ALIGN, ElementTags.ALIGN_LEFT); } 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; } }