简体   繁体   English

从以Unicode编写的RichTextBox的FlowDocument保存到DataFormats.Rtf之后

[英]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). ,它在C#中正确拼写并完全以编程方式写入FlowDocument,可以这么说,它似乎在内部分解,因此稍后将打开文件的RTF编辑器(例如Word 2016)上的拼写检查器会发现拼写错误(例如在上述图片中)。 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. 如果我使用TextRange保存FlowDocument,则行为不会有所不同。 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. 我怀疑这是RTF编写过程本身的局限性或错误。 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. 更新:这是RTF纯文本的图像,以防响铃响起。 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: 中间的粉红色文本是“错误的”单词,其底部和顶部的粉红色单词基本上是相同的单词,但是Word 2016找不到正确的拼写错误: 在此处输入图片说明

I Could not replicate the problem using this example (I used another Unicode string). 我无法使用此示例来复制问题(我使用了另一个Unicode字符串)。

    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());
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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