需要一个相当独特的WPF文本编辑器控件 [英] Need a rather unique WPF text editor control

查看:101
本文介绍了需要一个相当独特的WPF文本编辑器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在WPF(C#VS 2010 .NET 4.0)中编写一个专用的文本编辑器程序。这个程序将用于创建的文档具有非常特定的格式,我需要相当精确地控制边距,段落缩进和基于此格式的对齐等内容。开源或免费是最好的。



(我试图自动化几十年来在打字机上做过的事情.MS Word会起作用,但是用户希望为各种类型的段落创建多种样式,然后在输入文本时不断地在它们之间来回切换。)



我读过在 RichTextBox AvalonEdit ;这两个似乎都有很多超出我要求的功能(语法高亮,代码折叠等),虽然它们都缺少我真正需要的一些基本功能。



任何人都可以推荐其中任何一种,或者为我需要的控制建议一个更好的起点吗?以下是我的要求:



- 单个固定间距字体,只有粗体,下划线和斜体

- 可变左/右边距和自动换行,同时保持缩进

- 支持按键事件,包括[enter]和[tab]

- 能够以编程方式将文本插入符移动到任意位置

- 快速处理大型文档(大约10MB文本)

- 显示页面分隔符的查看模式(如MS Word,显示一页的底部和下一页的顶部,或者Adobe Reader启用滚动和显示页面之间的差距;我说全职因为我不想进入打印预览模式来查看分页符

- 左,中,右对齐

- 实时和全文拼写检查

- 显示边距和缩进级别的字样标尺

- 保存为HTML或者最好是XML格式

- 导出或打印到PDF格式

- T他通常复制/剪切/粘贴东西

- 撤消/重做

- 搜索和替换



附加很高兴有功能是:



- 支持文本格式模板

- 缩放(不是为了增加字体大小,而是为了增加页面大小显示)

- 拆分窗口

- 修订标记



我意识到我会必须编写代码来支持其中的一些功能,但任何有助于我开始并且已经实现了这些功能的东西都是我正在寻找的。



谢谢!

I''m trying to write a special-purpose text editor program in WPF (C# VS 2010 .NET 4.0). The documents this program will be used to create are of a very specific format, and I''ll need fairly precise control over things like margins, paragraph indention, and justification based on this format. Open source or free would be best.

(I''m trying to automate something that''s been done on typewriters for decades. MS Word would work, but the user would want to create several styles for the various types of paragraphs and then constantly flip back and forth between them as he entered text.)

I''ve read up a bit on RichTextBox and AvalonEdit; both of these seem to have tons of features that are way beyond my requirements (syntax highlighting, code folding, etc.) though they''re both missing some of the basic features I really need.

Can anyone recommend either of those, or suggest a better starting point for the control I need? Here are my requirements:

- Single fixed-pitch font with only bold, underline, and italics
- Variable left/right margins and automatic word wrap while maintaining indention
- Support for keystroke events including [enter] and [tab]
- Ability to programmatically move the text caret to arbitrary locations
- Handles large documents (say around 10MB of text) quickly
- A view mode showing page separators (like MS Word, showing the bottom of one page and top of the next page, or Adobe Reader with "Enable Scrolling" and "Show Gaps Between Pages"; I say "full-time" because I don''t want to have to go into "print preview" mode to see the page breaks
- Left, center, and right-justify
- Real-time and whole-document spell check
- Word-like ruler showing margins and indent level
- Save to HTML or preferably XML format
- Export or print to PDF format
- The usual copy/cut/paste stuff
- Undo/Redo
- Search and replace

Additional "nice to have" features are:

- Support for text format templates
- Zoom (not to increase font size, but to increase the size of the page display)
- Split window
- Revision marks

I realize I''ll have to write code to support some of these features, but anything that would help me get started and have some of these features already implemented is what I''m looking for.

Thanks!

推荐答案

首先,请看我对这个问题的评论。这是足够长的时间继续在一个单独的帖子,但首先是因为如果必须是某种答案。



从我对这种情况的解释你现在应该明白,你很可能是应该做所有这些工作的人。你能告诉我为什么不呢?



你的要求没什么特别的,没什么新鲜的。最困难的要求是快速加载10 M的文本。实际上,WPF有一个特点,因为我的不完整的WPF编辑器(不是我经常使用的编辑器),实际上非常快地加载它,但是......当你滚动它,比如说,向中间滚动时,它会变慢。这是因为WPF有单独的UI和渲染线程。



你错过了一些重要的功能,比如指示插入符号的位置(简单的WPF)等等作为宏,至少是键盘宏(我实现了它们,但遗憾的是,不完全没有P / Invoke; WPF仍然缺少重要的东西)。



为什么是PDF ?不是XPS(我认为在许多方面比该死的PDF更好)?



另外,你的居中,对齐等看起来不够。它应该丢失,或者你会转到另一端,实现接近Microsoft Word或LibreOffice的功能( http:// en.wikipedia.org/wiki/LibreOffice [ ^ ])。



如果你想走这条路线,为什么不考虑 System.Windows.Documents.FlowDocument ?请参阅:

http://msdn.microsoft.com/en-us /library/aa970909.aspx [ ^ ],

http:// msdn .microsoft.com / zh-cn / library / system.windows.documents.flowdocument.aspx [ ^ ]。



再次,矛盾就是你想要的显示不同的段落对齐,但是,从我的列表中可以理解,不是不同的字体(我指的是列表的第一项)。这与您可能用作基类的任何组件都不一致。或者您需要从非常低的级别开始,使用自定义渲染从 Control 类开始。但是想象一下如果使用 FlowDocument 的Rich Text作为基础会发生什么。您可以在整个文档中强制使用一种统一字体。到现在为止还挺好。但是这里有一个问题:您还将抑制剪贴板粘贴并将其替换为您自己的剪贴板。你明白为什么吗?否则,尝试粘贴将插入带有源格式的文本片段,而您的文档不应该呈现。并不是说这太难了;这是相当不愉快的。



还有什么? XML。没有只是XML。可能是这样的: http://en.wikipedia.org/wiki/OpenDocument [ ^ ]。



PDF导出?通常,人们使用iText或其.NET端口,iTextSharp:

http://en.wikipedia。 org / wiki / IText [ ^ ],

http://itextpdf.com/ [ ^ ],

http:// sourceforge。 net / projects / itextsharp / [ ^ ],

http://www.javatips.net/ blog / 2011/09 / create-pdf-with-itext-java-tutorial [ ^ ]。



再次考虑XPS:

[ ^ ]。



这是标准的事情:

http://www.ecma-international.org/publications/standards/Ecma-388.htm [ ^ ]。



顺便说一下, FlowDocument 可以作为XPS导出。



我已经提到了只是列表的一小部分。我想,主要问题是选择。您将处理从头开始(从我上面描述的意义上)开始所有内容的诱惑,以及缺少现有文本编辑器组件和相关砖墙中的帮助功能。好吧,几个砖墙...... :-)



-SA
First of all, please see my comment to the question. It''s long enough to continue in a separate post, but first of all because if has to be some kind of the answer.

From my explanations of this situation, you probably should have understood by now, that it''s very likely that you are the one who should do all this work. Can you tell me why not?

There is nothing special in your requirements, nothing very new. The most difficult requirement will be quick load of 10 M of text. Actually, there is one peculiarity of WPF, due to which my incomplete WPF editor (not the one I use on regular basis), actually loads this very quickly, but… when you scroll it, say, to the middle, it becomes slow. This is because WPF has separate UI and rendering threads.

You missed some important features, such as indication of the position of the caret (simple in WPF) and such thing as macro, at least keyboard macro (I implemented them, but, unfortunately, not completely without P/Invoke; something important is still missing from WPF).

Why PDF? Not XPS (which I think is better then damn PDF in a number of aspects)?

Also, your centering, alignment, etc. does not look adequate. It should either be missing, or you would go to the other end, implementation of features close to Microsoft Word or rather LibreOffice (http://en.wikipedia.org/wiki/LibreOffice[^]).

If you want to go take this route, why not considering System.Windows.Documents.FlowDocument? Please see:
http://msdn.microsoft.com/en-us/library/aa970909.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.documents.flowdocument.aspx[^].

The contradiction, again, is that you want to show different paragraph alignment but, as I can understand from your list, not different fonts (I refer to the first item of your list). This is not in line with any of the components you might use as a base class. Or you would need to start from very low level, from Control class with custom rendering. But imagine what happens if you use Rich Text of FlowDocument as the base. You can enforce one uniform font throughout the document. So far so good. But here is the catch: you will have also suppress the clipboard Paste and replace it with your own. Do you see why? Otherwise an attempt to Paste will insert a text fragment with source formatting, something your document is not suppose to render. Not that this is too difficult; it is rather unpleasant.

What else? XML. There is no "just XML". It could be this: http://en.wikipedia.org/wiki/OpenDocument[^].

PDF export? Usually, people use iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^],
http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial[^].

Again, consider XPS:
http://en.wikipedia.org/wiki/Open_XML_Paper_Specification[^].

This is a standard thing:
http://www.ecma-international.org/publications/standards/Ecma-388.htm[^].

By the way, FlowDocument can be exported as XPS.

I''ve mentioned only a small part of your list. I guess, the main problem will be the choice. You will deal with the temptation to start everything from scratch (in the sense I described above) and the lacks of helping features in existing text-editor-like components and related brick wall. Well, several brick walls… :-)

—SA


如果你不''请注意支付专业控件,请查看: DXRichEdit [ ^ ] - 它具有您需要的大部分功能。



您可以使用 XtraPrinting [ ^ ]图书馆导出为PDF



祝你好评

Espen Harlinn
If you don''t mind paying for a professional control, have a look at: DXRichEdit[^] - it has most of the features you require.

You can use the XtraPrinting[^] library to export to PDF

Best regards
Espen Harlinn


这篇关于需要一个相当独特的WPF文本编辑器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆