Font Preview

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

Font Preview

Post by chris319 »

Here is a simple program for previewing fonts. It consists of two string gadgets, one above the other. The user selects a font, and text can be entered in the gadget. Click a button on the right side of the window to select a font.

This program has only been tested on Windows 7.

Code: Select all

;Font Preview
;Updated on 2/29/2016 by chris319
OpenWindow(1,0,90,1024,400,"Font Preview")
ButtonGadget(4, 910, 100,100, 80, "Row 1")
ButtonGadget(3, 910, 200,100, 80, "Row 2")
LoadFont(3,"Arial",14)
SetGadgetFont(3,FontID(3)):SetGadgetFont(4,FontID(3))
SetGadgetColor(3,#PB_Gadget_BackColor,$ffffff)
SetGadgetColor(4,#PB_Gadget_BackColor,$ffffff)
fontSize = 36
result = FontRequester(FontName$, fontSize,#Null)
If result
  fontName$ = SelectedFontName():fontsize=SelectedFontSize()
EndIf
result = LoadFont(1,fontName$,fontSize)
StringGadget(1,0,0,900,200,"",#PB_String_BorderLess)
StringGadget(2,0,200,900,200,"",#PB_String_BorderLess)
;SetActiveGadget(1):
SetGadgetFont(1,FontID(1))
SetGadgetText(1,fontName$)

Repeat
event = WaitWindowEvent(1)

If event = #PB_Event_Gadget And EventGadget() = 3 ;ROW 2
  result = FontRequester(FontName$, fontSize,#Null)
If result
  fontName$ = SelectedFontName():fontsize=SelectedFontSize()
EndIf

result = LoadFont(2,fontName$,fontSize)
SetGadgetText(2,fontName$)
SetGadgetFont(2,FontID(2))

ElseIf event = #PB_Event_Gadget And EventGadget() = 4 ;ROW 1
  result = FontRequester(FontName$, fontSize,#Null)
If result
  fontName$ = SelectedFontName():fontsize=SelectedFontSize()
EndIf

result = LoadFont(1,fontName$,fontSize)
SetGadgetText(1,fontName$)
SetGadgetFont(1,FontID(1))

ElseIf Event = #PB_Event_CloseWindow
CloseWindow(1)
End
EndIf
ForEver
Last edited by chris319 on Mon Feb 29, 2016 7:40 pm, edited 2 times in total.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Font Preview

Post by davido »

@chris319,
Looks interesting. Thank you.
Works on Mac by replacing #White with $FFFFFF.
DE AA EB
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Re: Font Preview

Post by chris319 »

The original post was updated on 2/29/2016. You can now select a font for either row.
Post Reply