Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get Font Size if I know the LOGFONT structure?

1,609 views
Skip to first unread message

Yong Wang

unread,
Jun 21, 1999, 3:00:00 AM6/21/99
to
I believe this is a simple question,
but I just can't find the answer.

Thank you in advance.

Yong Wang

Willem De Kock

unread,
Jun 21, 1999, 3:00:00 AM6/21/99
to
The LOGFONT structure has a lfHeight (int) member. This gives you the
height of the font in Logical units. Logical units depends on the mapping
mode of the current device context (CDC::GetMapMode), i.e. if map mode is
MM_LOENGLISH, then each logical point is 0.01 inch.

[Complex part] When you create a CFont object, then if you specify hieght
positively, then the hieght you specifiy is compared against the cell
height of the font (i.e. includes the gap above the top of 'T' and below
the bottom of 'g'. If you specify the height negatively, then the height is
compared against the character height of the font, i.e. does not include
the space above T or below g. I assume a LOGFONT functions similarly
(although cannot garantee), thus a positive value from lfHeight = logical
height of character cell of font, negative value from lfHeight = logical
height of characters themselves (exclusing surrounding cell). Logical
points can be converted to device points, thus height by examing the
MapMode and using LPtoDP CDC functions.

Hope this helps.
Regards.

Yong Wang <yw...@masterx.com> wrote in article
<OKT3j3Cv#GA....@cppssbbsa02.microsoft.com>...

Yong Wang

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to

Jim M

unread,
Jun 23, 1999, 3:00:00 AM6/23/99
to
"Yong Wang" <yw...@masterx.com> wrote:

What size do you want ?

Points ? Pixels ? Millimetres ?
Vertical Height ? Horizontal Width ?

From the help files:

LOGFONT:
structure member "lfHeight"

Specifies the height, in logical units, of the font's character cell
or character. The character height value (also known as the em height)
is the character cell height value minus the internal-leading value.
The font mapper interprets the value specified in lfHeight in the
following manner.


> 0 :
The font mapper transforms this value into device units and matches it
against the cell height of the available fonts.

0:
The font mapper uses a default height value when it searches for a
match.

< 0:
The font mapper transforms this value into device units and matches
its absolute value against the character height of the available
fonts.

For all height comparisons, the font mapper looks for the largest font
that does not exceed the requested size.

This mapping occurs when the font is used for the first time.

For the MM_TEXT mapping mode, you can use the following formula to
specify a height for a font with a given point size:

lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

Hope this helps,

Jim M
--
@ Derbyshire

Alejandro Nadal

unread,
Oct 21, 2022, 6:23:46 AM10/21/22
to
23 years later, thanks for this info :) . I hope you are still there.
El miércoles, 23 de junio de 1999 a las 9:00:00 UTC+2, Jim M escribió:

JiiPee

unread,
Oct 22, 2022, 1:49:07 AM10/22/22
to
On 21/10/2022 13:23, Alejandro Nadal wrote:
> 23 years later, thanks for this info 😄 . I hope you are still there.

did it solve the problem? :)

vinod kc

unread,
Dec 4, 2022, 5:37:09 PM12/4/22
to
I think I am using this formula from 2019 in my own gui library, but today I noticed that there is a minus sign on the left of MulDiv function. So I was passing a positive number to my LOGFONT struct and now I realized. And voilà !! Suddenly my apps are showing a different text size after I added the minus sign.

JiiPee

unread,
Dec 5, 2022, 10:42:41 AM12/5/22
to
ye I also noted the minus. the documentation explains its purpose
0 new messages