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.
Odd Question About Fonts
Re: Odd Question About Fonts
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
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
"Have you tried turning it off and on again ?"
Re: Odd Question About Fonts
How would I set up and access a textMetric structure in PB for a given font?
Re: Odd Question About Fonts
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)
"Have you tried turning it off and on again ?"
Re: Odd Question About Fonts
Thank you for posting that sample code. Nice!
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Odd Question About Fonts
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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.