Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 7/13/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

SETFONT

Graphics Function: Finds a single font that matches a specified set of characteristics and makes it the current font used by the OUTGTEXT function. This routine is only available for Windows.

Module

USE IFQWIN

result = SETFONT (options)

options

(Input) Character*(*). String describing font characteristics (see below for details).

Results

The result type is INTEGER(2). The result is the index number (x as used in the nx option) of the font if successful; otherwise, -1.

The SETFONT function searches the list of available fonts for a font matching the characteristics specified in options. If a font matching the characteristics is found, it becomes the current font. The current font is used in all subsequent calls to the OUTGTEXT function. There can be only one current font.

The options argument consists of letter codes, as follows, that describe the desired font. The argument is neither case sensitive nor position sensitive.

t' fontname'

Name of the desired typeface. It can be any installed font.

hy

Character height, where y is the number of pixels.

wx

Select character width, where x is the number of pixels.

f

Select only a fixed-space font (do not use with the p characteristic).

p

Select only a proportional-space font (do not use with the f characteristic).

v

Select only a vector-mapped font (do not use with the r characteristic). Roman, Modern, and Script are examples of vector-mapped fonts, also called plotter fonts. True Type fonts (for example, Arial, Symbol, and Times New Roman) are not vector-mapped.

r

Select only a raster-mapped (bitmapped) font (do not use with the v characteristic). Courier, Helvetica, and Palatino are examples of raster-mapped fonts, also called screen fonts. True Type fonts are not raster-mapped.

e

Select the bold text format. This parameter is ignored if the font does not allow the bold format.

u

Select the underline text format. This parameter is ignored if the font does not allow underlining.

i

Select the italic text format. This parameter is ignored if the font does not allow italics.

b

Select the font that best fits the other parameters specified.

nx

Select font number x, where x is less than or equal to the value returned by the INTIALIZEFONTS function.

You can specify as many options as you want, except with nx, which should be used alone. If you specify options that are mutually exclusive (such as the pairs f/p or r/v), the SETFONT function ignores them. There is no error detection for incompatible parameters used with nx.

If the b option is specified and at least one font is initialized, SETFONT sets a font and returns 0 to indicate success.

In selecting a font, the SETFONT routine uses the following criteria, rated from highest precedence to lowest:

  1. Pixel height

  2. Typeface

  3. Pixel width

  4. Fixed or proportional font

You can also specify a pixel width and height for fonts. If you choose a nonexistent value for either and specify the b option, SETFONT chooses the closest match.

A smaller font size has precedence over a larger size. If you request Arial 12 with best fit, and only Arial 10 and Arial 14 are available, SETFONT selects Arial 10.

If you choose a nonexistent value for pixel height and width, the SETFONT function applies a magnification factor to a vector-mapped font to obtain a suitable font size. This automatic magnification does not apply if you specify the roption (raster-mapped font), or if you request a specific typeface and do not specify the b option (best-fit).

If you specify the nx parameter, SETFONT ignores any other specified options and supplies only the font number corresponding to x.

If a height is given, but not a width, SETFONT computes the width to preserve the correct font proportions.

If a width is given, but not a height, SETFONT uses a default height, which may vary from font type to font type. This may lead to characters that appear distorted, particularly when a very wide width is specified. This behavior is the same as that of the Windows* API CreateFontIndirect. A sample program is provided below showing you how to calculate the correct height for a given width.

The font functions affect only OUTGTEXT and the current graphics position; no other Fortran Graphics Library output functions are affected by font usage.

For each window you open, you must call INITIALIZEFONTS before calling SETFONT. INITIALIZEFONTS needs to be executed after each new child window is opened in order for a subsequent SETFONT call to be successful.

Example


 !  Build as a Graphics ap.
 USE IFQWIN
 INTEGER(2) fontnum, numfonts
 TYPE (xycoord) pos
 numfonts = INITIALIZEFONTS ( )
 !  Set typeface to Arial, character height to 18,
 !  character width to 10, and italic
 fontnum = SETFONT ('t''Arial''h18w10i')
 CALL MOVETO (INT2(10), INT2(30), pos)
 CALL OUTGTEXT('Demo text')
 END

Another example follows:


 ! The following program shows you how to compute
 !  an appropriate font height for a given font width
 !
 !  Build as a Graphics ap.
  USE IFQWIN
  INTEGER(2) fontnum, numfonts
  TYPE (xycoord) pos
  TYPE (rccoord) rcc
  TYPE (FONTINFO) info
  CHARACTER*11 str, str1
  CHARACTER*22 str2
  real rh
  integer h, inw
  str = "t'Arial'bih"
  str1= " "
  numfonts = INITIALIZEFONTS ( )
  ! Default both height and width.  This seems to work
  ! properly.  From this setting get the ratio between
  ! height and width.
  fontnum = SETFONT ("t'Arial'")
  ireturn = GETFONTINFO(info)
  rh =  real(info%pixheight)/real(info%avgwidth)

  ! Now calculate the height for a width of 40
  write(*,*) 'Input desired width:'
  read(*,*) inw
  h =int(inw*rh)
  write(str1,'(I3.3)') h
  str2 = str//str1
  print *,str2
  fontnum = SETFONT (str2)
  CALL MOVETO (INT2(10), INT2(50), pos)
  CALL OUTGTEXT('ABCDEFGabcdefg12345!@#$%')
  CALL MOVETO (INT2(10), INT2(50+10+h), pos)
  CALL OUTGTEXT('123456789012345678901234')
  ireturn = GETFONTINFO(info)
  call settextposition(4,1, rcc)
  print *,  info%avgwidth, info%pixheight
 END