Page 1 of 2

Hypertext Unicode support

Posted: Sat Mar 07, 2020 9:31 pm
by jgkoehn
I searched for this but can't figure out exactly what is going on.
I use RichViewEdit to load a RTF file with hyperlinks that have unicode in them.
However, when I test displaying them I have a problem in:

Code: Select all

procedure TMainForm.RichViewEditJump(Sender: TObject; id: Integer);
var
  RVData: TCustomRVFormattedData;
  ItemNo: Integer;
  s:      String;
begin
  RichViewEdit.GetJumpPointLocation(id, RVData, ItemNo);
  s := RVData.GetItemTag(ItemNo);
  HypTxt.Caption := 'Hyperlink:' + s; //Note this component is Unicode able
end;
The unicode is ???? or other characters not the correct characters which should be tw://[strong]?Λογος
I believe my problem is in a wrong setting in RichViewEdit or RVStyle but I can't figure it out.
You can see that unicode in the text displays just fine but hyerlinks do not.

I've attached a small rtf test file to use.

Re: Hypertext Unicode support

Posted: Sun Mar 08, 2020 9:51 am
by Sergey Tkachenko
This is an interesting RTF document. I did not think that a font keyword may be specified directly in a field code.
A font keyword also defines a code page for conversion from ANSI to Unicode, so hyperlink target (which is stored in RTF as ANSI text) is converted using a wrong code page.
It will be fixed in the next update.

Re: Hypertext Unicode support

Posted: Sun Mar 08, 2020 4:36 pm
by jgkoehn
Thank you Sergey,
A note that RTF was made in LibreOffice.
Here is another made in MS Word 365 and also the .docx that was converted to the rtf.

Do they seem to have the same thing going on?

Re: Hypertext Unicode support

Posted: Mon Mar 09, 2020 9:36 pm
by jgkoehn
Any idea on when the update will be?

Re: Hypertext Unicode support

Posted: Wed Mar 11, 2020 3:28 pm
by Sergey Tkachenko
It's the same problem. In the both these RTF documents, hyperlink target are stored as non-Unicode text.
The current version of TRichView converts hyperlink targets to Unicode using the default codepage specified in the RTF file. But it should be converted using the code page of the current font.
So this change will fix import of the both RTF documents.

We need to complete current work (porting SRVContols to Lazarus) before uploading. I hope we will be able to update TRichView in this weekend, or may be at the beginning of the next week.

Re: Hypertext Unicode support

Posted: Wed Mar 11, 2020 3:38 pm
by jgkoehn
Thanks sir appreciate the information

Re: Hypertext Unicode support

Posted: Thu Mar 19, 2020 8:40 am
by Sergey Tkachenko

Re: Hypertext Unicode support

Posted: Thu Mar 19, 2020 1:07 pm
by jgkoehn
Thank you sir

Re: Hypertext Unicode support

Posted: Thu Mar 19, 2020 8:55 pm
by jgkoehn
I installed the update but how can I check to make sure I have 18.3 installed? I still have the same error could be something on my end.
I'm working Delphi 7 The file I downloaded has 3/19/2020 as its date.

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 9:06 am
by Sergey Tkachenko
Every TRichView/TRichViewEdit control displays a version number at designtime. It must be 18.3.

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 3:04 pm
by jgkoehn
Ah thanks will check. Thank you

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 4:22 pm
by jgkoehn
Greetings, I do have 18.3 installed and that first file still gives ????? in a unicode enabled component. Thoughts?

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 5:42 pm
by Sergey Tkachenko
How do you view this string?
Delphi 7 is not Unicode-capable, neither Delphi IDE itself, nor its VCL controls.
So, if you view this string, even if it is loaded correctly, characters that cannot be converted from Unicode will be displayed as '?'.

I suggest a test.
Open ActionTest project (<TRichView Dir>\RichViewActions\Demos\Delphi\ActionTest\). Build it with debug info.
Open <TRichView Dir>\RichViewActions\Source\RichViewActions.pas
Put a breakpoint on the line 2027:

Code: Select all

  if DoShowForm(rve, InsertNew, Text, LinkTarget
Open your RTF in the ActionTest.
Right-click this hyperlink, choose "Hyperlink" in the context menu.
When Delphi stops on the breakpoint, press Ctrl+F7 to open "Evaluate/Modify" window.
Check the value of LinkTarget
It must be 'D:\Test\tw://[strong]??????'
But are '?' really question mark characters? Check the value of ord(LinkTarget[Length(LinkTarget)]),x
If this is a real question mark, it will be $3F.
If this is 'ς' (as it should), it will be $3C2.
If you want to edit Unicode strings in Delphi 7 application, you can use TNT Controls / TMS Unicode Components. RichViewActions can use them, if you compile your application with USERVTNT $define (you can activate it in RV_Defs.inc file).

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 8:23 pm
by jgkoehn
Yes, I've worked a lot with unicode in Delphi7. Thanks for the information that got me to thinking about something else. I found the problem.
My s was setting to String instead of WideString. Now to figure out the next portion. Thanks again.

Code: Select all

procedure TMainForm.RichViewEditJump(Sender: TObject; id: Integer);
var
  RVData: TCustomRVFormattedData;
  ItemNo: Integer;
  s:      String;
begin
  // NOTE: OnJump is called after the caret is repositioned to clicked item
  // But warning: a clicked item is not necessarily an active item!
  // (when clicking on left part of a picture or left part of the first character
  // a text item,
  // the caret moves before the item and the previous item becomes active!)
  RichViewEdit.GetJumpPointLocation(id, RVData, ItemNo);
  s := RVData.GetItemTag(ItemNo);
  HypTxt.Caption := 'Hyperlink:' + s;
  //Application.MessageBox(PChar(Format('Tag of clicked hyperlink is "%s"', [s])),
    //'Hyperlink', MB_OK or MB_ICONINFORMATION);
end;
This should be:

Code: Select all

procedure TMainForm.RichViewEditJump(Sender: TObject; id: Integer);
var
  RVData: TCustomRVFormattedData;
  ItemNo: Integer;
  sW:      WideString;
begin
  // NOTE: OnJump is called after the caret is repositioned to clicked item
  // But warning: a clicked item is not necessarily an active item!
  // (when clicking on left part of a picture or left part of the first character
  // a text item,
  // the caret moves before the item and the previous item becomes active!)
  RichViewEdit.GetJumpPointLocation(id, RVData, ItemNo);
  sW := RVData.GetItemTag(ItemNo);
  HypTxt.Caption := 'Hyperlink:' + sW;
  //Application.MessageBox(PChar(Format('Tag of clicked hyperlink is "%s"', [sW])),
    //'Hyperlink', MB_OK or MB_ICONINFORMATION);
end;

Re: Hypertext Unicode support

Posted: Fri Mar 20, 2020 8:32 pm
by jgkoehn
Excellent sir, working now. Plus the other problem for me was I think I was trying it on a RTF file that was not that great code wise. This simple one works good. Thanks again and for your patience.