#include ; #INDEX# ======================================================================================================================= ; Title .........: FontList F ; AutoIt Version : 3.2.10++ ; Description ...: Liste les polices installés. ; Author(s) .....: Kriss Cornello ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;FontList ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;_WinAPI_ShellGetSpecialFolderPath ;TTF_GetInfo ;_RH_BigEndianToInt ;_RH_FormatStringEllipsis ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: FontList ; Description ...: Liste les polices installés. ; Return values .: Retourne un tableau en 1D: [Face Name] avec $array[0]=Ubound($array)-1 ; Author ........: Kriss Cornello ; Related .......: _WinAPI_ShellGetSpecialFolderPath, _RH_TTF_GetInfo, _ArrayInsert, _RH_BigEndianToInt, _RH_FormatStringEllipsis ; Example .......: Yes ; =============================================================================================================================== Func FontList() $Path = _WinAPI_ShellGetSpecialFolderPath(0x0014) ;$CSIDL_FONTS = 0x0014 $Files = FileFindFirstFile($Path & '\*.ttf') Dim $FontList[1] While 1 Local $file = FileFindNextFile($Files) If @error Then ExitLoop $FontName = TTF_GetInfo(FileRead($Path & '\' & $file)) If @error Then ContinueLoop If (_ArraySearch($FontList, $FontName[0], 0,UBound($FontList)-1,0,0,0) = -1) And ((StringStripWS($FontName[1], 3) = 'Normal') Or ($FontName[1] = 'Regular')) Then _ArrayAdd($FontList, $FontName[0]) WEnd FileClose($Files) $FontList[0]=UBound($FontList)-1 Return $FontList EndFunc ;==>FontList #cs; === EXEMPLE === #include #include #include #include $FONTLIST = FontList() _ArrayDisplay($FONTLIST) #Region ### GUI ### $Fenetre = GUICreate("Fenetre", 309, 192, 360, 304) $Combo = GUICtrlCreateCombo("", 32, 16, 241, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $WS_TABSTOP, $CBS_DROPDOWNLIST)) For $i=0 To UBound($FONTLIST)-1 GUICtrlSetData(-1,$FONTLIST[$i]) Next $Label = GUICtrlCreateLabel("GUICtrlSetFont", 40, 88, 228, 17) GUISetState(@SW_SHOW) #EndRegion ### GUI ### While 1 Sleep(20) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo GUICtrlSetFont($Label,10,400,Default,$FONTLIST[_ArraySearch($FONTLIST,GUICtrlRead($Combo))]) EndSwitch WEnd #ce #region ;=== INTERNAL === 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 ;==>_WinAPI_ShellGetSpecialFolderPath Func TTF_GetInfo($bBinary) Local $tBinary = DllStructCreate("byte[" & BinaryLen($bBinary) & "]") DllStructSetData($tBinary, 1, $bBinary) Local $pBinary = DllStructGetPtr($tBinary) Local $pPointer = $pBinary Local $tTT_OFFSET_TABLE = DllStructCreate("word MajorVersion;" & _ "word MinorVersion;" & _ "word NumOfTables;" & _ "word SearchRange;" & _ "word EntrySelector;" & _ "word RangeShift;", _ $pPointer) $pPointer += 12 If DllStructGetData($tTT_OFFSET_TABLE, "MajorVersion") <> 256 And DllStructGetData($tTT_OFFSET_TABLE, "MinorVersion") <> 0 Then Return SetError(1, 0, 0) Local $iNumOfTables = 265 * BitAND(DllStructGetData($tTT_OFFSET_TABLE, "NumOfTables"), 0xF) + BitShift(DllStructGetData($tTT_OFFSET_TABLE, "NumOfTables"), 8) Local $iOffset, $tTT_TABLE_DIRECTORY $tTT_TABLE_DIRECTORY = DllStructCreate("char Tag[4];" & _ "dword CheckSum;" & _ "dword Offset;" & _ "dword Length;", _ $pPointer+ 16*($iNumOfTables-3)) If DllStructGetData($tTT_TABLE_DIRECTORY, "Tag") == "name" Then $iOffset = _RH_BigEndianToInt(DllStructGetData($tTT_TABLE_DIRECTORY, "Offset"), 4) Else $iOffset=0 $tTT_TABLE_DIRECTORY=0 For $i = 1 To $iNumOfTables $tTT_TABLE_DIRECTORY = DllStructCreate("char Tag[4];" & _ "dword CheckSum;" & _ "dword Offset;" & _ "dword Length;", _ $pPointer) $pPointer += 16 If DllStructGetData($tTT_TABLE_DIRECTORY, "Tag") == "name" Then $iOffset = _RH_BigEndianToInt(DllStructGetData($tTT_TABLE_DIRECTORY, "Offset"), 4) ExitLoop EndIf Next EndIf If Not $iOffset Then Return SetError(2, 0, 0) $pPointer = $pBinary + $iOffset Local $pDir = $pPointer Local $tTT_NAME_TABLE_HEADER = DllStructCreate("word FSelector;" & _ "word NRCount;" & _ "word StorageOffset;", _ $pPointer) $pPointer += 6 Local $iNRCount = _RH_BigEndianToInt(DllStructGetData($tTT_NAME_TABLE_HEADER, "NRCount"), 2) Local $iStorageOffset = _RH_BigEndianToInt(DllStructGetData($tTT_NAME_TABLE_HEADER, "StorageOffset"), 2) Local $aInfo[2], $tTT_NAME_RECORD, $bString, $iNameID, $iPlatform For $i = 1 To $iNRCount $tTT_NAME_RECORD = DllStructCreate("word PlatformID;" & _ "word EncodingID;" & _ "word LanguageID;" & _ "word NameID;" & _ "word StringLength;" & _ "word StringOffset;", _ $pPointer) $pPointer += 12 ; size of $tTT_NAME_RECORD $bString = DllStructGetData(DllStructCreate("byte[" & _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "StringLength"), 2) & "]", $pDir + $iStorageOffset + _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "StringOffset"), 2)), 1) $iNameID = _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "NameID"), 2) If (_RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "PlatformID"), 2) = 1) And ($iNameID = 1 Or $iNameID = 2) Then $aInfo[$iNameID-1] = _RH_FormatStringEllipsis(BinaryToString($bString), 100) If Not ($aInfo[0] = '' Or $aInfo[1] = '') Then ExitLoop EndIf Next Return $aInfo EndFunc ;==>TTF_GetInfo Func _RH_BigEndianToInt($iValue, $iSize = 2) Return Dec(Hex(BinaryMid($iValue, 1, $iSize))) EndFunc ;==>_RH_BigEndianToInt Func _RH_FormatStringEllipsis($sString, $iNumChars) Local $iLen = StringLen($sString) If $iLen <= $iNumChars Then Return $sString Return StringLeft($sString, $iNumChars - 3) & "..." EndFunc ;==>_RH_FormatStringEllipsis #endregion ;=== INTERNAL ===