/** * Write the content of this RtfCell */ public virtual void WriteContent(Stream result) { byte[] t; if (this.content.Count == 0) { result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length); if (this.parentRow.GetParentTable().GetTableFitToPage()) { result.Write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT.Length); } result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length); } else { for (int i = 0; i < this.content.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)this.content[i]; if (rtfElement is RtfParagraph) { ((RtfParagraph)rtfElement).SetKeepTogetherWithNext(this.parentRow.GetParentTable().GetTableFitToPage()); } rtfElement.WriteContent(result); if (rtfElement is RtfParagraph && i < (this.content.Count - 1)) { result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length); } } } result.Write(t = DocWriter.GetISOBytes("\\cell"), 0, t.Length); }
/// <summary> /// Write the content of this RtfCell /// </summary> public virtual void WriteContent(Stream result) { byte[] t; if (_content.Count == 0) { result.Write(RtfPhrase.ParagraphDefaults, 0, RtfPhrase.ParagraphDefaults.Length); if (_parentRow.GetParentTable().GetTableFitToPage()) { result.Write(RtfParagraphStyle.KeepTogetherWithNext, 0, RtfParagraphStyle.KeepTogetherWithNext.Length); } result.Write(RtfPhrase.InTable, 0, RtfPhrase.InTable.Length); } else { for (int i = 0; i < _content.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)_content[i]; if (rtfElement is RtfParagraph) { ((RtfParagraph)rtfElement).SetKeepTogetherWithNext(_parentRow.GetParentTable().GetTableFitToPage()); } rtfElement.WriteContent(result); if (rtfElement is RtfParagraph && i < (_content.Count - 1)) { result.Write(RtfParagraph.Paragraph, 0, RtfParagraph.Paragraph.Length); } } } result.Write(t = DocWriter.GetIsoBytes("\\cell"), 0, t.Length); }
/// <summary> /// Writes the content of this RtfParagraph. First paragraph specific data is written /// and then the RtfChunks of this RtfParagraph are added. /// </summary> public override void WriteContent(Stream result) { result.Write(ParagraphDefaults, 0, ParagraphDefaults.Length); result.Write(Plain, 0, Plain.Length); if (((RtfElement)this).InTable) { result.Write(InTable, 0, InTable.Length); } if (ParagraphStyle != null) { ParagraphStyle.WriteBegin(result); } result.Write(Plain, 0, Plain.Length); for (int i = 0; i < Chunks.Count; i++) { IRtfBasicElement rbe = (IRtfBasicElement)Chunks[i]; rbe.WriteContent(result); } if (ParagraphStyle != null) { ParagraphStyle.WriteEnd(result); } if (!((RtfElement)this).InTable) { result.Write(Paragraph, 0, Paragraph.Length); } Document.OutputDebugLinebreak(result); }
/** * Writes the content of this RtfListItem. * * @return A byte array with the content of this RtfListItem. */ public override byte[] Write() { MemoryStream result = new MemoryStream(); try { byte[] t; for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfChunk) { ((RtfChunk)rtfElement).SetSoftLineBreaks(true); } else if (rtfElement is RtfList) { result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length); this.containsInnerList = true; } result.Write(t = rtfElement.Write(), 0, t.Length); if (rtfElement is RtfList) { result.Write(t = this.parentList.WriteListBeginning(), 0, t.Length); result.Write(t = DocWriter.GetISOBytes("\\tab"), 0, t.Length); } } } catch (IOException) { } return(result.ToArray()); }
/** * Writes the content of this RtfParagraph. First paragraph specific data is written * and then the RtfChunks of this RtfParagraph are added. */ public override void WriteContent(Stream result) { result.Write(PARAGRAPH_DEFAULTS, 0, PARAGRAPH_DEFAULTS.Length); result.Write(PLAIN, 0, PLAIN.Length); if (inTable) { result.Write(IN_TABLE, 0, IN_TABLE.Length); } if (this.paragraphStyle != null) { this.paragraphStyle.WriteBegin(result); } result.Write(PLAIN, 0, PLAIN.Length); for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rbe = (IRtfBasicElement)chunks[i]; rbe.WriteContent(result); } if (this.paragraphStyle != null) { this.paragraphStyle.WriteEnd(result); } if (!inTable) { result.Write(PARAGRAPH, 0, PARAGRAPH.Length); } this.document.OutputDebugLinebreak(result); }
/** * Correct the indentation of RtfLists in this RtfListItem by adding left/first line indentation * from the parent RtfList. Also calls correctIndentation on all child RtfLists. */ protected internal void CorrectIndentation() { for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfList) { ((RtfList)rtfElement).CorrectIndentation(); } } }
/** * Inherit the list settings from the parent list to RtfLists that * are contained in this RtfListItem. * * @param listNumber The list number to inherit. * @param listLevel The list level to inherit. */ public void InheritListSettings(int listNumber, int listLevel) { for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfList) { ((RtfList)rtfElement).SetListNumber(listNumber); SetLevel(listLevel); } } }
/** * Returns the definition of the first list contained in this RtfListItem or * an empty byte array if no inner RtfLists exist. * * @return The definition of the first inner RtfList or an empty byte array. */ public byte[] WriteDefinition() { for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfList) { return(((RtfList)rtfElement).WriteDefinition()); } } return(new byte[0]); }
/** * Write the content of this RtfHeaderFooter. */ public virtual void WriteContent(Stream result) { result.Write(RtfElement.OPEN_GROUP, 0, RtfElement.OPEN_GROUP.Length); if (this.type == TYPE_HEADER) { if (this.displayAt == DISPLAY_ALL_PAGES) { result.Write(HEADER_ALL, 0, HEADER_ALL.Length); } else if (this.displayAt == DISPLAY_FIRST_PAGE) { result.Write(HEADER_FIRST, 0, HEADER_FIRST.Length); } else if (this.displayAt == DISPLAY_LEFT_PAGES) { result.Write(HEADER_LEFT, 0, HEADER_LEFT.Length); } else if (this.displayAt == DISPLAY_RIGHT_PAGES) { result.Write(HEADER_RIGHT, 0, HEADER_RIGHT.Length); } } else { if (this.displayAt == DISPLAY_ALL_PAGES) { result.Write(FOOTER_ALL, 0, FOOTER_ALL.Length); } else if (this.displayAt == DISPLAY_FIRST_PAGE) { result.Write(FOOTER_FIRST, 0, FOOTER_FIRST.Length); } else if (this.displayAt == DISPLAY_LEFT_PAGES) { result.Write(FOOTER_LEFT, 0, FOOTER_LEFT.Length); } else if (this.displayAt == DISPLAY_RIGHT_PAGES) { result.Write(FOOTER_RIGHT, 0, FOOTER_RIGHT.Length); } } result.Write(RtfElement.DELIMITER, 0, RtfElement.DELIMITER.Length); for (int i = 0; i < this.content.Length; i++) { if (this.content[i] is IRtfBasicElement) { IRtfBasicElement rbe = (IRtfBasicElement)this.content[i]; rbe.WriteContent(result); } } result.Write(RtfElement.CLOSE_GROUP, 0, RtfElement.CLOSE_GROUP.Length); }
/// <summary> /// Write the content of this RtfHeaderFooter. /// </summary> public virtual void WriteContent(Stream result) { result.Write(RtfElement.OpenGroup, 0, RtfElement.OpenGroup.Length); if (_type == TYPE_HEADER) { if (_displayAt == DISPLAY_ALL_PAGES) { result.Write(_headerAll, 0, _headerAll.Length); } else if (_displayAt == DISPLAY_FIRST_PAGE) { result.Write(_headerFirst, 0, _headerFirst.Length); } else if (_displayAt == DISPLAY_LEFT_PAGES) { result.Write(_headerLeft, 0, _headerLeft.Length); } else if (_displayAt == DISPLAY_RIGHT_PAGES) { result.Write(_headerRight, 0, _headerRight.Length); } } else { if (_displayAt == DISPLAY_ALL_PAGES) { result.Write(_footerAll, 0, _footerAll.Length); } else if (_displayAt == DISPLAY_FIRST_PAGE) { result.Write(_footerFirst, 0, _footerFirst.Length); } else if (_displayAt == DISPLAY_LEFT_PAGES) { result.Write(_footerLeft, 0, _footerLeft.Length); } else if (_displayAt == DISPLAY_RIGHT_PAGES) { result.Write(_footerRight, 0, _footerRight.Length); } } result.Write(RtfElement.Delimiter, 0, RtfElement.Delimiter.Length); for (int i = 0; i < _content.Length; i++) { if (_content[i] is IRtfBasicElement) { IRtfBasicElement rbe = (IRtfBasicElement)_content[i]; rbe.WriteContent(result); } } result.Write(RtfElement.CloseGroup, 0, RtfElement.CloseGroup.Length); }
/** * Writes the content of this RtfListItem. */ public override void WriteContent(Stream result) { byte[] t; if (this.paragraphStyle.GetSpacingBefore() > 0) { result.Write(RtfParagraphStyle.SPACING_BEFORE, 0, RtfParagraphStyle.SPACING_BEFORE.Length); result.Write(t = IntToByteArray(paragraphStyle.GetSpacingBefore()), 0, t.Length); } if (this.paragraphStyle.GetSpacingAfter() > 0) { result.Write(RtfParagraphStyle.SPACING_AFTER, 0, RtfParagraphStyle.SPACING_AFTER.Length); result.Write(t = IntToByteArray(this.paragraphStyle.GetSpacingAfter()), 0, t.Length); } if (this.paragraphStyle.GetLineLeading() > 0) { result.Write(RtfParagraph.LINE_SPACING, 0, RtfParagraph.LINE_SPACING.Length); result.Write(t = IntToByteArray(this.paragraphStyle.GetLineLeading()), 0, t.Length); } for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfChunk) { ((RtfChunk)rtfElement).SetSoftLineBreaks(true); } else if (rtfElement is RtfList) { result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length); this.containsInnerList = true; } rtfElement.WriteContent(result); if (rtfElement is RtfList) { switch (this.parentList.GetLevelFollowValue()) { case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING: break; case RtfListLevel.LIST_LEVEL_FOLLOW_TAB: this.parentList.WriteListBeginning(result); result.Write(RtfList.TAB, 0, RtfList.TAB.Length); break; case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE: this.parentList.WriteListBeginning(result); result.Write(t = DocWriter.GetISOBytes(" "), 0, t.Length); break; } } } }
/// <summary> /// Writes the content of this RtfListItem. /// </summary> public override void WriteContent(Stream result) { byte[] t; if (ParagraphStyle.GetSpacingBefore() > 0) { result.Write(RtfParagraphStyle.SpacingBefore, 0, RtfParagraphStyle.SpacingBefore.Length); result.Write(t = IntToByteArray(ParagraphStyle.GetSpacingBefore()), 0, t.Length); } if (ParagraphStyle.GetSpacingAfter() > 0) { result.Write(RtfParagraphStyle.SpacingAfter, 0, RtfParagraphStyle.SpacingAfter.Length); result.Write(t = IntToByteArray(ParagraphStyle.GetSpacingAfter()), 0, t.Length); } if (ParagraphStyle.GetLineLeading() > 0) { result.Write(LineSpacing, 0, LineSpacing.Length); result.Write(t = IntToByteArray(ParagraphStyle.GetLineLeading()), 0, t.Length); } for (int i = 0; i < Chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)Chunks[i]; if (rtfElement is RtfChunk) { ((RtfChunk)rtfElement).SetSoftLineBreaks(true); } else if (rtfElement is RtfList) { result.Write(Paragraph, 0, Paragraph.Length); _containsInnerList = true; } rtfElement.WriteContent(result); if (rtfElement is RtfList) { switch (_parentList.GetLevelFollowValue()) { case RtfListLevel.LIST_LEVEL_FOLLOW_NOTHING: break; case RtfListLevel.LIST_LEVEL_FOLLOW_TAB: _parentList.WriteListBeginning(result); result.Write(RtfList.Tab, 0, RtfList.Tab.Length); break; case RtfListLevel.LIST_LEVEL_FOLLOW_SPACE: _parentList.WriteListBeginning(result); result.Write(t = DocWriter.GetIsoBytes(" "), 0, t.Length); break; } } } }
/** * Writes the definition of the first element in this RtfListItem that is * an is {@link RtfList} to the given stream.<br> * If this item does not contain a {@link RtfList} element nothing is written * and the method returns <code>false</code>. * * @param out destination stream * @return <code>true</code> if a RtfList definition was written, <code>false</code> otherwise * @throws IOException * @see {@link RtfList#writeDefinition(Stream)} */ public bool WriteDefinition(Stream outp) { for (int i = 0; i < chunks.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)chunks[i]; if (rtfElement is RtfList) { RtfList rl = (RtfList)rtfElement; rl.WriteDefinition(outp); return(true); } } return(false); }
/** * Adds an Element to the Document * * @param element The element to be added * @return <code>false</code> * @throws DocumentException */ public override bool Add(IElement element) { if (pause) { return(false); } IRtfBasicElement rtfElement = rtfDoc.GetMapper().MapElement(element); if (rtfElement != null) { rtfDoc.Add(rtfElement); return(true); } else { return(false); } }
/** * Adds an element to the rtf document * * @param element The element to add */ public void Add(IRtfBasicElement element) { try { if (element is RtfInfoElement) { this.documentHeader.AddInfoElement((RtfInfoElement)element); } else { if (element is RtfImage) { ((RtfImage)element).SetTopLevelElement(true); } element.WriteContent(this.data.GetOutputStream()); this.lastElementWritten = element; } } catch (IOException) { } }
/** * Writes the RtfChapter and its contents */ public override void WriteContent(Stream result) { byte[] t; if (this.document.GetLastElementWritten() != null && !(this.document.GetLastElementWritten() is RtfChapter)) { result.Write(t = DocWriter.GetISOBytes("\\page"), 0, t.Length); } result.Write(t = DocWriter.GetISOBytes("\\sectd"), 0, t.Length); document.GetDocumentHeader().WriteSectionDefinition(result); if (this.title != null) { this.title.WriteContent(result); } for (int i = 0; i < items.Count; i++) { IRtfBasicElement rbe = (IRtfBasicElement)items[i]; rbe.WriteContent(result); } result.Write(t = DocWriter.GetISOBytes("\\sect"), 0, t.Length); }
/** * Updates the left, right and content indentation of all RtfParagraph and RtfSection * elements that this RtfSection contains. * * @param indentLeft The left indentation to add. * @param indentRight The right indentation to add. * @param indentContent The content indentation to add. */ private void UpdateIndentation(float indentLeft, float indentRight, float indentContent) { if (this.title != null) { this.title.SetIndentLeft((int)(this.title.GetIndentLeft() + indentLeft * RtfElement.TWIPS_FACTOR)); this.title.SetIndentRight((int)(this.title.GetIndentRight() + indentRight * RtfElement.TWIPS_FACTOR)); } for (int i = 0; i < this.items.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)this.items[i]; if (rtfElement is RtfSection) { ((RtfSection)rtfElement).UpdateIndentation(indentLeft + indentContent, indentRight, 0); } else if (rtfElement is RtfParagraph) { ((RtfParagraph)rtfElement).SetIndentLeft((int)(((RtfParagraph)rtfElement).GetIndentLeft() + (indentLeft + indentContent) * RtfElement.TWIPS_FACTOR)); ((RtfParagraph)rtfElement).SetIndentRight((int)(((RtfParagraph)rtfElement).GetIndentRight() + indentRight * RtfElement.TWIPS_FACTOR)); } } }
/** * Constructs a RtfSection for a given Section. If the autogenerateTOCEntries * property of the RtfDocument is set and the title is not empty then a TOC entry * is generated for the title. * * @param doc The RtfDocument this RtfSection belongs to * @param section The Section this RtfSection is based on */ public RtfSection(RtfDocument doc, Section section) : base(doc) { items = new ArrayList(); try { if (section.Title != null) { this.title = (RtfParagraph)doc.GetMapper().MapElement(section.Title); } if (document.GetAutogenerateTOCEntries()) { StringBuilder titleText = new StringBuilder(); foreach (IElement element in section.Title) { if (element.Type == Element.CHUNK) { titleText.Append(((Chunk)element).Content); } } if (titleText.ToString().Trim().Length > 0) { FD.RtfTOCEntry tocEntry = new FD.RtfTOCEntry(titleText.ToString()); tocEntry.SetRtfDocument(this.document); this.items.Add(tocEntry); } } foreach (IElement element in section) { IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element); if (rtfElement != null) { items.Add(rtfElement); } } UpdateIndentation(section.IndentationLeft, section.IndentationRight, section.Indentation); } catch (DocumentException) { } }
/** * Write the content of this RtfCell * * @return A byte array with the content of this RtfCell */ public byte[] Write() { MemoryStream result = new MemoryStream(); byte[] t; try { if (this.content.Count == 0) { result.Write(RtfParagraph.PARAGRAPH_DEFAULTS, 0, RtfParagraph.PARAGRAPH_DEFAULTS.Length); if (this.parentRow.GetParentTable().GetTableFitToPage()) { result.Write(RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT, 0, RtfParagraphStyle.KEEP_TOGETHER_WITH_NEXT.Length); } result.Write(RtfParagraph.IN_TABLE, 0, RtfParagraph.IN_TABLE.Length); } else { for (int i = 0; i < this.content.Count; i++) { IRtfBasicElement rtfElement = (IRtfBasicElement)this.content[i]; if (rtfElement is RtfParagraph) { ((RtfParagraph)rtfElement).SetKeepTogetherWithNext(this.parentRow.GetParentTable().GetTableFitToPage()); } result.Write(t = rtfElement.Write(), 0, t.Length); if (rtfElement is RtfParagraph && i < (this.content.Count - 1)) { result.Write(RtfParagraph.PARAGRAPH, 0, RtfParagraph.PARAGRAPH.Length); } } } result.Write(t = DocWriter.GetISOBytes("\\cell"), 0, t.Length); } catch (IOException) { } return(result.ToArray()); }
/** * Constructs a new RtfList for the specified List. * * @param doc The RtfDocument this RtfList belongs to * @param list The List this RtfList is based on * @since 2.1.3 */ public RtfList(RtfDocument doc, List list) : base(doc) { // setup the listlevels // Then, setup the list data below // setup 1 listlevel if it's a simple list // setup 9 if it's a regular list // setup 9 if it's a hybrid list (default) CreateDefaultLevels(); this.items = new ArrayList(); // list content RtfListLevel ll = (RtfListLevel)this.listLevels[0]; // get the list number or create a new one adding it to the table this.listNumber = document.GetDocumentHeader().GetListNumber(this); if (list.SymbolIndent > 0 && list.IndentationLeft > 0) { ll.SetFirstIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1)); ll.SetLeftIndent((int)((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR)); } else if (list.SymbolIndent > 0) { ll.SetFirstIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1)); ll.SetLeftIndent((int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR)); } else if (list.IndentationLeft > 0) { ll.SetFirstIndent(0); ll.SetLeftIndent((int)(list.IndentationLeft * RtfElement.TWIPS_FACTOR)); } else { ll.SetFirstIndent(0); ll.SetLeftIndent(0); } ll.SetRightIndent((int)(list.IndentationRight * RtfElement.TWIPS_FACTOR)); ll.SetSymbolIndent((int)((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR)); ll.CorrectIndentation(); ll.SetTentative(false); if (list is RomanList) { if (list.Lowercase) { ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_ROMAN); } else { ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_ROMAN); } } else if (list.Numbered) { ll.SetListType(RtfListLevel.LIST_TYPE_NUMBERED); } else if (list.Lettered) { if (list.Lowercase) { ll.SetListType(RtfListLevel.LIST_TYPE_LOWER_LETTERS); } else { ll.SetListType(RtfListLevel.LIST_TYPE_UPPER_LETTERS); } } else { // Paragraph p = new Paragraph(); // p.Add(new Chunk(list.GetPreSymbol()) ); // p.Add(list.GetSymbol()); // p.Add(new Chunk(list.GetPostSymbol()) ); // ll.SetBulletChunk(list.GetSymbol()); ll.SetBulletCharacter(list.PreSymbol + list.Symbol.Content + list.PostSymbol); ll.SetListType(RtfListLevel.LIST_TYPE_BULLET); } // now setup the actual list contents. for (int i = 0; i < list.Items.Count; i++) { try { IElement element = (IElement)list.Items[i]; if (element.Type == Element.CHUNK) { element = new ListItem((Chunk)element); } if (element is ListItem) { ll.SetAlignment(((ListItem)element).Alignment); } IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(element); for (int j = 0; j < rtfElements.Length; j++) { IRtfBasicElement rtfElement = rtfElements[j]; if (rtfElement is RtfList) { ((RtfList)rtfElement).SetParentList(this); } else if (rtfElement is RtfListItem) { ((RtfListItem)rtfElement).SetParent(ll); } ll.SetFontNumber(new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)))); if (list.Symbol != null && list.Symbol.Font != null && !list.Symbol.Content.StartsWith("-") && list.Symbol.Content.Length > 0) { // only set this to bullet symbol is not default ll.SetBulletFont(list.Symbol.Font); ll.SetBulletCharacter(list.Symbol.Content.Substring(0, 1)); } else if (list.Symbol != null && list.Symbol.Font != null) { ll.SetBulletFont(list.Symbol.Font); } else { ll.SetBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0))); } items.Add(rtfElement); } } catch (DocumentException) { } } }
/** * Takes an Element subclass and returns the correct IRtfBasicElement * subclass, that wraps the Element subclass. * * @param element The Element to wrap * @return A IRtfBasicElement wrapping the Element * @throws DocumentException */ public IRtfBasicElement MapElement(IElement element) { IRtfBasicElement rtfElement = null; if (element is IRtfBasicElement) { rtfElement = (IRtfBasicElement)element; rtfElement.SetRtfDocument(this.rtfDoc); return(rtfElement); } switch (element.Type) { case Element.CHUNK: if (((Chunk)element).GetImage() != null) { rtfElement = new RtfImage(rtfDoc, ((Chunk)element).GetImage()); } else if (((Chunk)element).HasAttributes() && ((Chunk)element).Attributes.ContainsKey(Chunk.NEWPAGE)) { rtfElement = new RtfNewPage(rtfDoc); } else { rtfElement = new RtfChunk(rtfDoc, (Chunk)element); } break; case Element.PHRASE: rtfElement = new RtfPhrase(rtfDoc, (Phrase)element); break; case Element.PARAGRAPH: rtfElement = new RtfParagraph(rtfDoc, (Paragraph)element); break; case Element.ANCHOR: rtfElement = new RtfAnchor(rtfDoc, (Anchor)element); break; case Element.ANNOTATION: rtfElement = new RtfAnnotation(rtfDoc, (Annotation)element); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElement = new RtfImage(rtfDoc, (Image)element); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElement = new RtfInfoElement(rtfDoc, (Meta)element); break; case Element.LIST: rtfElement = new RtfList(rtfDoc, (List)element); break; case Element.LISTITEM: rtfElement = new RtfListItem(rtfDoc, (ListItem)element); break; case Element.SECTION: rtfElement = new RtfSection(rtfDoc, (Section)element); break; case Element.CHAPTER: rtfElement = new RtfChapter(rtfDoc, (Chapter)element); break; case Element.TABLE: try { rtfElement = new TB.RtfTable(rtfDoc, (Table)element); } catch (InvalidCastException) { rtfElement = new TB.RtfTable(rtfDoc, ((SimpleTable)element).CreateTable()); } break; } return(rtfElement); }
/** * Constructs a new RtfList for the specified List. * * @param doc The RtfDocument this RtfList belongs to * @param list The List this RtfList is based on */ public RtfList(RtfDocument doc, List list) : base(doc) { this.listNumber = document.GetDocumentHeader().GetListNumber(this); this.items = new ArrayList(); if (list.SymbolIndent > 0 && list.IndentationLeft > 0) { this.firstIndent = (int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1); this.leftIndent = (int)((list.IndentationLeft + list.SymbolIndent) * RtfElement.TWIPS_FACTOR); } else if (list.SymbolIndent > 0) { this.firstIndent = (int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR * -1); this.leftIndent = (int)(list.SymbolIndent * RtfElement.TWIPS_FACTOR); } else if (list.IndentationLeft > 0) { this.firstIndent = 0; this.leftIndent = (int)(list.IndentationLeft * RtfElement.TWIPS_FACTOR); } else { this.firstIndent = 0; this.leftIndent = 0; } this.rightIndent = (int)(list.IndentationRight * RtfElement.TWIPS_FACTOR); this.symbolIndent = (int)((list.SymbolIndent + list.IndentationLeft) * RtfElement.TWIPS_FACTOR); this.numbered = list.IsNumbered(); for (int i = 0; i < list.Items.Count; i++) { try { IElement element = (IElement)list.Items[i]; if (element.Type == Element.CHUNK) { element = new ListItem((Chunk)element); } if (element is ListItem) { this.alignment = ((ListItem)element).Alignment; } IRtfBasicElement rtfElement = doc.GetMapper().MapElement(element); if (rtfElement is RtfList) { ((RtfList)rtfElement).SetListNumber(listNumber); ((RtfList)rtfElement).SetListLevel(listLevel + 1); ((RtfList)rtfElement).SetParent(this); } else if (rtfElement is RtfListItem) { ((RtfListItem)rtfElement).SetParent(this); ((RtfListItem)rtfElement).InheritListSettings(listNumber, listLevel + 1); } items.Add(rtfElement); } catch (DocumentException) { } } if (this.listLevel == 0) { CorrectIndentation(); } fontNumber = new ST.RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))); fontBullet = new ST.RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0))); }
/** * Takes an Element subclass and returns an array of RtfBasicElement * subclasses, that contained the mapped RTF equivalent to the Element * passed in. * * @param element The Element to wrap * @return An array of RtfBasicElement wrapping the Element * @throws DocumentException */ public IRtfBasicElement[] MapElement(IElement element) { ArrayList rtfElements = new ArrayList(); if (element is IRtfBasicElement) { IRtfBasicElement rtfElement = (IRtfBasicElement)element; rtfElement.SetRtfDocument(this.rtfDoc); return(new IRtfBasicElement[] { rtfElement }); } switch (element.Type) { case Element.CHUNK: Chunk chunk = (Chunk)element; if (chunk.HasAttributes()) { if (chunk.Attributes.ContainsKey(Chunk.IMAGE)) { rtfElements.Add(new RtfImage(rtfDoc, chunk.GetImage())); } else if (chunk.Attributes.ContainsKey(Chunk.NEWPAGE)) { rtfElements.Add(new RtfNewPage(rtfDoc)); } else if (chunk.Attributes.ContainsKey(Chunk.TAB)) { float tabPos = (float)((Object[])chunk.Attributes[Chunk.TAB])[1]; RtfTab tab = new RtfTab(tabPos, RtfTab.TAB_LEFT_ALIGN); tab.SetRtfDocument(rtfDoc); rtfElements.Add(tab); rtfElements.Add(new RtfChunk(rtfDoc, new Chunk("\t"))); } else { rtfElements.Add(new RtfChunk(rtfDoc, (Chunk)element)); } } else { rtfElements.Add(new RtfChunk(rtfDoc, (Chunk)element)); } break; case Element.PHRASE: rtfElements.Add(new RtfPhrase(rtfDoc, (Phrase)element)); break; case Element.PARAGRAPH: rtfElements.Add(new RtfParagraph(rtfDoc, (Paragraph)element)); break; case Element.ANCHOR: rtfElements.Add(new RtfAnchor(rtfDoc, (Anchor)element)); break; case Element.ANNOTATION: rtfElements.Add(new RtfAnnotation(rtfDoc, (Annotation)element)); break; case Element.IMGRAW: case Element.IMGTEMPLATE: case Element.JPEG: rtfElements.Add(new RtfImage(rtfDoc, (Image)element)); break; case Element.AUTHOR: case Element.SUBJECT: case Element.KEYWORDS: case Element.TITLE: case Element.PRODUCER: case Element.CREATIONDATE: rtfElements.Add(new RtfInfoElement(rtfDoc, (Meta)element)); break; case Element.LIST: rtfElements.Add(new RtfList(rtfDoc, (List)element)); break; case Element.LISTITEM: rtfElements.Add(new RtfListItem(rtfDoc, (ListItem)element)); break; case Element.SECTION: rtfElements.Add(new RtfSection(rtfDoc, (Section)element)); break; case Element.CHAPTER: rtfElements.Add(new RtfChapter(rtfDoc, (Chapter)element)); break; case Element.TABLE: try { rtfElements.Add(new RtfTable(rtfDoc, (Table)element)); } catch (InvalidCastException) { rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable)element).CreateTable())); } break; case Element.PTABLE: try { rtfElements.Add(new RtfTable(rtfDoc, (PdfPTable)element)); } catch (InvalidCastException) { rtfElements.Add(new RtfTable(rtfDoc, ((SimpleTable)element).CreateTable())); } break; } return((IRtfBasicElement[])rtfElements.ToArray(typeof(IRtfBasicElement))); }
/** * Adds an element to the rtf document * * @param element The element to add */ public void Add(IRtfBasicElement element) { try { if (element is RtfInfoElement) { this.documentHeader.AddInfoElement((RtfInfoElement) element); } else { if (element is RtfImage) { ((RtfImage) element).SetTopLevelElement(true); } element.WriteContent(this.data.GetOutputStream()); this.lastElementWritten = element; } } catch (IOException) { } }
/** * Imports the Cell properties into the RtfCell * * @param cell The Cell to import */ private void ImportCell(Cell cell) { this.content = new ArrayList(); if (cell == null) { this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders()); return; } this.colspan = cell.Colspan; this.rowspan = cell.Rowspan; if (cell.Rowspan > 1) { this.mergeType = MERGE_VERT_PARENT; } if (cell is RtfCell) { this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell)cell).GetBorders()); } else { this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); } this.verticalAlignment = cell.VerticalAlignment; if (cell.BackgroundColor == null) { this.backgroundColor = new RtfColor(this.document, 255, 255, 255); } else { this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor); } this.cellPadding = (int)this.parentRow.GetParentTable().GetCellPadding(); if (cell != null) { Paragraph container = null; foreach (IElement element in cell.Elements) { try { // should we wrap it in a paragraph if (!(element is Paragraph) && !(element is List)) { if (container != null) { container.Add(element); } else { container = new Paragraph(); container.Alignment = cell.HorizontalAlignment; container.Add(element); } } else { if (container != null) { IRtfBasicElement rtfElement = this.document.GetMapper().MapElement(container); rtfElement.SetInTable(true); this.content.Add(rtfElement); container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element is Paragraph && ((Paragraph)element).Alignment == Element.ALIGN_UNDEFINED) { ((Paragraph)element).Alignment = cell.HorizontalAlignment; } IRtfBasicElement rtfElement2 = this.document.GetMapper().MapElement(element); rtfElement2.SetInTable(true); this.content.Add(rtfElement2); } } catch (DocumentException) { } } if (container != null) { try { IRtfBasicElement rtfElement = this.document.GetMapper().MapElement(container); rtfElement.SetInTable(true); this.content.Add(rtfElement); } catch (DocumentException) { } } } }