Sign in to follow this  
Followers 0
rootx

Fonts preview script question

5 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



#2 ·  Posted

_WinAPI_EnumFontFamilies

Share this post


Link to post
Share on other sites

#3 ·  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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Hi guys, any Idea is welcome.

Share this post


Link to post
Share on other sites

#5 ·  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.

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
Sign in to follow this  
Followers 0

  • Similar Content

    • tremolux66
      By tremolux66
      I use a monospace font for editing AutoIt scripts in SciTE (currently, CourierNew 9pt). Regardless of what font size I set in the configuration, when I start SciTE to resume editing the script text is one size smaller than I specified. When I type Ctrl+<numpad-slash> the text changes to the desired size. The same is true of the output pane, and I have to reset the size for both areas every time I start SciTE.
      IIRC, I've made few other changes to the configuration (e.g., changed the search highlight color and disabled Tidy), so this behavior seems odd. About SciTE says it's version 3.6.0 (Aug. 4, 2015).
      Any idea how to fix this?
    • rootx
      By rootx
      I try to resolve my question with
      _WinAPI_AddFontResourceEx(@ScriptDir & "\font\myfont.ttf", $FR_PRIVATE, False) unsuccessful.. THX
    • Trolleule
      By Trolleule
      Hi,
      i did some researchs how to set the font and the only way is to overwrite the subclass with WM_DRAWITEM. With WM_SETFONT i can only change the font for all tab pages, but i want to change the font for a specific page.
      So i have to set the $TCS_OWNERDRAWFIXED style to the tab control to send the WM_DRAWITEM message to the parent window. When i set this style, i can change the fonts, but sadly the tab looses the nice and simple "AutoIt style". I created two child guis, the first is the owner draw tab and the second the "Normal" tab.
      My questions is, how to create this special "AutoIt style"???
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <ColorConstants.au3> Global Const $ODT_TAB = 101 Global Const $ODS_SELECTED = 0x0001 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODS_FOCUS = 0x0010 $hStrikeOutDefaultFont = _WinAPI_CreateFont(14, 0, 0, 0, 400, False, False, True) ; see system apps module $hGUI = GUICreate("Draw Tab", 500, 600) ; Create child GUIs to hold tabs $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180, $TCS_OWNERDRAWFIXED);BitOR($TCS_OWNERDRAWFIXED, $TCS_TOOLTIPS, $WS_TABSTOP, $WS_CLIPSIBLINGS)) $hTab_00 = GUICtrlCreateTabitem("00") GUICtrlCreateButton("00", 160, 90, 80, 30) $hTab_01 = GUICtrlCreateTabitem("01") GUICtrlCreateButton("01", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180) $hTab_10 = GUICtrlCreateTabitem("10") GUICtrlCreateButton("10", 160, 90, 80, 30) $hTab_11 = GUICtrlCreateTabitem("11") GUICtrlCreateButton("11", 160, 90, 80, 30) GUICtrlCreateTabitem ("") GUISetState() GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;~ GUIRegisterMsg($WM_SETFONT, "WM_SETFONT") ;~ GUICtrlSendMsg ( $hTab_1, $WM_SETFONT , $hStrikeOutDefaultFont, 1 ) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func WM_SETFONT($hWnd, $Msg, $wParam, $lParam) ConsoleWrite("$hWnd: " & $hWnd & " $Msg: " & $Msg & " $wParam: " & $wParam & " $lParam: " & $lParam & @CRLF) EndFunc Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $DRAWITEMSTRUCT $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam) If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID") Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID") Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction") Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState") Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm") Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC") If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG Local $iTextColor, $itmText $iTextColor = 0xFFFFFF Switch $itmID Case 0 $iBrushColor = 0x11AADD Case 1 $iBrushColor = 0xEEBB99 EndSwitch _WinAPI_SetBkMode($hDC, $TRANSPARENT) Local $iBrush = _WinAPI_CreateSolidBrush($iBrushColor) Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush) $g_tRECT = DllStructCreate($tagRect, DllStructGetPtr($DRAWITEMSTRUCT, "itmRect")) DllStructSetData($g_tRECT, "Left", DllStructGetData($g_tRECT, "Left")) DllStructSetData($g_tRECT, "Top", DllStructGetData($g_tRECT, "Top")) DllStructSetData($g_tRECT, "Right", DllStructGetData($g_tRECT, "Right")) DllStructSetData($g_tRECT, "Bottom", DllStructGetData($g_tRECT, "Bottom")+10) _WinAPI_FillRect ( $hDC, $g_tRECT, $iBrush ) _WinAPI_SetTextColor($hDC, $iTextColor) _WinAPI_DrawText($hDC, "Item " & $itmID, $g_tRECT, $DT_LEFT) _WinAPI_SelectObject($hDC, $iBrushOld) _WinAPI_DeleteObject($iBrush) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Thanks in advance
    • kcvinu
      By kcvinu
      Hi all,
      I would like to know how to check if a specific font is installed in user's system. If it is not installed, my program needs to install the font. (Don't worry about the copy right of the font. it's free) I have got some points from google which directs me into _WinAPI_AddFontResourceEx function. But help file says that this function is only for current session.  And i also got the _WinAPI_EnumFontFamilies function too. But before trying any of these, i would like to hear from the masters. 
    • algiuxas
      By algiuxas
      Hello,
      I need help with loading true type fonts(*.ttf), without installing it. (Font: star_jedi.zip)
      Thanks
      star_jedi.zip