public override string render() { StringBuilder rtf = new StringBuilder(); // --------------------------------------------------- // Prologue // --------------------------------------------------- rtf.AppendLine(@"{\rtf1\ansi\deff0"); rtf.AppendLine(); // --------------------------------------------------- // Insert font table // --------------------------------------------------- rtf.AppendLine(@"{\fonttbl"); for (int i = 0; i < _fontTable.Count; i++) { rtf.AppendLine(@"{\f" + i + " " + RtfUtility.unicodeEncode(_fontTable[i].ToString()) + ";}"); } rtf.AppendLine("}"); rtf.AppendLine(); // --------------------------------------------------- // Insert color table // --------------------------------------------------- rtf.AppendLine(@"{\colortbl"); rtf.AppendLine(";"); for (int i = 1; i < _colorTable.Count; i++) { RtfColor c = _colorTable[i]; rtf.AppendLine(@"\red" + c.Red + @"\green" + c.Green + @"\blue" + c.Blue + ";"); } rtf.AppendLine("}"); rtf.AppendLine(); /* * * // --------------------------------------------------- * // Preliminary * // --------------------------------------------------- * rtf.AppendLine(@"\deflang" + (int)_lcid + @"\plain\fs" + RtfUtility.pt2HalfPt(DefaultValue.FontSize) + @"\widowctrl\hyphauto\ftnbj"); */ rtf.AppendLine(); // --------------------------------------------------- // Document body // --------------------------------------------------- rtf.Append(base.render()); // --------------------------------------------------- // Ending // --------------------------------------------------- rtf.AppendLine("}"); return(rtf.ToString()); }
public override string render() { LinkedList <Token> tokList = buildTokenList(); StringBuilder result = new StringBuilder(_blockHead); if (_startNewPage) { result.Append(@"\pagebb"); } if (_linespacing >= 0) { result.Append(@"\sl-" + RtfUtility.pt2Twip(_linespacing) + @"\slmult0"); } if (_margins[Direction.Top] > 0) { result.Append(@"\sb" + RtfUtility.pt2Twip(_margins[Direction.Top])); } if (_margins[Direction.Bottom] > 0) { result.Append(@"\sa" + RtfUtility.pt2Twip(_margins[Direction.Bottom])); } if (_margins[Direction.Left] > 0) { result.Append(@"\li" + RtfUtility.pt2Twip(_margins[Direction.Left])); } if (_margins[Direction.Right] > 0) { result.Append(@"\ri" + RtfUtility.pt2Twip(_margins[Direction.Right])); } //if (_firstLineIndent != 0) { result.Append(@"\fi" + RtfUtility.pt2Twip(_firstLineIndent)); //} result.Append(AlignmentCode()); result.AppendLine(); // insert default char format intto the 1st position of _charFormats if (_defaultCharFormat != null) { result.AppendLine(_defaultCharFormat.renderHead()); } result.AppendLine(extractTokenList(tokList)); if (_defaultCharFormat != null) { result.Append(_defaultCharFormat.renderTail()); } result.AppendLine(_blockTail); return(result.ToString()); }
protected string extractTokenList(LinkedList <Token> tokList) { LinkedListNode <Token> node; StringBuilder result = new StringBuilder(); node = tokList.First; while (node != null) { if (node.Value.isControl) { result.Append(node.Value.text); } else { result.Append(RtfUtility.unicodeEncode(node.Value.text)); } node = node.Next; } return(result.ToString()); }
internal string renderHead() { StringBuilder result = new StringBuilder("{"); if (!string.IsNullOrEmpty(_localHyperlink)) { result.Append(@"{\field{\*\fldinst HYPERLINK \\l "); result.Append("\"" + _localHyperlink + "\""); if (!string.IsNullOrEmpty(_localHyperlinkTip)) { result.Append(" \\\\o \"" + _localHyperlinkTip + "\""); } result.Append(@"}{\fldrslt{"); } if (_font != null || _ansiFont != null) { if (_font == null) { result.Append(@"\f" + _ansiFont.Value); } else if (_ansiFont == null) { result.Append(@"\f" + _font.Value); } else { result.Append(@"\loch\af" + _ansiFont.Value + @"\hich\af" + _ansiFont.Value + @"\dbch\af" + _font.Value); } } if (_fontSize > 0) { result.Append(@"\fs" + RtfUtility.pt2HalfPt(_fontSize)); } if (_fgColor != null) { result.Append(@"\cf" + _fgColor.Value); } if (_bgColor != null) { result.Append(@"\chshdng0\chcbpat" + _bgColor.Value + @"\cb" + _bgColor.Value); } foreach (var fontStyle in _fontStyleMap) { if (FontStyle.containsStyleAdd(fontStyle.Key)) { result.Append(@"\" + fontStyle.Value); } else if (FontStyle.containsStyleRemove(fontStyle.Key)) { result.Append(@"\" + fontStyle.Value + "0"); } } if (_twoInOneStyle != TwoInOneStyle.NotEnabled) { result.Append(@"\twoinone"); switch (_twoInOneStyle) { case TwoInOneStyle.None: result.Append("0"); break; case TwoInOneStyle.Parentheses: result.Append("1"); break; case TwoInOneStyle.SquareBrackets: result.Append("2"); break; case TwoInOneStyle.AngledBrackets: result.Append("3"); break; case TwoInOneStyle.Braces: result.Append("4"); break; } } if (result.ToString().Contains(@"\")) { result.Append(" "); } if (!string.IsNullOrEmpty(_bookmark)) { result.Append(@"{\*\bkmkstart " + _bookmark + "}"); } return(result.ToString()); }