简体   繁体   中英

After saving to DataFormats.Rtf from a RichTextBox's FlowDocument written in Unicode

The process appears to "break" the words and therefore interfere with spell checking. For instance, this word 在此处输入图片说明 , which is spelled correctly in C# and written into FlowDocument fully programmatically, it appears to break up internally so to speak so the spell checker on the RTF editor (eg Word 2016) that will later open the file, will find a spelling error (like in the aforeposted image). If the word is copied and then directly pasted into plain text mode, it does not show a spelling error correctly.

The behavior is not different if I save the FlowDocument with TextRange. The problem does not appear in the English language. The problem is inconsistent, the word may show correctly occasionally.

I suspect that it's a limitation or bug of the RTF writing process itself. Perhaps occasionally there are internal line breaks of some sort. I wonder if anyone has found a solution to that problem in general.

Update: Here is an image from the plain text of the RTF in case it rings a bell. The middle pink text is the "wrong" word, the pink words at the bottom and top of it are basically the same word but Word 2016 doesn't find any spelling error with them correctly: 在此处输入图片说明

I Could not replicate the problem using this example (I used another Unicode string).

    public MainWindow()
    {
        InitializeComponent();
        RichTextBox rtb = new RichTextBox();
        rtb.Language = System.Windows.Markup.XmlLanguage.GetLanguage("fa-IR");
        rtb.Document.Blocks.Add(new Paragraph(new Run("درست")) { FlowDirection = FlowDirection.RightToLeft });

        TextRange tr = new TextRange(rtb.Document.ContentStart,
                            rtb.Document.ContentEnd);
        using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
        {
            tr.Save(ms, DataFormats.Rtf);
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            System.IO.File.WriteAllBytes(@"J:\test.rtf", ms.ToArray());
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM