Code : Tout sélectionner
; http://www.autoitscript.com/forum/topic/124231-extract-the-font-family-name-from-a-truetype-10-font/page__view__findpost__p__862778
;==============================================================
#Include <Array.au3>
#Include <File.au3>
$font_folder = _WinAPI_ShellGetSpecialFolderPath(0x0014) ;$CSIDL_FONTS = 0x0014
Global $FileList = _FileListToArray($font_folder, '*.ttf', 1)
Global $FontList[UBound($FileList) - 1][2]
For $i = 1 To $FileList[0]
$FontList[$i - 1][1] = $FileList[$i]
$FontList[$i - 1][0] = _WinAPI_GetFontResourceInfo($FileList[$i], 1)
If $FontList[$i - 1][0] = "Comic Sans MS" Then Exitloop ; exemple
Next
Msgbox(0,"", $FontList[$i - 1][0] &" : "& $font_folder &"\"& $FontList[$i - 1][1])
;_ArrayDisplay($FontList)
;================================================================
; extraits de WinAPIEx.au3 :
;=====================
Func _WinAPI_ShellGetSpecialFolderPath($CSIDL, $fCreate = 0)
Local $tPath = DllStructCreate('wchar[1024]')
Local $Ret = DllCall('shell32.dll', 'int', 'SHGetSpecialFolderPathW', 'hwnd', 0, 'ptr', DllStructGetPtr($tPath), 'int', $CSIDL, 'int', $fCreate)
If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, '')
EndIf
Return DllStructGetData($tPath, 1)
EndFunc
Func _WinAPI_GetFontResourceInfo($sFont, $fForce = 0)
If $fForce Then
If Not _WinAPI_AddFontResourceEx($sFont, 0x20) Then ;$FR_NOT_ENUM = 0x20
Return SetError(1, 0, '')
EndIf
EndIf
Local $tData = DllStructCreate('wchar[1024]')
Local $Ret = DllCall('gdi32.dll', 'int', 'GetFontResourceInfoW','wstr', $sFont, 'dword*', 1024, 'ptr', DllStructGetPtr($tData), 'dword', 0x01)
If (@error) Or (Not $Ret[0]) Then
$Ret = 0
EndIf
If $fForce Then
_WinAPI_RemoveFontResourceEx($sFont, 0x20) ;$FR_NOT_ENUM = 0x20
EndIf
If Not IsArray($Ret) Then
Return SetError(1, 0, '')
EndIf
Return DllStructGetData($tData, 1)
EndFunc
Func _WinAPI_AddFontResourceEx($sFont, $iFlag = 0, $fNotify = 0)
Local $Ret = DllCall('gdi32.dll', 'int', 'AddFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0)
If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
If $fNotify Then
DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'uint', 0x001D, 'int', 0, 'int', 0)
EndIf
Return $Ret[0]
EndFunc
Func _WinAPI_RemoveFontResourceEx($sFont, $iFlag = 0, $fNotify = 0)
Local $Ret = DllCall('gdi32.dll', 'int', 'RemoveFontResourceExW', 'wstr', $sFont, 'dword', $iFlag, 'ptr', 0)
If (@error) Or (Not $Ret[0]) Then
Return SetError(1, 0, 0)
EndIf
If $fNotify Then
DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', 0xFFFF, 'uint', 0x001D, 'int', 0, 'int', 0)
EndIf
Return 1
EndFunc