GetGadgetFontName() and GetGadgetFontSize()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
StarBootics
Addict
Addict
Posts: 1006
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

GetGadgetFontName() and GetGadgetFontSize()

Post 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
The Stone Age did not end due to a shortage of stones !
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: GetGadgetFontName() and GetGadgetFontSize()

Post 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).
User avatar
TI-994A
Addict
Addict
Posts: 2705
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: GetGadgetFontName() and GetGadgetFontSize()

Post 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:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: GetGadgetFontName() and GetGadgetFontSize()

Post by Andre »

+1

Maybe a better way of implementation than I requested with CatchSystemFont(), although this goes in the same direction... :wink:
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Post Reply