Freigeben über


AFONT( ) Function

Places information about available fonts into an array.

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

Return Values

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

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 (.T.).

  • nFlags
    You can specify an nFlags value of 1, which populates the array with the character sets available for a specified font.

Remarks

AFONT( ) places the names of available fonts into an array. You can also use AFONT( ) to determine available font sizes or if a font is scalable. Use GETFONT( ) to display a dialog containing available fonts, font sizes, and styles.

The nFlags parameter controls whether the third parameter passed is treated as the font size or font character set. If you do not pass an nFlag value, or if nFlag is 0 (for the first bit), then the third parameter is treated as a font size value. If nFlag is 1, then the third parameter is treated as a font character set.

If the third parameter passed is -1, and nFlag is 0 or not passed, the array is updated with all available font sizes for the font specified in cFontName for non-proportional fonts such as MS Sans Serif, and AFONT( ) returns True (.T.).

Note   This behavior is new in Visual FoxPro 8.0. In previous versions, if you specified any negative or positive font size for a non-proportional font, AFONT( ) returns False (.F.). This new behavior is equivalent to passing only the first two parameters.

Additionally, if the third parameter passed is 0, and nFlag is 0 or not passed for a non-proportional font, AFONT( ) returns False (.F.). This behavior is also new in Visual FoxPro 8.0. The behavior for proportional fonts such as TrueType or OpenType (Arial) has not changed.

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

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

FONTMETRIC( ) | GETFONT( ) | TXTWIDTH( ) | SYSMETRIC( ) | WFONT( )