Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct RTF string without bothering RichTextArea #1355

Closed
katatunix opened this issue Mar 29, 2019 · 12 comments
Closed

Construct RTF string without bothering RichTextArea #1355

katatunix opened this issue Mar 29, 2019 · 12 comments

Comments

@katatunix
Copy link

This is an enhancement request.

I have a long list of text lines, each line can have different color. I want to add them to a RichTextArea. Using the Append works but performance is not good.

It would be great if we can have a method to construct a RTF string without bothering the RichTextArea, then we can set RichTextArea.Rtf to the constructed string.

Note that while it's possible to use another lib for constructing RTF, but they use different classes/types compared to Eto (e.g., Font, Color ...), and I still want to use the Append method on the same RichTextArea.

@cwensley
Copy link
Member

Hey @katatunix, thanks for the request. I've actually been working on something along these lines (a TextBuffer of sorts) that has all the same api's as RichTextArea but lets you construct it separately then append (or set) it to the RichTextArea.

One thing that I'd like it to do is make it so it can be constructed in a background thread, but not all platforms would support this unfortunately. I'm still investigating this though.

@cwensley cwensley added this to the 2.x milestone Mar 29, 2019
@LaraSQP
Copy link

LaraSQP commented Nov 14, 2019

If you have any code on this, I would like to take a look at it.

@cwensley
Copy link
Member

@LaraSQP I just uploaded my work so far in PR #1507

@LaraSQP
Copy link

LaraSQP commented Nov 14, 2019

Since the RichTextArea control only handles a few properties (font + style, fore + back color), why not write a "simple" rtf class to compose an rtf string and then feed it to the RichTextArea.Rtf property?

Something like:

https://www.codeproject.com/Articles/30902/RichText-Builder-StringBuilder-for-RTF

Am I missing something here and coming across as a moron again?

@cwensley
Copy link
Member

cwensley commented Nov 14, 2019

@LaraSQP no, that totally works. GTK doesn't support RTF though.

I don't think Eto needs to provide that feature directly, as there's no reason you can't use an external RTF builder then feed it into Eto's control.

@LaraSQP
Copy link

LaraSQP commented Nov 15, 2019

Did not know about GTK and RTF. That's a bummer.

The external RTF builder won't work as is because of the problems brought up by the original poster (different classes/types compared to Eto e.g., Font, Color ...) and, in any case, the RTF stream would need to be converted into something displayable by GTK. Thus, your TextBuffer.

Darn

@cwensley
Copy link
Member

@LaraSQP You could theoretically build the RTF using an external tool/api, then load it into Eto. You can use Eto's Font/Color and translate those to an RTF-friendly format if really needed.

The problem with RTF however is that even though it is a "standard", it really is composed differently depending on the platform (at least Mac vs. Windows). The font names specified in the RTF in particular are very different. You can see the differences using TextEdit on Mac vs. WordPad on Windows.

Hope this helps.

@LaraSQP
Copy link

LaraSQP commented Nov 15, 2019

Messy indeed.

It must be said you have done a great work with the Linux port. Hardly any performance penalty despite heavy use of multiple fonts and colors.

The same code on Windows is a slug though.

@cwensley
Copy link
Member

The same code on Windows is a slug though.

Yeah, not sure how to get around that.. FlowDocument is extremely slow.

@LaraSQP
Copy link

LaraSQP commented Nov 21, 2019

Since the performance in Linux is excellent, would you know its performance is on a Mac?

@cwensley
Copy link
Member

@LaraSQP it should be pretty fast on macOS too. in my experience it's just WPF that is pretty slow at this point. I'd like to find a way to make it faster though (;

@LaraSQP
Copy link

LaraSQP commented Nov 21, 2019

In that case, consider this issue closed for me.

@cwensley cwensley removed this from the 2.x milestone May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants