Page 1 of 1

Getting the systems default font

Posted: Wed Mar 25, 2009 5:18 pm
by funnyguy
I need to get the font name, size, style of the Window Style. So I can create the gadgets with the correct size

Posted: Wed Mar 25, 2009 7:48 pm
by srod
Are you talking about sizing a gadget to fit the text to be placed inside it?

I don't want to attempt to answer your question when I'm not very clear what it is you're after.

Posted: Fri Mar 27, 2009 3:57 am
by netmaestro
I honestly don't know how to get the font info from the handle, but you may find this of some use:

Code: Select all

; window to test with
OpenWindow(0,0,0,320,240,"")

; get its font
wfont = SendMessage_(WindowID(0),#WM_GETFONT,0,0)
If Not wfont
  wfont = GetStockObject_(#DEFAULT_GUI_FONT)
EndIf

; find size for longest string you want to use
tmp = CreateImage(#PB_Any, 1024, 100)
StartDrawing(ImageOutput(tmp))
  DrawingFont(wfont)
  Debug TextWidth("this is the longest string I will want to write")
  Debug TextHeight("This is how tall it will be")
StopDrawing()
FreeImage(tmp)

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow

Posted: Fri Mar 27, 2009 10:39 am
by srod
Once you have the font handle, GetObject_() will fill in a LOGFONT structure for you from which the relevant font metrics and face name can be obtained.

However, for gadget positioning etc. it is not the font metrics you require but the text metrics and for that, netty's code above will do the job quite nicely for 'standard fonts'. For things like italic fonts you need to delve a wee bit deeper, but things get complex at that point! :)