Hypertext Unicode support

General TRichView support forum. Please post your questions here
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Hypertext Unicode support

Post 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.
Attachments
test.rtf
(759 Bytes) Downloaded 1851 times
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Hypertext Unicode support

Post 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.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post 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?
Attachments
Test2.rtf
(43.47 KiB) Downloaded 1797 times
Test2.docx
(11.94 KiB) Downloaded 1753 times
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post by jgkoehn »

Any idea on when the update will be?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Hypertext Unicode support

Post 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.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post by jgkoehn »

Thanks sir appreciate the information
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post by jgkoehn »

Thank you sir
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Hypertext Unicode support

Post by Sergey Tkachenko »

Every TRichView/TRichViewEdit control displays a version number at designtime. It must be 18.3.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post by jgkoehn »

Ah thanks will check. Thank you
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post by jgkoehn »

Greetings, I do have 18.3 installed and that first file still gives ????? in a unicode enabled component. Thoughts?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Hypertext Unicode support

Post 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).
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post 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;
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: Hypertext Unicode support

Post 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.
Post Reply