StarBootics wrote:...I would like to do is to reload the gadget font currently in use as a default one with different setting such as #PB_Font_Bold and/or #PB_Font_Italic...
Hello StarBootics. It would indeed be great to have such a cross-platform function, especially to match the default UI font. For the time being, here's a Windows-only workaround:
Code: Select all
EnableExplicit
Enumeration
#MainWindow
#Text1
#Text2
#Text3
#Font
EndEnumeration
Define sysFont.LOGFONT, sysFontName.s
Define wFlags, yDPI, scrDC, sysFontID, sysFontPointSize
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 400, 140, "Font Metrics", wFlags)
TextGadget(#Text1, 20, 10, 180, 20, "drawn with default gadget font:")
TextGadget(#Text2, 200, 10, 200, 20, "default gadget font, bold && italic:")
TextGadget(#Text3, 20, 60, 300, 80, "")
scrDC = StartDrawing(WindowOutput(#MainWindow))
yDPI = GetDeviceCaps_(scrDC, #LOGPIXELSY)
sysFontID = GetGadgetFont(#PB_Default)
Box(0, 35, 400, 15, #White)
DrawingFont(sysFontID)
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(20, 35, "AaBbCcDdEeFfGgHhIiJjKk", #Red)
StopDrawing()
GetObject_(sysFontID, SizeOf(LOGFONT), @sysFont)
sysFontName = PeekS(@sysFont\lfFaceName[0])
sysFontPointSize = MulDiv_(-sysFont\lfHeight, 72, yDPI)
SetGadgetText(#Text3, "Font data from GetGadgetFont():" + #CRLF$ +
"name: " + sysFontName + #CRLF$ +
"pixel height: " + Str(-sysFont\lfHeight) +
#CRLF$ + "point size: " + sysFontPointSize)
LoadFont(#Font, sysFontName, sysFontPointSize, #PB_Font_Bold | #PB_Font_Italic)
StartDrawing(WindowOutput(#MainWindow))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font))
DrawText(200, 35, "AaBbCcDdEeFfGgHhIiJjKk", #Blue)
StopDrawing()
While WaitWindowEvent() ! #PB_Event_CloseWindow : CloseWindow : Wend
I posted this in another thread, but adapted it here to re-load the default font with bold & italic styles.
