LightningBit

Pull font name and info from any fontfile, installed or not.

5 posts in this topic

Hi,

I've a collection of folders with fonts, which are not installed

What I wanted todo is to extra some of the font information from each font file file.

I found the WinAPIEx and the example scripts, and they work nicely on the installed fonts, but not on a directory of non-installed fonts

when I use the below (for the installed fonts) the array contains the filename and fontname as expected

#Include <Array.au3>
#Include <File.au3>
#Include <WinAPIEx.au3>


Opt('MustDeclareVars', 1)

Global $FileList = _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS), '*.ttf', 1)
Global $FontList[UBound($FileList) - 1][2]

For $i = 1 To $FileList[0]
    $FontList[$i - 1][0] = $FileList[$i]
    $FontList[$i - 1][1] = _WinAPI_GetFontResourceInfo($FileList[$i], 1)
Next


_ArrayDisplay($FontList, '_WinAPI_GetFontResourceInfo')

when I change the path to a local folder

Global $FileList = _FileListToArray("C:\DEV\TEST\FONTS\", '*.ttf', 1)

then the array contains only the filename, the fontname remains empty

I also tried with the other examples (example 3 here: https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_GetFontResourceInfo.htm ) but the same result, the rest of the info remains empty

anyone who can help a little?

the test machine :

- autoit-v3.3.15.0-beta

- with WinAPIEx built in

- Windows 8.1 Pro x64

 

Thank you

Share this post


Link to post
Share on other sites



Please don't post questions twice in our forums.

Jos

I was trying to remove my first post, but it was already gone

 

thanks

 

 

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What happens when you prefix the filename with the user path?:

#Include <Array.au3>
#Include <File.au3>
#Include <WinAPIEx.au3>


Opt('MustDeclareVars', 1)

Global $path = "C:\DEV\TEST\FONTS\"
Global $FileList = _FileListToArray($path, '*.ttf', 1)
Global $FileList = _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS), '*.ttf', 1)
Global $FontList[UBound($FileList) - 1][2]

For $i = 1 To $FileList[0]
    $FontList[$i - 1][0] = $FileList[$i]
    $FontList[$i - 1][1] = _WinAPI_GetFontResourceInfo($path & $FileList[$i], 1)
Next


_ArrayDisplay($FontList, '_WinAPI_GetFontResourceInfo')

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Jos,

I was thinking the same, changing it like this works also:

I tested witn one file, but there I realized, I was indeed using the full path, so I looked at the options for the FileListToArray function, and I saw you it defaults to "return the filename only" (= the False setting) so adding "True", it now returns the full path & filename

$bReturnPath [optional] If True the full path is appended to the file\folder path, otherwise it is relative to the $sFilePath folder. Default is False.
Global $FileList = _FileListToArray("C:\DEV\TEST\FONTS\", '*.ttf', 1, True)

 

Thanks for helping!

 

Now I came across the next issue : some fonts seem to give issues when extracting certain data :

 

ConsoleWrite("Debug : Getting the data .... " & @LF)
;~      FontGetInfoFromFile($sFile, 0, "Copyright")
     FontGetInfoFromFile($sFile, 1, "Font Family name")
     FontGetInfoFromFile($sFile, 2, "Font SubFamily name")
     FontGetInfoFromFile($sFile, 3, "Unique font identifier")
     FontGetInfoFromFile($sFile, 4, "Font full name")
;~      FontGetInfoFromFile($sFile, 5, "Version string")
     FontGetInfoFromFile($sFile, 6, "Postscript name")
     FontGetInfoFromFile($sFile, 7, "Trademark")
     FontGetInfoFromFile($sFile, 8, "Manufacturer Name")
     FontGetInfoFromFile($sFile, 9, "Designer")
     FontGetInfoFromFile($sFile, 10, "Description")
     FontGetInfoFromFile($sFile, 11, "URL Vendor")
     FontGetInfoFromFile($sFile, 16, "Preferred Family (Windows only)")
     FontGetInfoFromFile($sFile, 17, "Preferred SubFamily (Windows only)")
     FontGetInfoFromFile($sFile, 18, "Compatible Full (Mac OS only)")
     FontGetInfoFromFile($sFile, 19, "Sample text")
     FontGetInfoFromFile($sFile, 20, "PostScript CID findfont name")

     FontGetInfoFromFile($sFile, 256, "Font-specific names")

     ConsoleWrite("Debug : Done getting the data .... " & @LF & @CRLF)

     ConsoleWrite(_WinAPI_GetLastError & @LF)

 

this is the function

Func FontGetInfoFromFile($sFile, $n, $sElement)
    Local $s = _WinAPI_GetFontResourceInfo($sFile, Default, $n)
    If Not @error And $s Then ConsoleWrite($sElement & " = " & $s & @CRLF)

EndFunc   ;==>FontGetInfoFromFile

 

notice the 2 lines commented out : this works fine on a list of fonts

this is the result :

Debug : Found a font!C:\DEV\TEST\FONTS\Badmann.ttf
Debug : Getting the data .... 
Font Family name = Badmann
Font SubFamily name = Regular
Unique font identifier = ALLTYPE:Badmann Regular:ATECH
Font full name = Badmann
Postscript name = Badmann
Debug : Done getting the data .... 

Debug : Found a font!C:\DEV\TEST\FONTS\Bahamas.ttf
Debug : Getting the data .... 
Font Family name = Bahamas
Font SubFamily name = Plain
Unique font identifier = Bahamas Plain
Font full name = Bahamas Plain:
Postscript name = BahamasPlain
Debug : Done getting the data ....

when I uncomment any of those 2 lines :

 

Debug : Found a font!C:\DEV\TEST\FONTS\Badmann.ttf
Debug : Getting the data .... 
Font Family name = Badmann
Font SubFamily name = Regular
Unique font identifier = ALLTYPE:Badmann Regular:ATECH
Font full name = Badmann
Version string = Converted from C:\TTFONTS\Badmann.TF1 by ALLTYPE
Postscript name = Badmann
Debug : Done getting the data .... 

Debug : Found a font!C:\DEV\TEST\FONTS\Bahamas.ttf
Debug : Getting the data .... 
Font Family name = Bahamas
Font SubFamily name = Plain
Unique font identifier = Bahamas Plain
Font full name = Bahamas Plain:
"C:\DEV\AutoIt3\Include\WinAPIGdi.au3" (2480) : ==> Variable must be of type "Object".:
$sResult = $tResult.szTTFName
$sResult = $tResult^ ERROR

 

Anyone any idea? I attached 2 fonts which are having the issue, if you want to test it yourself

 

thanks

 

L.

 

Bahamas.ttf

Babylon5.ttf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now