Click here to Skip to main content
15,885,885 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
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!
Posted
Updated 9-Jan-13 18:12pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Jan-13 0:09am    
This is a reasonably posed important problem; I even voted 4 for the question (which really rarely happens these days), but just one trouble is: this is not really a question (there is no even a question mark).

This is just a Questions & Answers forum, so you post is somewhat out of its format...

I'm one of those freaks who use my own text editor in most cases, but how could I possibly help you? By writing yet another editor? Or by writing a whole book on writing editors? In principle, I could, as I know nearly everything what's involved, but... this is too much work, and not the most interesting and potentially fruitful in the world...

—SA
J. Elliott 10-Jan-13 0:13am    
Sorry... CodeProject seems to have changed its format since I last posted here. There used to be programming forums where this would be more appropriate, but I can't find them tonight!

My question is (para 4 above): Can anyone recommend either of those, or suggest a better starting point for the control I need?

This isn't intended to be yet another general-purpose text editor, but is very specific in its purpose. There is quite a market for such a program in the target demographic I'm aiming this project towards, if it's done right. I just don't want to reinvent the wheel is all, if such a control already exists that can handle most of the project's requirements.
Sandeep Mewara 10-Jan-13 0:33am    
If you are looking for C# forum: http://www.codeproject.com/Forums/1649/Csharp.aspx
J. Elliott 10-Jan-13 0:21am    
And thanks for the 4 vote! Much appreciated.
Sergey Alexandrovich Kryukov 10-Jan-13 1:37am    
I almost put a big answer (well, may be not a real one, but a number of notes), but the CodeProject script hangs on it, so I cannot retrieve already written text at this moment.
—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
 
Share this answer
 
Comments
Espen Harlinn 10-Jan-13 10:05am    
A number of good points :-D
Sergey Alexandrovich Kryukov 10-Jan-13 10:08am    
Thank you, Espen.
—SA
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Jan-13 10:11am    
Interesting, a 5. :-)

To me, you are a very much of a 3rd-party person. Do you see what I mean? You often bring something not widely known but interesting, all from 3rd parties. What, always looking around for a wide range of products, on a very regular basis?

By the way, thank you very much again for giving me a link to ILSpy. So far, works like a charm. And it was built at once (except some test projects); all source code is put together, not a single bit of binary code without source. Even a bit more convenient than Reflector. The only benefit of Reflector I see so far is the disassembly into Delphi Pascal and F#...

—SA
Espen Harlinn 10-Jan-13 18:08pm    
I've been subscribing to the universal edition of Dxperience for some years now, it's certainly a well designed set of components.

ILSpy is an impressive tool, and I'm glad you found some good use for it :-D
Sergey Alexandrovich Kryukov 10-Jan-13 18:28pm    
:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900