Recent

Author Topic: jDrawingView question about text size  (Read 1630 times)

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
jDrawingView question about text size
« on: May 27, 2019, 08:40:54 pm »
I'm happily using jDrawingView.DrawTextAligned in several places, but is there a way to know in advance how many pixels the text will take, horizontally and vertically?

For example, in Windows, we have TCanvas.TextWidth and TCanvas.TextHeight

Is it possible to get the same information in jDrawingView?

Thanks!
manlio mazzon gmail

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jDrawingView question about text size
« Reply #1 on: May 28, 2019, 01:01:37 am »

Ok.

I will try some solution/improvement!

Thank you!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
Re: jDrawingView question about text size
« Reply #2 on: May 30, 2019, 08:52:55 am »
That would be great, thanks!

And on the same subject, would it also be possible to set font properties like Bold and Italic?

Thanks!
manlio mazzon gmail

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jDrawingView question about text size
« Reply #3 on: June 02, 2019, 07:52:23 am »

Done!!!

NEW!

Property:
  TextTypeFace   

Methods:
    GetTextHeight
    GetTextWidth
    SetFontFromAssets
    DrawTextFromAssetsFont
    GetTextBox

Updated!
  demo "AppDrawingViewDemo1"

Thank you!!
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
Re: jDrawingView question about text size
« Reply #4 on: June 02, 2019, 11:38:31 am »
Thank you so much!

May I suggest one further enhancement? (I am going to do this in my copy of the code, perhaps you may want to include it for everyone)

Right now, DrawText, DrawTextAligned, DrawTextMultiline, etc. are procedures.

My suggestion is to change them to functions, which return the rectangle where the text has been drawn (like GetTextBox).

In this way, the old code doesn't change, if you don't need the text coordinates after DrawText you can ignore the result of the call. But if you need it, you can just get it from the result of the function.

At least in my case, this is an efficient way of doing things because:

1. Most of the time, when I write text on a drawingview, I want to know where it goes. This is especially true when I write several strings of text in various places on the screen.

2. When I don't care where the text goes, it's usually just a single string on a drawingview, so even if the function makes the extra work of getting the final position of the text, which I don't use, it doesn't really waste that much extra CPU time, and the convenience of having the position with one function call instead of two (every time) is much more than the extra CPU time I occasionally waste.

Anyway, that's what makes sense to me, you may consider whether it can also make sense in general.

Many heartfelt thanks for your great work.
manlio mazzon gmail

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jDrawingView question about text size
« Reply #5 on: June 02, 2019, 08:10:00 pm »
Quote
My suggestion is to change them to functions, which return the rectangle where the text has been drawn (like GetTextBox)....

Yes,  there may be some overload for intensive drawing/processing.... and more important: not memory disposed if the array [like GetTextBox] returned isn't used [and released!] by the user.....

So, we can think in something like functions  DrawTextF , DrawTextAlignedF, DrawTextMultilineF, etc.

F?  or Ex? or 2? or  B? or Box? ....

What about?

EDITED:  chosen Ex    .... "F"  is being used as "Format"  ( ex. StrToFloatF
« Last Edit: June 04, 2019, 08:04:11 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

Manlio

  • Full Member
  • ***
  • Posts: 164
  • Pascal dev
Re: jDrawingView question about text size
« Reply #6 on: June 03, 2019, 06:10:58 pm »
I didn't realize that the array needs to be freed by the user.

So, let me go back to the drawing board...

For now I will use the methods as they are. While working with them, I may end up writing some additional methods, for my convenience, and in that case, after testing them thoroughly, I'll send you a copy, and you may decide whether they are useful enough for inclusion in LAMW

Thank you and all the best :)
manlio mazzon gmail

jmpessoa

  • Hero Member
  • *****
  • Posts: 2302
Re: jDrawingView question about text size
« Reply #7 on: June 04, 2019, 07:59:07 am »
Done!

Added "DrawTextEx" functions to return  text box/frame....

[ Updated "AppDrawingViewDemo1" ]

Thank you!
« Last Edit: June 04, 2019, 08:04:57 am by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

 

TinyPortal © 2005-2018