# Function Reference

# _WinAPI_GetGlyphOutline

Retrieves the outline or bitmap for a character in the TrueType font

#include <WinAPIGdi.au3>
_WinAPI_GetGlyphOutline ( $hDC, $sChar, $iFormat, ByRef $pBuffer [, $tMAT2 = 0] )

## Parameters

$hDC | A handle to the device context which font is selected.
$sChar | The character for which data is to be returned.
$iFormat | The format of the data that the function retrieves. This parameter can be one of the following values: $GGO_BEZIER $GGO_BITMAP $GGO_GLYPH_INDEX $GGO_GRAY2_BITMAP $GGO_GRAY4_BITMAP $GGO_GRAY8_BITMAP $GGO_METRICS $GGO_NATIVE $GGO_UNHINTED
$pBuffer | Returns a pointer to a memory block (buffer) that receives the outline or bitmap data. Optionaly, you can set this parameter to 0 before function call, then the function will allocate the required memory block itself. Otherwise, it must be a valid memory pointer returned by the _WinAPI_CreateBuffer() function, or by previously calling this function. If the $GGO_METRICS is specified, this parameter is ignored, and function only returns the information about a glyph (see below).
$tMAT2 | [optional] $tagMAT2 structure specifying a transformation matrix for the character. If this parameter is 0 (Default), the transformation will not be used (it is identity matrix).

## Return Value

Success: | $tagGLYPHMETRICS structure containing information about the placement and orientation of a glyph, @extended flag returns a number of bytes copied to the buffer (if used), in bytes.
Failure: | Sets the @error flag to non-zero.

## Remarks

Note that, for the $GGO_GRAY... values, the function retrieves a glyph bitmap that contains n^2+1 (n squared plus one) levels of gray.
The glyph bitmap returned by _WinAPI_GetGlyphOutline() when $GGO_BITMAP is specified is a DWORD-aligned, row-oriented, monochrome bitmap.
When $GGO_GRAY2_BITMAP is specified, the bitmap returned is a DWORD-aligned, row-oriented array of bytes whose values range from 0 to 4.
When $GGO_GRAY4_BITMAP is specified, the bitmap returned is a DWORD-aligned, row-oriented array of bytes whose values range from 0 to 16.
When $GGO_GRAY8_BITMAP is specified, the bitmap returned is a DWORD-aligned, row-oriented array of bytes whose values range from 0 to 64.
When you no longer need the buffer allocated by this function, you must call the _WinAPI_FreeMemory() function (do not use any other memory routines) to release occupied memory.

## Related

_WinAPI_CreateBuffer, _WinAPI_FreeMemory

## See Also

Search GetGlyphOutline in MSDN Library.

## Example

    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <SendMessage.au3>
    #include <StaticConstants.au3>
    #include <WinAPIGdi.au3>
    #include <WinAPIGdiDC.au3>
    #include <WinAPIHObj.au3>
    #include <WinAPIMem.au3>

    ; Creates logical font ("Times") and retrieve bitmap bits for a random character
    Local $hDC = _WinAPI_CreateCompatibleDC(0)
    Local $hFont = _WinAPI_CreateFont(512, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Times')
    Local $hSv = _WinAPI_SelectObject($hDC, $hFont)
    Local $pData = 0
    Local $tGM = _WinAPI_GetGlyphOutline($hDC, ChrW(Random(65, 90, 1)), $GGO_BITMAP, $pData)
    Local $W = DllStructGetData($tGM, 'BlackBoxX')
    Local $H = DllStructGetData($tGM, 'BlackBoxY')
    _WinAPI_SelectObject($hDC, $hSv)
    _WinAPI_DeleteObject($hFont)

    ; Create 1 bits-per-pixel bitmap
    Local $hBmp = _WinAPI_CreateBitmap(32 * Ceiling($W / 32), $H, 1, 1, $pData)

    ; Crop bitmap to the required size and colorize it
    Local $aColorTable[2] = [0xFFFFFF, 0xC00000]
    Local $hDib = _WinAPI_CreateDIB($W, $H, 1, _WinAPI_CreateDIBColorTable($aColorTable), 2)
    $hSv = _WinAPI_SelectObject($hDC, $hDib)
    _WinAPI_DrawBitmap($hDC, 0, 0, $hBmp, $MERGEPAINT)
    _WinAPI_SelectObject($hDC, $hSv)
    _WinAPI_DeleteObject($hBmp)

    ; Free unnecessary resources
    _WinAPI_FreeMemory($pData)
    _WinAPI_DeleteDC($hDC)

    ; Create GUI
    Local $hForm = GUICreate('Test ' & StringReplace(@ScriptName, '.au3', '()'), $W, $H)
    Local $idPic = GUICtrlCreatePic('', 0, 0, $W, $H)
    Local $hPic = GUICtrlGetHandle($idPic)

    ; Set bitmap to control
    _SendMessage($hPic, $STM_SETIMAGE, 0, $hDib)
    $hBmp = _SendMessage($hPic, $STM_GETIMAGE)
    If $hBmp <> $hDib Then
        _WinAPI_DeleteObject($hDib)
    EndIf

    ; Show GUI
    GUISetState(@SW_SHOW)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE