Sign in to follow this  
Followers 0
rootx

How to use font without install it?

7 posts in this topic

#1 ·  Posted (edited)

I try to resolve my question with

_WinAPI_AddFontResourceEx(@ScriptDir & "\font\myfont.ttf", $FR_PRIVATE, False)

unsuccessful.. THX

Edited by rootx

Share this post


Link to post
Share on other sites



#3 ·  Posted

now it works, I used a hidden label to force to load him.

Share this post


Link to post
Share on other sites

#4 ·  Posted

With this fonts doen't work! Why? I try on Windows 10 64bit. Thx

#include <APIGdiConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>

_WinAPI_AddFontResourceEx(@ScriptDir&"\font\Android.ttf", $FR_PRIVATE,False)


GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 100)
GUICtrlCreateLabel('Simple Text', 10, 25, 380, 50, $SS_CENTER)
GUICtrlSetFont(-1, 38, -1, -1, 'Android')
GUICtrlSetColor(-1, 0xF06000)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

http://www.dafont.com/it/android.font

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

I assume you double checked the path you specified is correct?
You should try and add a check to see if the font is loaded or not. Like so:

#include <APIGdiConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>

$iSuccess = _WinAPI_AddFontResourceEx(@ScriptDir&"\font\Android.ttf", $FR_PRIVATE,False)
If $iSuccess=0 Then Exit MsgBox(0, "", "Font did not load successfully")


GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), 400, 100)
GUICtrlCreateLabel('Simple Text', 10, 25, 380, 50, $SS_CENTER)
GUICtrlSetFont(-1, 38, -1, -1, 'Android')
GUICtrlSetColor(-1, 0xF06000)
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

I have no problems with the script, but i am currently testing on my Windows 7 Ultimate 64bit, but if my answer do not help you, i can try it on my win10 machine also.

Thanks for the link to the font, helps a lot ;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

???? The file.... does not appear to be a valid font. WTF??? If I try to open a .ttf file outside the FONTS folder I receive this error. What does the firewall with fonts!

https://www.youtube.com/watch?v=pzzIQq1mjDI

My Firewall is active, I have Administrative permissions!

Edited by rootx

Share this post


Link to post
Share on other sites

#7 ·  Posted

Seems to be a weird one. I would suggest trying this: Unable to install fonts on Windows 10

It seems some people experience problems with fonts on removable media. Guess it's something that will be fixed at some point...

A solution for your application could be to use FileInstall to the @TempDir. I would imagine it would help, but with the firewall strangeness also being a possibility, who knows.

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
      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  
    • 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