Type Font_Name_Type NameAsString
FileName AsString End Type ReDimShared Fonts(10000) As Font_Name_Type ReDimShared MonoFonts(10000) As Font_Name_Type Screen_NewImage(1280, 720, 32) GetFontList GetMonoFontList
numbered = -1'number our quick list
l = 20'number of lines to print to the screen
w = 50'width to print to the screen
SubGetFontList Shell_Hide"Powershell -command " + Chr$(34) + "Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'|Out-File -Encoding Ascii 'temp_fontlist.txt'" + Chr$(34)
f = FreeFile Open"temp_fontlist.txt"ForBinaryAs #f Do UntilEOF(1) Line Input #1, temp$
sep = InStr(temp$, ":")
l$ = _Trim$(Left$(temp$, sep - 1))
r$ = _Trim$(Mid$(temp$, sep + 1)) If l$ <> "PSPath"Then If l$ <> ""Then' skip the blank space lines
Fonts(count).Name = l$
Fonts(count).FileName = r$
count = count + 1 End If Else Exit Do' we can stop reading files at this point (according to my tests) End If Loop Close f Kill"temp_fontlist.txt"' clean up the file after we're done with parsing it.
count = count - 1' adjust for that last count + 1, which we didn't use. ReDim_Preserve Fonts(count) As Font_Name_Type
'a quick and simple combsort to make certain our list is in alphabetical order
gap = count Do
gap = 10 * gap \ 13 If gap < 1Then gap = 1
i = 0
swapped = 0 Do If Fonts(i).Name > Fonts(i + gap).NameThen Swap Fonts(i).Name, Fonts(i + gap).Name Swap Fonts(i).FileName, Fonts(i + gap).FileName
swapped = -1 End If
i = i + 1 Loop Until i + gap > count Loop Until gap = 1And swapped = 0 End Sub
A version which should give us a scrollable list of all font names (note that some of these are system fonts, if you don't filter them out -- such as those with the .fon extension), as well as tell us if the font in question is monospace or not.
Screenshot below:
I'm thinking this should work whether it's shelling out to CMD or Terminal either one. If not, then I'll just have to play around with it a bit more to try and see what the heck's wrong this time with it.
03-14-2024, 12:18 PM (This post was last modified: 03-14-2024, 12:20 PM by SpriggsySpriggs.)
Using the Win32 API, one can also access the registry to list all installed fonts:
Code: (Select All)
Option Explicit
$Console:Only
$NoPrefix
'$Include:'WinReg.BI'
Const STANDARD_RIGHTS_READ = &H00020000
Const KEY_QUERY_VALUE = &H0001
Const KEY_ENUMERATE_SUB_KEYS = &H0008
Const KEY_NOTIFY = &H0010
Const SYNCHRONIZE = &H00100000
Const ERROR_SUCCESS = 0
Const KEY_READ = (STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE)
Dim As _Offset hKey
Dim As String sRoot: sRoot = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" + Chr$(0)
If RegOpenKeyEx(HKEY_LOCAL_MACHINE, _Offset(sRoot), 0, KEY_READ, _Offset(hKey)) = ERROR_SUCCESS Then
QueryKey (hKey)
Else
Print "OOPS"
End If
RegCloseKey (hKey)
Sub QueryKey (hKey As _Offset)
Const MAX_VALUE_NAME = 16383
Const ERROR_SUCCESS = 0
Dim As _Unsigned Long cbName, cValues, cchMaxValue, cbMaxValueData
Dim As _Unsigned Long i, retCode
Dim As String achValue: achValue = Space$(MAX_VALUE_NAME)
Dim As _Unsigned Long cchValue: cchValue = MAX_VALUE_NAME
retCode = RegQueryInfoKey(hKey, 0, 0, 0, 0, 0, 0, _Offset(cValues), _Offset(cbMaxValueData), 0, 0, 0)
Dim As String buffer: buffer = Space$(cbMaxValueData)
If cValues Then
'Print "Number of values: "; cValues
For i = 0 To cValues
cchValue = MAX_VALUE_NAME
achValue = Space$(MAX_VALUE_NAME)
retCode = RegEnumValue(hKey, i, _Offset(achValue), _Offset(cchValue), 0, 0, 0, 0)
If retCode = ERROR_SUCCESS Then
Dim As _Unsigned Long lpData: lpData = cbMaxValueData
buffer = Space$(cbMaxValueData)
Dim As _Unsigned Long dwRes: dwRes = RegQueryValueEx(hKey, _Offset(achValue), 0, 0, _Offset(buffer), _Offset(lpData))
Print i; Mid$(achValue, 1, InStr(achValue, Chr$(0)) - 1), Mid$(buffer, 1, InStr(buffer, Chr$(0)) - 1)
End If
Next
End If
End Sub
(03-14-2024, 05:51 AM)SMcNeill Wrote: @TerryRitchie I think I've got it sorted out -- you're shelling out to command prompt and not terminal. Give this a run from the command line, like you did above, and see if you still get the error message:
(You can see the difference in the two methods above with command prompt. The first tosses the error like you're experiencing. The second runs with no issues. )
so the change with the code I've been sharing should be just to make certain to add that "cmd" to the front of that shell statement, as we see above.
I tried the line in both command prompt (command) and terminal (cmd) and this time I did not get an error message but still no text file created.
New to QB64pe? Visit the QB64 tutorial to get started. QB64 Tutorial
@TerryRitchie At this point, all I can determine is your version of Windows/QB64PE/PC is broke.
Batang & BatangChe & Gungsuh & GungsuhChe (TrueType) : b
a
t
a
n
g
.
t
t
c
If you look at the above, it's giving you the proper information. To the left is the font name. On the right, after the : is the font file name -- it's just interrupted by a crapload of CRLF characters.
batang.ttc
.ttc? Why isn't that a .ttf? What the heck is a .ttc? LOL!
Bt what's odd here is the NAME is formatted properly, with proper encoding and spacing. That's 100% ANSI/ASCII/UTF8 text. (Whatever your system is set to default to.) But what the heck is with the "one character, 100 spaces between characters??"
That's just a simple PRINT statement at work, correct??
Then that's NOT *just* a CRLF that you're dealing with -- if it was b (CRLF) a (CRLF) t (CRLF)..., then *those characters would all be printed at the start of the line!
Instead, we're seeing something even stranger such as b (CRLF) (Space 50) a (CRLF) (Space 50) t (CRLF) (Space 50)... WTH type of formatting produces output like that??!!
I'm lost as to what's glitching out on your PC with this one. You've got me 100% stumped here!