# Function Reference

# _WinAPI_GetFontMemoryResourceInfo

Reads out font information from a TTF loaded into the memory

#include <WinAPIGdi.au3>
_WinAPI_GetFontMemoryResourceInfo ( $pMemory [, $iFlag = 1] )

## Parameters

$pMemory | A pointer value the struct that contains the binary data of the TTF
$iFlag | [optional] An integer value. Default is 1 (Font Family name). See remarks for others values

## Return Value

Success: | A string value of the font information.
Failure: | 0.

## Remarks

$iFlag | Meaning
--- | ---
0 | Copyright notice
1 | Font Family name. (Default)
2 | Font Subfamily name. Font style (italic, oblique) and weight (light, bold, black, etc.). A font with no particular differences in weight or style (e.g. medium weight, not italic) should have the string "Regular" stored in this position.
3 | Unique font identifier. Usually similar to 4 but with enough additional information to be globally unique. Often includes information from Id 8 and Id 0.
4 | Full font name. This should be a combination of strings 1 and 2. Exception: if the font is “Regular” as indicated in string 2, then use only the family name contained in string 1. This is the font name that Windows will expose to users.
5 | Version string. Must begin with the syntax ‘Version n.nn ‘ (upper case, lower case, or mixed, with a space following the number).
6 | Postscript name for the font.
7 | Trademark. Used to save any trademark notice/information for this font. Such information should be based on legal advice. This is distinctly separate from the copyright.
8 | Manufacturer Name.
9 | Designer. Name of the designer of the typeface.
10 | Description. Description of the typeface. Can contain revision information, usage recommendations, history, features, etc.
11 | URL Vendor. URL of font vendor (with protocol, e.g., http://, ftp://). If a unique serial number is embedded in the URL, it can be used to register the font.
12 | URL Designer. URL of typeface designer (with protocol, e.g., http://, ftp://).
13 | License description. Description of how the font may be legally used, or different example scenarios for licensed use. This field should be written in plain language, not legalese.
14 | License information URL. Where additional licensing information can be found.
15 | Reserved; Set to zero.
16 | Preferred Family (Windows only). In Windows, the Family name is displayed in the font menu. The Subfamily name is presented as the Style name. For historical reasons, font families have contained a maximum of four styles, but font designers may group more than four fonts to a single family. The Preferred Family and Preferred Subfamily IDs allow font designers to include the preferred family/subfamily groupings. These IDs are only present if they are different from IDs 1 and 2.
17 | Preferred Subfamily (Windows only). See above.
18 | Compatible Full (Mac OS only). On the Mac OS, the menu name is constructed using the FOND resource. This usually matches the Full Name. If you want the name of the font to appear differently than the Full Name, you can insert the Compatible Full Name here.
19 | Sample text. This can be the font name, or any other text that the designer thinks is the best sample text to show what the font looks like.
20 | PostScript CID findfont name.

## Example

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPIGdi.au3>

    Example()

    Func Example()
        Local $bFont = _MemFont() ;load binary data (TTF) to use it later in GDI+
        Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $sFontInternalName
        Local $hCollection, $tFont

        $hGUI = GUICreate("GDI+", 720, 235)
        GUISetState()

        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (anti aliasing)
        _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT) ;set the anti aliasing for fonts

        $hCollection = _GDIPlus_FontPrivateCreateCollection() ;create a PrivateFontCollection object to add fonts later
        $tFont = DllStructCreate('byte[' & BinaryLen($bFont) & ']') ;create byte struct to add font to collection
        DllStructSetData($tFont, 1, $bFont)
        _GDIPlus_FontPrivateAddMemoryFont($hCollection, $tFont) ;add font to collection

        $hBrush = _GDIPlus_BrushCreateSolid(0xFF00007F) ;create a brush with a defined color for the text
        $hFormat = _GDIPlus_StringFormatCreate() ;create a string format object
        $sFontInternalName = _WinAPI_GetFontMemoryResourceInfo(DllStructGetPtr($tFont)) ;get internal font name
        $hFamily = _GDIPlus_FontFamilyCreate($sFontInternalName, $hCollection) ;create a font family object
        $hFont = _GDIPlus_FontCreate($hFamily, 70) ;create a font object
        $tLayout = _GDIPlus_RectFCreate(0, 0, 720, 235) ;create a $tagGDIPRECTF structure to save x, y position of the text
        _GDIPlus_StringFormatSetAlign($hFormat, 1) ;center text
        _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ;center text
        _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt" & @LF & "forever", $hFont, $tLayout, $hFormat, $hBrush) ;draw the string

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; Clean up resources
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_FontPrivateCollectionDispose($hCollection)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()
    EndFunc   ;==>Example

    Func _MemFont($bSaveBinary = False, $sSavePath = @ScriptDir) ;compressed base64 saved TTL font
        Local $vMemFont
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont &= ' '
        $vMemFont = _WinAPI_Base64Decode($vMemFont)
        Local $tSource = DllStructCreate('byte[' & BinaryLen($vMemFont) & ']')
        DllStructSetData($tSource, 1, $vMemFont)
        Local $tDecompress
        _WinAPI_LZNTDecompress($tSource, $tDecompress, 31304)
        $tSource = 0
        Local $bString = Binary(DllStructGetData($tDecompress, 1))
        If $bSaveBinary Then
            Local $hFile = FileOpen($sSavePath & "\ETHNOCEN.TTF", 18)
            FileWrite($hFile, $bString)
            FileClose($hFile)
        EndIf
        Return $bString
    EndFunc   ;==>_MemFont

    Func _WinAPI_Base64Decode($sB64String)
        Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
        If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
        Local $tBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
        $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $tBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
        If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
        Return DllStructGetData($tBuffer, 1)
    EndFunc   ;==>_WinAPI_Base64Decode

    Func _WinAPI_LZNTDecompress(ByRef $tInput, ByRef $tOutput, $iBufferSize)
        $tOutput = DllStructCreate("byte[" & $iBufferSize & "]")
        If @error Then Return SetError(1, 0, 0)
        Local $aRet = DllCall("ntdll.dll", "uint", "RtlDecompressBuffer", "ushort", 0x0002, "struct*", $tOutput, "ulong", $iBufferSize, "struct*", $tInput, "ulong", DllStructGetSize($tInput), "ulong*", 0)
        If @error Then Return SetError(2, 0, 0)
        If $aRet[0] Then Return SetError(3, $aRet[0], 0)
        Return $aRet[6]
    EndFunc   ;==>_WinAPI_LZNTDecompress