Jump to content

Recommended Posts

Posted (edited)

why some fonts do not appear? in other programs like paint.net the font preview work. Thx

 

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <file.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include<ComboConstants.au3>
#include <GUIComboBox.au3>

$Form1 = GUICreate("Form1", 300, 200, -1, -1)
$iPic = GUICtrlCreatePic("", 0, 0, 300, 60)
$hPic = GUICtrlGetHandle($iPic)

$Combo1 = GUICtrlCreateCombo("Select Font", 25, 64, 250, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))

$s_FontList = _FileListToArray(@WindowsDir & "\Fonts\","*.ttf")
$NFontList = UBound($s_FontList)-1

For $ff = 1 to $NFontList
    GUICtrlSetData($Combo1, StringTrimRight($s_FontList[$ff],4))
Next
Global $hGraphic
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hPic)
_GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ; Clean up resources
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            Exit
        Case $Combo1

    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $combo1, $hWndCombo
            Switch $iCode
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                    $sFont = GUICtrlRead($Combo1)
                    $sFontname = _WinAPI_GetFontResourceInfo(@WindowsDir & "\Fonts\" & $sFont & ".ttf")
                    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
                    _GDIPlus_GraphicsDrawString($hGraphic, $sFontname, 10, 10, $sFontname, 10)
        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

 

Edited by rootx
Posted

Why some fonts are not displayed in the GDI??

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <file.au3>
#include <array.au3>
#include <WindowsConstants.au3>
#include <GuiEdit.au3>
#include<ComboConstants.au3>
#include <GUIComboBox.au3>
#include <WinAPIGdi.au3>
#include <WinAPIShellEx.au3>
$Form1 = GUICreate("Form1", 300, 200, -1, -1)
$iPic = GUICtrlCreatePic("", 0, 0, 300, 60)
$hPic = GUICtrlGetHandle($iPic)

$Combo1 = GUICtrlCreateCombo("Select Font", 25, 64, 250, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_DROPDOWNLIST))

$s_FontList =  _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS), '*.ttf', 1)


$NFontList = UBound($s_FontList)-1

For $ff = 1 to $NFontList
    GUICtrlSetData($Combo1, StringTrimRight($s_FontList[$ff],4))
Next
Global $hGraphic
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hPic)
_GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ; Clean up resources
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            Exit
        Case $Combo1

    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $hWndFrom
        Case $combo1, $hWndCombo
            Switch $iCode
                    ; no return value
                Case $CBN_SELCHANGE ; Sent when the user changes the current selection in the list box of a combo box
                    _DebugPrint("$CBN_SELCHANGE" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode)
                   $sFont = GUICtrlRead($Combo1)
                   $sFontnamex = _FileListToArray(_WinAPI_ShellGetSpecialFolderPath($CSIDL_FONTS),$sFont& '*.ttf', 1)[1]
                   $sFontname = _WinAPI_GetFontResourceInfo(@WindowsDir & "\Fonts\" & $sFontnamex)
                    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)
                    _GDIPlus_GraphicsDrawString($hGraphic, $sFontname, 10, 10, $sFontname, 10)
        EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint

 

Posted

If you ConsoleWrite the font names you'll see names like Arial, "Arial bold", "Arial italic", "Arial narrow", etc. Only the first name in this list is a valid font name. The rest are font names plus one or more attribute names. You have to remove the attribute part of the font name to show the font in the GUI. And you should add the attribute to the font to be able to see that it in fact is eg. a bold font. You need a little bit more code.

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
×
×
  • Create New...