Page 1 of 1

GetGadgetFontName() and GetGadgetFontSize()

Posted: Sat Aug 03, 2013 2:23 am
by StarBootics
Hello,

Some 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.
So far, the only way I have found is to load an arbitrary font like :

Code: Select all

LoadFont(1, "Arial", 12, #PB_Font_Bold) 
LoadFont(2, "Arial", 12)
But doing this has many :
  • 1. Two fonts as to be Loaded/Unloaded
    2. We are mixing the default font and the loaded font together in the same GUI
Imagine if we can reload the default font with different setting like this :

Code: Select all

LoadFont(1, GetGadgetFontName(#PB_Default), GetGadgetFontSize(#PB_Default), #PB_Font_Bold)
Nice and sweet, 1 font loaded, no font mixing in the GUI.

Regards
StarBootics

Re: GetGadgetFontName() and GetGadgetFontSize()

Posted: Sat Aug 03, 2013 5:40 am
by Danilo
I would like this, too. It is good to know the default gadget font name and size for creating new custom gadgets and using different styles (Bold, Italic, HighQuality, Underline, ...),
or use the default GUI font with different sizes (for header, footer, chapters, ordinary text, etc.).

GetGadgetFontName() and GetGadgetFontSize(). Maybe add GetGadgetFontStyle() if possible (returns #PB_Font_Bold etc. flags combination).

Re: GetGadgetFontName() and GetGadgetFontSize()

Posted: Sat Aug 03, 2013 3:21 pm
by TI-994A
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. :wink:

Re: GetGadgetFontName() and GetGadgetFontSize()

Posted: Sat Aug 03, 2013 11:36 pm
by Andre
+1

Maybe a better way of implementation than I requested with CatchSystemFont(), although this goes in the same direction... :wink: