Share your advanced PureBasic knowledge/code with the community.
chris319
Enthusiast
Posts: 782 Joined: Mon Oct 24, 2005 1:05 pm
Post
by chris319 » Wed Jul 23, 2014 7:46 pm
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
blueb
Addict
Posts: 1044 Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico
Post
by blueb » Thu Jul 24, 2014 2:34 pm
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
- It was too lonely at the top.
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
falsam
Enthusiast
Posts: 630 Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:
Post
by falsam » Thu Jul 24, 2014 3:41 pm
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
➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect.
falsam
Enthusiast
Posts: 630 Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:
Post
by falsam » Thu Jul 24, 2014 4:31 pm
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.
➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect.
chris319
Enthusiast
Posts: 782 Joined: Mon Oct 24, 2005 1:05 pm
Post
by chris319 » Fri Jul 25, 2014 1:27 am
This was written in about 15 minutes. You guys embellish it as you wish.
davido
Addict
Posts: 1890 Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK
Post
by davido » Fri Jul 25, 2014 7:34 am
@
chris319 , Not bad for 15 minutes work!!
Saves me lots of time - can never remember the exact names of fonts.
Thank you, very much.
DE AA EB
Bisonte
Addict
Posts: 1233 Joined: Tue Oct 09, 2007 2:15 am
Post
by Bisonte » Fri Jul 25, 2014 8:06 am
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....
P ureB asic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom
English is not my native language...
(I often use DeepL to translate my texts.)
blueb
Addict
Posts: 1044 Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico
Post
by blueb » Fri Jul 25, 2014 1:26 pm
@falsam
Perfect... works for me!
- It was too lonely at the top.
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
chris319
Enthusiast
Posts: 782 Joined: Mon Oct 24, 2005 1:05 pm
Post
by chris319 » Wed Jul 30, 2014 7:06 am
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.
chris319
Enthusiast
Posts: 782 Joined: Mon Oct 24, 2005 1:05 pm
Post
by chris319 » Mon Apr 03, 2017 1:32 am
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