Board index » delphi » DLR - RichEdit SLOW in getting attributes

DLR - RichEdit SLOW in getting attributes

I have another problem, when I scan thru all the text to get all the
attributes for all characters in a RichEdit, it can take quite some time
:( Especially if there is a bunch of text in there.

My problem is that MOST of the time, there are only a few places where
the text is not of the default attributes, but yet, I have to go thru
each character to get the attributes to see what they are.

Here's what I want to do. I want to take all bolded text and in my
output file stick keywords like {bold+} and {bold-} around text that is
bolded. And of course other formatting keywords as well. When I do:
For x:=1 to Lenght(rich1.text) do
     begin
      rich1.selstart:=x;
      rich1.sellength:=1;
      get the attributes and determine what to do
      end;

This takes a bit of time. If I remove the
selstart/sellength/gettattributes logic, then it flows pretty fast. I
would think there should be a way of scanning for anything that is not
default attributes and find out the text ranges for them. But I can find
anythihng like that, it seems I have to interogate EVERY text position.

So, if my text was:
     Have a NICE day
And the word "nice" was bold, using my logic, I would loop thru 15 times
looking at attributes to determine that the one word "nice" was bolded.
I would like to know if there is a function that returns a list of
textranges and their attributes. This would be faster.

Davie

 

Re:DLR - RichEdit SLOW in getting attributes


Quote
In article <3B27C970.2B76...@smatters.com>, Davie wrote:
> And the word "nice" was bold, using my logic, I would loop thru 15 times
> looking at attributes to determine that the one word "nice" was bolded.
> I would like to know if there is a function that returns a list of
> textranges and their attributes. This would be faster.

A faster way would be to use a binary chop technique making use of
SelAttributes.ConsistentAttibutes

First select all the text and then check

  if caBold in RichEdit.SelAttributes.ConsistentAttibutes

If true, then the text is either all bold or all non-bold and you check
via fsBold in SelAttributes.Style.

If caBold not within ConsistentAttributes, then some but not all of the
text is bolded and you can recursively split the selected text to check
each half.

When splitting, I would suggest checking the bold status at the split
point and adjust if the split occurs in the middle of bolded text.

Mike Orriss (TeamB and DevExpress)

Re:DLR - RichEdit SLOW in getting attributes


That's a GREAT idea. I would beg of you to show me an example of this is
actual code if you have any.,

Also, I don't fully understand what you mean by:

Quote
>>When splitting, I would suggest checking the bold status at the split
>>point and adjust if the split occurs in the middle of bolded text.

Do you mean to slide the split point until the status changes?

Davie

Quote
"Mike Orriss (TeamB)" wrote:
> In article <3B27C970.2B76...@smatters.com>, Davie wrote:
> > And the word "nice" was bold, using my logic, I would loop thru 15 times
> > looking at attributes to determine that the one word "nice" was bolded.
> > I would like to know if there is a function that returns a list of
> > textranges and their attributes. This would be faster.

> A faster way would be to use a binary chop technique making use of
> SelAttributes.ConsistentAttibutes

> First select all the text and then check

>   if caBold in RichEdit.SelAttributes.ConsistentAttibutes

> If true, then the text is either all bold or all non-bold and you check
> via fsBold in SelAttributes.Style.

> If caBold not within ConsistentAttributes, then some but not all of the
> text is bolded and you can recursively split the selected text to check
> each half.

> When splitting, I would suggest checking the bold status at the split
> point and adjust if the split occurs in the middle of bolded text.

> Mike Orriss (TeamB and DevExpress)

Re:DLR - RichEdit SLOW in getting attributes


Quote
In article <3B28F378.F92FE...@smatters.com>, Davie wrote:
> That's a GREAT idea. I would beg of you to show me an example of this is
> actual code if you have any.,

Not that I can find at the moment (still building my new W2K system from
the remnants of my crashed NT4).

Quote
> Do you mean to slide the split point until the status changes?

Yes. You do not want bolded text to be split between two sections.
Provided that the bold status is different between the left and right of
the split, it makes the code clean and concise.

Mike Orriss (TeamB and DevExpress)

Other Threads