/** * Constructs a new RtfPhrase for the RtfDocument with the given Phrase * * @param doc The RtfDocument this RtfPhrase belongs to * @param phrase The Phrase this RtfPhrase is based on */ public RtfPhrase(RtfDocument doc, Phrase phrase) : base(doc) { if (phrase == null) { return; } if (phrase.HasLeading()) { this.lineLeading = (int)(phrase.Leading * TWIPS_FACTOR); } else { this.lineLeading = 0; } ST.RtfFont phraseFont = new ST.RtfFont(null, phrase.Font); for (int i = 0; i < phrase.Count; i++) { IElement chunk = (IElement)phrase[i]; if (chunk is Chunk) { ((Chunk)chunk).Font = phraseFont.Difference(((Chunk)chunk).Font); } try { IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk); for (int j = 0; j < rtfElements.Length; j++) { chunks.Add(rtfElements[j]); } } catch (DocumentException) { } } }
/** * Tests for equality of RtfFonts. RtfFonts are equal if their fontName, * fontSize, fontStyle and fontSuperSubscript are equal * * @param obj The RtfFont to compare with this RtfFont * @return <code>True</code> if the RtfFonts are equal, <code>false</code> otherwise */ public override bool Equals(Object obj) { if (!(obj is RtfFont)) { return(false); } RtfFont font = (RtfFont)obj; bool result = true; result = result & this.fontName.Equals(font.GetFontName()); return(result); }
/** * Constructs a RtfParagraph belonging to a RtfDocument based on a Paragraph. * * @param doc The RtfDocument this RtfParagraph belongs to * @param paragraph The Paragraph that this RtfParagraph is based on */ public RtfParagraph(RtfDocument doc, Paragraph paragraph) : base(doc) { ST.RtfFont baseFont = null; if (paragraph.Font is ST.RtfParagraphStyle) { this.paragraphStyle = this.document.GetDocumentHeader().GetRtfParagraphStyle(((ST.RtfParagraphStyle)paragraph.Font).GetStyleName()); baseFont = this.paragraphStyle; } else { baseFont = new ST.RtfFont(this.document, paragraph.Font); this.paragraphStyle = new ST.RtfParagraphStyle(this.document, this.document.GetDocumentHeader().GetRtfParagraphStyle("Normal")); this.paragraphStyle.SetAlignment(paragraph.Alignment); this.paragraphStyle.SetFirstLineIndent((int)(paragraph.FirstLineIndent * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetIndentLeft((int)(paragraph.IndentationLeft * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetIndentRight((int)(paragraph.IndentationRight * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetSpacingBefore((int)(paragraph.SpacingBefore * RtfElement.TWIPS_FACTOR)); this.paragraphStyle.SetSpacingAfter((int)(paragraph.SpacingAfter * RtfElement.TWIPS_FACTOR)); if (paragraph.HasLeading()) { this.paragraphStyle.SetLineLeading((int)(paragraph.Leading * RtfElement.TWIPS_FACTOR)); } this.paragraphStyle.SetKeepTogether(paragraph.KeepTogether); } for (int i = 0; i < paragraph.Count; i++) { IElement chunk = (IElement)paragraph[i]; if (chunk is Chunk) { ((Chunk)chunk).Font = baseFont.Difference(((Chunk)chunk).Font); } else if (chunk is RtfImage) { ((RtfImage)chunks[i]).SetAlignment(this.paragraphStyle.GetAlignment()); } try { IRtfBasicElement[] rtfElements = doc.GetMapper().MapElement(chunk); for (int j = 0; j < rtfElements.Length; j++) { chunks.Add(rtfElements[j]); } } catch (DocumentException) { } } }
/** * Constructs a RtfChunk based on the content of a Chunk * * @param doc The RtfDocument that this Chunk belongs to * @param chunk The Chunk that this RtfChunk is based on */ public RtfChunk(RtfDocument doc, Chunk chunk) : base(doc) { if (chunk == null) { return; } if (chunk.Attributes != null && chunk.Attributes[Chunk.SUBSUPSCRIPT] != null) { this.superSubScript = (float)chunk.Attributes[Chunk.SUBSUPSCRIPT]; } if (chunk.Attributes != null && chunk.Attributes[Chunk.BACKGROUND] != null) { this.background = new RtfColor(this.document, (Color)((Object[])chunk.Attributes[Chunk.BACKGROUND])[0]); } font = new ST.RtfFont(doc, chunk.Font); content = chunk.Content; }
/** * Writes the definition of the font list */ public virtual void WriteDefinition(Stream result) { byte[] t; result.Write(DEFAULT_FONT, 0, DEFAULT_FONT.Length); result.Write(t = IntToByteArray(0), 0, t.Length); result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(FONT_TABLE, 0, FONT_TABLE.Length); for (int i = 0; i < fontList.Count; i++) { result.Write(OPEN_GROUP, 0, OPEN_GROUP.Length); result.Write(FONT_NUMBER, 0, FONT_NUMBER.Length); result.Write(t = IntToByteArray(i), 0, t.Length); RtfFont rf = (RtfFont)fontList[i]; rf.WriteDefinition(result); result.Write(COMMA_DELIMITER, 0, COMMA_DELIMITER.Length); result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); } result.Write(CLOSE_GROUP, 0, CLOSE_GROUP.Length); this.document.OutputDebugLinebreak(result); }
/** * Gets the index of the font in the list of fonts. If the font does not * exist in the list, it is added. * * @param font The font to get the id for * @return The index of the font */ public int GetFontNumber(RtfFont font) { if (font is RtfParagraphStyle) { font = new RtfFont(this.document, (RtfParagraphStyle)font); } int fontIndex = -1; for (int i = 0; i < fontList.Count; i++) { if (fontList[i].Equals(font)) { fontIndex = i; } } if (fontIndex == -1) { fontIndex = fontList.Count; fontList.Add(font); } return(fontIndex); }
/** * Gets the number of the specified RtfFont * * @param font The RtfFont for which to get the number * @return The number of the font */ public int GetFontNumber(ST.RtfFont font) { return(this.fontList.GetFontNumber(font)); }
/** * Constructs a RtfField for a RtfDocument. This is not very usefull, * since the RtfField by itself does not do anything. Use one of the * subclasses instead. * * @param doc The RtfDocument this RtfField belongs to. * @param font The Font this RtfField should use */ protected RtfField(RtfDocument doc, Font font) : base("", font) { this.document = doc; this.font = new ST.RtfFont(this.document, font); }