Using Intel® Visual Fortran to Create and Build Windows*-Based Applications

ID 757211
Date 7/23/2021
Public
Document Table of Contents

Setting the Font and Displaying Text

Before a program can display text in a particular font, it must know which of the initialized fonts to use. SETFONT makes one of the initialized fonts the current (or "active") font. SETFONT has the following syntax:

result =SETFONT (options)

The function's argument consists of letter codes that describe the desired font: typeface, character height and width in pixels, fixed or proportional, and attributes such as bold or italic. These options are discussed in detail in the SETFONT entry in the Language Reference in the Intel® Visual Fortran Compiler User and Reference Guides. For example:

  USE IFQWIN
  INTEGER(2) index, numfonts
  numfonts = INITIALIZEFONTS ( )
  index = SETFONT('t''Cottage''h18w10')

This sets the typeface to Cottage, the character height to 18 pixels and the width to 10 pixels.

The following example sets the typeface to Arial, the character height to 14, with proportional spacing and italics (the pi codes):

  index = SETFONT('t''Arial''h14pi')

If SETFONT successfully sets the font, it returns the font's index number. If the function fails, it returns a negative integer. Call GRSTATUS to find the source of the problem; its return value indicates why the function failed. If you call SETFONT before initializing fonts, a run-time error occurs.

SETFONT updates the font information when it is used to select a font. GETFONTINFO can be used to obtain information about the currently selected font.SETFONT sets the user fields in the fontinfo type (a derived type defined in DFLIB.MOD), and GETFONTINFO returns the user-selected values. The following user fields are contained in fontinfo:

  TYPE fontinfo
   INTEGER(2) type ! 1 = truetype, 0 = bit map
   INTEGER(2) ascent ! Pixel distance from top to baseline
   INTEGER(2) pixwidth ! Character width in pixels, 0=prop
   INTEGER(2) pixheight ! Character height in pixels
   INTEGER(2) avgwidth ! Average character width in pixels
   CHARACTER(32) facename ! Font name
  END TYPE fontinfo

To find the parameters of the current font, call GETFONTINFO. For example:

   USE IFQWIN
  TYPE (fontinfo) font
  INTEGER(2) i, numfonts
  numfonts = INITIALIZEFONTS()
  i = SETFONT ( ' t ' 'Arial ' )
  i = GETFONTINFO(font)
  WRITE (*,*) font.avgwidth, font.pixheight, font.pixwidth

After you initialize the fonts and make one the active font, you can display the text on the screen.

To display text on the screen after selecting a font:

  1. Select a starting position for the text with MOVETO.

  2. Optionally, set a text display angle with SETGTEXTROTATION.

  3. Send the text to the screen (in the current font) with OUTGTEXT.

MOVETO moves the current graphics point to the pixel coordinates passed to it when it is invoked. This becomes the starting position of the upper-left corner of the first character in the text. SETGTEXTROTATION can set the text's orientation in increments of one-tenth of a degree.

Did you find the information on this page useful?

Characters remaining:

Feedback Message