MQL4 Reference Object Functions TextSetFont

TextSetFont

The function sets the font for displaying the text using drawing methods and returns the result of that operation. Arial font with the size -120 (12 pt) is used by default.

bool  TextSetFont(
   const string  name,            // font name or path to font file on the disk
   int           size,            // font size
   uint          flags=0,         // combination of flags
   int           orientation=0    // text slope angle
   );

Parameters

name

[in]  Font name in the system or the name of the resource containing the font or the path to font file on the disk.

size

[in]  The font size that can be set using positive and negative values. In case of positive values, the size of a displayed text does not depend on the operating system's font size settings. In case of negative values, the value is set in tenths of a point and the text size depends on the operating system settings ("standard scale" or "large scale"). See the Note below for more information about the differences between the modes.

flags=0

[in]  Combination of flags describing font style.

orientation=0

[in]  Text's horizontal inclination to X axis, the unit of measurement is 0.1 degrees. It means that orientation=450 stands for inclination equal to 45 degrees.

Returned value

Returns true if the current font is successfully installed, otherwise false. Possible code errors:

  • ERR_INVALID_PARAMETER(4003) - name presents NULL or "" (empty string),
  • ERR_INTERNAL_ERROR(4001) - operating system error (for example, an attempt to create a non-existent font).

Note

If "::" is used in font name, the font is downloaded from EX4 resource. If name font name is specified with an extension, the font is downloaded from the file, if the path starts from "\" or "/", the file is searched relative to MQL4 directory. Otherwise, it is searched relative to the path of EX4 file which called TextSetFont() function.

The font size is set using positive or negative values. This fact defines the dependence of the text size from the operating system settings (size scale).

  • If the size is specified by a positive number, this size is transformed into physical measurement units of a device (pixels) when changing a logical font into a physical one, and this size corresponds to the height of the symbol glyphs picked from the available fonts. This case is not recommended when the texts displayed by TextOut() function and the ones displayed by OBJ_LABEL ("Label") graphical object are to be used together on the chart.
  • If the size is specified by a negative number, this number is supposed to be set in tenths of a logical point (-350 is equal to 35 logical points) and is divided by 10. An obtained value is then transformed into physical measurement units of a device (pixels) and corresponds to the absolute value of the height of a symbol picked from the available fonts. Multiply the font size specified in the object properties by -10 to make the size of a text on the screen similar to the one in OBJ_LABEL object.

The flags can be used as the combination of style flags with one of the flags specifying the font width. Flag names are shown below.

Flags for specifying font style

Flag

Description

FONT_ITALIC

Italic

FONT_UNDERLINE

Underline

FONT_STRIKEOUT

Strikeout

 

Flags for specifying font width

Flag

FW_DONTCARE

FW_THIN

FW_EXTRALIGHT

FW_ULTRALIGHT

FW_LIGHT

FW_NORMAL

FW_REGULAR

FW_MEDIUM

FW_SEMIBOLD

FW_DEMIBOLD

FW_BOLD

FW_EXTRABOLD

FW_ULTRABOLD

FW_HEAVY

FW_BLACK

See also

Resources, ResourceCreate(), ResourceSave(), TextOut()