Page 1 of 1
Odd Question About Fonts
Posted: Sun Jul 27, 2014 7:10 pm
by chris319
I have an odd question about fonts.
When I draw a character in PB there is an enclosing background box which extends above and below the character forms themselves. Is this a function of PB, Windows, or the font itself? Does anyone know how the size of this enclosing box is calculated? I'm trying to align some text based on the tops and bottoms of the actual characters, rather than the enclosing box.
Re: Odd Question About Fonts
Posted: Sun Jul 27, 2014 7:33 pm
by luis
That's the cell around the char. It's there to make room for the ascending and descending part of the chars and their accents.
The height of the cell should be constant, the width is variable.
The chars are all aligned on a base line with part of some chars ascending and other descending from that.
You may find some of the info you are looking for in the TEXTMETRIC structure
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Some background on the nomenclature used
http://support.microsoft.com/kb/74299
Re: Odd Question About Fonts
Posted: Sun Jul 27, 2014 7:42 pm
by chris319
How would I set up and access a textMetric structure in PB for a given font?
Re: Odd Question About Fonts
Posted: Sun Jul 27, 2014 8:29 pm
by luis
chris319 wrote:How would I set up and access a textMetric structure in PB for a given font?
Code: Select all
Define TM.TEXTMETRIC
pointsize = 48
; http://msdn.microsoft.com/en-us/library/dd183499%28v=vs.85%29.aspx
fnt = LoadFont(#PB_Any, "Arial", -pointsize)
font_obj = FontID(fnt)
HWnd = 0 ; handle of your win here, 0 = desktop
hDC = GetDC_(HWnd)
Debug "logical height requested = " + StrF((pointsize * GetDeviceCaps_(hDC, #LOGPIXELSY)) / 72.0)
old_obj = SelectObject_(hDC, font_obj)
GetTextMetrics_(hDC, @TM)
SelectObject_(hDC, old_obj)
Debug "Height = " + TM\tmHeight
Debug "InternalLeading = " + TM\tmInternalLeading
Debug "Ascent = " + TM\tmAscent
Debug "Descent = " + TM\tmDescent
Debug "cell height = " + Str(TM\tmHeight + TM\tmInternalLeading)
Re: Odd Question About Fonts
Posted: Mon Jul 28, 2014 12:46 am
by chris319
Thank you for posting that sample code. Nice!
Re: Odd Question About Fonts
Posted: Fri Oct 16, 2015 12:55 am
by chris319
Re: Odd Question About Fonts
Posted: Fri Oct 16, 2015 4:21 am
by IdeasVacuum
It is indeed, thanks for that link! You can by the way use PB's 2D drawing lib to determine text size. That would be cross-platform so might be worth considering.