Recent

Author Topic: [SOLVED] [LAMW] jCanvas and text measurement  (Read 20172 times)

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
Re: [LAMW] jCanvas and text measurement
« Reply #15 on: December 07, 2021, 07:25:10 am »
it'd be amazing!

I keep discovering it, I'm able to make pretty cool things but I can't find FontStyle. I found PaintTextSize but I can't figure out how to set the font Italic or Bold, is it possible? It'd be pretty useful.

« Last Edit: December 07, 2021, 10:07:18 am by r.lukasiak »

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
Re: [LAMW] jCanvas and text measurement
« Reply #16 on: December 07, 2021, 09:42:24 am »
I found some workaround for TextWidth and TextHeight. I use jDrawingView functions to calculate the dimensions and use them to draw the text on jCanvas but I'm not sure if there are some drawbacks of this solution but in my case it's giving (seemingly) accurate values.

After setting Canvas as needed:
Code: Pascal  [Select][+][-]
  1. DrawingView.FontSize:=round(Canvas.PaintTextSize);
  2. DrawingView.FontFace:=Canvas.Typeface;
  3. //DrawingView.TextTypeFace:=Canvas.???; //there is no TextTypeFace on jCanvas  
  4.  
and DrawingView.GetTextWidth or DrawingView.GetTextWidth seem to give accurate values.

I'm just wondering why the same properties  on DrawingView and Canvas (and other components as well) have different naming and what's even more surprising they have different data type. I don't know much about typography so real type for FontSize maybe makes sense (does it?) but as far as I'm concerned no pixel can be 0.5? (can it?). DrawingView.GetTextWidth returns single.
I don't mind using Round() but it just makes me wonder :-)

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: [LAMW] jCanvas and text measurement
« Reply #17 on: December 07, 2021, 06:13:59 pm »

Why you need jDrawingView? 
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
Re: [LAMW] jCanvas and text measurement
« Reply #18 on: December 07, 2021, 06:28:19 pm »
I'm using jDrawingView for calculating TextWidth and TextHeight. jCanvas doesn't have these functions so I'm using DrawingView to get it and I use the values to draw text on jCanvas. A little workaround :-) So far it's actually working well, however I'm not sure if there are some drawbacks :/

jmpessoa

  • Hero Member
  • *****
  • Posts: 2296
Re: [LAMW] jCanvas and text measurement
« Reply #19 on: December 08, 2021, 04:56:36 am »
Done!

Improved jCanvas component!

added new properties:

Code: Pascal  [Select][+][-]
  1.     property FontFace: TFontFace read FFontFace write SetFontface;
  2.     property TextTypeFace: TTextTypeFace read FTextTypeFace write SetTextTypeFace;  
  3.  

added new methods:

Code: Pascal  [Select][+][-]
  1.     function GetTextHeight(_text: string): single;
  2.     function GetTextWidth(_text: string): single;  
  3.  

warning:  the property "TypeFace" was replaced by "FontFace"

hint: on "Read error" dialog click "Continue loading" and then
delete jCanvas component from form and "Save All" the project....
and then insert  jCanvas again... and "Run" --> "Clean up and build" to produce new binaries...
« Last Edit: December 08, 2021, 04:59:21 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
Re: [LAMW] jCanvas and text measurement
« Reply #20 on: December 08, 2021, 06:32:01 pm »
Excellent! you made my day, Sir!
I'll test it in moment.

UPDATE:
I had updated using FPCupDeluxe but no effect, new functions weren't available so I downloaded sources from you website and just unzipped in the LAMW location. Functions are available, I modified my code, "clean up and build" but... now the app doesn't work at all. I also tried a new project and the same. only the title page shows up and nothing else happens (even though I set ActinBarTitle=abtHide)
Normally it appears just for a moment and then disappears behind my app but now it gets stuck on that screen.
Any clue what I screwed up?   :o
« Last Edit: December 08, 2021, 07:30:55 pm by r.lukasiak »

dseligo

  • Hero Member
  • *****
  • Posts: 1178
Re: [LAMW] jCanvas and text measurement
« Reply #21 on: December 08, 2021, 08:57:51 pm »
I had updated using FPCupDeluxe but no effect, new functions weren't available

I had same problem. To solve it I made small batch with following commands:
Code: Text  [Select][+][-]
  1. cd \LAMW\ccr\lamw
  2. C:\LAMW\fpcbootstrap\git\cmd\git.exe checkout master
  3. C:\LAMW\fpcbootstrap\git\cmd\git.exe reset --hard
  4. C:\LAMW\fpcbootstrap\git\cmd\git.exe pull
  5. pause

It came up with some errors ("overwritten by merge") in demos directory. I just deleted these directories and run batch file again with success (that was probably error in FPCUPdeluxe as well).
After that I just rebuild Lazarus.

so I downloaded sources from you website and just unzipped in the LAMW location. Functions are available, I modified my code, "clean up and build" but... now the app doesn't work at all. I also tried a new project and the same. only the title page shows up and nothing else happens (even though I set ActinBarTitle=abtHide)
Normally it appears just for a moment and then disappears behind my app but now it gets stuck on that screen.

Try to create new project and see if it works. Also try some simple demos to see if it works.
That way you'll know if the problem is in your app or in Lazarus installation.

r.lukasiak

  • Full Member
  • ***
  • Posts: 138
Re: [LAMW] jCanvas and text measurement
« Reply #22 on: December 08, 2021, 09:44:21 pm »
Quote
It came up with some errors ("overwritten by merge") in demos directory. I just deleted these directories and run batch file again with success (that was probably error in FPCUPdeluxe as well).
After that I just rebuild Lazarus.
I just downloaded and unzipped sources directly but the script is a better idea. I'm using Linux but git commands are the same so I can wrap it into a bash script.
Only thing I didn't do is rebuilding Lazarus. Now I'm trying to do so but it's giving me some error, it says clocale.ppu is missing but it's not. I'm trying to figure it out. Do you think not rebuilding Lazarus might cause my problem?

Quote
Try to create new project and see if it works. Also try some simple demos to see if it works.
That way you'll know if the problem is in your app or in Lazarus installation.
I tried a new project and the result is the same. It gets stuck on the title screen, even though it's supposed to be hidden. It doesn't even fire OnCreate event. I added ShowMessage on OnCreate even but it doesn't even show up.

UPDATE:
I reinstalled everything using FPXupDeluxe and it looks like this time it pulled the latest version of LAMW. I fired the update script and I got:
Quote
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
HEAD is now at f7178ffc Improved jCanvas component
Already up to date.
I opened my project, it mentioned something about Read Error so as you said, I removed jCanvas, saved the project and added it back. Everything went smoothly. I built the project etc but I faced the same problem, the app doesn't work, it stops at the title screen.

UPDATE #2:
I rebuilt everything one more time and now it seems to be ok, the app ran as it should. Now I'm testing new functions and they work perfectly!
One more time, thanks a lot for your great help!
« Last Edit: December 08, 2021, 10:21:12 pm by r.lukasiak »

 

TinyPortal © 2005-2018