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"); // page size rtf.AppendLine(@"\paperw" + RtfUtility.paperWidthInTwip(_paper, _orientation) + @"\paperh" + RtfUtility.paperHeightInTwip(_paper, _orientation)); // page margin rtf.AppendLine(@"\margt" + RtfUtility.pt2Twip(_margins[Direction.Top])); rtf.AppendLine(@"\margr" + RtfUtility.pt2Twip(_margins[Direction.Right])); rtf.AppendLine(@"\margb" + RtfUtility.pt2Twip(_margins[Direction.Bottom])); rtf.AppendLine(@"\margl" + RtfUtility.pt2Twip(_margins[Direction.Left])); // orientation if (_orientation == PaperOrientation.Landscape) { rtf.AppendLine(@"\landscape"); } // header/footer if (_header != null) { rtf.Append(_header.Render()); } if (_footer != null) { rtf.Append(_footer.Render()); } rtf.AppendLine(); // --------------------------------------------------- // Document body // --------------------------------------------------- rtf.Append(base.Render()); // --------------------------------------------------- // Ending // --------------------------------------------------- rtf.AppendLine("}"); return(rtf.ToString()); }
internal string renderHead() { StringBuilder result = new StringBuilder("{"); if (!string.IsNullOrEmpty(_localHyperlink)) { //result.Append(@"{\field{\*\fldinst HYPERLINK \\l "); result.Append(@"{\field{\*\fldinst HYPERLINK "); 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 (_foregroundColor != null) { result.Append(@"\cf" + _foregroundColor.Value); } // Removes underline and hacks foreground result.Append(@"\cf1\ulnone"); if (_backgroundColor != null) { result.Append(@"\chshdng0\chcbpat" + _backgroundColor.Value + @"\cb" + _backgroundColor.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()); }