### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: TEdit height vs font size  (Read 1221 times)

#### Kaller

• New Member
• Posts: 44
##### TEdit height vs font size
« on: April 24, 2022, 03:30:42 am »
How does the height of a TEdit relate to the font height? Is it predictable?

#### dbannon

• Hero Member
• Posts: 2045
##### Re: TEdit height vs font size
« Reply #1 on: April 24, 2022, 05:24:42 am »
Seems to for me, is your experience otherwise ?  Here is '40' and '6' respectively.
Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

#### AlexTP

• Hero Member
• Posts: 1846
##### Re: TEdit height vs font size
« Reply #2 on: April 24, 2022, 07:41:48 am »
Poster means 'what is the formula to get the height from the font.size?'

#### dbannon

• Hero Member
• Posts: 2045
##### Re: TEdit height vs font size
« Reply #3 on: April 24, 2022, 09:40:49 am »
Well, in case the OP does want to know what the relationship is ....

1. Use the source Luke !
2. Remember, each OS will be different, these controls are drawn by the local systems, not Lazarus.
3. Do some tests -
Code: Pascal  [Select][+][-]
1. procedure TForm1.Button1Click(Sender: TObject);
2. begin
3.     Edit1.Font.Height := Edit1.Font.Height + 10;
4.     Memo1.Append('Font Height = ' + inttostr(Edit1.Font.Height) + ' and ctrl height = ' + inttostr(Edit1.Height));
5. end;

Gives me, on Linux using Mate Desktop, today -

Code: [Select]
`Font Height = 10 and ctrl height = 21Font Height = 20 and ctrl height = 32Font Height = 30 and ctrl height = 44Font Height = 40 and ctrl height = 55Font Height = 50 and ctrl height = 66Font Height = 60 and ctrl height = 77Font Height = 70 and ctrl height = 88Font Height = 80 and ctrl height = 100Font Height = 90 and ctrl height = 111Font Height = 100 and ctrl height = 122`
If you are only programming for one OS, my might be happy with the rule of thumb that data indicates but I most certainly would not trust it !  You will have to look at the source. Not a great answer. I won't send you a performance review .....

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

#### rvk

• Hero Member
• Posts: 4816
##### Re: TEdit height vs font size
« Reply #4 on: April 24, 2022, 09:57:39 am »
Have you looked at the wiki?
https://wiki.lazarus.freepascal.org/Font

The documentation is indeed severly lacking
https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tfont.height.html

For Windows you can also look at the documentation of Delphi.

Quote
Font.Height = -Font.Size * Font.PixelsPerInch / 72

Note that Height can be negative.
Quote
Use Height to specify the height of the font in pixels. If the value is negative, the internal leading that appears at the top of each line of text is not measured. If the value is positive, Height represents the height of the characters plus the internal leading.

« Last Edit: April 24, 2022, 09:59:35 am by rvk »

#### wp

• Hero Member
• Posts: 9908
##### Re: TEdit height vs font size
« Reply #5 on: April 24, 2022, 12:59:16 pm »
How does the height of a TEdit relate to the font height? Is it predictable?
Why do you want to know that? In order to align controls? Use anchoring instead (View > Anchor Editor, https://wiki.freepascal.org/Anchor_Sides)

#### dsiders

• Hero Member
• Posts: 673
##### Re: TEdit height vs font size
« Reply #6 on: April 24, 2022, 05:03:37 pm »
The documentation is indeed severly lacking
https://lazarus-ccr.sourceforge.io/docs/lcl/graphics/tfont.height.html

That URL has not been updated in some time.  Perhaps you can review https://dsiders.gitlab.io/lazdocsnext/lcl/graphics/tfont.html.

For Windows you can also look at the documentation of Delphi.
Quote
Font.Height = -Font.Size * Font.PixelsPerInch / 72

Which is also in in the graphics.pp source code.

I'll try to add the other information to the help topics. They'll appear on the URL I posted above.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

#### dsiders

• Hero Member
• Posts: 673
##### Re: TEdit height vs font size
« Reply #7 on: April 24, 2022, 06:00:42 pm »
I'll try to add the other information to the help topics. They'll appear on the URL I posted above.

Size and Height topics for TFont have been updated in:

https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/103d5a7c78fcfba17b31b069d4985975aebb314d

They will appear on LazDocsNext  with the next upload.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

• Hero Member
• Posts: 11773
##### Re: TEdit height vs font size
« Reply #8 on: April 24, 2022, 06:44:07 pm »
I hope it does not, because it is not correct:
1. negative size are pixels (screen)
2. positive size are points (canvas)

That also means that the formula given is not correct. It is only correct for a given resolution.

I will adapt it it to reflect how you really make sure it is correct. (Very old subject)
Black themes should be banned.

#### dsiders

• Hero Member
• Posts: 673
##### Re: TEdit height vs font size
« Reply #9 on: April 24, 2022, 07:19:32 pm »
I hope it does not, because it is not correct:
1. negative size are pixels (screen)
2. positive size are points (canvas)

That also means that the formula given is not correct. It is only correct for a given resolution.

I will adapt it it to reflect how you really make sure it is correct. (Very old subject)

I am always interested in corrections.

The formulas are documented as they exist today. I documented the relationship between Height and Size using the same. If that changes, obviously it'll have to be revisited. On my 96 DPI system, height and size interact as described.

Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

#### rvk

• Hero Member
• Posts: 4816
##### Re: TEdit height vs font size
« Reply #10 on: April 24, 2022, 11:01:24 pm »
I hope it does not, because it is not correct:
1. negative size are pixels (screen)
2. positive size are points (canvas)

That also means that the formula given is not correct. It is only correct for a given resolution.
That would be hugely contrary to the documentation of the Delphi-version.
There it says the internal leading is the difference for negative and positive. Not Pixels or points.

You probably meant that Size is in points and Height is in pixels.
Negative or positive has nothing to do with the choice of points or pixels (but with including internal leading or not).

#### jamie

• Hero Member
• Posts: 4672
##### Re: TEdit height vs font size
« Reply #11 on: April 25, 2022, 06:15:10 pm »
72 dpi rings a bell !
The only true wisdom is knowing you know nothing

#### Kaller

• New Member
• Posts: 44
##### Re: TEdit height vs font size
« Reply #12 on: May 15, 2022, 04:31:34 am »
The problem I had was to create an "in place" editing box for a caption inside a panel of a certain size and I wanted to know in advance exactly how must space an edit box would take up in the panel. There are canvas  functions for textwidth and textheight but the editbox is a little bigger, how much bigger?  So can that be calculated as some function of the text? I fudged it by creating a hidden sample text box and then discarding it but I wondered if I could just do a calculation? Or not.
« Last Edit: May 15, 2022, 04:40:13 am by Kaller »

#### AlexTP

• Hero Member
• Posts: 1846
##### Re: TEdit height vs font size
« Reply #13 on: May 15, 2022, 11:35:07 am »
Quote
> and I wanted to know in advance exactly how must space an edit box would take up in the panel.
It is not solvable in cross-platform way: all OS'es (widgetsets) have different calculations.

Especially macOS.
« Last Edit: May 15, 2022, 12:23:18 pm by AlexTP »