Jump to content

ASCII Art Signatures


Recommended Posts

I've been playing around with FIGLet for generating ascii art signatures and I've written my own version in AutoIt to generate them. There are a couple of pre-requisites:

[1] Some FIGlet fonts. You can download a package here

[2] Zip.au3 which can be found here

If you don't change the script then you'll need to place the fonts in a sub-folder where the script resides called "fonts". Alternatively, just change the definition of $gFontDir to point to your fonts location. Here's the script:

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Zip.au3>

Global $gInputText, $gComboFont, $gEditSignature, $gCurrentFont = ""
Global $gFontData, $gFontMetaData[10], $gFontDir = @ScriptDir & "\fonts\"

_Main()

Exit

Func _Main()
    ; Create and show GUI
    GUICreate("AutoFiglet", 810, 426, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX))
    GUICtrlCreateLabel("Text to display", 8, 8, 550, 16)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKLEFT))
    $gInputText = GUICtrlCreateInput("", 8, 28, 550, 20)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKLEFT))
    GUICtrlCreateLabel("Font", 566, 8, 236, 16)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKRIGHT))
    $gComboFont = GUICtrlCreateCombo("", 566, 28, 236, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $CBS_SORT, $WS_VSCROLL))
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKHEIGHT, $GUI_DOCKTOP, $GUI_DOCKRIGHT))
    $gEditSignature = GUICtrlCreateEdit("", 8, 56, 794, 320, BitOR($ES_AUTOVSCROLL, $WS_HSCROLL, $ES_WANTRETURN))
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKBOTTOM))
    GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
    Local $btnGenerate = GUICtrlCreateButton("Generate", 680, 384, 122, 32, $BS_DEFPUSHBUTTON)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKHEIGHT, $GUI_DOCKWIDTH))
    GUISetState(@SW_SHOW)

    ; Load all the fonts in to the combo
    Local $sFontFile, $hFF = FileFindFirstFile($gFontDir & "*.flf")
    While 1
        $sFontFile = FileFindNextFile($hFF)
        If (@error = 1) Or $sFontFile = "" Then ExitLoop
        $sFontFile = StringLeft($sFontFile, StringLen($sFontFile) - 4)
        GUICtrlSetData($gComboFont, $sFontFile)
    WEnd
    _GUICtrlComboBox_SetCurSel(GUICtrlGetHandle($gComboFont), 0)
    FileClose($hFF)

    ; WM_COMMAND will tell us when the text has changed
    GUIRegisterMsg($WM_COMMAND, "_WmCommand")

    Local $nMsg
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnGenerate, $gComboFont
                _Display(GUICtrlRead($gInputText), GUICtrlRead($gComboFont))
        EndSwitch
    WEnd
    
    ; Discard GUI
    GUIDelete()
EndFunc   ;==>_Main

Func _WmCommand($hWndGUI, $msgID, $wParam, $lParam)
    If $lParam = GUICtrlGetHandle($gInputText) Then
        If _WinAPI_HiWord($wParam) = $EN_CHANGE Then
            _Display(GUICtrlRead($gInputText), GUICtrlRead($gComboFont))
        EndIf
    EndIf
EndFunc   ;==>_WmCommand

Func _Display($sText, $sFontName)
    Local $i, $j, $sChar, $sOutput = ""

    _LoadFont($sFontName)
    For $i = 1 To $gFontMetaData[2]
        For $j = 1 To StringLen($sText)
            $sChar = StringMid($sText, $j, 1)
            $sOutput &= _GetCharacter($sChar, $i)
        Next
        $sOutput &= @CRLF
    Next
    GUICtrlSetData($gEditSignature, $sOutput)
EndFunc   ;==>_Display

Func _LoadFont($sFontName)
    If $sFontName = $gCurrentFont Then Return
    
    Local $aTemp, $sTemp, $nUBound, $sFileLocation = $gFontDir & $sFontName & ".flf", $fTemp = False

    ; Try and unzip it first
    FileCopy($sFileLocation, @TempDir & "\" & $sFontName & ".zip")
    _Zip_UnzipAll(@TempDir & "\" & $sFontName & ".zip", @TempDir)
    If @error = 0 Then
        ; It unzipped OK so let's flag the temporary file
        $fTemp = True
        $sFileLocation = @TempDir & "\" & $sFontName & ".flf"
    EndIf
    FileDelete(@TempDir & "\" & $sFontName & ".zip")

    ; Read in the figlet font in to out array
    _FileReadToArray($sFileLocation, $gFontData)
    $aTemp = StringSplit($gFontData[1], " ", 2) ; Split the first line at spaces
    $nUBound = UBound($aTemp) ; Remember how many parameters we have
    $sTemp = $aTemp[0] ; This contains the signature and the hard blank character
    $gFontMetaData[0] = StringLeft($sTemp, StringLen($sTemp) - 1) ; Signature
    $gFontMetaData[1] = StringRight($sTemp, 1) ; Hard blank
    $gFontMetaData[2] = Number($aTemp[1]) ; Height of each letter
    ;$gFontMetaData[3] = Number($aTemp[2])
    ;$gFontMetaData[4] = Number($aTemp[3])
    ;$gFontMetaData[5] = Number($aTemp[4])
    $gFontMetaData[6] = Number($aTemp[5])
    ;If ($nUBound > 6) Then $gFontMetaData[7] = Number($aTemp[6])
    ;If ($nUBound > 7) Then $gFontMetaData[8] = Number($aTemp[7])
    ;If ($nUBound > 8) Then $gFontMetaData[9] = Number($aTemp[8])
    ;If ($gFontMetaData[0] <> "flf2a") Then Return SetError(1, 0, $sFontName & " is not a valid font")
    If $fTemp Then FileDelete($sFileLocation)
    $gCurrentFont = $sFontName
EndFunc   ;==>_LoadFont

Func _GetCharacter($sChar, $nLine)
    Local $nStart = $gFontMetaData[6] + ((Asc($sChar) - 32) * $gFontMetaData[2]), $sTemp
    $sTemp = $gFontData[$nStart + $nLine + 1]
    $sTemp = StringReplace($sTemp, StringRight($sTemp, 1), "")
    $sTemp = StringReplace($sTemp, $gFontMetaData[1], " ")
    Return $sTemp
EndFunc   ;==>_GetCharacter

I've tried to set the resizing for the main dialog but there's a small issue when you size it smaller but I'm not worrying about that just now. Using the script above you can generate signatures using ascii art fonts like this:

  ____, _, _,  ____,  ____,   __,   ____,     __,   ____,    ____,  ____,  ____,  __,   

 (-/_| (-|  \ (-|    (-/  \  (-|   (-|       (-|   (-(__    (-/    (-/  \ (-/  \ (-|    

 _/  |, _|__/  _|,    _\__/,  _|_,  _|,       _|_,  ____)    _\__,  _\__/, _\__/, _|__, 

(      (      (      (       (     (         (     (        (      (      (      (      

and this:

 .----------------.  .----------------.  .----------------. 

| .--------------. || .--------------. || .--------------. |

| |      __      | || |   ______     | || |     ______   | |

| |     /  \     | || |  |_   _ \    | || |   .' ___  |  | |

| |    / /\ \    | || |    | |_) |   | || |  / .'   \_|  | |

| |   / ____ \   | || |    |  __'.   | || |  | |         | |

| | _/ /    \ \_ | || |   _| |__) |  | || |  \ `.___.'\  | |

| ||____|  |____|| || |  |_______/   | || |   `._____.'  | |

| |              | || |              | || |              | |

| '--------------' || '--------------' || '--------------' |

 '----------------'  '----------------'  '----------------' 

Note that you'll need to replace spaces with non-breaking ones so that browsers don't screw up the format. Non-breaking spaces can normally be typed on the keyboard by holding down [Alt] and typing 0160 on the numeric keypad.

Have fun. I'm expecting some stellar signatures to crop up from here :)

          ______   ______  

|\     /|(  ___ \ (  __  \ 

| )   ( || (   ) )| (  \  )

| | _ | || (__/ / | |   ) |

| |( )| ||  __ (  | |   | |

| || || || (  \ \ | |   ) |

| () () || )___) )| (__/  )

(_______)|/ \___/ (______/

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