Jump to content

Font Selector


Fossil Rock
 Share

Recommended Posts

I found that XP doesn't allow half point sizes (8 ok, 8.5 no go, but 8.5 is a valid size if input manually) using the _ChooseFont function.

I was wondering if anyone has written a custom font selector.

If not, does anyone know where the attributes for a font are stored (in the .TTF file maybe) ?

Edited by Fossil Rock

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

As you can see

#include <GUIConstants.au3>

GUICreate ("My GUI") ; will create a dialog box that when displayed is centered

$font="Comic Sans MS"
GUICtrlCreateLabel ("underlined label",10,20)
GUICtrlSetFont (-1,8, 400, 4, $font)   ; will display underlined characters

GUICtrlCreateLabel ("underlined label",10,40)
GUICtrlSetFont (-1,8.5, 400, 4, $font)   ; will display underlined characters

GUICtrlCreateLabel ("italic label", 10,60)
GUICtrlSetFont (-1,8, 400, 2, $font)   ; will display italic characters

GUICtrlCreateLabel ("italic label", 10,80)
GUICtrlSetFont (-1,8.5, 400, 2, $font)   ; will display italic characters

GUISetState ()    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

AutoIt allows to set font size ie 8.5. Now your task is to write own font dialog which has any fontsize wished and allowed by AutoIt.

The point of world view

Link to comment
Share on other sites

As you can see

...

AutoIt allows to set font size ie 8.5. Now your task is to write own font dialog which has any fontsize wished and allowed by AutoIt.

Thanks, but I'm aware that AutoIt supports the font size, as do all the apps I've tried it in where it doesn't use that particular font selector.

The 'dialog' is where I need assistance. I need to program the controls and am looking for the attributes that each font supports. Not all fonts support every attribute (size/bold/italic and so on). I can build the controls with all possible combinations, but would rather get the attributes already assigned to each font.

I probably can accomplish what I want by just creating the controls to handle every possible combination, but should someone have a better idea, I would like to hear it.

I particularly like the one used with MSPaint. Recreating that one would be great. If anyone knows how to active that font selector or code one that works the same, please let me know.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
Share on other sites

Thanks, but I'm aware that AutoIt supports the font size, as do all the apps I've tried it in where it doesn't use that particular font selector.

The 'dialog' is where I need assistance. I need to program the controls and am looking for the attributes that each font supports. Not all fonts support every attribute (size/bold/italic and so on). I can build the controls with all possible combinations, but would rather get the attributes already assigned to each font.

I probably can accomplish what I want by just creating the controls to handle every possible combination, but should someone have a better idea, I would like to hear it.

I particularly like the one used with MSPaint. Recreating that one would be great. If anyone knows how to active that font selector or code one that works the same, please let me know.

This is just an excerpt from something I'm working on, it's not exactly what you're looking for, but it might help.

$child3 = GUICreate("Font",320, 130,-1,-1,-1,$WS_EX_ACCEPTFILES,$parent)
$fontlist = _FontGetList(0)
GuiCtrlCreateLabel("Choose a Font:",10,15,80,20)
$fontselect = GuiCtrlCreateCombo("Arial",95,10,215,20)
For $i = 1 to $fontlist[0]
GuiCtrlSetData($fontselect,$fontlist[$i],"Arial")
Next
GuiCtrlCreateLabel("Font Size:",10,40,80,20)
$fontsize = GuiCtrlCreateCombo("2",95,35,45,20)
GuiCtrlSetData($fontsize,"4|5|6|7|8|9|10|11|12|14|16|18|20|22|24|26|28|30|32|36|48|72","10")
GuiCtrlCreateLabel("Font Style:",10,65,80,20)
$fontstyle = GuiCtrlCreateCombo("Normal",95,60,75,20)
GuiCtrlSetData($fontstyle,"Italic|Underline|Strike","Normal")
$setfont = GuiCtrlCreateButton("Set Font",75,90,75,25)
$cancelfont = GuiCtrlCreateButton("Cancel",155,90,75,25)
GUISetState()
Do
$msg3 = GUIGetMsg()
if $msg3 = $setfont then
if GuiCtrlRead($fontstyle) = "Normal" then
$attribute = 0
elseif GuiCtrlRead($fontstyle) = "Italic" then
$attribute = 2
elseif GuiCtrlRead($fontstyle) = "Underline" then
$attribute = 4
elseif GuiCtrlRead($fontstyle) = "Strike" then
$attribute = 8
endif
GUICtrlSetFont($edit,GuiCtrlRead($fontsize),400,$attribute,GuiCtrlRead($fontselect))
ExitLoop
endif
if $msg3 = $cancelfont then
ExitLoop
endif
Until $msg3 = $GUI_EVENT_CLOSE
GUIDelete($child3)

this is the include function

;===============================================================================
; Function Name: _FontGetList()
; Description: Returns an array with a list of all fonts currently installed on the system.
; Parameter(s): $i_opt - An Integer, 0 or 1.  0 will create a 1D array with font names only.
;                                             1 will create a 2d array with font names in the first column, font file names in the second
; Requirement(s): None
; Return Value(s): 1D-2D Array = [0] or [0][0] Contains total number of fonts.
; Author(s): Simucal <simucal@gmail.com>
; Revision: 20060501A
;
;===============================================================================
Func _FontGetList($i_opt = 0)
    Dim $a_FontNames[1], $a_FontNamesFiles[1][1], $i = 1
    If @OSTYPE = "WIN32_NT" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
    If @OSTYPE = "WIN32_WINDOWS" Then $regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts"
    While 1
        $s_temp = RegEnumVal($regkey, $i)
        If @error <> 0 Then ExitLoop
        $s_temp2 = RegRead($regkey, $s_temp)
        $s_temp = StringRegExpReplace($s_temp, "\s\(.*?\)(\s*)?", "")
        If $i_opt = 0 Then
            ReDim $a_FontNames[ ($i + 1) ]
            $a_FontNames[$i] = $s_temp
        ElseIf $i_opt = 1 Then
            ReDim $a_FontNames[ ($i + 1) ]
            $a_FontNames[$i] = $s_temp & "|" & $s_temp2
        EndIf
        $i = $i + 1
    WEnd
    If $i_opt = 0 Then
        _ArraySort($a_FontNames)
        $a_FontNames[0]= (UBound($a_FontNames) - 1)
        Return ($a_FontNames)
    ElseIf $i_opt = 1 Then
        _ArraySort($a_FontNames); Sort with font names and files as a single array
        For $i = 1 To (UBound($a_FontNames) - 1); then split it up into 2D, so they will be alphabatized together.
            $s_fontsplit = StringSplit($a_FontNames[$i], "|")
            If IsArray($s_fontsplit) = 1 Then
                ReDim $a_FontNamesFiles[ ($i + 1) ][2]
                $a_FontNamesFiles[$i][0] = $s_fontsplit[1]
                $a_FontNamesFiles[$i][1] = $s_fontsplit[2]
            EndIf
        Next
        $a_FontNamesFiles[0][0] = (UBound($a_FontNamesFiles) - 1)
        Return ($a_FontNamesFiles)
    EndIf
EndFunc
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

You may think your setting it to 8.5 but in reality it will choose the closest size available if 8.5 isn't available.

Point size 8, 8.5 and 9 are clearly different if you know what you're looking for.

Agreement is not necessary - thinking for one's self is!

My-Colors.jpg

cuniform2.gif

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...