private string ReHighlight(string text) { StringTokenizer tokenizer = new StringTokenizer(text); Token token; StringBuilder body = new StringBuilder(); do { token = tokenizer.Next(); switch (token.Kind) { case TokenKind.Word: if (KeyWords.ContainsKey(token.Value)) { body.Append(colorTag(KeyWords[token.Value].Color, token.Value)); } else { goto default; } break; case TokenKind.QuotedString: body.Append(colorTag(StringColor, token.Value)); break; case TokenKind.Comment: body.Append(colorTag(CommentColor, token.Value)); break; case TokenKind.EOL: body.Append("\\par\n\\cf1 "); break; default: body.Append(rtfEscaped(token.Value)); break; } } while (token.Kind != TokenKind.EOF); StringBuilder colorTable = new StringBuilder(); colorTable.Append(@"{\colortbl;"); foreach (Color color in UsedColors) { colorTable.AppendFormat("\\red{0}\\green{1}\\blue{2};", color.R, color.G, color.B); } colorTable.Append("}"); // Construct final rtf StringBuilder rtf = new StringBuilder(); rtf.AppendLine(@"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 " + rtfEscaped(Font.Name) + ";}}"); rtf.AppendLine(colorTable.ToString()); rtf.Append(@"\pard\f0\fs" + (int)(Font.SizeInPoints * 2)+ " "); rtf.Append(body); rtf.AppendLine(@"}"); return rtf.ToString(); }
private string ReHighlight(string text) { StringTokenizer tokenizer = new StringTokenizer(text); Token token; StringBuilder body = new StringBuilder(); do { token = tokenizer.Next(); switch (token.Kind) { case TokenKind.Word: if (KeyWords.ContainsKey(token.Value)) { body.Append(colorTag(KeyWords[token.Value].Color, token.Value)); } else { goto default; } break; case TokenKind.QuotedString: body.Append(colorTag(StringColor, token.Value)); break; case TokenKind.Comment: body.Append(colorTag(CommentColor, token.Value)); break; case TokenKind.EOL: body.Append("\\par\n\\cf1 "); break; default: body.Append(rtfEscaped(token.Value)); break; } } while (token.Kind != TokenKind.EOF); StringBuilder colorTable = new StringBuilder(); colorTable.Append(@"{\colortbl;"); foreach (Color color in UsedColors) { colorTable.AppendFormat("\\red{0}\\green{1}\\blue{2};", color.R, color.G, color.B); } colorTable.Append("}"); // Construct final rtf StringBuilder rtf = new StringBuilder(); rtf.AppendLine(@"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 " + rtfEscaped(Font.Name) + ";}}"); rtf.AppendLine(colorTable.ToString()); rtf.Append(@"\pard\f0\fs" + (int)(Font.SizeInPoints * 2) + " "); rtf.Append(body); rtf.AppendLine(@"}"); return(rtf.ToString()); }