dotnet / dotnet/wpf

RichTextBox Rtf property wrong converting non ascii chars

Open
#4,011 11 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version : 3.1.405
* Windows version: Windows 10
* Does the bug reproduce also in WPF for .NET Framework 4.8?: No (4.6.1)
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No

**Problem description:** The RichTextBox cannot convert non ascii chars from my rtf string.

[string rtf ="{\\rtf1\\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Arial;}} {\\colortbl\\red0\\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang32\\fs30\\f2\\cf0 \\cf0\\qj\\sl15\\slmult0{\\f2 {\\ltrch entête}\\li0\\ri0\\sa0\\sb0\\fi0\\qj\\sl15\\slmult0\\par}}}"

if (rtf.Length > 2)
{
FlowDocument flowDocument = new FlowDocument
{
LineHeight = 1,
Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentUICulture.Name),
};

using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(rtf)))
{
TextRange text = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

if (stream.Length != 0)
{
text.Load(stream, DataFormats.Rtf);
}

text.ClearAllProperties();
}

return flowDocument;
}](url)

My RichTextbox display "Entête ". Problem with the conversion of "ê" (non ASCII chars)

**Actual behavior:** My RichTextbox display "Entête ". Problem with the conversion of "ê" (non ASCII chars)

**Expected behavior:** My RichTextbox display "Entête ". Problem with the conversion of "ê"

**Minimal repro:** Always

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.