🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.ms.programmer
Article #1421

Re: Font madness...

#1421
From: Len POPP
Date: Wed, 27 Feb 1991 09:59
50 lines
2733 bytes
In article <1991Feb25.204847.18731@watserv1.waterloo.edu>,
tom@mims-iris.waterloo.edu (Tom Haapanen) writes:
>I'm trying to do some font handling, and having great difficulty
>despite RTFM, RTFM and RTFM again (all SDK manuals, Petzold and Yao).
>
>If I do EnumFonts() I can figure out what point sizes are available
>on a given hDC (by doing a GetTextMetrics() and other magic to convert
>a LOGFONT height into points).  But if I know what pointsize I want
>(say, 8-point Helv), how do I select that size?  CreateFontIndirect()
>and CreateFont() both want the height in device pixels, and including
>the internal leading of the font.  How do I get 8-point?

I recently had to deal with this problem myself.  The answer is ... RTFM!  :-)

In the Windows 3.0 SDK Reference vol. 1, under CreateFont, it says:

    nHeight	int	Specifies the desired height (in logical units) of
		the font.  The font height can be specified in three ways:
		if nHeight is greater than zero, it is transformed into
		device units and matched against the cell height of the
		available fonts.  [...]  If it is less than zero, it is
		transformed into device units and the absolute value is
		matched against the character height of the available fonts.
		[etc.]

(Similar words are found under LOGFONT in vol. 2.)

So:

1. The font height is given in logical units, ie. according to the current
   mapping mode of the hdc.  That may be something like MM_TWIPS, which is
   easy (8 pts == 160 twips), or it may be MM_TEXT, in which case you have
   to look at GetDeviceCaps(hdc, LOGPIXELSY) to figure out how big 8 points is.

2. If nHeight > 0, it's the "cell height"; if nHeight < 0, it's the
   "character height".  (This is a bit confusing, because these aren't the
   same terms that are defined in section 2.12.  Oh well.)  What this really
   means is that if nHeight is positive it includes internal leading, and if
   it's negative it doesn't.  So in your case, use a negative number to get
   an 8-point font.

Simple!

Disclaimer: I don't speak officially for Microsoft Corp.  I didn't write
Windows.  I do use it an awful lot, though.

		Len Popp
		uunet!microsoft!lenp, lenp@microsoft.uucp

P.S.  Who's your pick for the F1 championship this year, Tom?
Technical Details
Message-ID: <70920@microsoft.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!lenp
References: <1991Feb25.204847.18731@watserv1.waterloo.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!lenp
From: lenp@microsoft.UUCP (Len POPP)
Newsgroups: comp.windows.ms.programmer
Subject: Re: Font madness...
Keywords: Windows fonts
Message-ID: <70920@microsoft.UUCP>
Date: 27 Feb 91 09:59:01 GMT
References: <1991Feb25.204847.18731@watserv1.waterloo.edu>
Reply-To: lenp@microsoft.UUCP (Len Popp)
Organization: Microsoft Corp., Redmond WA
Lines: 50