Page 1 of 1

Font Preview

Posted: Sun Dec 20, 2015 7:35 pm
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

Re: Font Preview

Posted: Sun Dec 20, 2015 10:18 pm
by davido
@chris319,
Looks interesting. Thank you.
Works on Mac by replacing #White with $FFFFFF.

Re: Font Preview

Posted: Mon Feb 29, 2016 7:28 pm
by chris319
The original post was updated on 2/29/2016. You can now select a font for either row.