Font Metrics

Share your advanced PureBasic knowledge/code with the community.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Font Metrics

Post by chris319 »

Here is a little program for font metrics based on code posted by Luis here: http://www.purebasic.fr/english/viewtop ... 69#p449339

Code: Select all

     Define TM.TEXTMETRIC
     
     pointsize = 100
     
     ; 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 "Point size: " + Str(pointsize)
     ;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 "Internal Leading = " + TM\tmInternalLeading
     Debug "External Leading = " + TM\tmExternalLeading
     Debug "Ascent = " + TM\tmAscent
     Debug "Descent = " + TM\tmDescent
     Debug "cell Height = " + Str(TM\tmHeight + TM\tmInternalLeading)