|
Post by honky on Aug 2, 2021 14:58:19 GMT
Hello xxgeek, with your "magic VBS code", would there be a way to force Jb to choose a font that we would have put in the folder with the JB code, in the same form as the one they have in the Windows/Font folder of the OS (".ttf") ? Magic it's magic
|
|
|
Post by tsh73 on Aug 2, 2021 17:40:40 GMT
Having TTF file along JB program will not do your any good For font could be used, they have to be installed by OS (that is, Windows)
But again, it has to be done only once
"If you want this program look really slick please install fonts from program folder" , kind of ?
we had old processor simulator (written in old VB) which use font to present 8 HEX digits as seven-segment display indicator Without font it defaults to Times New Roman About half of installations go with Times New Roman ;)
|
|
|
Post by xxgeek on Aug 2, 2021 19:21:22 GMT
Intriguing question Honky. Depending on what you are trying to accomplish it could be as easy as 1 2 3, or it could be a fairly difficult undertaking.
1. If you are writing this for your own PC, then it's easy. 2. If you want your program to work on another PC, then you've got some work to do.
By default, Windows 10 does not allow the running of Powershell scripts, but it does allow cmd.exe to run batch scripts. and with a batch script you can do most anything, including getting around Windows security.
On your own PC: Copy your font.ttf file into the c:\Windows\Fonts folder by hand (not using JB code, it's a protected folder and you'll get an "access denied"" error at runtime) Then in your JB code, use that font as you would any other font.
On someone elses PC: This is a different story and quite involved. Not sure if appropriate to discuss here because it involves "elevated priviledges", and bypassing Windows security. It can be done, but I can't detail it for you. You'll have to research it.
Basically though, you'll need to have cmd.exe call a batch script to elevate priviledges that allow running powershell scripts. Have your code write a batch script, and either a vbs script or a powershell script. The batch script is allowed to run using cmd.exe, but powershell scripts are not allowed "usually", so you need to have the batch script write a vbs script script to "elevate privileges", disable policy restrictions and copy the font.ttf to Windows\Fonts. (or a powershell script to do the same) Then call the script in JB code eg:. Run "wscript myscript.vbs" or for a powershell script eg: run "powershell myscript.ps1" -- powershell scripts use .ps1 extensions And after that is done in your JB code, use that font in your JB code as you would any other font.
I've been studying this method for a while, and keep going back to it. So far haven't accomplished my goal, but someday I will buckle down and get it done.
Nothing is impossible! - Just different levels of difficulty along the way
Good luck. Let us know how it works out. - - Hopefully the easy way is all you need for what you are trying to accomplish.
EDIT - On second thought, you may not need cmd to run, or make a script. JB can write vbs scripts and run them. I was thinking of the method I am working on, using powershell. I say "may" because I'm unsure at this time of the limits of running a vbs script. there may be restrictions on what a vbs script is allowed to do. But, if Powershell is used (and run it's script with elevated priviledges and policy restrictions removed, through cmd use of a batch file, restrictions are few to non existant.
|
|
|
Post by honky on Aug 3, 2021 8:44:49 GMT
Ah ok, fonts can only be accessed when they're in the Windows folder, that's good to know. But if we manage to put the font in the right place (Windows/Fonts folder), will JB accept (recognize) the name of the font to fetch it?
|
|
|
Post by Rod on Aug 3, 2021 9:19:09 GMT
Short answer is no. It isn’t enough to put the font file in a folder, Windows has to know it is there so it needs registered and installed.
Just BASIC has no tools to do that.
Also there are restrictions on what font characters can be displayed by Just BASIC, wingdings for example simply does not work. It is to do with the character table that Just BASIC uses.
What is it you are trying to display? You can just keep a bitmap of the characters you need and print those to a graphic resource.
|
|
|
Post by honky on Aug 3, 2021 11:05:30 GMT
Short answer is no. It isn’t enough to put the font file in a folder, Windows has to know it is there so it needs registered and installed. Just BASIC has no tools to do that. Also there are restrictions on what font characters can be displayed by Just BASIC, wingdings for example simply does not work. It is to do with the character table that Just BASIC uses. What is it you are trying to display? You can just keep a bitmap of the characters you need and print those to a graphic resource. I just tried with a font taken from "Dafont" and placed in: "Windows/Fonts"; and indeed, it does not work. I'll have to make bmp (and maybe sprites) out of them; that will work.
|
|
|
Post by xxgeek on Aug 3, 2021 16:30:52 GMT
Paste this into the JB IDE and save it to a file.bas (any name) Place your font(s) in the same folder. Further instruction in the code.
It can't be done?
It's "magic"
For .ttf files ONLY
'Name - JB Font Intaller 'Author xxgeek 'Date Aug 2021
'place this code before any code stating fonts in your code 'This program will install all fonts (files ending in .ttf) in the same folder this file is run from.
nomainwin q$ = chr$(34) 'write a script to file open "installFonts.vbs" for output as #1
#1, "Set objShellApp = CreateObject(";q$;"Shell.Application";q$;")" #1, "Set objFSO = CreateObject(";q$;"Scripting.FileSystemObject";q$;")" #1, "Const FONTS = &H14&" #1, "Set objFolder = objShellApp.Namespace(FONTS)" #1, "FontsFolder = ";q$;DefaultDir$;q$ #1, "If objFSO.FolderExists(FontsFolder) = True Then" #1, "For Each objFile In objFSO.GetFolder(FontsFolder).Files" #1, "If Right(LCase(objFile.Name), 4) = ";q$;".ttf";q$;" Then" #1, "If objFSO.FileExists(objFolder.Self.Path & ";q$;"\";q$;" & objFile.Name) = False Then objFolder.CopyHere objFile.Path" #1, "End If" #1, "Next" #1, "Else" #1, "MsgBox ";q$;"Not able to find font folder ";q$;" & strWindowsFonts" #1, "End If" close #1
run "wscript installFonts.vbs"
'give a couple of seconds for script to complete. 'if you want, you can install multiple fonts, whatever .ttf files are in the same folder will be installed 'increase 2000000 to whatever works depending on number of fonts (2000000 was tested on one font install) for x = 1 to 200000 next x
'#######################################################################
'The rest of your code can go here, and if you want to use the font(s) you installed just do the same as you 'would for any other font. As long as you use the correct name of the font, it will work. 'If you goto the menu in JB IDE and select Setup>Editor Fonts - You will see your new font(s) in the list 'You can get the correct name from that list. Enjoy! 'eg : main.default, "font mynewfont 10 Bold" 'eg : "main.button, "!font mynewfont 14 Bold '#######################################################################
|
|
|
Post by honky on Aug 3, 2021 17:27:15 GMT
@: xxgeek: Your script has correctly placed the font in "Windows/Fonts folder" and it appears in: "JB Fontdialog". But as ROD says, this is not enough, JB is not going to look for it.
EDIT "Windows/Bloc Note" display the new font well Re Edit: The font is: "OldLondon" from Dafont (Gothique)
|
|
|
Post by xxgeek on Aug 3, 2021 19:12:08 GMT
@: xxgeek: Your script has correctly placed the font in "Windows/Fonts folder" and it appears in: "JB Fontdialog". But as ROD says, this is not enough, JB is not going to look for it. EDIT "Windows/Bloc Note" display the new font well Re Edit: The font is: "OldLondon" from Dafont (Gothique) Post the code you ran here.
|
|
|
Post by xxgeek on Aug 3, 2021 20:03:07 GMT
That particular font you want to use wants to play rough. When I tested the above I used the .ttf file of Old London, and got the same result you did, even after attempting many variations of the name. I went and downloaded the Old London font myself, and found it to be a zip file containing a couple of .ttf files and a couple of .otf files. I tried the .otf file and it worked for me after changing my code to copy the .otf file instead of the ttf. Why the .ttf doesn't work is beyond me. It worked on the previous ttf files I tested. I don't intend to try and find out why.
I updated my code to show you that using the otf file works with a demonstration.
If this doesn't work for you, I am at a loss.
I gave more time delay, so it will be a few seconds before you see the results. I just used an old window from one of my apps to display the font in the header (BAS<2>EXE) It should now appear in the Old London font (as long as you put the OldLondon.otf file in the same dir as this file when you run it. Now there are 2 versions of the JB Font Installer, one for ttf files and one for otf files.
For .otf files only
'Name - JB Font Installer - DEMO - For Demonstration ONLY 'Author xxgeek 'Date Aug 2021
'place this code before any code stating fonts in your code 'This program will install all fonts (files ending in .otf) in the same folder this file is run from.
nomainwin q$ = chr$(34) 'write a script to file open "installFonts.vbs" for output as #1
#1, "Set objShellApp = CreateObject(";q$;"Shell.Application";q$;")" #1, "Set objFSO = CreateObject(";q$;"Scripting.FileSystemObject";q$;")" #1, "Const FONTS = &H14&" #1, "Set objFolder = objShellApp.Namespace(FONTS)" #1, "FontsFolder = ";q$;DefaultDir$;q$ #1, "If objFSO.FolderExists(FontsFolder) = True Then" #1, "For Each objFile In objFSO.GetFolder(FontsFolder).Files" #1, "If Right(LCase(objFile.Name), 4) = ";q$;".otf";q$;" Then" #1, "If objFSO.FileExists(objFolder.Self.Path & ";q$;"\";q$;" & objFile.Name) = False Then objFolder.CopyHere objFile.Path" #1, "End If" #1, "Next" #1, "Else" #1, "MsgBox ";q$;"Not able to find font folder ";q$;" & strWindowsFonts" #1, "End If" close #1
run "wscript installFonts.vbs"
'give a couple of seconds for script to complete. 'if you want, you can install multiple fonts, whatever .otf files are in the same folder will be installed 'increase 2000000 to whatever works depending on number of fonts (2000000 was tested on one font install) for x = 1 to 4000000 next x WindowWidth = 600 WindowHeight = 320 UpperLeftX=INT((DisplayWidth-WindowWidth)/2) UpperLeftY=INT((DisplayHeight-WindowHeight)/2) BackgroundColor$ = "lightgray" ForegroundColor$ = "black"
'add some text ,some buttons, and a menu to the Window statictext #pick.header, "BAS <2> EXE", 190, 30, 590, 45 checkbox #pick.password, "Password this EXE File", [yespass], [nopass], 200, 170, 160, 20 checkbox #pick.bit32, "Make 32 bit EXE", [bit32], [nobit32], 120, 140, 160, 20 checkbox #pick.bit64, "Make 64bit EXE", [bit64], [nobit64], 290, 140, 160, 20 statictext #pick.info, "Select a working Just Basic Source Code File (.bas)", 30, 95, 590, 40 statictext #pick.jbforums, "Visit the Just Basic Forums @ https://justbasiccom.proboards.com/", 125, 270, 590, 20 button #pick.default, "Select File", [defaultClick],UL 140, 215, 135, 35 button #pick.32, "Cancel", [cancel],UL 320, 215, 135, 35
'open the Window, and set some Fonts for each statictext, and buttons open "BAS2EXE v1.2" for window_nf as #pick #pick, "trapclose [quit.pick]" #pick, "font Arial 10 bold" #pick.header, "!font OldLondon 22 bold" #pick.password, "font Arial 12 bold" #pick.info, "!font Arial 16 bold" #pick.jbforums "!font Arial 8 bold" #pick.32, "!font Arial 12 bold" #pick.bit64, "font Arial 12 bold" #pick.bit32, "font Arial 12 bold" #pick.default, "!font Arial 12 bold" #pick.default, "!setfocus" wait
[cancel] close #pick end
[quit.pick] close #pick end
|
|
|
Post by honky on Aug 4, 2021 11:18:59 GMT
Your new code has correctly placed "OldLondon.otf" (open type) in Windows/Fonts The font appears well in: JB fontdialog (where I select it). But my JB doesn't want it It works with your display type, but not mine I have to watch how you display it. My code:
NOMAINWIN mapw=500: maph= 400 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 TEXTBOX #w.letextbox, 20 , 40, 180, 25 BUTTON #w.go, "Go !", [go], UL, 270, 40, 40, 20 TEXTEDITOR #w.te, 30, 150, 180, 230 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "down;fill darkpink;color white;backcolor darkpink" FONTDIALOG "OldLondon 12 bold", var$ #w.g, "font OldLondon 14 bold" #w.g, "place 20 100": #w.g, "\ Good morning" #w.te, "!font OldLondon 14 bold" #w.te, "Good morning" wait [closeHelp] CLOSE #w END
|
|
|
Post by honky on Aug 4, 2021 11:32:50 GMT
Hey, it's work with statictext, but not with graphicbox or texteditor
NOMAINWIN mapw=500: maph= 500 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 ' TEXTBOX #w.letextbox, 20 , 40, 180, 25 ' BUTTON #w.go, "Go !", [go], UL, 270, 40, 40, 20 statictext #w.gg, "Good <2> Morning", 190, 30, 590, 45
TEXTEDITOR #w.te, 30, 220, 180, 120 GRAPHICBOX #w.g, 5, 80, 400, 200 OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "down;fill darkpink;color white;backcolor darkpink" ' FONTDIALOG "OldLondon 12 bold", var$ #w.g, "font OldLondon 14 bold" #w.g, "place 20 100": #w.g, "\ Good morning" #w.te, "!font OldLondon 14 bold" #w.te, "Good morning" #w.gg, "!font OldLondon 22 bold" wait [closeHelp] CLOSE #w END
|
|
|
Post by xxgeek on Aug 4, 2021 12:04:13 GMT
I was just about to post when I saw your new post. I ran the code below (added your font to all button, textbox, statictext, and text editor and it works for me. All text is in Old London font here.
I'm using Win 10 pro, you?
Don't know Honky. It should be working for you. Try the code below, because before I edited it, I got the same results you got. For .otf files ONLY
nomainwin q$ = chr$(34)
open "installFonts.vbs" for output as #1
#1, "Set objShellApp = CreateObject(";q$;"Shell.Application";q$;")" #1, "Set objFSO = CreateObject(";q$;"Scripting.FileSystemObject";q$;")" #1, "Const FONTS = &H14&" #1, "Set objFolder = objShellApp.Namespace(FONTS)" #1, "FontsFolder = ";q$;DefaultDir$;q$ #1, "If objFSO.FolderExists(FontsFolder) = True Then" #1, "For Each objFile In objFSO.GetFolder(FontsFolder).Files" #1, "If Right(LCase(objFile.Name), 4) = ";q$;".otf";q$;" Then" #1, "If objFSO.FileExists(objFolder.Self.Path & ";q$;"\";q$;" & objFile.Name) = False Then objFolder.CopyHere objFile.Path" #1, "End If" #1, "Next" #1, "Else" #1, "MsgBox ";q$;"Not able to find font folder ";q$;" & strWindowsFonts" #1, "End If" close #1
run "wscript installFonts.vbs"
for x = 1 to 4000000 next x
mapw=500: maph= 400 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 TEXTBOX #w.letextbox, 20 , 40, 180, 25 BUTTON #w.go, "Go !", [go], UL, 270, 40, 40, 20 TEXTEDITOR #w.te, 30, 150, 180, 230 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "down;fill darkpink;color white;backcolor darkpink" FONTDIALOG "OldLondon 12 bold", var$ #w.letextbox, "!font OldLondon 12 bold" #w.go, "!font OldLondon 12 bold" #w.g, "font OldLondon 14 bold" #w.g, "place 20 100": #w.g, "\ Good morning" #w.te, "!font OldLondon 14 bold" #w.te, "Good morning" wait [closeHelp] CLOSE #w END
|
|
|
Post by Rod on Aug 4, 2021 17:40:35 GMT
If the font works it works, so you are either specifying an unsupported size parameter or not allowing enough room in the control to display the font height.
|
|
|
Post by tsh73 on Aug 4, 2021 18:32:36 GMT
I just went and downloaded www.dafont.com/old-london.fontinstalled ttf font by double clicking It is listed in font dialog as "Old London" So it has to be named in JB as "Old_London" Then I put that underscore, it started working.
|
|