Page 1 of 1

Font Selector

Posted: Wed Jul 23, 2014 7:46 pm
by chris319
Here is a handy tool for selecting fonts and for obtaining the correct name for a font for use with LoadFont().

Code: Select all

FontRequester(#NULL$, #Null, #Null)
fontName$ = SelectedFontName()
fontSize = SelectedFontSize()

LoadFont(0, fontName$, fontSize)
OpenWindow(0, 0, 0, 600, 200, "Font Selector", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
StartDrawing (WindowOutput(0))
DrawingFont(FontID(0))
DrawText(50, 75, "Some text drawn in " + fontName$ + " " + Str(fontSize))
StopDrawing()

Repeat
  Delay(10)
Until  WaitWindowEvent() = #PB_Event_CloseWindow

Re: Font Selector

Posted: Thu Jul 24, 2014 2:34 pm
by blueb
Nice..

Be even handier if the program placed the information onto the clipboard
so that it would place into your IDE:

e.g. LoadFont(0, "Arial", 12, #PB_Font_Bold |#PB_Font_Underline)


Hmmm.. something to work on :)

Re: Font Selector

Posted: Thu Jul 24, 2014 3:41 pm
by falsam
Thank for sharing chris319:)

Add : Color & Style

Code: Select all

FontName$ = "Arial"         ; set initial font 
FontSize  = 14              ; set initial size 
FontColor = RGB(0, 0, 0)    ; set initial Color
FontStyle = 0               ; set initial Style

Result = FontRequester(FontName$, FontSize, #PB_FontRequester_Effects, FontColor, FontStyle)

If result
  FontName$= SelectedFontName()
  FontSize = SelectedFontSize()
  FontColor= SelectedFontColor()
  FontStyle= SelectedFontStyle()
  
  LoadFont(0, fontName$, fontSize, fontStyle)
  OpenWindow(0, 0, 0, 600, 200, "Font Selector", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
  StartDrawing (WindowOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(0))
  DrawText(50, 75, "Some text drawn in " + fontName$ + " " + Str(fontSize), FontColor)
  StopDrawing()

  Repeat
    
  Until  WaitWindowEvent(10000) = #PB_Event_CloseWindow
Else
  Debug "The requester was canceled."
EndIf

Re: Font Selector

Posted: Thu Jul 24, 2014 4:31 pm
by falsam
blueb wrote:Be even handier if the program placed the information onto the clipboard
so that it would place into your IDE:

e.g. LoadFont(0, "Arial", 12, #PB_Font_Bold |#PB_Font_Underline)


Hmmm.. something to work on :)
Save and create your executable (Example : Font Selector).

Code: Select all

Define.s Message, FontName, FontStyle
Define.i FontSize, n

Result = FontRequester("Arial", 10, 0, RGB(0, 0, 0), #False)

If result  
  If SelectedFontStyle()  
    FontStyle=", "
    
    If SelectedFontStyle() & #PB_Font_Bold 
      FontStyle + "#PB_Font_Bold"
    EndIf
    
    If SelectedFontStyle() & #PB_Font_Italic
      FontStyle + "#PB_Font_Italic"
    EndIf
  
    If SelectedFontStyle() & #PB_Font_StrikeOut
      FontStyle + "#PB_Font_StrikeOut"
    EndIf
    
    If SelectedFontStyle() & #PB_Font_Underline
      FontStyle + "#PB_Font_Underline"
    EndIf 
  
    If SelectedFontStyle() & #PB_Font_HighQuality
      FontStyle + "#PB_Font_HighQuality"
    EndIf
    
    FontStyle = ReplaceString(FontStyle, "#PB", "|#PB",0, 4)
  EndIf
    
  Message = "LoadFont(#PB_Any, " + Chr(34)+SelectedFontName()+Chr(34) +", " + Str(SelectedFontSize()) + FontStyle +")" 
   
  SetClipboardText(Message)
  HandleIDESci=Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
  SendMessage_(HandleIDESci, #WM_PASTE,0,0) 
EndIf

Add Font Selector in Pure Basic tools. Do not forget to assign a key or key combination shortcut to launch it from your editor.

Image

Re: Font Selector

Posted: Fri Jul 25, 2014 1:27 am
by chris319
This was written in about 15 minutes. You guys embellish it as you wish.

Re: Font Selector

Posted: Fri Jul 25, 2014 7:34 am
by davido
@chris319, Not bad for 15 minutes work!!
Saves me lots of time - can never remember the exact names of fonts.

Thank you, very much. :D

Re: Font Selector

Posted: Fri Jul 25, 2014 8:06 am
by Bisonte
Nice Shot @falsam :

Code: Select all

SetClipboardText(Message)
HandleIDESci=Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
SendMessage_(HandleIDESci, #WM_PASTE,0,0)
The idea to take the clipboard and paste some text to the ide.... Image

Re: Font Selector

Posted: Fri Jul 25, 2014 1:26 pm
by blueb
@falsam

Perfect... works for me! :D

Re: Font Selector

Posted: Wed Jul 30, 2014 7:06 am
by chris319
Unfortunately, it's not perfect. The optimum way to get a font name in Windows is as follows:
In Windows Explorer, right click on the font file name and bring up "Properties", then click on "Details" and look at "Title".
Without going into an elaborate explanation, this is due to the goofy way Windows handles fonts.

Re: Font Selector

Posted: Mon Apr 03, 2017 1:32 am
by chris319
Some embellishments have been added. It now prints the size and style.
The PB font selector sometimes concatenates the font name and style, e.g. the font name is Deja Vu Sans and the style is "Condensed"; the font name returned by the font selector will be "Deja Vu Sans Condensed".

The possible styles are:

Regular
Bold Italic
Bold
Italic
Underline
StrikeOut
High Quality

Code: Select all

;Font Preview
;Created on 12/20/2015 by chris319 UPDATED 4/2/2017
OpenWindow(1,0,0,1024,400,"Font Preview")

fontSize = 36: fontName$ = "arial"
result = FontRequester(FontName$, fontSize,#Null)

If result
  fontName$ = SelectedFontName()
  fontsize=SelectedFontSize()
  fontStyle=SelectedFontStyle()

  If fontStyle = #Null: fontStyle$ = "Regular"
  ElseIf fontstyle & 768: fontStyle$ = "Bold Italic"
  ElseIf fontStyle & #PB_Font_Bold: fontStyle$ = "Bold"
  ElseIf fontStyle & #PB_Font_Italic: fontStyle$ = "Italic"
  ElseIf fontStyle & #PB_Font_HighQuality: fontStyle$ = "High Quality"
  ElseIf fontStyle & #PB_Font_StrikeOut: fontStyle$ = "Strikeout"
  ElseIf fontstyle & #PB_Font_Underline: fontStyle$ = "Underline"
;  ElseIf fontstyle & #PB_FontRequester_Effects: fontStyle$ = ""
EndIf
EndIf

result = LoadFont(1,fontName$,fontSize)
StringGadget(1,0,0,900,200,"",#PB_String_BorderLess)

SetActiveGadget(1):SetGadgetFont(1,FontID(1))
SetGadgetColor(1,#PB_Gadget_BackColor,#Yellow)
SetGadgetText(1,fontName$ +"  " + Str(fontSize)+"  "+fontStyle$)

Repeat
event = WaitWindowEvent(1)

If event = #PB_Event_Gadget And EventGadget() = 3
result = FontRequester(FontName$, fontSize,#Null)

If result
  fontName$ = SelectedFontName():fontsize=SelectedFontSize()
EndIf

ElseIf Event = #PB_Event_CloseWindow
CloseWindow(1)
End
EndIf
ForEver