Lazarus

Programming => Packages and Libraries => Topic started by: torumyax on February 10, 2018, 06:25:43 pm

Title: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 06:25:43 pm
Hi! (from Japan)

I just started using Lazarus a few weeks ago. (and am very happy, thank you guys!)

Then I just realized VirtualTreeView-Lazarus 5.5.3-r1 does not show Kanji characters correctly on Ubuntu. It displays fine on Windows.
(see attachment)

Strangely, Hiragana and Katakana characters are displayed correctly. It gets half disappeared only when string contains Kanji characters.

Setting DefaultNodeHeight and changing the font setting don't seem to change anything.

Could you give me any suggestion? Much appreciated.


-------------------------------------------------------
Windows 10:
Lazarus 1.8.0 r56594 FPC 3.0.4 x86_64-win64-win32/win64

Ubuntu 17.10
Lazarus 1.8.0 rc4+dfsg-1 FPC 3.0.2 x86_64-linux-gtk2
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 07:36:08 pm
OK, I just created and attached the simplest project with a test file. Thanks!
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 07:48:55 pm
Hi torumyax,

Where you display in VTV "< not good" how should the correct text look like? I compared the text with the one from the txt file and it looks the same to me. Can you paste here the correct versions?


PS: If you paste the text in a TEdit, it displays correctly?
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 07:56:46 pm
Hello GetMem. Thanks for the reply.

I posted the screenshot in the first post where it shows both wrong (on Ubuntu) and correct (on Windows).

https://forum.lazarus.freepascal.org/index.php?action=dlattach;topic=40042.0;attach=25209;image

Cheers!

PS: A TEdit displays it correctly.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 08:10:54 pm
The example project I attached shows, on Ubuntu, like this (see attachment).
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 08:11:31 pm
@torumyax
Ok. I see now. Unfortunately I don't have Ubuntu to test, strangely enough on Linux Mint the text is displayed correctly. Please try the following(OnPaintText event):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.VirtualStringTree1PaintText(Sender: TBaseVirtualTree;
  2.   const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   TextType: TVSTTextType);
  4. begin
  5.   if TextType = ttNormal then
  6.     TargetCanvas.Font.Size := ; //decrease the font here, try to change the font type if necessary
  7. end;

Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 08:19:38 pm
@GetMem
Tried. No luck... orz
(see the attachment)
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 08:26:30 pm
OK then. The next thing we should try is to draw the text manually. Please set DefaultNodeHight to a slightly larger value 25 for example, then:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.VirtualStringTree1PaintText(Sender: TBaseVirtualTree;
  2.   const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   TextType: TVSTTextType);
  4. var
  5.   Data: PNodeData;
  6.   R: TRect;
  7. begin
  8.   if TextType = ttNormal then
  9.   begin
  10.     Data := VirtualStringTree1.GetNodeData(Node);
  11.     SetBKMode(TargetCanvas.Handle, TRANSPARENT);
  12.     TargetCanvas.Font.Name := 'Sans Serif';
  13.     TargetCanvas.Font.Size := 12;
  14.     R := TBaseVirtualTree(Sender).GetDisplayRect(Node, Column, False);
  15.     DrawText(Canvas.Handle, PChar(Data^.Column0), Length(Data^.Column0), R, DT_LEFT or DT_BOTTOM or DT_SINGLELINE);
  16.   end;
  17. end;
You can play with the values(Font size, font type, DT_Bottom, etc..).
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 08:36:58 pm
Done. But I got compile errors...
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 08:37:57 pm
Quote
Done. But I got compile errors...
uses LCLIntf, LCLType; 
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 08:45:59 pm
Opps, newbie... Thank you.

It gets little better.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 08:49:32 pm
Quote
It gets little better.
Try to change the font size to 10 or 9. You can play with other font types too.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 08:57:38 pm
It got better, but this seems to be a temp workaround. It still shows a line with Kanji character slightly lower than other lines...
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 09:02:21 pm
Quote
It got better, but this seems to be a temp workaround. It still shows a line with Kanji character slightly lower than other lines...
Instead of  DT_BOTTOM you can use DT_VCENTER (vertical center).
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 09:09:44 pm
Quote
Instead of  DT_BOTTOM you can use DT_VCENTER (vertical center).

I thought "That's it" But it did not affect...

I set DefaultNodeHeight to default this time. See the lines with Kanji are lower than other?
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 09:18:42 pm
Quote
I thought "That's it" But it did not affect...
I set DefaultNodeHeight to default this time. See the lines with Kanji are lower than other?
This is really hard  :). When you have a Kanji text and you're under linux, do something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.VirtualStringTree1PaintText(Sender: TBaseVirtualTree;
  2.   const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   TextType: TVSTTextType);
  4. var
  5.   Data: PNodeData;
  6.   R: TRect;
  7. begin
  8.   if TextType = ttNormal then
  9.   begin
  10.     Data := VirtualStringTree1.GetNodeData(Node);
  11.     SetBKMode(TargetCanvas.Handle, TRANSPARENT);
  12.     TargetCanvas.Font.Name := 'Sans Serif';
  13.     TargetCanvas.Font.Size := 12;
  14.     R := TBaseVirtualTree(Sender).GetDisplayRect(Node, Column, False);
  15.     {$IFDEF LclGtk2},
  16.     Dec(R.Top, 2); //only on linux and with Kanji
  17.     {$ENDIF};
  18.     DrawText(Canvas.Handle, PChar(Data^.Column0), Length(Data^.Column0), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
  19.   end;
  20. end;
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 09:27:16 pm
No luck..
(BTW, I removed , after the compiler directive)

Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 09:30:07 pm
Not R.Left, you need R.Top(I edited my post in the mean time), sorry for the confusion.
Code: Pascal  [Select][+][-]
  1.  
  2. //..
  3.  {$IFDEF LclGtk2},
  4.  Dec(R.Top, 2); //only on linux and with Kanji
  5.  {$ENDIF};
  6. //..

PS: But you need to detect somehow between Kanji and other text type.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 09:34:31 pm
Oh, I got it.
But, it did not change. Even if I changed it to 
Dec(R.Top, 4);
or Dec(R.Top, 8);
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 09:42:04 pm
OMG torumyax. We did not see the mistake, it was a typo. Instead of:
Quote
DrawText(Canvas.Handle, PChar(Data^.Column0), Length(Data^.Column0), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
we need:
Quote
DrawText(TargetCanvas.Handle, PChar(Data^.Column0), Length(Data^.Column0), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE);

DT_VCENTER should work fine.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 10, 2018, 09:51:16 pm
Aha. it happens. :D

Now something is happening.
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: balazsszekely on February 10, 2018, 09:55:24 pm
Now just remove the ifdef, you don't need it:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.VirtualStringTree1PaintText(Sender: TBaseVirtualTree;
  2.   const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  3.   TextType: TVSTTextType);
  4. var
  5.   Data: PNodeData;
  6.   R: TRect;
  7. begin
  8.   if TextType = ttNormal then
  9.   begin
  10.     Data := VirtualStringTree1.GetNodeData(Node);
  11.     SetBKMode(TargetCanvas.Handle, TRANSPARENT);
  12.     TargetCanvas.Font.Name := 'Sans Serif';
  13.     TargetCanvas.Font.Size := 10;
  14.     R := TBaseVirtualTree(Sender).GetDisplayRect(Node, Column, False);
  15.     DrawText(TargetCanvas.Handle, PChar(Data^.Column0), Length(Data^.Column0), R, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
  16.   end;
  17. end;
Title: Re: VirtualTreeView shows Kanji characters half dissapeared on Ubuntu
Post by: torumyax on February 24, 2018, 01:57:11 pm
Just an update...

It seems this is a widgetset bug.
https://bugs.freepascal.org/view.php?id=33215

ps. thanks a lot @GetMem.
TinyPortal © 2005-2018