Partager via


AFONT( ) Function

Places information about available fonts, such as their names, into an array.

Tip

You can also use AFONT( ) to determine available font sizes or if a font is scalable. To display a dialog box containing available fonts, font sizes, and styles, use the GETFONT( ) function. For more information, see GETFONT( ) Function.

AFONT(ArrayName [, cFontName [, nFontSize | nFontCharSet [, nFlags]]])

Parameters

  • ArrayName
    Specifies the variable array into which the names of available fonts are placed. If the array is not large enough to contain all the fonts, Visual FoxPro automatically increases the size of the array. If you specify an existing two-dimensional array, Visual FoxPro changes the array to a one-dimensional array.

  • cFontName
    Specifies a font for which information is placed into the array.

    If the font you specify supports only discrete font sizes (8-point, 10-point, ...), the font sizes are stored to the array, and AFONT( ) returns True (.T.). If the font you specify in cFontName is scalable (supports fractional font size values), the array has a single element containing –1, and AFONT( ) returns True (.T.).

    If the font you specify is not available, the array is not created, and AFONT( ) returns False (.F.).

  • nFontSize
    Specifies a size for the font specified in cFontName.

    If the font size nFontSize is available for the font specified in cFontName, the array has a single element containing a True (.T.) value, and AFONT( ) returns True (.T.). If the font size is not available for the specified font, the array is not created, and AFONT( ) returns False (.F.).

  • nFontCharSet
    Specifies a character set for the font specified in cFontName. If the font character set specified is available for the font specified in cFontName, the array has a single element containing a True (.T.) value, and AFONT( ) returns True (.T.). If the font character set is not available for the specified font, the array is not created, and AFONT( ) returns False (.F.).

  • nFlags
    Controls whether the third parameter passed is treated as the font size or font character set.

    The following table describes behavior for various nFlags values specified.

    nFlags

    Description

    Omitted or 0 for the first bit

    Third parameter is treated as a font size value.

    If third parameter is -1, array is updated with all available font sizes for the font specified in cFontName for nonproportional fonts, such as MS Sans Serif, and AFONT( ) returns True (.T.). This behavior in Visual FoxPro 8.0 and later is equivalent to passing only the first two parameters.

    Note

    In versions prior to Visual FoxPro 8.0, if you specified any negative or positive font size for a non-proportional font, AFONT( ) returned False (.F.).

    If the third parameter passed is 0, for nonproportional fonts, AFONT( ) returns False (.F.) for Visual FoxPro 8.0 and later. However, the behavior for proportional fonts such as TrueType or OpenType (Arial) has not changed.

    1

    Third parameter is treated as a font character set. Array is populated with character sets available for the specified font.

    If the third parameter passed is -1, array is updated with all available font character sets for the font specified in cFontName.

Return Value

Logical data type. AFONT( ) returns True (.T.) if array is successfully created. Otherwise, AFONT( ) returns False (.F.).

Remarks

If only ArrayName was passed in versions earlier than Visual FoxPro 8.0, the array populated in AFONT( ) included extra fonts that were really part of a single font family. For example, the array might have included the following Arial fonts under Visual FoxPro 7.0:

  • Arial

  • Arial Baltic

  • Arial Black

  • Arial CE

  • Arial CYR

  • Arial Greek

  • Arial Narrow

  • Arial Tur

Many of these fonts are not included in a standard Font Picker dialog box such as the GETFONT( ) function. In this version of Visual FoxPro, the array in AFONT( ) excludes these extra fonts. For example, the array only includes the following fonts:

  • Arial

  • Arial Baltic

  • Arial Black

Example

The following example uses AFONT( ) to create an array containing the names of all available fonts. The name of each font is displayed, along with an example of the font. If there are more than 10 fonts installed, only the first 10 are displayed.

CLEAR
=AFONT(gaFontArray)  && Array containS font names.
gnNumFonts = ALEN(gaFontArray)  && Number of fonts
IF gnNumFonts > 10
   gnNumFonts = 10  && Display first 10 fonts.
ENDIF

FOR nCount = 1 TO gnNumFonts
   ? ALLTRIM(gaFontArray(nCount))  && Display font name.
   ?? '  This is an example of ' ;
      + ALLTRIM(gaFontArray(nCount)) FONT gaFontArray(nCount), 8
ENDFOR

See Also

Reference

FONTMETRIC( ) Function

SYSMETRIC( ) Function

WFONT( ) Function

TXTWIDTH( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)