Sign in to follow this  
Followers 0
lokster

How to load .ttf font file?

5 posts in this topic

I am making a frontend for MEncoder. As a parameter for the subtitle font, mencoder accepts .ttf filename.

On my GUI there is a combobox which listst all fonts in some directory.

I want to make it when I select some item, the font of a label to change to the selected font.

Here is just an example of what I want to do (this is not the real script, it is not finished yet...):

#include <GUIConstants.au3>
#Include <GuiCombo.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=D:\lokster\AutoIt Projects\fonts\AForm1.kxf
$Form1 = GUICreate("AForm1", 148, 66, 197, 115)
$Combo1 = GUICtrlCreateCombo("", 0, 0, 145, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetOnEvent(-1, "ACombo1Change")
$Label1 = GUICtrlCreateLabel("Font Sample", 0, 24, 147, 41, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "Bye")

ListFonts(@WindowsDir &"\Fonts\") ;this directory is just for example...

While 1
    Sleep(100)
WEnd

Func Bye()
    Exit
EndFunc

Func ListFonts($dir)
    $search = FileFindFirstFile($dir & '*.ttf')  
    if $search <> -1 then
        While 1
            $file = FileFindNextFile($search) 
            If @error Then ExitLoop
            GUICtrlSetData($Combo1,$file&'|')
        WEnd
    EndIf
    FileClose($search)
    _GUICtrlComboSetCurSel ( $Combo1, 0)
EndFunc

Func ACombo1Change()
    ;here i want to change the font of $Label1
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You may need to install the font to be able to use it.

Having the fonts in "some directory" may not be enough.

Edited by Ármányos Kő

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

To set the font use:

GUICtrlSetFont (controlID, size [, weight [, attribute [, fontname]]] )

controlID: The control identifier (controlID) as returned by a GUICtrlCreate... function.

size: Fontsize (default is 9).

weight : [optional] Font weight (default 400 = normal).

attribute: [optional] To define italic:2 underlined:4 strike:8 char format (add together the values of all the styles required, 2+4 = italic and underlined).

fontname: [optional] The name of the font to use.

Taken from: You guessed it! the help file :)

Share this post


Link to post
Share on other sites

To set the font use:

GUICtrlSetFont (controlID, size [, weight [, attribute [, fontname]]] )

controlID: The control identifier (controlID) as returned by a GUICtrlCreate... function.

size: Fontsize (default is 9).

weight : [optional] Font weight (default 400 = normal).

attribute: [optional] To define italic:2 underlined:4 strike:8 char format (add together the values of all the styles required, 2+4 = italic and underlined).

fontname: [optional] The name of the font to use.

Taken from: You guessed it! the help file :)

Yes... I know that function, but the fontname parameter is the name of the font, not the filename.

I figured out how to get around the problem - list only the installed fonts, and then get the selected font filename by reading it from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts.

This is only a workaround for what I initially wanted, but it works, so... topic closed:)

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