string underlined like in spelling

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

string underlined like in spelling

Post by Cosmin3 »

Hi.
I want to use some of the spelling code so I can underline some strings in ScaleRichView. This strings can contain any character.
I can't use the code as it is because:
1. It has to work for any "delimiters".
2. The spelling is not using Unicode.

I just want to find the (wide)strings in visible area and underline them.
I found TRVWordMisspellPainter.Draw in RVWordPaint.pas but I don't know how to use it.

Can you help me, please?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This functionality is not supported. You can try to implement it, but with not guarantees. I know some users tried to use it, even created their new word painters, using different drawing method (not wavy underlines).

Generally, it should work like this:

Code: Select all

function GetWordPaintList(RVData: TCustomRVFormattedData; ItemNo: Integer): TRVWordPainterList; 
var 
  Item: TCustomRVItemInfo; 
begin 
  Item := RVData.GetItem(ItemNo); 
  if not Assigned(Item.WordPaintList) then 
    Item.WordPaintList := TRVWordPainterList.Create; 
  Result := Item.WordPaintList; 
end;
Adding underlines to the ItemNo-th item in RVData, between characters specified with StartOffs and Length:

Code: Select all

GetWordPaintList(RVData, ItemNo).Add(TRVWordMisspellPainter.Create(StartOffs, Length)) 
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Thank you.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

I intend to make a separate thread in which the text from ScaleRichView will be scanned and some strings underlined.
Are there any special precautions I should take with ScaleRichView/RichViewEdit or I can make a standard thread?
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

I have 2 suggestions for a future version:
1. Ability to underline tab items as well;
2. In RVData.GetItem(ItemNo).WordPaintList to be able to set underline color for each item. I mention this because I use underline not just for spelling and I want, for example, to underline in the same time words with red and something else with orange.

And 2 bugs to report:
1. For a text in a table cell: when the last line is close to the down border cell then the underline is not visible.
2. In a ScaleRichView page if the last text line is right before the dot line then the underline is visible on the next page.

I hope you'll implement/fix these as soon as possible.
Thank you.
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post by proxy3d »

You can send me example RVF of the document for the first bug?
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Sorry for the delayed reply; my internet connection was down for almost 2 days.
The text file is not a rvf; it's a rtf. It's created with WordXP and modified with Wordpad.
It's easy to make one. But if you stil want me to send you the file, I will send it...
Here is a link to a screen capture with both situations: with or without a new line between undelined text and border cell
http://img134.imageshack.us/my.php?image=capturens2.png
You can clearly notice that most of the red line is not visible. It's not easy for the user to see that is underlined.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

A problem with InvalidateDrawItem.
It's a RichViewEdit function, I know, but I think the problem may be connected with ScaleRichView also.
When I use it in a separate thread it doesn't always repaint the item (Spacing parameter is 3). But if I use Spacing 1000 (!) it works.
This happens sometimes only when I edit the item. Other methods of changing the text, like Paste, work fine.
For example if in a text line I have "Line2" (underlined) and I insert a space between "Line" and "2" then "Line" continues to be underlined.
But if I Insert a space using Paste then "Line" is not underlined anymore.
In both cases TCustomRVFormattedData(CurRVData.GetRVData).InvalidateDrawItem(ItemNo, 3) is executed exactly the same.
After the editing operation if I "force" a RePaint (for example if I minimize then restore the application) then the red underline is erased.

The thread is stopped in a safe place at OnChanging event, at OnItemTextEdit event RVData.GetItem(ItemNo).ItemState is set to [] and then at OnChange event the thread is restarted. After 200 ms it rescans the hole text line in which the modified item is and calls InvalidateDrawItem for each item (from the text line).

A similar problem is with the code from LiveSpelling.
In OnSpellingCheck event I wrote "if AWord = 'Misspelledtext' then Misspelled := True;". In a text line in editor I wrote "Misspelledtext". It's underlined.
I insert a space between "Misspelled" and "text". The underline is gone.
I remove the space using only Delete/Backspace. "Misspelledtext" is not underlined. Only if I move the text cursor or if I force a RePaint the underline is drawn.
Strange, if I select the space then I press Delete then the underline is drawn immediately.

Please help me solve the problem.
Thank you.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Strange, I cannot reproduce the problem with not updating live spelling underlines.
I added the following code in OnSpellingCheck:
Misspelled := Pos('a', AWord)<>0;
and played with it.
It worked as expected, when I added space and deleted it by backspace (both in 'aaabbb' and in 'bbbaaa').

Do you use the latest version of ScaleRichView?
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Yes, I'm using the latest version.

The problem is not from my code - I just now tried with ActionTest Demo.
I wrote "Misspelledtext" in a new line at the beginning in readme.rvf, I saved and then I closed the application.
I opened it again; "Misspelledtext" is not underlined. Only if I edit the file anywhere else then it's underlined.
Afterward is behaving exactly like I said: insert a space between "Misspelled" and "text" + delete it with backspace = "Misspelledtext" not underlined (until I move the text cursor).
I said in my previous post "This happens sometimes only when I edit the item".
This means that for some words in text it works, for others it doesn't.

If you want I will send you this modified version (even the exe file if you want to).

PS: the difference between my test and your test is that when you insert a space one of the two new words is underlined. In my case neither of them are underlined. This has an influence on how is underlined when the space is deleted with backspace.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I understand. It is not underlined because this word is considered as being edited. Such words are not underlined until you move the caret.

MS Word works in the same way, even more strictly (the edited word is not underlined until you move the caret outside of it. In TRichViewEdit/TSRichViewEdit, any caret movement causes rechecking the edited word).
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

Ok, but now what can I do with the (related I think) problem in my thread? Do I have to set Spacing parameter at 1000 in InvalidateDrawItem so it could work?
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Spacing=1000 invalidates 1000 pixels around this item, i.e. usually the full window.
Can you test your code on TRichViewEdit? I am not sure where the problem is - in TRichViewEdit itself or in ScaleRichView.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

I believe it's happening only in ScaleRichView.
But to make sure I will test also in TRichViewEdit.

Later edit: Hmm, looks like I was wrong. It does the same in RVEditDemo.
If you want I will send you this modified demo so you can debug the problem more easily...
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, send the demo (as simple as possible, with TRichViewEdit) to [email protected]
Post Reply