diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/RtfWriter.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/RtfWriter.cs index d2c764d832..3d4f9d0cbe 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/RtfWriter.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/RtfWriter.cs @@ -145,7 +145,7 @@ namespace ICSharpCode.TextEditor.Util printWord = word.Word; } - rtf.Append(printWord.Replace(@"\", @"\\").Replace("{", "\\{").Replace("}", "\\}")); + AppendText(rtf, printWord); } offset += word.Length; break; @@ -160,5 +160,31 @@ namespace ICSharpCode.TextEditor.Util return rtf.ToString(); } + + static void AppendText(StringBuilder rtfOutput, string text) + { + //rtf.Append(printWord.Replace(@"\", @"\\").Replace("{", "\\{").Replace("}", "\\}")); + foreach (char c in text) { + switch (c) { + case '\\': + rtfOutput.Append(@"\\"); + break; + case '{': + rtfOutput.Append("\\{"); + break; + case '}': + rtfOutput.Append("\\}"); + break; + default: + if (c < 256) { + rtfOutput.Append(c); + } else { + // yes, RTF really expects signed 16-bit integers! + rtfOutput.Append("\\u" + unchecked((short)c).ToString() + "?"); + } + break; + } + } + } } }