Loading an EditField with rtf is very slow

Although I own the latest Xojo revision, I continue to use RB 2012r1 for some projects.
In that project, I load and save an EditField with lots of paragrahps with formatted rtf data: different font names, sizes, bold, etc.
Loading this text is very slow, so I am looking for a way to speed up things.
I remember that some time ago, in a post in the old RealBasic forum, a fast way to load and save rtf data in an internal format was explained, but after searching, I can not find this post.
Does anybody know about this post.

I assume you do not mean EDITFIELD… but in fact mean TEXTAREA… if not… then first thing I’d do is update the code, as EDITFIELD was deprecated quite a while back.

A styled TextArea using RTFData property is quite fast. I use it to load and save “notes” in a database application

RTFData is fine for small amounts of text, but gets exponentially slower as the length grows, becoming unusable surprisingly quickly (in one test, I found getting .rtfData from a TextArea containing 8000 characters (not words) took 25 seconds). This is well documented, with a number of threads about it in this forum. One such thread is

https://forum.xojo.com/761-please-fix-extraordinarily-slow-parser-for-rtfdata

which also has several workarounds.

Dave, It was correct, I used an EditField, but now I created a test program with a TextArea, but the result is as slow as before.

Jonathan: As for the instructing thread you mentioned, I am developing for windows, I want to test with RTFValue, but I can not see TextArea1.RTFValue Or TextArea1.StyledText.RTFValue, properties, even in the manuals does not mention it. Can you tell me where is RTFValue and how to use it.

In my test, i have a Microsoft Access Memo field that contains all the RTF text.
Once loaded to a TextArea, I see that it has 88 StyleRuns and 16368 characters.
Using the standard TextArea1.StyledText.RTFData = strMyData is terribly slow, including the flicker you can see for the loading of every stylerun (i think so).

Using the demo program StyledText.rbp, pasting the text from my test program is practically the same, with the added problem that this demo uses memoryblocks, and I do not know how to assign the memoryblock to an Access Memo field, because of the binary zeros in the memory block.

Don’t know what to tell you…
I wrote a test program…

This loaded 309,856 characters of RTF data (19x bigger) and did it in 0.59 seconds

  Dim f As FolderItem
  Dim t As TextInputStream
  Dim rtfData As String
  Dim ms As Double
  ms=Microseconds
  f=GetFolderItem("").child("snapdragon.rtf")
  t=TextInputStream.Open(f)
  rtfData=t.readall
  t.close
  ms=Microseconds
  textarea1.StyledText.RTFData=rtfdata
  MsgBox Str((Microseconds-ms)/1000000)+" "+Str(rtfData.Len)

The solutions in that thread are for Mac only, I’m afraid.

Dave, I just tried your code (Xojo R3, Mavericks, Cocoa, not that I think that matters). Here’s what I got using the string (is in bold, if that matters):

This is a testThis is a test
This is a testThis is a test

  1. RTF file of about 700 characters - 4.5 seconds
  2. RTF file of 2000 characters – 115.5 seconds

Jon

I still don’t know what to tell you…
I ran that on Xojo3.1 , Mt. Lion, on a newer iMac

300,000+ characters in less than a second

I just this exact method in the notes section of a database application… where the notes are not huge… but routinely exceed 1 to 2k in size… and I have not noticed enough of a lag to be perceptible.

Dave: This is for Mac, the routine you posted is what I am already using for Windows, and loading my 16.000 characters lasts 6 seconds. In an old VB6 program, the same text lasts nothing to load.

There is no RTFValue property for Windows, so, I am thinking about some possibility to access the memory holded by the TextArea, and getting and setting it directly.

I wil try a test program using the RichTextBox.ocx, to know how complicated is to use it.

Just throwing this out there for information purposes. The Formatted Text Control has its own RTF reader/writer and is 100% Xojo code. It might be a solution for your needs as it is cross-platform. It also lets you have inline images and hyperlinks.

It’s not free but for those that need some of its features its worth it. Plus, it comes unencrypted so you can modify to suite your own needs. More information at http://www.bkeeney.com/formatted-text-control/

Hi Bob,
I would like to know if I can create Pdf from the field content (Formatted Text Control) using BKeeney Shorts
(I have MBS DynaPdf plugin too)
If yes, Please, could you give me same snippet ?

Thanks

[quote=45162:@luicano monti]Hi Bob,
I would like to know if I can create Pdf from the field content (Formatted Text Control) using BKeeney Shorts
(I have MBS DynaPdf plugin too)
If yes, Please, could you give me same snippet ?

Thanks[/quote]
You’ve asked me in a number of forums. The answer is I do not know. We’ve gotten RTF working in Shorts (using parts of FTC) and we’ve been abel to convert that to PDF. It’s not been extensively tested so we’re not sure what does NOT work yet.

I have investigated the possibility of converting to PDF directly from FTC. Since we were not the original developers of FTC there are some structure deficiencies that make it hard to do. We started with the FTIterator (see HTMLIterator) and attempted to use the example that MBS has for converting StyledText to PDF but it’s been only partially successful. Text converts but the styles and alignment do not and there are some other things that aren’t working very well yet either.

Thanks Bob.

Dear Bob,

I experimented today with the demo. I tried to load RTF created with Windows Wordpad. A 14,802 bytes document with pictures took forever until the program gave up. The same document without pictures loaded fine in about 1 second, but… Apparently, hard returns are seen as chr(13) return only and do not generate a linefeed. So text comes on top of the current line.

Same experiment with a TextEdit RTF worked perfectly, though.

I suppose it maybe possible to go around the bug by editing the source, but I am kind of dismayed at this time.

I had hoped a better level of compatibility with the Windows platform.

Any chance of seing a new version address such issues before I decide to purchase ?

TIA

You can send me your test document and I’ll look at when I can…

I just ran the same experiment ; results are reproductible. Will send you the files. Thank you.

Thanks!

Bob, if you find issues or ways to enhance the speed time of the RTF, please let me know. Opening up my about window (which as FTC embedded for the EULA) is slow. and the profiler says it is the insertRTF method that is taking all the time. I have only been able to play around/debug it just for a few minutes so I really havent had time to see where I am doing something wrong. And I am using 3.1.1 not 3.1.2.

thanks for FTC!
sb

There shouldn’t be any difference in that in version 3.1.2. Can you send me a copy of your EULA and how you’re loading it? Constant, load from file, etc. I’ll see what I can do.

I will send you the window/code later today… I am at a customer site that I dont have access to dropbox.

thanks!