#include ; #INDEX# ======================================================================================================================= ; Title .........: FontList ; AutoIt Version : 3.2.10++ ; Description ...: Liste les polices installés. ; Author(s) .....: Kriss Cornello ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;FontList ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;_WinAPI_ShellGetSpecialFolderPath ;_RH_TTF_GetInfo ;_RH_BigEndianToInt ;_RH_FormatStringEllipsis ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name...........: FontList ; Description ...: Liste les polices installés. ; Return values .: Retourne un tableau en 2D: [Face Name] [Postscript name] ; 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 $FontName[1] Dim $Postscript[1] While 1 Local $file = FileFindNextFile($Files) If @error Then ExitLoop $array = _RH_TTF_GetInfo(FileRead($Path&'\'&$file)) If @error Then ContinueLoop If (_ArraySearch($FontName,$array[1][1])=-1) And ((StringStripWS($array[2][1],3)='Normal') Or ($array[2][1]='Regular')) Then _ArrayAdd($FontName,$array[1][1]) _ArrayAdd($Postscript,$array[6][1]) EndIf WEnd FileClose($Files) _ArrayDelete($FontName,0) _ArrayDelete($Postscript,0) Dim $Lista[UBound($FontName)][2] For $i=0 To UBound($Lista)-1 $Lista[$i][0]=$FontName[$i] $Lista[$i][1]=$Postscript[$i] Next Return $Lista EndFunc #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][0]) Next $Label = GUICtrlCreateLabel("PostScript name", 40, 88, 228, 17) GUISetState(@SW_SHOW) #EndRegion ### GUI ### While 1 Sleep(20) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Combo GUICtrlSetData($Label,$FONTLIST[_ArraySearch($FONTLIST,GUICtrlRead($Combo))][1]) 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 Func _RH_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) EndIf Local $iNumOfTables = 265 * BitAND(DllStructGetData($tTT_OFFSET_TABLE, "NumOfTables"), 0xF) + BitShift(DllStructGetData($tTT_OFFSET_TABLE, "NumOfTables"), 8) Local $iOffset Local $tTT_TABLE_DIRECTORY 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 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[28][3] = [["Copyright notice"],["Font Name"],["Subfamily Name"],["Identifier"],["Full Font Name"],["Version"],["Postscript Name"],["Trademark"],["Manufacturer"],["Designer"],["Description"],["URL Vendor"], _ ["URL Designer"],["License Description"],["License Info URL"],["Reserved Field "],["Preferred Family"],["Preferred Subfamily"],["Compatible Full"],["Sample text"],["PostScript CID Findfont Name"],["WWS Family Name"],["WWS Subfamily Name"]] Local $tTT_NAME_RECORD, $bString, $iNameID, $iPlatform Local $iLangID = -1 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) $iPlatform = _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "PlatformID"), 2) If $iNameID < 23 Then If $iPlatform = 1 Then $aInfo[$iNameID][1] = _RH_FormatStringEllipsis(BinaryToString($bString), 100) ElseIf $iPlatform = 3 Then If $iLangID = -1 And $iNameID = 0 Then $iLangID = _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "LanguageID"), 2) If _RH_BigEndianToInt(DllStructGetData($tTT_NAME_RECORD, "LanguageID"), 2) = $iLangID Then $aInfo[$iNameID][2] = _RH_FormatStringEllipsis(BinaryToString($bString, 3), 100) EndIf EndIf Next Return $aInfo EndFunc ;==>_RH_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